ABAP - Grouping Fields in Field Catalog - Spider's Web
ABAP - Grouping Fields in Field Catalog - Spider's Web
ABAP - Grouping Fields in Field Catalog - Spider's Web
Spider's web
…share your own experience
In some cases you find a report with ALV output where there are maybe hundreds of fields available to be displayed.
This can be VERY confusing for the user when he tries to select just few fields he wants to display but all fields are
listed in one HUGE list together.
This example shows how to group fields that can be separated with some logic, e.g. fields from MARA, fields from
MARC, fields from MARD, …
When you create such groups, user can make a pre-selection by selecting the GROUP and then only fields belonging
to that specific group are being offered for selection in ALV FILTER or LAYOUT change.
TYPES:
* Type definition for an ALV line
BEGIN OF ts_data,
mara TYPE mara,
marc TYPE marc,
mard TYPE mard,
END OF ts_data,
DATA:
gt_data TYPE tt_data, "ALV data
gt_fcat TYPE lvc_t_fcat, "ALV Field Calatog
gt_alv_groups TYPE lvc_t_sgrp, "ALV Field Groups
go_grid TYPE REF TO cl_gui_alv_grid,
go_container TYPE REF TO cl_gui_custom_container.
Now we add the core functionality – we assume there is a screen 0100 created with custom control called
GO_CONTAINER
oprsteny.com/?p=1350 1/5
11/20/2019 ABAP – Grouping fields in field catalog | Spider's web
START-OF-SELECTION.
PERFORM load_data CHANGING gt_data.
We load data from MARA (up to 10 entries) and all their corresponding sub-entries from tables MARC and MARD.
SELECT *
FROM mara
INTO TABLE lt_mara
UP TO 10 ROWS.
SELECT *
FROM marc
INTO TABLE lt_marc
FOR ALL ENTRIES IN lt_mara
WHERE matnr = lt_mara-matnr.
SELECT *
FROM mard
INTO TABLE lt_mard
FOR ALL ENTRIES IN lt_marc
WHERE matnr = lt_marc-matnr
AND werks = lt_marc-werks.
ls_data-marc = <ls_marc>.
oprsteny.com/?p=1350 2/5
11/20/2019 ABAP – Grouping fields in field catalog | Spider's web
READ TABLE lt_mard
TRANSPORTING NO FIELDS
WITH KEY matnr = <ls_mara>-matnr
werks = <ls_marc>-werks.
IF sy-subrc <> 0.
APPEND ls_data TO ct_data.
ELSE.
ls_data-mard = <ls_mard>.
APPEND ls_data TO ct_data.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDFORM.
Here comes the interesting part – building field catalog where we specify the Field-Groups
FIELD-SYMBOLS:
<ls_fcat> LIKE LINE OF ct_fcat,
<ls_group> LIKE LINE OF ct_groups.
TRANSPORTING NO FIELDS
WITH KEY sp_group = iv_groupname.
IF sy-subrc <> 0.
APPEND INITIAL LINE TO ct_groups ASSIGNING .
<ls_group>-sp_group = iv_groupname.
<ls_group>-text = iv_tabname.
ENDIF.
<ls_fcat>-tabname = 'GT_DATA'.
<ls_fcat>-fieldname = |{ iv_tabname }-{ <ls_fcat>-fieldname }|.
**********************************************************************
* THIS IS THE IMPORTANT PART
<ls_fcat>-sp_group = iv_groupname.
**********************************************************************
FORM display_alv.
IF go_container IS INITIAL.
CREATE OBJECT go_container
EXPORTING
container_name = 'GO_CONTAINER'.
go_grid->set_table_for_first_display(
EXPORTING
it_special_groups = gt_alv_groups
CHANGING
it_outtab = gt_data
it_fieldcatalog = gt_fcat " Field Catalog
).
ENDIF.
ENDFORM.
oprsteny.com/?p=1350 4/5
11/20/2019 ABAP – Grouping fields in field catalog | Spider's web
This is the output and if you go to the FILTER or LAYOUT modification, you should be able to filter by the groups you
defined:
RELAT E D
ABAP - Dynamically show and ABAP - ALV Context menu + keep ABAP - ALV custom toolbar button
hide ALV (as sidebar) row selection after a filter is + Import data from clip board
2016-07-13 applied 2014-01-31
In "ABAP" 2014-01-31 In "ABAP"
In "ABAP"
oprsteny.com/?p=1350 5/5