‎2022 May 24 8:49 AM
Hi all,

Hi my ALV layout variant settings are lost once there is whether there is_stable or omit out is_stable, there is no difference.
CALL METHOD go_grid->set_frontend_fieldcatalog
EXPORTING
it_fieldcatalog = lt_fieldcatalog.
CALL METHOD go_grid->set_frontend_layout
EXPORTING
is_layout = gs_layout.
CALL METHOD go_grid->set_variant
EXPORTING
is_variant = gx_variant
i_save = 'A'.
*_ Call refresh once after updated catalog before manipulating
* project totals data
CALL METHOD go_grid->refresh_table_display
EXPORTING
is_stable = lwa_stbl
i_soft_refresh = 'X'.
‎2022 May 31 2:26 AM
Hi all,
Found the source of the problem in the program that is causing the selected ALV layout variant got lost when displaying the output. Right before calling the go_grid->refresh_table_display, program is calling go_grid->get_frontend_fieldcatalog and this importing current fieldcatalog is overwriting the selected alv layout variant from the selection screen. I commented out this and populate the lt_fieldcatalog with the selected alv variant from the selection screen gt_fieldcatalog and the problem is fixed.
DATA lt_fieldcatalog TYPE lvc_t_fcat.
FIELD-SYMBOLS <fs_fieldcatalog> TYPE lvc_s_fcat.
DATA : lwa_stbl type lvc_s_stbl. "ins
* ** Row,Col Stable
lwa_stbl-row = 'X'.
lwa_stbl-col = 'X'.
REFRESH gt_fcode.
*_ If ALV object not initialized
IF go_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = go_grid.
ENDIF.
* start del
**_ Import current fieldcatalog from displayed ALV
* CALL METHOD go_grid->get_frontend_fieldcatalog
* IMPORTING
* et_fieldcatalog = lt_fieldcatalog.
* end del
* start ins
* *_ Always copy and adjust from pre-build catalog to avoid seq error
lt_fieldcatalog = gt_fieldcatalog.
* end ins
LOOP AT lt_fieldcatalog ASSIGNING <fs_fieldcatalog>
WHERE fieldname = 'BUDGET_AWARDED'
OR fieldname = 'PFY_TOTAL'
OR fieldname = 'FY_TOTAL'
* begin ins
OR fieldname = 'LAST_SUBM_TOTAL'
OR fieldname = 'CURR_SUBM_TOTAL'
* end ins
OR fieldname = 'WLP01'
OR fieldname = 'WLP02'
OR fieldname = 'WLP03'
OR fieldname = 'WLP04'
OR fieldname = 'WLP05'
OR fieldname = 'WLP06'
OR fieldname = 'WLP07'
OR fieldname = 'WLP08'
OR fieldname = 'WLP09'
OR fieldname = 'WLP10'
OR fieldname = 'WLP11'
OR fieldname = 'WLP12'
OR fieldname = 'TOTAL_ITD'
OR fieldname = 'BUDGET_BALANCE'.
IF pv_show_total = gc_x.
<fs_fieldcatalog>-do_sum = gc_a.
ELSE.
<fs_fieldcatalog>-do_sum = space.
ENDIF.
ENDLOOP.
CALL METHOD go_grid->set_frontend_fieldcatalog
EXPORTING
it_fieldcatalog = lt_fieldcatalog.
* * begin ins
CALL METHOD go_grid->set_frontend_layout
EXPORTING
is_layout = gs_layout.
CALL METHOD go_grid->set_variant
EXPORTING
is_variant = gx_variant
i_save = 'A'.
* end ins
*_ Call refresh once after updated catalog before manipulating
* project totals data
CALL METHOD go_grid->refresh_table_display
EXPORTING
is_stable = lwa_stbl "ins
i_soft_refresh = 'X'.
PERFORM f_update_alv_total.
‎2022 May 24 12:55 PM
It's probably gs_variant as it seems you defined the program name nowhere (nor the ALV name).
‎2022 May 25 2:47 AM
sandra.rossi
Have. Sy-repid and username already set in. But it has no effect when passed to go_grid->set_table_for_first_display or go_grid->refresh_table_display
*_ Variant
gs_variant-report = sy-repid.
gs_variant-username = sy-uname.
PERFORM f_select_variant.
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
is_variant = gs_variant
i_save = 'A'
is_layout = gs_layout
it_toolbar_excluding = gt_exclude
CHANGING
it_outtab = gt_print
it_fieldcatalog = gt_fieldcatalog
it_sort = gt_sort.
‎2022 May 25 6:55 AM
OK. Why do you overcomplexify by calling the field catalog, sort and filter criteria methods instead of only passing the parameter IS_VARIANT of set_table_for_first_display?
Note that this is very common requirement, and you have examples all over the place, even in SAP demo programs.
‎2022 May 27 8:14 AM
sandra.rossi
Yup it is common if it is just remained that. Only passing the parameter IS_VARIANT of set_table_for_first_display can actually works. Found the issue causing it but no idea to show the variant settings because the causing variant problem subroutine f_change_display_mode is required by the program.
Apparently after calling this go_grid->set_table_for_first_display there is a f_change_display mode subroutine. As shown below the contents of f_change_display_mode. So the issue is the layout variant settings are lost while using method refresh_table_display of class cl_gui_alv_grid.
PERFORM f_change_display_mode.
FORM f_change_display_mode .
DATA: lt_fieldcatalog TYPE lvc_t_fcat,
lwa_fieldcatalog TYPE lvc_s_fcat.
FIELD-SYMBOLS <fs_fieldcatalog> TYPE lvc_s_fcat.
*_ If ALV object not initialized
IF go_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = go_grid.
ENDIF.
*_ Always copy and adjust from pre-build catalog to avoid seq error
lt_fieldcatalog = gt_fieldcatalog.
LOOP AT lt_fieldcatalog ASSIGNING <fs_fieldcatalog>
WHERE fieldname = 'FY_TOTAL'
OR fieldname = 'WLP01'
OR fieldname = 'WLP02'
OR fieldname = 'WLP03'
OR fieldname = 'WLP04'
OR fieldname = 'WLP05'
OR fieldname = 'WLP06'
OR fieldname = 'WLP07'
OR fieldname = 'WLP08'
OR fieldname = 'WLP09'
OR fieldname = 'WLP10'
OR fieldname = 'WLP11'
OR fieldname = 'WLP12'.
IF gv_ok_code = 'DISP_MONTH'.
IF <fs_fieldcatalog>-fieldname = 'FY_TOTAL'.
<fs_fieldcatalog>-no_out = gc_x.
ELSE.
<fs_fieldcatalog>-no_out = space.
ENDIF.
ELSEIF gv_ok_code = 'DISP_YEAR'.
IF <fs_fieldcatalog>-fieldname = 'FY_TOTAL'.
<fs_fieldcatalog>-no_out = space.
ELSE.
<fs_fieldcatalog>-no_out = gc_x.
ENDIF.
ENDIF.
ENDLOOP.
*_ If subtotal/total function set disabled, remove the func from catalog
IF gv_mode_disptotal = space.
lwa_fieldcatalog-do_sum = space.
MODIFY lt_fieldcatalog FROM lwa_fieldcatalog
TRANSPORTING do_sum
WHERE do_sum <> ''.
ENDIF.
CALL METHOD go_grid->set_frontend_fieldcatalog
EXPORTING
it_fieldcatalog = lt_fieldcatalog.
IF gv_total_disabled = gc_x.
*_ Always call this function to disable total/subtotal function
PERFORM f_change_display_func USING space.
ELSE.
*_ Call refresh once after updated catalog before manipulating
* project totals data
CALL METHOD go_grid->refresh_table_display
EXPORTING
i_soft_refresh = 'X'.
IF gv_mode_disptotal = gc_x.
*_ If subtotal/total function set enabled, manually toggle the func
* in order to generate value set otherwise it'll be missing in another
* display view mode (month/year)
PERFORM f_change_display_func USING space.
PERFORM f_change_display_func USING 'X'.
ELSE.
*_ Call func to manipulate project totals data
PERFORM f_update_alv_total.
ENDIF.
ENDIF. "_ Total/Subtotal function disabled
‎2022 May 27 9:05 AM
I don't have any issue with this minimal reproducible code (press SAVE to refresh).
TABLES sscrfields.
DATA go_alv TYPE REF TO cl_gui_alv_grid.
DATA gt_sflight TYPE TABLE OF sflight.
PARAMETERS p_varian TYPE disvariant-variant.
SELECTION-SCREEN BEGIN OF SCREEN 1001.
PARAMETERS dummy.
SELECTION-SCREEN END OF SCREEN 1001.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varian.
DATA(fcat) = VALUE lvc_t_fcat( ).
DATA(varian) = VALUE disvariant( report = sy-repid username = sy-uname ).
CALL FUNCTION 'LVC_VARIANT_SELECT'
EXPORTING
i_user_specific = 'X'
it_default_fieldcat = fcat
CHANGING
cs_variant = varian
EXCEPTIONS
OTHERS = 0.
p_varian = varian-variant.
AT SELECTION-SCREEN OUTPUT.
CASE sy-dynnr.
WHEN 1001.
IF go_alv IS INITIAL.
CREATE OBJECT go_alv
EXPORTING
i_parent = cl_gui_container=>screen0.
SELECT * FROM sflight INTO TABLE gt_sflight.
go_alv->set_table_for_first_display(
EXPORTING i_structure_name = 'SFLIGHT'
i_save = 'A'
is_variant = VALUE #( report = sy-repid username = sy-uname variant = p_varian )
CHANGING it_outtab = gt_sflight ).
ENDIF.
ENDCASE.
AT SELECTION-SCREEN.
CASE sy-dynnr.
WHEN 1000.
IF sscrfields-ucomm = 'ONLI'.
CALL SELECTION-SCREEN 1001.
ENDIF.
WHEN 1001.
IF sscrfields-ucomm = 'SPOS'.
go_alv->refresh_table_display( i_soft_refresh = 'X' ).
ENDIF.
ENDCASE.
sscrfields-ucomm = ''.
AT SELECTION-SCREEN ON EXIT-COMMAND.
CASE sy-dynnr.
WHEN 1001.
go_alv->free( ).
FREE go_alv.
ENDCASE.
‎2022 May 31 2:26 AM
Hi all,
Found the source of the problem in the program that is causing the selected ALV layout variant got lost when displaying the output. Right before calling the go_grid->refresh_table_display, program is calling go_grid->get_frontend_fieldcatalog and this importing current fieldcatalog is overwriting the selected alv layout variant from the selection screen. I commented out this and populate the lt_fieldcatalog with the selected alv variant from the selection screen gt_fieldcatalog and the problem is fixed.
DATA lt_fieldcatalog TYPE lvc_t_fcat.
FIELD-SYMBOLS <fs_fieldcatalog> TYPE lvc_s_fcat.
DATA : lwa_stbl type lvc_s_stbl. "ins
* ** Row,Col Stable
lwa_stbl-row = 'X'.
lwa_stbl-col = 'X'.
REFRESH gt_fcode.
*_ If ALV object not initialized
IF go_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = go_grid.
ENDIF.
* start del
**_ Import current fieldcatalog from displayed ALV
* CALL METHOD go_grid->get_frontend_fieldcatalog
* IMPORTING
* et_fieldcatalog = lt_fieldcatalog.
* end del
* start ins
* *_ Always copy and adjust from pre-build catalog to avoid seq error
lt_fieldcatalog = gt_fieldcatalog.
* end ins
LOOP AT lt_fieldcatalog ASSIGNING <fs_fieldcatalog>
WHERE fieldname = 'BUDGET_AWARDED'
OR fieldname = 'PFY_TOTAL'
OR fieldname = 'FY_TOTAL'
* begin ins
OR fieldname = 'LAST_SUBM_TOTAL'
OR fieldname = 'CURR_SUBM_TOTAL'
* end ins
OR fieldname = 'WLP01'
OR fieldname = 'WLP02'
OR fieldname = 'WLP03'
OR fieldname = 'WLP04'
OR fieldname = 'WLP05'
OR fieldname = 'WLP06'
OR fieldname = 'WLP07'
OR fieldname = 'WLP08'
OR fieldname = 'WLP09'
OR fieldname = 'WLP10'
OR fieldname = 'WLP11'
OR fieldname = 'WLP12'
OR fieldname = 'TOTAL_ITD'
OR fieldname = 'BUDGET_BALANCE'.
IF pv_show_total = gc_x.
<fs_fieldcatalog>-do_sum = gc_a.
ELSE.
<fs_fieldcatalog>-do_sum = space.
ENDIF.
ENDLOOP.
CALL METHOD go_grid->set_frontend_fieldcatalog
EXPORTING
it_fieldcatalog = lt_fieldcatalog.
* * begin ins
CALL METHOD go_grid->set_frontend_layout
EXPORTING
is_layout = gs_layout.
CALL METHOD go_grid->set_variant
EXPORTING
is_variant = gx_variant
i_save = 'A'.
* end ins
*_ Call refresh once after updated catalog before manipulating
* project totals data
CALL METHOD go_grid->refresh_table_display
EXPORTING
is_stable = lwa_stbl "ins
i_soft_refresh = 'X'.
PERFORM f_update_alv_total.
‎2022 May 31 7:23 AM
Good to know, thanks for the feedback.
Don't forget to explain the context right in your question (that you have a button to change the layout after the ALV is displayed), otherwise people can't understand why you need to do all this stuff for displaying an ALV with given variant. A minimal reproducible example is welcome too.