REUSE_ALV_LIST_DISPLAY- 29

light111Displaying ICON in a separate column in ALV

 

 

The previous post REUSE_ALV_LIST_DISPLAY- 28 shows how to make interactive list alv. This post shows how to display ICON as a separate field in list alv.


The ICON table stores all the ICONs. We have to add a field in the ALV structure to display the ICON as a separate column in list alv. For that field lets the data element lets take as ICON_D .

1

Create a SE11 structure that add all fields of SPLFI table and also one more field as ICON referring to the data element ICON_D.

2


Open the type group ICON in Tx- SE11.

3

In our LAV we will make use of ICON_LED_GREEN, ICON_LED_RED & ICON_LED_YELLOW.   Note down their value. 

4


Execute Tx- ICON and search for the icon ON_LED_GREEN, ICON_LED_RED & ICON_LED_YELLOW. It looks like as highlighted below.

56


Code Snippet:


———-data declarations——–
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_flight,
box.
INCLUDE STRUCTURE zflight_s_alv.
TYPES: END OF ty_flight.
DATA: lt_spfli TYPE TABLE OF ty_flight.
DATA: ls_spfli TYPE ty_flight.
DATA: ls_layout TYPE slis_layout_alv.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv.

———————————–
START-OF-SELECTION.
PERFORM build_data.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_list_alv.

&————————————————-
& Form BUILD_DATA
&————————————————-*
FORM build_data.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE lt_spfli UP TO 15 ROWS.
LOOP AT lt_spfli INTO ls_spfli.
IF sy-tabix BETWEEN 1 AND 5.
ls_spfli-icon = ‘@5B@’.  
ELSEIF sy-tabix BETWEEN 6 AND 10.
ls_spfli-icon = ‘@5C@’.
ELSE.
ls_spfli-icon = ‘@5D@’.
ENDIF.

MODIFY lt_spfli FROM ls_spfli TRANSPORTING icon.
ENDLOOP.
ENDFORM. ” BUILD_DATA

&———————————————————————
& Form BUILD_FIELDCATALOG
&———————————————————————*
FORM build_fieldcatalog.

CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE’
EXPORTING
i_program_name = sy-cprog
i_structure_name = ‘ZFLIGHT_S_ALV’
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.

ENDFORM. ” BUILD_FIELDCATALOG

&————————————————–
& Form BUILD_LAYOUT
&————————————————–*
FORM build_layout.
ls_layout-zebra = ‘X’.
ls_layout-box_fieldname = ‘BOX’.
ENDFORM. ” BUILD_LAYOUT

&—————————————————
& Form DISPLAY_LIST_ALV
&—————————————————-*
FORM display_list_alv.

CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’
EXPORTING
i_callback_program = sy-cprog
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = lt_spfli
EXCEPTIONS
program_error = 1
OTHERS = 2.
CASE sy-subrc.
WHEN 1.
MESSAGE ‘Program Error’ TYPE ‘I’.
WHEN OTHERS.
ENDCASE.
ENDFORM. ” DISPLAY_LIST_ALV


Program Output: Here one specific column shows the icons.

7.jpg


 

One comment

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 )

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