SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow


Enable SAP Users Create Own Layout Variants using set_table_for_first_display


SAP users want to configure ALV grid layout settings and change the standart ABAP report according to their requirements.
SAP users want to customize the ALV layout and create custom layouts for own use or for global use.

For an ABAP developer this means enabling SAP system users create User or Global layout variants for the ALV grid display.

If the ABAP programmer is using method set_table_for_first_display of cl_gui_alv_grid type ALV grid object, then it is very easy to let SAP users create own layout variants and manage layout variants.

To manage this task, ABAP developers can use is_variant and i_save export parameters of the set_table_for_first_display method call.

sap-alv-grid-layout-settings-and-layout-variants

i_save parameter has 4 possible values.

U: An i_save parameter value "U" means that the user can only save user-specific layouts.
X: An i_save parameter value "X" means that the users are enabled to save only global layouts. So other users can also use these global layouts too.
A: An i_save parameter value "A" means that the SAP user can save both user specific and global layouts.
Space: An empty or space i_save parameter value which is default for i_save means users cannot save own layouts either global or user specific layout.





Below, ABAP developers can find example ABAP code which enables SAP users save own layout variants on ABAP ALV Grid screens.

Especially focus on the is_variant and i_save parameters, and gs_variant variable.

" Variables and Declarations
DATA :
  " scrfname = Name of a Screen Element
  g_container TYPE scrfname VALUE 'CC_CONTAINER_GRID',
  " CL_GUI_CUSTOM_CONTAINER is a class interface
  g_custom_container TYPE REF TO cl_gui_custom_container,
  " ALV Grid
  g_grid TYPE REF TO cl_gui_alv_grid.

DATA gs_variant TYPE disvariant.

"Create CONTAINER object with reference to container name in the screen
CREATE OBJECT g_custom_container EXPORTING container_name = g_container.
" Create GRID object with reference to parent name
CREATE OBJECT g_grid EXPORTING i_parent = g_custom_container.

gs_variant-report = sy-repid. "Enable users save own LAYOUTs

" SET_TABLE_FOR_FIRST_DISPLAY
CALL METHOD g_grid->set_table_for_first_display
  EXPORTING
    "is_layout = gs_layout
    is_variant = gs_variant
    i_save = 'A' "possible values U,X,A,' ' or space
  CHANGING
    "it_sort = gt_sort " for SubTotals
    it_fieldcatalog = gt_fieldcatalog
    it_outtab = gt_outtab. " Data
Code

Note that I did not copy here all ABAP codes required for a real demo.
But the above ABAP codes are taken from a real working ABAP report.

ABAP developers should add their own codes for :
Populating gt_fieldcatalog variable for set_table_for_first_display method it_fieldcatalog parameter
Populating ALV Grid data, it_outtab parameter value which is gt_outtab variable here.



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.