Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Creating DYNAMIC FIELD CATALOG.

You can change the field catalog during runtime .
To achieve this you can use the method 'get_frontend_fieldcatalog',
of class 'cl_gui_alv_grid'.

Step 1.

Create an internal table of type LVC_T_FCAT.

Step 2.

Call method 'get_frontend_fieldcatalog' of class cl_gui_alv_grid
and populate the field catalog using the parameter 'et_fieldcatalog' .
This parameter will give you the field catalog of the current displayed
screen.

Step 3.

Now loop at the field catalog and make the required changes.

Step 4.

Call the method 'set_table_for_first_display' and pass the field catalog.

Example:
In this example ,SLFIGHT details will be displayed first and if you press
the push button on the screen(SWITCH) ,SFLIGHT details will be displayed
with changes like 1. OUTPUT LENGTH OF CONNID WILL BE CHANGED.
                            2. FIELD PLANETYPE WILL BE HIDDEN.
                            3. GRAND TOTAL OF FIELD PRICE WILL BE CALCULATED.

REPORT zalv_dynamic_fieldcatalog.
DATA:
t_sflight TYPE TABLE OF sflight,
fs_sflight TYPE sflight.
DATA:
r_container TYPE REF TO cl_gui_custom_container,
r_grid TYPE REF TO cl_gui_alv_grid.
DATA:
t_fcat TYPE lvc_t_fcat,
fs_fcat TYPE lvc_s_fcat.
SELECT * FROM sflight INTO TABLE t_sflight.
CALL SCREEN 100.
*&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------

MODULE status_0100 OUTPUT.
SET PF-STATUS 'SCREEN'.
SET TITLEBAR 'SFLIGHT DETAILS'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'SWITCH'.
CALL METHOD r_grid->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = t_fcat.
LOOP AT t_fcat INTO fs_fcat.
CASE fs_fcat-fieldname.
WHEN 'CONNID'.
fs_fcat-outputlen = '10'.
MODIFY t_fcat FROM fs_fcat.
WHEN 'PLANETYPE'.
fs_fcat-no_out = 'X'.
MODIFY t_fcat FROM fs_fcat.
WHEN 'PRICE'.
fs_fcat-do_sum = 'X'.
MODIFY t_fcat FROM fs_fcat.
ENDCASE.
ENDLOOP.
CALL METHOD r_grid->set_table_for_first_display
CHANGING
it_fieldcatalog = t_fcat
it_outtab = t_sflight.
ENDCASE.
ENDMODULE. "user_command_0100 INPUT
*&---------------------------------------------------------------------
*& Module list OUTPUT
*&---------------------------------------------------------------------
MODULE list OUTPUT.
CREATE OBJECT r_container
EXPORTING
container_name = 'CONTAINER'.
CREATE OBJECT r_grid
EXPORTING
i_parent = r_container.
CALL METHOD r_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = t_sflight.
ENDMODULE. " HANDLER OUTPUT

Result:

Display after pressing push button.

Gran total of field PRICE.

  • No labels