Add Image Button to An Abap Program

You can add an image in a container and display that.  In this article ,  I show how to specify clickable the image.

Step 1   Upload *BMP File
Step 2  Create program

STEP 1  Upload *BMP File – Upload Image

Go to SMW0 and upload image.

Choose Binary data for WebRFC applications and press enter keysmw0_001.

Give your package name and run(f8).
Click create button on the toolbar and give the image name and description.
smw0_003

Click import button and import your bmp image file.

STEP 2  Create program

Create container.
button001
PBO :

*  build button                        screen num  –  container name   –   image name
PERFORM set_button   USING ‘100’ ‘B_PERSONEL’ ‘ZIMG_PERSONEL’ .

PAI : (Here set session break point and determine the w_int value. After you can use this functionality)

data lv_1 type string.
data lv_2 type string.
data lv_3 type string.
w_int(4TYPE c.

CLEAR lv_1,  lv_2 lv_3 ,w_int.
SPLIT syucomm AT ” INTO lv_1 lv_2 lv_3.
w_int lv_2.

READ TABLE ole_control_map_table
INTO ole_control_map_wa WITH KEY shell_id = w_int.
IF systsubrc = 0.
CASE systtabix.

 WHEN 2.     2 can change according to place the container.
***   write your code when your button  clicked       

      WHEN OTHERS.
CLEAR ok_code.
ENDCASE.

CHECK NOT ok_code IS INITIAL.
CALL FUNCTION ‘CONTROL_DISPATCH’
EXPORTING
fcode ok_code.
ENDIF.

—————————————————————————————————————————————

Data declaritons :


DATApic_data LIKE w3mime OCCURS 0,
pic_size TYPE i,
repid LIKE syrepid,
url(255TYPE c,
ok_code LIKE syucomm,
w_int(4TYPE c.

DATAquery_table LIKE w3query OCCURS WITH HEADER LINE,
html_table LIKE w3html OCCURS 1.

DATAreturn_code LIKE  w3paramret_code,
content_type LIKE  w3paramcont_type,
content_length LIKE  w3paramcont_len.

data pos_x type i,
pos_y type i,
w_init(1).

data gv_screen(3).

INCLUDE simagecontrolclassdef.
INCLUDE simagecontrolclassimpl.

DATAbutton1 TYPE REF TO c_image_control,
button2 TYPE REF TO c_image_control,
button2_2 TYPE REF TO c_image_control,
button3 TYPE REF TO c_image_control,
button4 TYPE REF TO c_image_control.

data lv_1 type string.
data lv_2 type string.
data lv_3 type string.

Class :

CLASS c_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS event_handler_image_click
FOR EVENT image_click OF c_image_control
IMPORTING mouse_pos_x mouse_pos_y.
ENDCLASS.

DATA event_receiver  TYPE REF TO c_event_receiver.
DATA event_receiver_kasa  TYPE REF TO c_event_receiver.
DATA event_receiver_sevkiyat  TYPE REF TO c_event_receiver.

*———————————————————————*
*       CLASS c_event_receiver IMPLEMENTATION
*———————————————————————*
CLASS c_event_receiver IMPLEMENTATION.
METHOD event_handler_image_click.
pos_x mouse_pos_x.
pos_y mouse_pos_y.
ENDMETHOD.
ENDCLASS.

 

There is code set_button below.

FORM set_button  USING    value(p_0014)
value(p_0015)
value(p_0016).

clear button1 event_receiver.

CREATE OBJECT button1.
CALL METHOD button1->create_control
EXPORTING
dynnr     p_0014
repid     syrepid
style     ws_dlgframe
container p_0015.
CALL METHOD button1->register_event_image_click.
CREATE OBJECT event_receiver“only need this line once
SET HANDLER event_receiver->event_handler_image_click
FOR button1.
CALL METHOD button1->set_display_mode
EXPORTING
display_mode display_mode_fit_center.

PERFORM load_pic_from_db
TABLES pic_data
USING p_0016
CHANGING pic_size.

PERFORM call_function_url.

CALL METHOD button1->load_image_from_url
EXPORTING
url url.

ENDFORM.                    ” SET_BUTTON

FORM load_pic_from_db TABLES pic_data
USING pic_name
CHANGING pic_size.

CLEARquery_table[],
html_table,
return_code,
content_type,
content_length.

query_tablename ‘_OBJECT_ID’.
query_tablevalue pic_name.
APPEND query_table.

CALL FUNCTION ‘WWW_GET_MIME_OBJECT’
TABLES
query_string   query_table
html           html_table
mime           pic_data
CHANGING
return_code    return_code
content_type   content_type
content_length content_length
EXCEPTIONS
OTHERS         1.

IF sysubrc 0.
pic_size content_length.
ENDIF.

ENDFORM.                    “load_pic_from_db

FORM  call_function_url.
CALL FUNCTION ‘DP_CREATE_URL’
EXPORTING
type    ‘IMAGE’
subtype ‘GIF’
size    pic_size
TABLES
data    pic_data
CHANGING
url     url.
ENDFORM.                    ” call_function_url

 

Secreen shot  (Language = TR)
button002

 

 

 

 

2 thoughts on “Add Image Button to An Abap Program

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s