[ABAP] Einfaches Popup-Fenster mit Eingabefeld anzeigen

* Button Pos 2 Länge 20, sendet Kommando 'CMD_SHOW'
SELECTION-SCREEN: PUSHBUTTON 2(20) btn1 USER-COMMAND cmd_show.

* Popup-Fenster (Selektionsbild 100) deklarieren
SELECTION-SCREEN BEGIN OF SCREEN 100 TITLE title.
PARAMETERS: p_text TYPE string.
SELECTION-SCREEN END OF SCREEN 100.

INITIALIZATION.
* Fenstertitel
  title = 'Popup'.
* Button-Text setzen
  btn1 = |{ icon_activity }Popup anzeigen|.

AT SELECTION-SCREEN.
* wenn Button-Kommando 'CMD_SHOW'
  IF sy-ucomm = 'CMD_SHOW'.
* Popup-Fenster (Selektionsbild 100) anzeigen
    CALL SELECTION-SCREEN 100 STARTING AT 10 5.
  ENDIF.

START-OF-SELECTION.
* Datenausgabe
  WRITE: / p_text.

[ABAP] Einfaches Popupfenster mit Texteditor anzeigen

Variante 1 (cl_gui_dialogbox_container)

DATA: o_cnt TYPE REF TO cl_gui_dialogbox_container.
DATA: o_edit TYPE REF TO cl_gui_textedit.
DATA: it_editor TYPE STANDARD TABLE OF char1024.

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS on_close FOR EVENT close OF cl_gui_dialogbox_container
      IMPORTING sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.
* Event, wenn auf das Schließen-Kreuz geklickt wird
  METHOD on_close.
    IF NOT o_edit IS INITIAL.
* vor dem Schließen Text aus dem Editor holen
      o_edit->get_text_as_stream( IMPORTING text = it_editor ).

      sender->free( ).
    ENDIF.
  ENDMETHOD.
ENDCLASS.

* Button Pos 2 Länge 20, sendet Kommando 'CMD_SHOW'
SELECTION-SCREEN: PUSHBUTTON 2(20) btn1 USER-COMMAND cmd_show.

INITIALIZATION.
* Button-Text setzen
  btn1 = |{ icon_activity }Popup anzeigen|.

AT SELECTION-SCREEN.
* wenn Button-Kommando 'CMD_SHOW'
  IF sy-ucomm = 'CMD_SHOW'.

    o_cnt = NEW #( no_autodef_progid_dynnr = abap_true
                   caption = 'Texteditor'
                   top = 100
                   left = 200
                   width = 640
                   height = 240 ).

* on_close Handler setzen
    SET HANDLER lcl_events=>on_close FOR o_cnt.

* neues Editorobjekt erzeugen (überschreibt vorherige Referenz!)
    o_edit = NEW #( wordwrap_mode = cl_gui_textedit=>wordwrap_at_windowborder
                    wordwrap_to_linebreak_mode = cl_gui_textedit=>true
                    parent = o_cnt ).

* feste Zeichenbreite
    o_edit->set_font_fixed( mode = cl_gui_textedit=>true ).
  ENDIF.

START-OF-SELECTION.
  LOOP AT it_editor ASSIGNING FIELD-SYMBOL(<l>).
    WRITE: / <l>.
  ENDLOOP.

Variante 2 (SELECTION-SCREEN)

DATA: it_editor TYPE STANDARD TABLE OF char1024.

* Button Pos 2 Länge 20, sendet Kommando 'CMD_SHOW'
SELECTION-SCREEN: PUSHBUTTON 2(20) btn1 USER-COMMAND cmd_show.

* Popup-Fenster (Selektionsbild 100) deklarieren
SELECTION-SCREEN BEGIN OF SCREEN 100 TITLE title.
SELECTION-SCREEN END OF SCREEN 100.

INITIALIZATION.
* Fenstertitel
  title = 'Texteditor'.
* Button-Text setzen
  btn1 = |{ icon_activity }Popup anzeigen|.

AT SELECTION-SCREEN.
* wenn Button-Kommando 'CMD_SHOW'
  IF sy-ucomm = 'CMD_SHOW'.
* cl_gui_container=>screen1 == SELECTION-SCREEN 100
    DATA(o_edit) = NEW cl_gui_textedit( wordwrap_mode = cl_gui_textedit=>wordwrap_at_windowborder
                                        wordwrap_to_linebreak_mode = cl_gui_textedit=>true
                                        parent = cl_gui_container=>screen1 ).

* feste Zeichenbreite
    o_edit->set_font_fixed( mode = cl_gui_textedit=>true ).

* Popup-Fenster (Selektionsbild 100) anzeigen -> cl_gui_container=>screen1 wird erzeugt
    CALL SELECTION-SCREEN 100 STARTING AT 10 5 ENDING AT 100 20.

* Text aus dem Editor holen
    o_edit->get_text_as_stream( IMPORTING text = it_editor ).

* Editorobjekt freigeben
    FREE: o_edit.
  ENDIF.

START-OF-SELECTION.
  LOOP AT it_editor ASSIGNING FIELD-SYMBOL(<l>).
    WRITE: / <l>.
  ENDLOOP.

[ABAP] Zwei Editfelder mit Label in einer Zeile

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

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (5) lbl1.
PARAMETERS: p_nr TYPE i.
SELECTION-SCREEN COMMENT (6) lbl2.
PARAMETERS: p_file TYPE localfile.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.
  title = 'Auswahl'.
  lbl1 = 'Nr.:'.
  lbl2 = 'Name:'.

[ABAP] Zwei Radiobuttons mit je einem Label in einer Zeile

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE title.
  
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_rb1 RADIOBUTTON GROUP grp1.
SELECTION-SCREEN COMMENT (7) lbl1 FOR FIELD p_rb1.
PARAMETERS: p_rb2 RADIOBUTTON GROUP grp1.
SELECTION-SCREEN COMMENT (7) lbl2 FOR FIELD p_rb2.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.
  title = 'Auswahl'.
  lbl1 = 'Teil A'.
  lbl2 = 'Teil B'.

[ABAP] Checkbox mit Label und Eingabefeld in einer Zeile

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

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_chk1 AS CHECKBOX.
SELECTION-SCREEN COMMENT (6) lbl1 FOR FIELD p_chk1.
PARAMETERS: p_file TYPE localfile.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.
  title = 'Auswahl'.
  lbl1 = 'Datei:'.

[ABAP] Radiobuttons mit Label und Eingabefeldern in einer Zeile

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

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_rb1 RADIOBUTTON GROUP grp1 DEFAULT 'X'.
SELECTION-SCREEN COMMENT (15) lbl1 FOR FIELD p_rb1.
PARAMETERS: p_file1 TYPE localfile.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_rb2 RADIOBUTTON GROUP grp1.
SELECTION-SCREEN COMMENT (15) lbl2 FOR FIELD p_rb2.
PARAMETERS: p_file2 TYPE localfile.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.
  title = 'Auswahl'.
  lbl1 = 'Datei 1:'.
  lbl2 = 'Datei 2:'.

[ABAP] Oberflächenelemente per Button ausblenden

TABLES: sscrfields.

* Anzeigestatus
CONSTANTS: BEGIN OF e_status,
             open  TYPE i VALUE 0,
             close TYPE i VALUE 1,
           END OF e_status.

DATA: status_blk2 TYPE i.

SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE title1.
PARAMETERS: p1 TYPE string.
SELECTION-SCREEN: END OF BLOCK blk1.

* Button zum ein- / ausblenden
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (4) btn_oc USER-COMMAND btn_cmd_oc.
SELECTION-SCREEN COMMENT 6(25) lbl_oc.
SELECTION-SCREEN END OF LINE.

* Anzeigeblock, der ein- / ausgeblendet werden soll
SELECTION-SCREEN: BEGIN OF BLOCK blk2 WITH FRAME TITLE title2.
PARAMETERS: s1 TYPE string MODIF ID b2.
PARAMETERS: s2 TYPE string MODIF ID b2.
SELECTION-SCREEN: END OF BLOCK blk2.

INITIALIZATION.
  title1 = 'Kundennummer'.
  title2 = 'Eingabe'.

  lbl_oc  = 'Eingabe'.

  status_blk2 = e_status-close.

  PERFORM set_btn_icon USING status_blk2 CHANGING btn_oc.

AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    CASE screen-group1.   " Name der Modifikationsgruppe
      WHEN 'B2'.          " wenn in Modifikationsgruppe 'B2'
        " je nach Status den Anzeigeblock aktivieren / deaktivieren
        IF status_blk2 = e_status-open.
          screen-active = '1'.
        ELSE.
          screen-active = '0'.
        ENDIF.
    ENDCASE.
    MODIFY SCREEN.
  ENDLOOP.

  PERFORM set_btn_icon USING status_blk2 CHANGING btn_oc.

AT SELECTION-SCREEN.
  " Kommando des Buttons abfangen
  CASE sscrfields-ucomm.
    WHEN 'BTN_CMD_OC'.
      IF status_blk2 = e_status-open.
        status_blk2 = e_status-close.
      ELSE.
        status_blk2 = e_status-open.
      ENDIF.
  ENDCASE.

* Staus-Icon des Buttons setzen
FORM set_btn_icon USING iv_status TYPE i CHANGING btn_icon TYPE any.
  CASE iv_status.
    WHEN e_status-close.
      btn_icon = icon_data_area_expand.
    WHEN e_status-open.
      btn_icon = icon_data_area_collapse.
  ENDCASE.
ENDFORM.

[ABAP] Subscreens auf dem Selektionsbild verwenden und per Pushbutton umschalten

SELECTION-SCREEN COMMENT /1(50) comm1.
SELECTION-SCREEN SKIP.

* TabStrip als Containerobjekt, ohne Tabs
SELECTION-SCREEN BEGIN OF TABBED BLOCK sub FOR 3 LINES.
SELECTION-SCREEN END OF BLOCK sub.

* Umschaltbuttons
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 1.
SELECTION-SCREEN PUSHBUTTON (10) btn_1 USER-COMMAND btn_back.
SELECTION-SCREEN PUSHBUTTON (10) btn_2 USER-COMMAND btn_fwd.
SELECTION-SCREEN END OF LINE.

* SUBSCREEN 1
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE title1.
PARAMETERS: p1 TYPE string.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN END OF SCREEN 100.

* SUBSCREEN 2
SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE title2.
PARAMETERS: p2 TYPE string.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN END OF SCREEN 200.

* SUBSCREEN 3
SELECTION-SCREEN BEGIN OF SCREEN 300 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE title3.
PARAMETERS: p3 TYPE string.
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN END OF SCREEN 300.

INITIALIZATION.
  comm1 = 'Beispiel für die Verwendung von Subscreens'.

  title1 = 'Sub1'.
  title2 = 'Sub2'.
  title3 = 'Sub3'.

  btn_1 = |{ icon_column_left }Zurück|.
  btn_2 = |{ icon_column_right }Vor|.

* Subscreen 100 anzeigen
  sub-prog = sy-repid.
  sub-dynnr = 100.

  p1 = '11'.
  p2 = '22'.
  p3 = '33'.

AT SELECTION-SCREEN.

  CASE sy-dynnr.
    WHEN 100.
      IF sy-ucomm = 'BTN_BACK'.
        sub-dynnr = 300.
      ELSEIF sy-ucomm = 'BTN_FWD'.
        sub-dynnr = 200.
      ENDIF.
    WHEN 200.
      IF sy-ucomm = 'BTN_BACK'.
        sub-dynnr = 100.
      ELSEIF sy-ucomm = 'BTN_FWD'.
        sub-dynnr = 300.
      ENDIF.
    WHEN 300.
      IF sy-ucomm = 'BTN_BACK'.
        sub-dynnr = 200.
      ELSEIF sy-ucomm = 'BTN_FWD'.
        sub-dynnr = 100.
      ENDIF.
  ENDCASE.

START-OF-SELECTION.

  WRITE: / p1, p2, p3.

[ABAP] Elemente auf einer GroupBox zusammenfassen

* Fasst PARAMETERS und SELECT-OPTIONS auf dem Bildschirm
* zu einer GroupBox "sel1" zusammen, Überschrift "title"
SELECTION-SCREEN BEGIN OF BLOCK sel1 WITH FRAME TITLE title.
  PARAMETERS: ...
  SELECT-OPTIONS: ...
SELECTION-SCREEN END OF BLOCK sel1.

INITIALIZATION.
  title = 'Test1'. " Titel des Selektionsblockes (GroupBox) festlegen