Hello,
I've got a report where we can choose a variant in the selection screen.
SELECTION-SCREEN BEGIN OF BLOCK SEL2 WITH FRAME TITLE TEXT-002.
PARAMETERS p_layout TYPE slis_vari.
SELECTION-SCREEN END OF BLOCK SEL2.
I've got it setup so that when the user runs the report, the field p_layout is filled with his default variant or if he has none it's empty.
My problem is when the field is empty the result ALV is always shown with the default variant.
For example:
User has 2 variants - SAV1 and SAV2 (default).
User enters selection screen and p_layout is filled with SAV2.
Scenario 1:
User presses F8 and the ALV is shown with the variant SAV2
Scenario 2:
User changes p_layout to SAV1 and presses F8. ALV is shown with SAV1 variant
Scenario 3:
User emptys p_layout (p_layout IS INITIAL), presses F8 and ALV is shown with SAV2 variant - the default one
What can I do so that when p_layout IS INITIAL the ALV shows all the columns?
This is how I define the layout:
gr_layout = gr_alv->get_layout( ).
MOVE sy-repid TO gs_layout_key-report.
gr_layout->set_key( gs_layout_key ).
gr_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
gr_layout->set_default( 'X' ).
gr_layout->set_initial_layout( p_layout ).
F4 help for p_layout:
ls_layout_key-report = sy-repid.
ls_layout_info = cl_salv_layout_service=>f4_layouts( ls_layout_key ).
p_layout = ls_layout_info-layout.
Initialization of p_layout:
gs_variant-report = sy-repid.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
I_SAVE = 'A'
CHANGING
CS_VARIANT = gs_variant
EXCEPTIONS
WRONG_INPUT = 1
NOT_FOUND = 2
PROGRAM_ERROR = 3
OTHERS = 4.
IF sy-subrc = 2 OR sy-subrc = 0.
p_layout = gs_variant-variant.
ELSE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
the sy-subrc = 2 is there to prevent error if user has no layouts => p_layout stays empty
Thank you in advance!