REUSE_ALV_LIST_DISPLAY- 15

light11Use of ALV Field Catalog & hiding fields on ALV using field catalog property

 

 

 

The previous post REUSE_ALV_LIST_DISPLAY- 14 shows  multiple list ALVs in one program by setting the ALV layout property. This post shows how to use the ALV field catalog and its use.


Code Snippet:  To display the alv we need to pass at least the structure name or the field catalog table to the ALV FM. Below we pass both structure name as ‘SPFLI’ as well as field catalog table.


———-data declarations——–
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_flight.
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.
———————————–

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.
ENDFORM. ” BUILD_DATA

&———————————————————————
& Form BUILD_FIELDCATALOG
&———————————————————————
FORM build_fieldcatalog.
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-detail_popup = ‘X’.
ls_layout-detail_titlebar = ‘Detailed Flight Info’.
ls_layout-f2code = ‘&ETA’.
ls_layout-window_titlebar = ‘Flight Info’.
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
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:

1.jpg


Code Snippet:  Here  the field catalog table is built up and passes to the list ALV FM. The structure name is not passed to the display ALV FM.


———-data declarations——–
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_flight.
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.
———————————–

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.
ENDFORM. ” BUILD_DATA

&———————————————————————
& Form BUILD_FIELDCATALOG
&———————————————————————
FORM build_fieldcatalog.
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-detail_popup = ‘X’.
ls_layout-detail_titlebar = ‘Detailed Flight Info’.
ls_layout-f2code = ‘&ETA’.
ls_layout-window_titlebar = ‘Flight Info’.
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’   ” once field catalog is passed, no need to pass structure name
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:

2.jpg


Lets consider the case that we don’t want to display few fields present in the structure ‘SPFLI’ in the list ALV. This can be done by having the field catalog table. The field catalog table control many behaviors of each column of the structure.  

As a use case lets hide two fields ‘FLTYPE’ & ‘PERIOD’ of the structure. 

3.jpg

Code Snippet: 


———-data declarations——–
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_flight.
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.
———————————–

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

” Set the field catalog property- NO_OUT for the fields that should be hidden on the list ALV output

LOOP AT lt_fieldcat INTO ls_fieldcat.
IF ls_fieldcat-fieldname = ‘FLTYPE’ OR ls_fieldcat-fieldname = ‘PERIOD’ .
ls_fieldcat-no_out = ‘X’.
MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING no_out.
ENDIF.
ENDLOOP.

ENDFORM. ” BUILD_FIELDCATALOG

&————————————————–
& Form BUILD_LAYOUT
&————————————————–
FORM build_layout.
ls_layout-zebra = ‘X’.
ls_layout-detail_popup = ‘X’.
ls_layout-detail_titlebar = ‘Detailed Flight Info’.
ls_layout-f2code = ‘&ETA’.
ls_layout-window_titlebar = ‘Flight Info’.
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
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: The two fields are hidden.

4.jpg


 

Advertisements

One thought on “REUSE_ALV_LIST_DISPLAY- 15

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