SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Dialog Box and Splitter Containers



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dialog Programming
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Fri Nov 23, 2007 10:28 pm    Post subject: Dialog Box and Splitter Containers Reply with quote

This example shows how to use the dialog box container and the splitter container.

A dialog box 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 button of the dialog box. The toolbar has an OK and a Cancel button. To keep the example simple, these 2 buttons only closes the dialog screen. The dialog box can also be closed by using the close button in the top right corner of the dialog box. This button is standard functionality, however you have to do the coding for closing the dialog box yourself.

Steps:
  • Create a screen
  • Place dynpro button on the screen that opens the dialog box. Name: DIALOG_BUTTON. Caption: Show dialog box. Function code: DIALOG
  • Place another dynpro on the screen to exit the program. Name: EXIT_BUTTON. Caption: Exit. Function code: EXIT.
  • Place a custom control on the screen for the dialog box. Name: DIALOG_CONTAINER
  • Place a custom control on the screen for the toolbar control. Name: TOOLBAR_CONTAINER


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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dialog Programming All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.