REUSE_ALV_LIST_DISPLAY- 27

light11Layout as user input to the list ALV

 

 

 

The previous post REUSE_ALV_LIST_DISPLAY- 26 shows how to change , save and select layout. This post shows how to take LAYOUT as user input and  make use of it.


Code Snippet:


———-data declarations——–
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_flight,
box.
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.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_variant TYPE disvariant.
PARAMETERS: p_var TYPE disvariant-variant.
———————————–
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
PERFORM load_variant.

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

&————————————————-
& Form BUILD_DATA
&————————————————-*
FORM build_data.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE lt_spfli UP TO 20 ROWS.
ENDFORM. ” BUILD_DATA

&———————————————————————
& Form BUILD_FIELDCATALOG
&———————————————————————
FORM build_fieldcatalog.
DATA: ls_fieldcat TYPE LINE OF slis_t_fieldcat_alv.
CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE’
EXPORTING
i_program_name = sy-cprog
I_INTERNAL_TABNAME =
i_structure_name = ‘SPFLI’
* I_CLIENT_NEVER_DISPLAY = ‘X’
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
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 LOAD_VARIANT
&———————————————————————
FORM load_variant.
DATA: ls_var TYPE disvariant.
ls_var-report = sy-cprog.
ls_var-username = sy-uname.
CALL FUNCTION ‘REUSE_ALV_VARIANT_F4’
EXPORTING
is_variant = ls_var
* I_TABNAME_HEADER =
* I_TABNAME_ITEM =
* IT_DEFAULT_FIELDCAT =
* I_SAVE = ‘ ‘
* I_DISPLAY_VIA_GRID = ‘ ‘
IMPORTING
* e_exit =
es_variant = ls_var
EXCEPTIONS
not_found = 1
program_error = 2
OTHERS = 3.
IF ls_var-variant IS NOT INITIAL.
p_var = ls_var-variant.
ENDIF.
ENDFORM. ” LOAD_VARIANT
&———————————————————————
& Form BUILD_VARIANT
&———————————————————————*

FORM build_variant.
ls_variant-report = sy-cprog.
ls_variant-username = sy-uname.
ls_variant-variant = p_var.
ENDFORM. ” BUILD_VARIANT
&—————————————————
& 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
i_save = ‘A’
is_variant = ls_variant
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: Very first time the program is executed, there would  be no already saved layout. Press F4 and there in no value. Execute the program.

1

All the fields displayed. Now click on change layout button. Select few fields to hide and finally click on COPY button.

2

The changed layout applied. Now click on SAVE layout button.

3

Provide layout name and a meaningful description and SAVE it.

4

Go back.

5

Now press F4 button for the layout field.

6

It should show all the layout name that are saved. We have only one. Select the layout.

7

Execute the program.

8

The first ALV display screen hides the fields as per the layout set.

9


 

Advertisements

One thought on “REUSE_ALV_LIST_DISPLAY- 27

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 )

Google+ photo

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

Connecting to %s