SAP ABAP-Select layout of alv through selection screen
Recently,my consultant cc a problem to me.
The case is described as below.
There is one report needs too much execution time.So my customer needs to run this report as background job.But when they view the result,they need to print it out as the ALV layout they want.One parameter about alv settings is required on the selection screen.
Below is my implemention about this requirement.
… PARAMETERS: p_vari LIKE disvariant-variant.";alv layout … AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari. gs_alv_variant-report = sy-repid. CALL FUNCTION 'REUSE_ALV_VARIANT_F4' EXPORTING is_variant = gs_alv_variant i_save = 'A' IMPORTING es_variant = gs_alv_variant EXCEPTIONS not_found = 2. IF sy-subrc = 2. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. p_vari = gs_alv_variant-variant. ENDIF. … DATA: gr_layout TYPE REF TO cl_salv_layout. DATA: key TYPE salv_s_layout_key. … gr_layout = gr_table->;get_layout( ). key-report = sy-repid.”report id gr_layout->;set_key( key ). gr_layout->;set_default( abap_true ). gr_layout->;set_save_restriction( cl_salv_layout=>;restrict_none ). IF p_vari IS NOT INITIAL. gr_layout->;set_initial_layout( p_vari ).”here we set the layout the user chooses ENDIF.