ALV with List Box
The post displays alv with SPFLI table and one additional field for list box. So created a structure with include structure ‘SPFLI’ and an extra field as SIGNAL.
Create a program as below code:
DATA: lr_grid TYPE REF TO cl_gui_alv_grid,
lt_fcat TYPE lvc_t_fcat,
lt_spfli TYPE TABLE OF ztest_s_spfli,
lt_dd TYPE lvc_t_drop.
START-OF-SELECTION.
CALL SCREEN 0001.
&———————————————————————
& Module DISPLAY_ALV OUTPUT
*&———————————————————————
MODULE display_alv OUTPUT.
IF lr_grid IS NOT BOUND.
CREATE OBJECT lr_grid
EXPORTING
i_parent = cl_gui_container=>screen0.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE lt_spfli.
CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE’
EXPORTING
i_structure_name = ‘ZTEST_S_SPFLI’
CHANGING
ct_fieldcat = lt_fcat.
* Enable field for drop down
LOOP AT lt_fcat ASSIGNING FIELD–SYMBOL(<fs_fcat>).
CASE <fs_fcat>–fieldname.
WHEN ‘SIGNAL’.
<fs_fcat>–edit = abap_true.
<fs_fcat>–drdn_hndl = ‘1’.
<fs_fcat>–outputlen = 8.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
* prepare the dropdown table
DO 4 TIMES.
APPEND INITIAL LINE TO lt_dd ASSIGNING FIELD–SYMBOL(<fs_dd>).
<fs_dd>–handle = ‘1’.
IF sy–index = 1.
<fs_dd>–value = ‘ ‘.
ELSEIF sy–index = 2.
<fs_dd>–value = ‘Green’.
ELSEIF sy–index = 3.
<fs_dd>–value = ‘Yellow’.
ELSEIF sy–index = 4.
<fs_dd>–value = ‘Red’.
ENDIF.
ENDDO.
* Set the drop down table
CALL METHOD lr_grid->set_drop_down_table
EXPORTING
it_drop_down = lt_dd.
CALL METHOD lr_grid->set_table_for_first_display
CHANGING
it_outtab = lt_spfli
it_fieldcatalog = lt_fcat.
ENDIF.
ENDMODULE.
Screen flow logic.
Output: SIGNAL field with list box