[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] Verwendung von Tabstips auf dem Selektionsbildschirm

Variante 1 (Tabstrip (TabControl) verwenden)

* Tabstrip erzeugen, 10 Zeilen hoch
SELECTION-SCREEN BEGIN OF TABBED BLOCK tbl FOR 10 LINES.
SELECTION-SCREEN TAB (15) tbl_tab1 USER-COMMAND tab1 DEFAULT SCREEN 9001.
SELECTION-SCREEN TAB (15) tbl_tab2 USER-COMMAND tab2 DEFAULT SCREEN 9002.
SELECTION-SCREEN END OF BLOCK tbl.

* Subscreen 9001 für Tab1
SELECTION-SCREEN BEGIN OF SCREEN 9001 AS SUBSCREEN.
PARAMETERS: pa_test.
SELECTION-SCREEN END OF SCREEN 9001.

* Subscreen 9002 für Tab2
SELECTION-SCREEN BEGIN OF SCREEN 9002 AS SUBSCREEN.
PARAMETERS: pa_test2.
SELECTION-SCREEN END OF SCREEN 9002.

INITIALIZATION.
* Tabnamen vergeben
  tbl_tab1 = 'Tab1'.
  tbl_tab2 = 'Tab2'.

* aktiven Tab setzen, Großbuchstaben beachten
  tbl-activetab = 'TAB1'.
  tbl-dynnr = 9001.
  tbl-prog  = sy-repid.

AT SELECTION-SCREEN.
* Ereignis bei Klick auf Tabstrip abfangen
  CASE sy-ucomm.
    WHEN 'TAB1'.
      MESSAGE 'TAB1' TYPE 'S'.
    WHEN 'TAB2'.
      MESSAGE 'TAB2' TYPE 'S'.
  ENDCASE.

START-OF-SELECTION.
  WRITE: / 'Aktiver Tab:', tbl-activetab.
  WRITE: / 'Aktiver Tab Subscreen:', tbl-dynnr.
  WRITE: / 'Programmname:', tbl-prog.

Variante 2 (zuletzt gewählen Tabstrip zwischenspeichern)

* nach Listenverarbeitung wieder zurück zum Selektionsbildschirm
* und dort den letzten gewählten Tab anzeigen
CONSTANTS: gv_tbl_memory TYPE c LENGTH 10 VALUE 'TBL_ACTIVE'.

* Tabstrip erzeugen, 20 Zeilen hoch
SELECTION-SCREEN BEGIN OF TABBED BLOCK tbl FOR 10 LINES.
SELECTION-SCREEN TAB (15) tbl_tab1 USER-COMMAND tab1 DEFAULT SCREEN 9001.
SELECTION-SCREEN TAB (15) tbl_tab2 USER-COMMAND tab2 DEFAULT SCREEN 9002.
SELECTION-SCREEN END OF BLOCK tbl.

* Subscreen 9001 für Tab1
SELECTION-SCREEN BEGIN OF SCREEN 9001 AS SUBSCREEN.
PARAMETERS: pa_test.
SELECTION-SCREEN END OF SCREEN 9001.

* Subscreen 9002 für Tab2
SELECTION-SCREEN BEGIN OF SCREEN 9002 AS SUBSCREEN.
PARAMETERS: pa_test2.
SELECTION-SCREEN END OF SCREEN 9002.

INITIALIZATION.
* Tabnamen vergeben
  tbl_tab1 = 'Tab1'.
  tbl_tab2 = 'Tab2'.

* Zustand des Tabstrips aus dem Zwischenspeicher holen
  IMPORT tbl FROM MEMORY ID gv_tbl_memory.

AT SELECTION-SCREEN.
  CASE sy-ucomm.
    WHEN 'TAB1'.
      MESSAGE 'TAB1' TYPE 'I'.
    WHEN 'TAB2'.
      MESSAGE 'TAB2' TYPE 'I'.
  ENDCASE.

START-OF-SELECTION.
* Zustand des Tabstrips in den Zwischenspeicher ablegen
  EXPORT tbl TO MEMORY ID gv_tbl_memory.

  WRITE: / 'Aktiver Tab:', tbl-activetab.
  WRITE: / 'Aktiver Tab Subscreen:', tbl-dynnr.
  WRITE: / 'Programmname:', tbl-prog.