[ABAP] Varianten eines Reports lesen

* Suchhilfe PROGNAME einbinden
PARAMETERS: p_report TYPE varid-report MATCHCODE OBJECT progname DEFAULT sy-repid.
PARAMETERS: p_langu TYPE t002-spras DEFAULT sy-langu.

START-OF-SELECTION.

* Varianten des Reports in den Tabellen VARID (Variantenkatalog) und VARIT (Variantentexte) suchen
* die gefundenen Tabelleninhalte werden in der Ausgabetabelle it_variants als getrennte
* Strukturen V und VT gespeichert
  SELECT FROM varid AS v
    INNER JOIN varit AS vt ON ( v~report EQ vt~report AND v~variant EQ vt~variant )
    FIELDS v~*, vt~*
    WHERE v~mlangu = @p_langu
      AND vt~langu = @p_langu
      AND v~report = @p_report
    INTO TABLE @DATA(it_variants).

  IF sy-subrc = 0.
* Hier Objekte für die Ausgabe hinzufügen
    cl_demo_output=>write_data( it_variants ).

* HTML-Code vom Demo-Output holen
    DATA(lv_html) = cl_demo_output=>get( ).

* Daten im Inline-Browser im SAP-Fenster anzeigen
    cl_abap_browser=>show_html( EXPORTING title       = |Varianten des Reports { p_report }|
                                          html_string = lv_html
                                          container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
    WRITE: space.
  ELSE.
    WRITE: / |Keine Varianten zu Report { p_report } gefunden.|.
  ENDIF.

[ABAP] Element des Selektionsbiles über RadioButtons ein-/ausblenden

PARAMETERS

* PARAMETERS
* Element, dass ein-/bzw. ausgeblendet werden soll
SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (9) lbl1 FOR FIELD p_test.
  PARAMETERS: p_test TYPE matnr.
SELECTION-SCREEN END OF LINE.

* Radiobutton 1, sendet USER_COMMAND, damit beim Umschalten AT SELECTION-SCREEN OUTPUT ausgelöst wird
SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (9) lbl2 FOR FIELD p_rb1.
  PARAMETERS: p_rb1 RADIOBUTTON GROUP grp DEFAULT 'X' USER-COMMAND rb.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (9) lbl3 FOR FIELD p_rb2.
  PARAMETERS: p_rb2 RADIOBUTTON GROUP grp.
SELECTION-SCREEN END OF LINE.

INITIALIZATION.
  lbl1 = 'Material:'.
  lbl2 = '      An:'.
  lbl3 = '     Aus:'.

AT SELECTION-SCREEN OUTPUT.
* Elemente des Selektionsbiles durchgehen
  LOOP AT SCREEN INTO DATA(wa).
* Wenn Element 'P_TEST'
    IF wa-name = 'P_TEST'.
* Aktvsetzung in Abhängigkeit von RB2
      wa-active = COND #( WHEN p_rb2 = abap_true THEN 0 ELSE 1 ).
      MODIFY SCREEN FROM wa.
    ENDIF.
  ENDLOOP.

SELECT-OPTIONS

* Element, dass ein-/bzw. ausgeblendet werden soll
SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (9) lbl1 FOR FIELD so_test.
  SELECT-OPTIONS: so_test FOR sy-uname MODIF ID 100.
SELECTION-SCREEN END OF LINE.

* Radiobutton 1, sendet USER_COMMAND, damit beim Umschalten AT SELECTION-SCREEN OUTPUT ausgelöst wird
SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (9) lbl2 FOR FIELD p_rb1.
  PARAMETERS: p_rb1 RADIOBUTTON GROUP grp DEFAULT 'X' USER-COMMAND rb.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (9) lbl3 FOR FIELD p_rb2.
  PARAMETERS: p_rb2 RADIOBUTTON GROUP grp.
SELECTION-SCREEN END OF LINE.

INITIALIZATION.
  lbl1 = 'Name:'.
  lbl2 = '  An:'.
  lbl3 = ' Aus:'.

AT SELECTION-SCREEN OUTPUT.
* Elemente des Selektionsbiles durchgehen
  LOOP AT SCREEN INTO DATA(wa).
* Wenn Element 'SO_TEST'
    IF wa-group1 = '100'.
* Aktvsetzung in Abhängigkeit von RB2
      wa-active = COND #( WHEN p_rb2 = abap_true THEN 0 ELSE 1 ).
      MODIFY SCREEN FROM wa.
    ENDIF.
  ENDLOOP.

[ABAP] Domänenwerte in einer ComboBox im Selektionsbild darstellen

DATA: it_val TYPE vrm_values.

PARAMETERS: p_type TYPE char1 OBLIGATORY AS LISTBOX VISIBLE LENGTH 20.

INITIALIZATION.

  CLEAR: it_val.

* Domänenwerte holen
  cl_reca_ddic_doma=>get_values( EXPORTING id_name   = 'CCCATEGORY'
                                 IMPORTING et_values = DATA(it_dval) ).

  IF lines( it_dval ) > 0.
* wenn Werte vorhanden, dann Auswahlliste erstellen
    it_val = VALUE vrm_values( FOR v IN it_dval ( key  = v-domvalue_l
                                                  text = v-ddtext ) ).

* Auswahlliste setzen
    CALL FUNCTION 'VRM_SET_VALUES'
      EXPORTING
        id              = 'P_TYPE'
        values          = it_val
      EXCEPTIONS
        id_illegal_name = 1
        OTHERS          = 2.

    IF sy-subrc = 0.
* Vorselektion 'Punkt eins'
      p_type = it_val[ 1 ]-key.
    ENDIF.
  ENDIF.

START-OF-SELECTION.
* akt. Selektion der ComboBox heraussuchen
  TRY.
      DATA(s) = it_val[ key = p_type ].

      WRITE: / s-key, s-text.
    CATCH cx_root.
  ENDTRY.

Links

[ABAP] SCREEN-Felder im Selektionsbild manuell setzen

DATA: pernr TYPE persno.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE title.

PARAMETERS: pa_bukrs TYPE pa0001-bukrs.
SELECT-OPTIONS: so_pernr FOR pernr.

TYPES: ty_it_screen TYPE STANDARD TABLE OF screen WITH DEFAULT KEY.
DATA: it_screen TYPE ty_it_screen.

SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.

  title = 'Testblock'.

* SCREEN-Felder auslesen
  LOOP AT SCREEN INTO DATA(lv_screen).
    APPEND lv_screen TO it_screen.
  ENDLOOP.

  %_pa_bukrs_%_app_%-text = 'Par'.
  %_so_pernr_%_app_%-text = 'SelOpt'.

START-OF-SELECTION.
*SSCRFIELDS-UCOMM
*TITLE
*%_PA_BUKRS_%_APP_%-TEXT
*PA_BUKRS
*%_SO_PERNR_%_APP_%-TEXT
*%_SO_PERNR_%_APP_%-OPTI_PUSH
*SO_PERNR-LOW
*%_SO_PERNR_%_APP_%-TO_TEXT
*SO_PERNR-HIGH
*%_SO_PERNR_%_APP_%-VALU_PUSH
*%_17SNS0000194656_%_%_%_%_%_%_

* SCREEN-Felder ausgeben
  cl_demo_output=>display_data( it_screen ).

[ABAP] SAP-Suchhilfe verwenden

Beispiel 1 (MATCHCODE OBJECT)

* Suchhilfen anlegen, ändern: SE11

* Tabellen
*
* DD30L - Suchhilfen
* DD30T - Texte zu Suchhilfen
* DD33S - Zuordnung von Suchhilfefeldern

* MATCHCODE OBJECT verknüpft das Eingabefeld des Parameters mit einer Suchhilfe aus dem ABAP Dictionary
* Beispiel: Suchhilfe /iwbep/sh_ddshlp_elem sucht nach Suchhilfen :)
PARAMETERS: p_dd03l TYPE shlpname MATCHCODE OBJECT /iwbep/sh_ddshlp_elem.

Beispiel 2 (Suche von Suchhilfen zu einer Tabelle in der Tabelle DD30L)

* Parameterwert für Tabellenname, um Suchhilfen zu einer Tabelle zu ermitteln
PARAMETERS: p_table TYPE selmethod DEFAULT 'USR02'.

START-OF-SELECTION.

  SELECT l~shlpname,
         l~as4local,
         l~selmethod,
         t~ddtext
    INTO TABLE @DATA(it_dd30l)
    FROM dd30l AS l
    INNER JOIN dd30t AS t ON l~shlpname = t~shlpname
    WHERE t~ddlanguage = @sy-langu
      AND l~selmethod = @p_table.

  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_dd30l ).

*   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( |Suchhilfen zur Tabelle { p_table }| ).
        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
        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_columnname( ) } [{ o_col->get_long_text( ) }]| ).
        ENDLOOP.

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

[ABAP] SELECT-OPTIONS Auswahldialog anzeigen

Variante 1 (RANGE)

DATA: rg_matnr TYPE RANGE OF matnr.

CALL FUNCTION 'COMPLEX_SELECTIONS_DIALOG'
  EXPORTING
    title             = 'Auswahl'
    text              = 'Materialnummern'
  TABLES
    range             = rg_matnr
  EXCEPTIONS
    no_range_tab      = 1
    cancelled         = 2
    internal_error    = 3
    invalid_fieldname = 4
    OTHERS            = 5.

IF sy-subrc = 0.
  cl_demo_output=>display( rg_matnr ).
ENDIF.

Variante 2 (RSTABFIELD)

DATA(lv_tab_field) = VALUE rstabfield( tablename = 'CSKS' fieldname = 'KOSTL' ).

DATA: rg_test TYPE RANGE OF csks-kostl.

CALL FUNCTION 'COMPLEX_SELECTIONS_DIALOG'
  EXPORTING
    title             = 'Auswahl'
    text              = 'Kostenstelle'
    tab_and_field     = lv_tab_field
    help_field        = 'CSKS-KOSTL'
  TABLES
    range             = rg_test
  EXCEPTIONS
    no_range_tab      = 1
    cancelled         = 2
    internal_error    = 3
    invalid_fieldname = 4
    OTHERS            = 5.

IF sy-subrc = 0.
  cl_demo_output=>display( rg_test ).
ENDIF.

[ABAP] Klasse für die Anzeige von Funktionbuttons im Selektionsbild

* Quelle: https://abapblog.com/articles/tricks/127-selection-screen-function-key-in-form-function-module-or-method

* Klasse greift auf Systemprogramm RSDBRUNT im Paket SLDBV zu
CLASS zcl_sel_button DEFINITION FINAL.
  PUBLIC SECTION.
    CLASS-METHODS: activate
      IMPORTING i_btn_no TYPE i.

    CLASS-METHODS: deactivate
      IMPORTING i_btn_no TYPE i.

    CLASS-METHODS: set_info
      IMPORTING i_btn_no    TYPE i
                i_text      TYPE gui_text OPTIONAL
                i_icon      TYPE icon_d OPTIONAL
                i_icon_text TYPE gui_ictext OPTIONAL
                i_quickinfo TYPE gui_info OPTIONAL.

  PRIVATE SECTION.
    CONSTANTS: co_current_screen TYPE string VALUE '(RSDBRUNT)CURRENT_SCREEN'.
    CONSTANTS: co_current_scr TYPE string VALUE '(RSDBRUNT)CURRENT_SCR'.

    CLASS-METHODS: set_visible
      IMPORTING i_btn_no  TYPE i
                i_visible TYPE abap_bool.
ENDCLASS.

CLASS zcl_sel_button IMPLEMENTATION.

* Button aktivieren
  METHOD activate.
    set_visible( i_btn_no  = i_btn_no
                 i_visible = abap_true  ).
  ENDMETHOD.

* Button deaktivieren
  METHOD deactivate.
    set_visible( i_btn_no  = i_btn_no
                 i_visible = abap_false ).
  ENDMETHOD.

* Button-Infos setzen
  METHOD set_info.

    IF i_btn_no BETWEEN 1 AND 5 AND NOT i_text IS INITIAL AND NOT i_icon IS INITIAL.

      DATA(sscr) = CONV string( |({ sy-cprog })SSCRFIELDS| ).

      ASSIGN (sscr) TO FIELD-SYMBOL(<sscr>).
      IF <sscr> IS ASSIGNED.
        ASSIGN COMPONENT |FUNCTXT_0{ i_btn_no }| OF STRUCTURE <sscr> TO FIELD-SYMBOL(<btn_text>).
        IF <btn_text> IS ASSIGNED.
          <btn_text> = VALUE smp_dyntxt( icon_id   = i_icon
                                         icon_text = i_icon_text
                                         text      = i_text
                                         quickinfo = i_quickinfo
                                       ).
        ENDIF.
      ENDIF.
    ENDIF.

  ENDMETHOD.

* Button Sichtbarkeit setzen
  METHOD set_visible.

    IF i_btn_no BETWEEN 1 AND 5.
* Funktionsbutton aktivieren/deaktivieren
      FIELD-SYMBOLS: <screen> TYPE sydb0_screen.

      ASSIGN (co_current_screen) TO <screen>.
      IF <screen> IS ASSIGNED.

        DATA(idx) = i_btn_no - 1.
        <screen>-func_keys+idx(1) = i_visible.

      ENDIF.

* Funktionsbutton anzeigen/verbergen
      FIELD-SYMBOLS: <scr> TYPE sydb0_scr_stack_line.

      ASSIGN (co_current_scr) TO <scr>.
      IF <scr> IS ASSIGNED.

        DATA(button) = |FC0{ i_btn_no }|.

        IF i_visible EQ abap_true.
          DELETE <scr>-excl WHERE fcode EQ button.
        ELSE.
          IF NOT line_exists( <scr>-excl[ fcode = button ] ).
            APPEND VALUE #( fcode = button ) TO <scr>-excl.
          ENDIF.
        ENDIF.

      ENDIF.

    ENDIF.

  ENDMETHOD.
ENDCLASS.

PARAMETERS: p_active AS CHECKBOX USER-COMMAND cba.

INITIALIZATION.
* zwei Funktions-Buttons einfügen
  zcl_sel_button=>set_info( EXPORTING
                              i_btn_no    = 1
                              i_text      = 'Text1'
                              i_icon      =  icon_abc
                              i_icon_text = 'Text1'
                              i_quickinfo = 'Info1'
                          ).
  zcl_sel_button=>activate( 1 ).

  zcl_sel_button=>set_info( EXPORTING
                              i_btn_no    = 2
                              i_text      = 'Text2'
                              i_icon      =  icon_activate
                              i_icon_text = 'Text2'
                              i_quickinfo = 'Info2'
                          ).
  zcl_sel_button=>activate( 2 ).

AT SELECTION-SCREEN OUTPUT.
* je nach Status der Checkbox p_active Funktionsbutton 3 ein- oder ausblenden
  IF p_active EQ abap_true.
    zcl_sel_button=>set_info( EXPORTING
                                i_btn_no    = 3
                                i_text      = 'Text3'
                                i_icon      =  icon_add_row
                                i_icon_text = 'Text3'
                                i_quickinfo = 'Info3'
                            ).

    zcl_sel_button=>activate( 3 ).
  ELSE.
    zcl_sel_button=>deactivate( 3 ).
  ENDIF.

AT SELECTION-SCREEN.
* Kommando abfangen (Nummerierung 'FC01' ... 'FC05')
  CASE sy-ucomm.
* wenn Funktionstaste 1 gedrückt
    WHEN 'FC01'.
      MESSAGE sy-ucomm TYPE 'S'.
* wenn Funktionstaste 2 gedrückt
    WHEN 'FC02'.
      MESSAGE sy-ucomm TYPE 'S'.
* wenn Funktionstaste 3 gedrückt
    WHEN 'FC03'.
      MESSAGE sy-ucomm TYPE 'S'.
  ENDCASE.

[ABAP] Element des Selektionsbildes lesen und Wert für dynamische F4-Suchhilfe benutzen

PARAMETERS: p_table LIKE dd02l-tabname DEFAULT 'T100'.
PARAMETERS: p_field TYPE slis_fieldname.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_field.

  DATA: it_fieldvalues TYPE STANDARD TABLE OF rsselread WITH DEFAULT KEY.
  APPEND VALUE #( name = 'P_TABLE' " Dynprofeld P_TABLE
                  kind = 'P'       " P - PARAMETER, S - SELECT-OPTION
                ) TO it_fieldvalues.

* Element des Selektionsbildes lesen
  CALL FUNCTION 'RS_SELECTIONSCREEN_READ'
    EXPORTING
      program     = sy-repid
      dynnr       = sy-dynnr
    TABLES
      fieldvalues = it_fieldvalues.

  DATA(lv_tabname) = it_fieldvalues[ 1 ]-fieldvalue.

  IF NOT lv_tabname IS INITIAL.
    TRANSLATE lv_tabname TO UPPER CASE.

    SELECT fieldname
      FROM dd03l
      INTO TABLE @DATA(it_cols)
      WHERE tabname = @lv_tabname.

    IF sy-subrc = 0.
      DATA: it_return TYPE STANDARD TABLE OF ddshretval WITH DEFAULT KEY.

* F4-Hilfe mit Übergabe der anzuzeigenden Werte in interner Tabelle
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          retfield        = 'FIELDNAME' " Rückgabewert aus dem Feld FIELDNAME
          dynpprog        = sy-repid
          dynpnr          = sy-dynnr
          dynprofield     = 'P_FIELD'   " Name des Dynpro-Feldes für die automatische Werterückgabe
          value_org       = 'S'         " Werteübergabe: C: zellenweise, S: strukturiert
          window_title    = 'Auswahl'
        TABLES
          value_tab       = it_cols     " Übergabe-Tabelle mit Werten für die Anzeige und Auswahl
          return_tab      = it_return   " Rückgabe-Tabelle mit den ausgewählten (geklickten) Elementen
        EXCEPTIONS
          parameter_error = 1
          no_values_found = 2
          OTHERS          = 3.

      IF sy-subrc = 0.
        IF lines( it_return ) > 0.
          MESSAGE it_return[ 1 ]-fieldval TYPE 'S'.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

[ABAP] Eigener Startbutton (PUSHBUTTON) für START-OF-SELECTION auf dem Selektionsbild

* http://havliczech.blogspot.com/2017/04/how-to-trigger-start-of-selection-event.html
PARAMETERS: p_string TYPE string DEFAULT 'abc' LOWER CASE.

SELECTION-SCREEN SKIP.

* PUSHBUTTON triggert Test-Kommando 'SHOW'
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON 2(30) btn1 USER-COMMAND show.
SELECTION-SCREEN END OF LINE.

* PUSHBUTTON triggert Kommando 'ONLI' (Ausführen) auf dem Selektionsbild
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON 2(30) bstart USER-COMMAND onli.
SELECTION-SCREEN END OF LINE.

INITIALIZATION.
  btn1 = 'Show'.
  bstart = 'Start'.

AT SELECTION-SCREEN.
* User-Command prüfen
  CASE sy-ucomm.
    WHEN 'ONLI'.
      MESSAGE 'Springe jetzt zu START-OF-SELECTION.' TYPE 'S'.
    WHEN 'SHOW'.
      MESSAGE p_string TYPE 'I'.
  ENDCASE.

START-OF-SELECTION.
* Wenn User-Command 'ONLI' (Ausführen) getriggert wurde
  WRITE: 'Fertig.'.