Tag Archive for 'icon'

SAP: Clickable Icon Button in ALV fields


Adding a button inside an ALV fields is a very simple task to do which needs only a few line of codes. what I always do is I create a field on ALV and populate that field with an Icon of my choice and declare it as a Hotspot so it will react on a single click and it works perfectly just like a button.

First Thing to do is to specify a field in our internal table that we will use to hold the Icon(refer to code #1).

[codesyntax lang="abap" lines="no" title="CODE #1"]
TYPES: BEGIN OF t_alvbutton,
icon TYPE string, “icon field
kunnr LIKE kna1-kunnr,
name1 LIKE kna1-name1,
END OF t_alvbutton.

DATA: it_alvbutton TYPE STANDARD TABLE OF t_alvbutton,
wa_alvbutton TYPE t_alvbutton.
[/codesyntax]

Proceed to the data retrieval and populate the it_alvbutton. I assume you know how to retrieve data from database so there’s no need to show you the select statement for our example. After that, loop on every records of it_alvbutton to specify the Icon that we want to display(refer to code #2).

[codesyntax lang="abap" lines="no" title="CODE #2"]
LOOP AT it_alvbutton INTO wa_alvbutton.
wa_alvbutton-icon = ‘@0X@’.
MODIFY it_alvbutton FROM wa_alvbutton.
ENDLOOP.
[/codesyntax]

@0X@ is the code for print icon. For the complete list of icons, check it out here.

Now the important part is to define a field in ALV that will hold the icon. To show you how simple it is to do that, please refer to code #3.

[codesyntax lang="abap" lines="no" title="CODE #3" escaped="true"]
DATA: ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.

DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-seltext_l = &2.
ls_fieldcat-outputlen = &3.
ls_fieldcat-hotspot = &4. “X to declare the field as a hotspot
ls_fieldcat-icon = &5. “X to declare the field as an icon
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.

m_fieldcat 'ICON' 'Print' '20' 'X' 'X'. “this specific field is a hotspot and an icon
m_fieldcat 'KUNNR' 'Customer No.' '10'.
m_fieldcat 'NAME1' 'Customer Name' '35'.
m_fieldcat . . .
m_fieldcat . . .

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
. . .
. . .
[/codesyntax]

The figure below shows an example of print icon as a button.

Icon Button in ALV

Now refer to code #4 to handle the command when a user clicks on the icon button.

[codesyntax lang="abap" lines="no" title="CODE #4" escaped="true"]
FORM f_user_command USING ucomm LIKE sy-ucomm
v_selfld TYPE slis_selfield.

IF ucomm = '&IC1' AND v_selfld-fieldname = 'ICON'.
“code goes in here when user clicks on our print button
ENDIF.
[/codesyntax]

Creative Commons License

SAP: List of Icons

I could show you here the complete list of icons with its corresponding code but I rather show you a couple line of codes that will provide you the list of icons. So please refer to the code #1.

[codesyntax lang="abap" lines="no" title="CODE #1" container="div"]
TABLES: icon.
DATA: icontext(4) TYPE c.

SELECT * FROM icon.
WRITE: / icon-id+1(2).
CONCATENATE ‘@’ icon-id+1(2) ‘@’ INTO icontext.
WRITE: 10 icontext AS ICON, icon-name.
ENDSELECT.
[/codesyntax]

Create a blank program on transaction SE38 and add the code above. Just activate it and execute. You now have your own list of icons for your reference whenever you need it.