[ABAP] ALV – Auswahlpopup für Selektion einer Anzeigevariante anzeigen

DATA: ls_variant LIKE disvariant.
DATA: lv_exit TYPE c.

PARAMETERS p_vari LIKE disvariant-variant.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.

  CLEAR ls_variant.

  ls_variant-report = sy-repid.
  ls_variant-username = sy-uname.

  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      is_variant    = ls_variant
      i_save        = 'A'
    IMPORTING
      e_exit        = lv_exit
      es_variant    = ls_variant
    EXCEPTIONS
      not_found     = 1
      program_error = 2
      OTHERS        = 3.

  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    IF lv_exit EQ space.
      p_vari = ls_variant-variant.
    ENDIF.
  ENDIF.

[ABAP] SALV-Table – Benutzerspezifisches Layout setzen

* https://belajarabap.wordpress.com/2022/01/29/alv-report-using-cl_salv_table/
* http://abapmentor.expertise-team.com/post/display-alv-list-easily-in-abap-using-cl-salv-table-part-ii-enable-layout-settings.aspx
* https://community.sap.com/t5/application-development-blog-posts/defining-and-displaying-user-defined-layouts-using-factory-method/ba-p/13500044

* REPORT: SALV_DEMO_TABLE_LAYOUT

PARAMETERS: p_layout TYPE disvariant-variant.

INITIALIZATION.
  DATA(lv_key) = VALUE salv_s_layout_key( report = sy-repid ).

  p_layout = cl_salv_layout_service=>get_default_layout( s_key = lv_key )-layout.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
  DATA(lv_key) = VALUE salv_s_layout_key( report = sy-repid ).

  p_layout = cl_salv_layout_service=>f4_layouts( lv_key )-layout.

START-OF-SELECTION.

  SELECT FROM mara
    FIELDS *
    INTO TABLE @DATA(it_mara)
    UP TO 100 ROWS.

  IF sy-subrc = 0.
    TRY.
*   SALV-Table
        DATA: o_salv TYPE REF TO cl_salv_table.

        cl_salv_table=>factory( IMPORTING r_salv_table = o_salv
                                CHANGING  t_table      = it_mara ).

*   Grundeinstellungen
        o_salv->get_functions( )->set_all( abap_true ).
        o_salv->get_columns( )->set_optimize( abap_true ).
        o_salv->get_display_settings( )->set_list_header( 'MARA' ).
        o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
        o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).

*   Spaltenüberschriften: technischer Name und Beschreibungstexte, Short Text und Medium Text leer lassen für Autosize
        LOOP AT o_salv->get_columns( )->get( ) ASSIGNING FIELD-SYMBOL(<c>).
          DATA(o_col) = <c>-r_column.
          o_col->set_short_text( || ).
          o_col->set_medium_text( || ).
          o_col->set_long_text( |{ o_col->get_long_text( ) }| ).
        ENDLOOP.

* SALV-Layout setzen, Layout-Buttons aktivieren
        DATA(o_layout) = o_salv->get_layout( ).
        o_layout->set_default( abap_true ).
        o_layout->set_key( VALUE #( report = sy-repid ) ).
        o_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).

        IF p_layout IS INITIAL.
          o_layout->set_initial_layout( 'DEFAULT' ).
        ELSE.
          o_layout->set_initial_layout( p_layout ).
        ENDIF.

        o_salv->display( ).
      CATCH cx_root INTO DATA(e_txt).
        WRITE: / e_txt->get_text( ).
    ENDTRY.
  ENDIF.