The dialog box container and the splitter container

This example shows how to use the dialogbox container and the splitter container.

A dialogbox container is created, and a splitter container with 2 rows and 1 column is placed on it.

To keep the example simple row 1 of the splitter container is not used, but you can use it to place a control.

Row 2 is used to place a toolbar control in the buttom of the dialogbox. The toolbar has an OK and a Cancel button. To keep the example simple, these 2 buttons only closes the dialog screen. The dialogbox can also be closed by using the close button in the top right corner of the dialogbox. This button is standard fucntionallity, however you have to do the coding for closing the dialogbox yourself.

Steps:

The screen:

 

The code:

   REPORT sapmz_hf_dialogbox_cont.

   * Icons for the toolbar
   TYPE-POOLS:icon.

   * Predefinition of the event handler class. Necessary if
   * you want to make references to the class before it is defined
   CLASS lcl_event_handler  DEFINITION DEFERRED.

   *----------------------------------------------------------------------
   * G L O B A L   D A T A
   *----------------------------------------------------------------------
   DATA:
     ok_code LIKE sy-ucomm,
   * Dialog container
     go_dialog_container        TYPE REF TO cl_gui_dialogbox_container,
   * Splitter container
     go_splitter_container      TYPE REF TO cl_gui_splitter_container,
   * Event handler class
     go_event_handler           TYPE REF TO lcl_event_handler,
   * SAP Toolbar
     go_toolbar                 TYPE REF TO cl_gui_toolbar.

   *----------------------------------------------------------------------
   * Table and workarea for registration of events. Note that a TYPE REF
   * to cls_event_handler must be created before you can
   * reference types cntl_simple_events and cntl_simple_event.
   *----------------------------------------------------------------------
   DATA:
     gi_events                  TYPE cntl_simple_events,
     g_event                    TYPE cntl_simple_event.

   *---------------------------------------------------------------------*
   *       CLASS lcl_event_handler
   *---------------------------------------------------------------------*
   * This class is used to handle events from the dialobox
   * and the toolbar
   *---------------------------------------------------------------------*
   CLASS lcl_event_handler DEFINITION.
     PUBLIC SECTION.
       METHODS:
   *     Close event of the dialogbox
         on_close
           FOR EVENT close OF cl_gui_dialogbox_container
             IMPORTING sender,
   *     Select event of the toolbar
         on_function_selected
           FOR EVENT function_selected OF cl_gui_toolbar
             IMPORTING fcode.
   ENDCLASS.

   CLASS lcl_event_handler IMPLEMENTATION.
   *----------------------------------------------------------------------
   * Handles the Close event of the dialogbox. The colse event is
   * triggered when the close button in the top right corner of the
   * dialogbox is pushed. Closes the dialog box
   *----------------------------------------------------------------------
     METHOD on_close.
       IF NOT sender IS INITIAL.
         CALL METHOD sender->free
           EXCEPTIONS
             OTHERS = 1.
         IF sy-subrc <> 0.
   *      Error handling
         ENDIF.
         FREE go_dialog_container.
         CLEAR go_dialog_container.
       ENDIF.
     ENDMETHOD.

   *----------------------------------------------------------------------
   * Handles the Function Selected event of the toolbar, which is
   * triggered when one of the buttons on the toolbar is pushed.
   * Both pushbuttons closes the dialogbox
   *----------------------------------------------------------------------
     METHOD on_function_selected.
       CASE fcode.
         WHEN 'OK'.
           CALL METHOD go_dialog_container->free.
           FREE go_dialog_container.
           CLEAR go_dialog_container.


         WHEN 'CANCEL'.
           CALL METHOD go_dialog_container->free.
           FREE go_dialog_container.
           CLEAR go_dialog_container.
       ENDCASE.

     ENDMETHOD.
   ENDCLASS.


   START-OF-SELECTION.
   * Necessary to get access to certain predefined constants
     CLASS cl_gui_cfw DEFINITION LOAD.
     SET SCREEN '100'.


   *&---------------------------------------------------------------------*
   *&      Module  USER_COMMAND_0100  INPUT
   *&---------------------------------------------------------------------*
   * Handles the 2 dynpro pushbuttons on screen
   *----------------------------------------------------------------------
   MODULE user_command_0100 INPUT.
     CASE ok_code.
       WHEN 'EXIT'.
         LEAVE TO SCREEN 0.
       WHEN 'DIALOG'.
         PERFORM show_dialog_box.
     ENDCASE.
   ENDMODULE.                 " USER_COMMAND_0100  INPUT

   *&---------------------------------------------------------------------*
   *&      Form  show_dialog_box
   *&---------------------------------------------------------------------*
   * Performed when the Show dialog box button is pushed.
   *----------------------------------------------------------------------*
   FORM show_dialog_box.

     IF go_dialog_container IS INITIAL.
   *----------------------------------------------------------------------
   *   Create Dialogbox
   *----------------------------------------------------------------------
       CREATE OBJECT go_dialog_container
         EXPORTING
   *       PARENT                      =
           width                       = 400
           height                      = 150
           style                       = cl_gui_control=>ws_sysmenu
   *       REPID                       =
   *       dynnr                       = '100'
   *       LIFETIME                    = lifetime_default
           top                         = 100
           left                        = 350
           caption                     = 'My dialog box'
   *       NO_AUTODEF_PROGID_DYNNR     =
   *       METRIC                      = 0
   *       NAME                        =
         EXCEPTIONS
           CNTL_ERROR                  = 1
           CNTL_SYSTEM_ERROR           = 2
           CREATE_ERROR                = 3
           LIFETIME_ERROR              = 4
           LIFETIME_DYNPRO_DYNPRO_LINK = 5
           EVENT_ALREADY_REGISTERED    = 6
           ERROR_REGIST_EVENT          = 7
           others                      = 8.
       IF sy-subrc <> 0.
   *      Do some error handling..............
       ENDIF.



   *----------------------------------------------------------------------
   * Create Splitter container and configure
   *----------------------------------------------------------------------
       CREATE OBJECT go_splitter_container
         EXPORTING
           parent         =  go_dialog_container
           rows           =  2
           columns        = 1
        EXCEPTIONS
          others = 1.
       IF sy-subrc <> 0.
   *      Do some error handling..............
       ENDIF.

   *   Set row height for row 1
       CALL METHOD go_splitter_container->set_row_height
         EXPORTING
           id             = 1
           height         = 90.

   *   The splitter container should not have a border
       CALL METHOD go_splitter_container->set_border
         EXPORTING
           border = cl_gui_cfw=>false.

   *   Configure the splitter bar. The splitterbar is configures
   *   so that it can't be moved
       CALL METHOD go_splitter_container->set_row_sash
         EXPORTING
           id             = 1    "Configure splitter bar no. 1
           type           = 0    "Type_movable
           value          = 0.   "False



   *----------------------------------------------------------------------
   * Create Toolbar and set parent to the Splitter container
   *----------------------------------------------------------------------
       CREATE OBJECT go_toolbar
         EXPORTING
           parent = go_splitter_container
         EXCEPTIONS
           others = 1.
       IF sy-subrc <> 0.

       ENDIF.


   * Add a buttons
       CALL METHOD go_toolbar->add_button
         EXPORTING
           fcode         = 'OK'              "Function Code
           icon          = icon_okay         "ICON name
           is_disabled   = ' '               "Disabled = X
           butn_type     = cntb_btype_button "Type of button
           text          = 'OK'              "Text on button
           is_checked    = ' '               "Button selected
         EXCEPTIONS
           OTHERS        = 1.
       IF sy-subrc <> 0.
   *      Do some error handling..............
       ENDIF.

       CALL METHOD go_toolbar->add_button
         EXPORTING
           fcode         = 'CANCEL'          "Function Code
           icon          = icon_cancel       "ICON name
           is_disabled   = ' '               "Disabled = X
           butn_type     = cntb_btype_button "Type of button
           text          = 'Cancel'          "Text on button
           is_checked    = ' '               "Button selected
        EXCEPTIONS
           OTHERS = 1.
      IF sy-subrc <> 0.
   *      Do some error handling..............
      ENDIF.

   *----------------------------------------------------------------------
   * Add Toolbar control to row 2 of the Splitter container
   *----------------------------------------------------------------------
       CALL METHOD go_splitter_container->add_control
         EXPORTING row = 2
           column = 1
           control = go_toolbar.


   *----------------------------------------------------------------------
   * Create object for the event handler class
   *----------------------------------------------------------------------
       CREATE OBJECT go_event_handler.

   *----------------------------------------------------------------------
   *   Set Handler for the dialog container. Note that you don't have to
   *   register the events for this class
   *----------------------------------------------------------------------
       SET HANDLER go_event_handler->on_close
           FOR go_dialog_container.

   *----------------------------------------------------------------------
   * Create event handler table for the toolbar control, and register
   * the events
   *----------------------------------------------------------------------

   * Create event table. The event ID must be found in the
   * documentation of the specific control
       CLEAR g_event.
       REFRESH gi_events.
       g_event-eventid    = go_toolbar->m_id_function_selected.
       g_event-appl_event = 'X'.    "This is an application event
       APPEND g_event TO gi_events.

   *   Use the events table to register events for the control
       CALL METHOD go_toolbar->set_registered_events
         EXPORTING
            events = gi_events.

   *   Set handler
       SET HANDLER go_event_handler->on_function_selected
         FOR go_toolbar.

   * Synchronization
       CALL METHOD cl_gui_cfw=>flush.

     ENDIF.
   ENDFORM.                    " show_dialog_box
Converted from CHM to HTML with chm2web Standard 2.7 (unicode)