[ABAP] Dynamisches Selektionsbild-Popup erzeugen

CLASS lcl_dynamic_popup DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS
      show
        RETURNING VALUE(rv_ok) TYPE abap_bool.
ENDCLASS.

CLASS lcl_dynamic_popup IMPLEMENTATION.
  METHOD show.

    rv_ok = abap_true.

* Werte für Selektionbild definieren
    DATA: p_carrid TYPE s_carr_id.
    DATA: so_werks TYPE gds_selrange_werks_tab.
    DATA: p_werks_no TYPE werks.
    DATA: p_check  TYPE xfeld.
    DATA: rb_1 TYPE xfeld.
    DATA: rb_2 TYPE xfeld.
    DATA: lb_language TYPE spras.

    lb_language = sy-langu.

* Selektionsbildelemente für das Popup
* die Eingabewerte werden mit den Variablen über die Felder "ref" verknüpft
    DATA(it_attr) = VALUE sci_atttab(
* Group1 für die folgenden Felder
                                      (
                                        kind = 'G'
                                        text = 'Gruppe1'
                                        ref  = REF #( sy-index )
                                      )
* Parameter
                                      (
                                          kind       = 'S'
                                          text       = 'Carrid'
                                          obligatory = abap_true
                                          ref        = REF #( p_carrid )
                                      )
* SELECT-OPTIONS
                                      (
                                          kind       = 'S'
                                          text       = 'Werk'
                                          ref        = REF #( so_werks )
                                      )
* SELECT-OPTIONS NO INTERVALS
                                      (
                                          kind       = 'T'
                                          text       = 'Werk2'
                                          ref        = REF #( p_werks_no )
                                      )
* Group2 für die folgenden Felder
                                      (
                                        kind = 'G'
                                        text = 'Gruppe2'
                                        ref  = REF #( sy-index )
                                      )
* Checkbox
                                      (
                                          kind       = 'C'
                                          text       = 'Check'
                                          ref        = REF #( p_check )
                                      )
* Radiobuttons mit Group
                                      (
                                          kind         = 'R'
                                          text         = 'Radiobutton1'
                                          button_group = 'GR1'
                                          ref          = REF #( rb_1 )
                                      )
                                      (
                                          kind         = 'R'
                                          text         = 'Radiobutton2'
                                          button_group = 'GR1'
                                          ref          = REF #( rb_2 )
                                      )
* Listbox
                                      (
                                          kind = 'L'
                                          text = 'Sprache'
                                          ref  = REF #( lb_language )
                                      )
                                    ).

* Selektionsbild erzeugen und Popup anzeigen
    IF abap_true = cl_ci_query_attributes=>generic( p_name       = CONV #( sy-repid )
                                                    p_title      = 'Dynamisches Popup'
                                                    p_display    = abap_false " abap_true: Anzeige im READONLY-Modus
                                                    p_attributes = it_attr ).
      rv_ok = abap_false.
    ENDIF.

* Werte ausgeben
    WRITE: / 'CARRID:', p_carrid.
    WRITE: / 'WERKS:', COND string( WHEN lines( so_werks ) > 0 THEN so_werks[ 1 ]-low ELSE '' ).
    WRITE: / 'WERKS2:', p_werks_no.
    WRITE: / 'Check:', p_check.
    WRITE: / 'RB1:', rb_1.
    WRITE: / 'RB2:', rb_2.
    WRITE: / 'LANGUAGE:', lb_language.

  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  IF abap_true = lcl_dynamic_popup=>show( ).
    WRITE: / 'Ok.'.
  ELSE.
    WRITE: / 'Abbruch.'.
  ENDIF.

[ABAP] Debuggen in Popup-Fenstern

  1. Text-Datei auf dem Desktop erstellen mit folgendem Inhalt
    [FUNCTION]
    Command=/H
    Title=Debugger
    Type=SystemCommand
    
  2. zu debuggendes ABAP-Programm ausführen und wenn das zu debuggende Popup hoch kommt -> per Drag&Drop die Text-Datei auf das Popupfenster ziehen

Links

[ABAP] Klasse zur Darstellung von Nachrichtentexten in einem SALV-Grid in einem Popup-Dialog

CLASS lcl_popup_msg_box DEFINITION.

  PUBLIC SECTION.
* Typ Textzeile
    TYPES: BEGIN OF ty_textline,
             idx  TYPE rspos,
             text TYPE bapi_msg,
           END OF ty_textline.

    TYPES: ty_it_messagetab TYPE STANDARD TABLE OF ty_textline WITH DEFAULT KEY.

* Typ Button-Event
    TYPES: ty_it_events TYPE STANDARD TABLE OF cntl_simple_event WITH DEFAULT KEY.

* Anzeige des Popups
    CLASS-METHODS show
      IMPORTING
                i_window_title   TYPE string
                i_window_top     TYPE i
                i_window_left    TYPE i
                i_window_width   TYPE i
                i_window_height  TYPE i
                i_show_functions TYPE boolean
                i_it_messages    TYPE ty_it_messagetab
      RETURNING VALUE(rv_ok)     TYPE boolean.

  PRIVATE SECTION.

* Button Funktionskonstanten
    CONSTANTS: co_btn_ok TYPE ui_func VALUE 'BTN_OK'.
    CONSTANTS: co_btn_cancel TYPE ui_func VALUE 'BTN_CANCEL'.

* Message-Tabelle
    CLASS-DATA: it_messages TYPE ty_it_messagetab.

* GUI-Objekte
    CLASS-DATA: o_cnt TYPE REF TO cl_gui_dialogbox_container.
    CLASS-DATA: o_salv TYPE REF TO cl_salv_table.
    CLASS-DATA: o_split TYPE REF TO cl_gui_splitter_container.
    CLASS-DATA: o_tool TYPE REF TO cl_gui_toolbar.
    CLASS-DATA: gv_retval TYPE boolean VALUE abap_false.

* on_close-Handler
    CLASS-METHODS:
      on_close FOR EVENT close OF cl_gui_dialogbox_container
        IMPORTING
            sender.
* on_function_selected Handler
    CLASS-METHODS:
      on_function_selected FOR EVENT function_selected OF cl_gui_toolbar
        IMPORTING
            fcode
            sender.

ENDCLASS.

CLASS lcl_popup_msg_box IMPLEMENTATION.

  METHOD show.

    it_messages = i_it_messages.

* Container für GUI-Elemente
    o_cnt = NEW #( parent = cl_gui_container=>default_screen
                   caption = |{ i_window_title }|
                   top = i_window_top
                   left = i_window_left
                   width = i_window_width
                   height = i_window_height
                   no_autodef_progid_dynnr = abap_true
                 ).

* on_close-Handler setzen
    SET HANDLER on_close FOR o_cnt.

* Splitter für Grid und Toolbar
    o_split = NEW #( parent = o_cnt
                     no_autodef_progid_dynnr = abap_true
                     rows = 2
                     columns = 1 ).

* Unteren Splitterbereich setzen
    o_split->set_row_sash( id    = 2
                           type  = cl_gui_splitter_container=>type_movable
                           value = cl_gui_splitter_container=>false ).

    o_split->set_row_sash( id    = 2
                           type  = cl_gui_splitter_container=>type_sashvisible
                           value = cl_gui_splitter_container=>false ).

    o_split->set_row_height( id = 2 height = 8 ).

* Oberen und unteren Splittercontainer holen
    DATA(o_container_top)    = o_split->get_container( row = 1 column = 1 ).
    DATA(o_container_bottom) = o_split->get_container( row = 2 column = 1 ).
* Toolbar für Buttons erzeugen
    DATA(o_tool) = NEW cl_gui_toolbar( parent       = o_container_bottom
                                       display_mode = cl_gui_toolbar=>m_mode_horizontal
                                       align_right  = 1 ).

* Toolbarevents
    DATA(it_events) = VALUE ty_it_events( ( eventid    = cl_gui_toolbar=>m_id_function_selected
                                            appl_event = abap_true ) ).

    o_tool->set_registered_events( events = it_events ).

* Buttons + Separator einfügen
    o_tool->add_button( fcode       = co_btn_ok
                        icon        = icon_okay
                        butn_type   = cntb_btype_button
                        text        = 'Ok'
                        quickinfo   = 'Ok'
                        is_checked  = abap_false
                        is_disabled = abap_false ).

    o_tool->add_button( fcode       = ''
                        icon        = ''
                        butn_type   = cntb_btype_sep
                        text        = ''
                        quickinfo   = ''
                        is_checked  = abap_false
                        is_disabled = abap_false ).

    o_tool->add_button( fcode       = co_btn_cancel
                        icon        = icon_cancel
                        butn_type   = cntb_btype_button
                        text        = 'Abbruch'
                        quickinfo   = 'Abbruch'
                        is_checked  = abap_false
                        is_disabled = abap_false ).

* on_function_selected-Handler
    SET HANDLER on_function_selected FOR o_tool.

* SALV-Grid im oberen Splitter einfügen
    cl_salv_table=>factory( EXPORTING
                              r_container  = o_container_top
                            IMPORTING
                              r_salv_table = o_salv
                            CHANGING
                              t_table      = it_messages ).

* Eigenschaften SALV-Grid
    o_salv->get_columns( )->set_optimize( abap_true ).
    o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
    IF i_show_functions = abap_true.
      o_salv->get_functions( )->set_all( ).
    ENDIF.
    o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).
    o_salv->display( ).

* Dummy-Screen aufrufen und somit cl_gui_container=>default_screen erzeugen -> Trägerdynpro für cl_gui_dialogbox_container
    CALL SCREEN 100.

* nach Buttonclick noch die Ergebnisrückgabe
    rv_ok = gv_retval.
  ENDMETHOD.

  METHOD on_close.

* cl_gui_dialogbox_container bei Klick auf Schließen-Kreuz schließen
    IF sender IS NOT INITIAL.
      sender->free( ).
    ENDIF.

* Zum aufrufenden Dynpro zurück
    LEAVE TO SCREEN 0.

  ENDMETHOD.

* Button ermitteln -> Reaktion -> Setzen des Rückgabewertes beim Schließen des Popups
  METHOD on_function_selected.
    CASE fcode.
      WHEN co_btn_ok.
        gv_retval = abap_true.
      WHEN co_btn_cancel.
        gv_retval = abap_false.
    ENDCASE.

* Popup-Fenster schließen
    on_close( o_cnt ).
  ENDMETHOD.
ENDCLASS.

* Dummy-Screen für cl_gui_container=>default_screen deklarieren
SELECTION-SCREEN BEGIN OF SCREEN 100.
SELECTION-SCREEN END OF SCREEN 100.

START-OF-SELECTION.

* Nachrichtentabelle erzeugen
  DATA(it_msg) = VALUE lcl_popup_msg_box=>ty_it_messagetab( ( idx = 1 text = 'Nachricht 1' )
                                                            ( idx = 2 text = 'Nachricht 2' )
                                                          ).

* Popup mit Nachrichten anzeigen
  IF abap_true = lcl_popup_msg_box=>show( EXPORTING
                                            i_window_title   = 'Meldungen'
                                            i_window_top     = 100
                                            i_window_left    = 100
                                            i_window_width   = 240
                                            i_window_height  = 240
                                            i_show_functions = abap_false
                                            i_it_messages    = it_msg ).
    WRITE: / 'OK.'.
  ELSE.
    WRITE: / 'Abbruch.'.
  ENDIF.

[ABAP] Dialogbox mit SALV-Table ohne zusätzliches Dynpro

* Eventhandlerklasse
CLASS cl_handle_events DEFINITION.
  PUBLIC SECTION.
    METHODS on_close FOR EVENT close OF cl_gui_dialogbox_container
      IMPORTING sender.
ENDCLASS.

CLASS cl_handle_events IMPLEMENTATION.
  METHOD on_close.
    IF sender IS NOT INITIAL.
      sender->free( ).
    ENDIF.
  ENDMETHOD.
ENDCLASS.

DATA: it_sflight TYPE STANDARD TABLE OF sflight.

START-OF-SELECTION.
  " Daten holen
  SELECT * INTO TABLE it_sflight FROM sflight WHERE carrid = 'LH'.

  " Container für Popup erzeugen
  DATA(o_gui_cnt) = NEW cl_gui_dialogbox_container( no_autodef_progid_dynnr = abap_true
                                                    caption = 'Ausgabe Testdaten für Lufthansa'
                                                    top = 20
                                                    left = 20
                                                    width = 1280
                                                    height = 400 ).

  DATA: o_salv TYPE REF TO cl_salv_table.

  " SALV-Table erzeugen
  cl_salv_table=>factory( EXPORTING
                            r_container  = o_gui_cnt
                          IMPORTING
                            r_salv_table = o_salv
                          CHANGING
                            t_table      = it_sflight ).

  " Events registrieren
  DATA(o_events) = NEW cl_handle_events( ).
  SET HANDLER o_events->on_close FOR o_gui_cnt.

  " SALV-Table anzeigen
  o_salv->display( ).

  " Anzeige des Popup erzwingen
  WRITE: / space.