REUSE_ALV_LIST_DISPLAY- 9

light11Use of ALV LAYOUT- Displaying check box and traffic light by setting the layout property

 

 

 

The previous post REUSE_ALV_LIST_DISPLAY- 6  and REUSE_ALV_LIST_DISPLAY- 7  shows how to show traffic light and check box in the list alv. This post shows how to display check box and light together by using the layout property.


Code Snippet:


———-data declarations——–
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_flight,
box,                                                ” add a field for check box of char length 1
light.                                               ” ADD a filed for the traffic light of length char 1
INCLUDE STRUCTURE spfli.
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.
———————————–

START-OF-SELECTION.
PERFORM build_data.
PERFORM build_layout.
PERFORM display_list_alv.

&————————————————-
& Form BUILD_DATA
&————————————————-*
FORM build_data.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE lt_spfli.
LOOP AT lt_spfli INTO ls_spfli.
IF sy-tabix LE 5.
ls_spfli-box = abap_true.
ls_spfli-light = 1.    ” RED light
ELSEIF sy-tabix GT 5 AND sy-tabix LE 15.

ls_spfli-box = abap_false.
ls_spfli-light = 2.  ” yellow light
ELSE.
ls_spfli-box = abap_true.
ls_spfli-light = 3. ” green light
ENDIF.
MODIFY lt_spfli FROM ls_spfli TRANSPORTING box light.
ENDLOOP.
ENDFORM. ” BUILD_DATA
&————————————————–
& Form BUILD_LAYOUT
&————————————————–
FORM build_layout.
ls_layout-zebra = ‘X’.
“ls_layout-no_vline = ‘X’.
“ls_layout-no_colhead = ‘X’.
ls_layout-box_fieldname = ‘BOX’.              ” Pass the field name that will act as check box
ls_layout-lights_fieldname = ‘LIGHT’.       ” Pass the field name that will act as traffic light
ENDFORM. ” BUILD_LAYOUT
&—————————————————
& Form DISPLAY_LIST_ALV
&—————————————————-
FORM display_list_alv.
CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’
EXPORTING
i_callback_program = sy-cprog
i_structure_name = ‘SPFLI’
is_layout = ls_layout
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:

8.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