REUSE_ALV_LIST_DISPLAY- 20

light11Use of special group in list ALV

 

 

 

The previous post REUSE_ALV_LIST_DISPLAY- 19 shows how to calculate total, subtotal and top of page event. This post shows how to make use of special group in list ALV.


Code Snippet:  Here  6 fields are hidden in teh lav list by the field catalog property no_out.


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

———————————–

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.

LOOP AT lt_fieldcat INTO ls_fieldcat.
CASE ls_fieldcat-fieldname.
WHEN ‘COUNTRYFR’ OR
‘COUNTRYTO’ OR
‘CITYFROM’ OR
‘CITYTO’ OR
‘AIRPFROM’ OR
‘AIRPTO’ .
ls_fieldcat-no_out = ‘X’.
MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING no_out.
WHEN OTHERS.
ENDCASE.                                       

ENDLOOP.

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: Click the layout button

1

In the right section of the popup window of the change layout, all the hidden fields are available. You can select one by one fields that you want to make visible in the ALV display or you can make use of the button  [ << ] to add all fields. Select the [<< ] button.

2

All the hidden fields are added to the display section. Now select Copy button.

3

Now the ALV display changed i.e all 6 hidden fields appear in the output.

4


Consider the case that alv structure is really very large and a large number of fields are hidden by the field catalog property NO_OUT.  In such a case if we go to the layout and want to add few hidden fields to the display field list, then the user has to look for specific fields in the long hidden list. In such case it is useful we can define logically related fields to one group and if the user selects that group all the fields of that group is displayed and it can be added to the display field list. 


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: lt_special_groups TYPE slis_t_sp_group_alv.

———————————–

START-OF-SELECTION.
PERFORM build_data.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM build_special_group.
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.

LOOP AT lt_fieldcat INTO ls_fieldcat.
CASE ls_fieldcat-fieldname.
WHEN ‘COUNTRYFR’ OR
‘COUNTRYTO’ OR
‘CITYFROM’ OR
‘CITYTO’ OR
‘AIRPFROM’ OR
‘AIRPTO’ .
ls_fieldcat-no_out = ‘X’.
MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING no_out.
WHEN OTHERS.
ENDCASE.

” Add fields to different groups in the field catalog

CASE ls_fieldcat-fieldname.
WHEN ‘COUNTRYFR’ OR ‘COUNTRYTO’.
ls_fieldcat-sp_group = ‘G1’.
MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING sp_group.
WHEN ‘CITYFROM’ OR ‘CITYTO’.
ls_fieldcat-sp_group = ‘G2’.
MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING sp_group.
WHEN ‘AIRPFROM’ OR ‘AIRPTO’.
ls_fieldcat-sp_group = ‘G3’.
MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING sp_group.
WHEN OTHERS.
ENDCASE.
ENDLOOP.

ENDFORM. ” BUILD_FIELDCATALOG

&————————————————–
& Form BUILD_LAYOUT
&————————————————–
FORM build_layout.
ls_layout-zebra = ‘X’.
ls_layout-box_fieldname = ‘BOX’.
ENDFORM. ” BUILD_LAYOUT
&———————————————————————
& Form BUILD_SPECIAL_GROUP
&———————————————————————
FORM build_special_group.
DATA: ls_special_group TYPE slis_sp_group_alv.
ls_special_group-sp_group = ‘G1’.
ls_special_group-text = ‘Country Group’.
APPEND ls_special_group TO lt_special_groups.

ls_special_group-sp_group = ‘G2’.
ls_special_group-text = ‘City Group’.
APPEND ls_special_group TO lt_special_groups.

ls_special_group-sp_group = ‘G3’.
ls_special_group-text = ‘Airport Group’.
APPEND ls_special_group TO lt_special_groups.
ENDFORM. ” BUILD_SPECIAL_GROUP
&—————————————————
& 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
it_special_groups = lt_special_groups
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: All 6 fields are hidden now. Click on layout tab.
5

In the right side of the change layout popup window, we have a list box now due to that we have defined a special group table. By default all hidden fields appear. Select the drop down list box.

6

We defined 3 groups, all appear here, for each group 2 fields are associated in the field catalog. So choose group G2.

7

Now all the fields of group G2 appears under the hidden field section. Select [<<] to add them all[2 fields) to the display list.

8

Well 2 fields added to the display list. Select COPY button.

9

Both fields appear in the alv list.

10


 

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 )

Facebook photo

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

Connecting to %s