Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

create cl_gui_toolbar object

Former Member
0 Kudos

Hy, I am creating an cl_gui_toolbar object in this way:

DATA:

container_doc TYPE REF TO cl_gui_custom_container,

g_container_doc TYPE scrfname VALUE 'DOC_ZONE',

add_doc TYPE REF TO cl_gui_toolbar.

CREATE OBJECT container_doc

EXPORTING container_name = g_container_doc.

CREATE OBJECT add_doc

EXPORTING parent = container_doc.

But I cant see anything in my screen, ave i to use another method to set display mode or something like this?

thanx!

9 REPLIES 9

laxmanakumar_appana
Active Contributor
0 Kudos

Hi,

Use add_button to add tool bar buttons

  • Add a button

CALL METHOD go_toolbar->add_button

EXPORTING fcode = 'EXIT' "Function Code

icon = icon_system_end "ICON name

is_disabled = ' ' "Disabled = X

butn_type = cntb_btype_button "Type of button

text = 'Exit' "Text on button

quickinfo = 'Exit program' "Quick info

is_checked = ' '. "Button selected

check this URL :

http://www.henrikfrank.dk/abapexamples/ABAP%20objects%20and%20controls/toolbar_control.htm

Laxman

former_member188685
Active Contributor
0 Kudos

Hi,

Did you check the SAP demo program

<b>SAPTOOLBAR_DEMO1</b>

regards

vijay

0 Kudos

Here is the code for it..

check it..

PROGRAM saptoolbar_demo1.
DATA: mytoolbar TYPE REF TO cl_gui_toolbar,
        mytoolbar_h TYPE REF TO cl_gui_toolbar,
        mytoolbar_v TYPE REF TO cl_gui_toolbar,
        mycontainer_h TYPE REF TO cl_gui_custom_container,
        mycontainer_v TYPE REF TO cl_gui_custom_container,
        b_init TYPE c,
        ok_code LIKE sy-ucomm,
        edfcode TYPE ui_func,
        edicon TYPE iconname,
        edtip TYPE iconquick,
        edtext TYPE text40,
        edtype TYPE tb_btype,
        edoutput(20),
        edposx TYPE i,
        edposy TYPE i,
        rdclick,
        rddrop,
        rdhorz,
        rdvert,
        cbenabled TYPE c,
        cbchecked TYPE c,
        cbvisible TYPE c,
        buttongroup TYPE ttb_button,
        myevent_tab TYPE cntl_simple_events,
        myevent TYPE cntl_simple_event,
*        alignment TYPE i,
        menu_dynamic TYPE REF TO cl_ctmenu,
        menu_static TYPE REF TO cl_ctmenu,
        id_item TYPE cntb_unique_id,
        fcode_item TYPE ui_func,
        tab_btnmnu TYPE ttb_btnmnu,
        wa_btnmnu TYPE stb_btnmnu.

CALL SCREEN 100.

*-----------------------------------------------------------------------
*********************** LCL_MY_EVENT_HANDLER ***************************
*-----------------------------------------------------------------------
CLASS lcl_my_event_handler DEFINITION.

  PUBLIC SECTION.
    METHODS: on_function_selected
               FOR EVENT function_selected OF cl_gui_toolbar
                 IMPORTING fcode,
             on_dropdown_clicked
               FOR EVENT dropdown_clicked OF cl_gui_toolbar
                 IMPORTING fcode posx posy.
ENDCLASS.                    "lcl_my_event_handler DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_my_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS lcl_my_event_handler IMPLEMENTATION.
  METHOD on_function_selected.

    edoutput = fcode.
    edposx = 0.
    edposy = 0.
    CLEAR rddrop.
    rdclick ='X'.

    CASE fcode.
      WHEN 'SET_INFO'.
        CALL METHOD mytoolbar->set_button_info
          EXPORTING
            fcode     = fcode
            icon      = '@0Z@'
            text      = 'change'
            quickinfo = 'just changed'.
    ENDCASE.

  ENDMETHOD.                    "lcl_my_event_handler

  METHOD on_dropdown_clicked.

    edoutput = fcode.
    edposx = posx.
    edposy = posy.
    rddrop ='X'.
    CLEAR rdclick.
    DATA: submenu TYPE REF TO cl_ctmenu,
          subsubmenu TYPE REF TO cl_ctmenu.

    IF menu_dynamic IS INITIAL.
      CREATE OBJECT menu_dynamic.
      CALL METHOD menu_dynamic->add_function
        EXPORTING
          fcode = 'dynamic0'
          text  = text-011.                                 "#EC NOTEXT

      CALL METHOD menu_dynamic->add_separator.

      CALL METHOD menu_dynamic->add_function
        EXPORTING
          fcode = 'dynamic1'
          text  = text-008.                                 "#EC NOTEXT

      CREATE OBJECT subsubmenu.
      CALL METHOD subsubmenu->add_function
        EXPORTING
          fcode       = 'subsub1'
          text        = text-019
          icon        = '@01@'
          accelerator = 'D'.                                "#EC NOTEXT
      CALL METHOD subsubmenu->add_function
        EXPORTING
          fcode       = 'subsub2'
          text        = text-020
          accelerator = 'E'.                                "#EC NOTEXT

      CREATE OBJECT submenu.
      CALL METHOD submenu->add_function
        EXPORTING
          fcode = 'sub1'
          text  = text-017.                                 "#EC NOTEXT
      CALL METHOD submenu->add_function
        EXPORTING
          fcode = 'sub2'
          text  = text-018.                                 "#EC NOTEXT
      CALL METHOD submenu->add_submenu
        EXPORTING
          menu = subsubmenu
          text = text-016
          icon = '@03@'.                                    "#EC NOTEXT

      CALL METHOD menu_dynamic->add_submenu
        EXPORTING
          menu = submenu
          text = text-015.

      CALL METHOD menu_dynamic->add_function
        EXPORTING
          fcode       = 'dynamic3'
          text        = text-010
          checked     = 'X'
          accelerator = 'A'.                                "#EC NOTEXT

      CALL METHOD menu_dynamic->add_function
        EXPORTING
          fcode       = 'dynamic4'
          text        = text-013
          icon        = '@05@'
          checked     = 'X'
          accelerator = 'B'
          disabled    = 'X'.                                "#EC NOTEXT

      CALL METHOD menu_dynamic->add_function
        EXPORTING
          fcode       = 'dynamic5'
          text        = text-014
          icon        = '@07@'
          checked     = 'X'
          accelerator = 'C'
          hidden      = 'X'.                                "#EC NOTEXT

    ENDIF.

    CALL METHOD mytoolbar->track_context_menu
      EXPORTING
        context_menu = menu_dynamic
        posx         = edposx
        posy         = edposy.
  ENDMETHOD.                    "lcl_my_event_handler

ENDCLASS.                    "lcl_my_event_handler IMPLEMENTATION
*-----------------------------------------------------------------------
************************* LCL_MY_EVENT_HANDLER *************************
*-----------------------------------------------------------------------
DATA: evt_receiver TYPE REF TO lcl_my_event_handler.


*-----------------------------------------------------------------------
* module status_0100.
*-----------------------------------------------------------------------
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'TOOLBAR'.
  SET TITLEBAR '001'.
  IF b_init IS INITIAL.

    edfcode = 'test'.                                       "#EC NOTEXT
    edicon  = '@01@'.                                       "#EC NOTEXT
    edtip   = text-004.
    edtext  = 'Test'.                                       "#EC NOTEXT
    edtype = cntb_btype_dropdown.
    cbenabled = 'X'.
    cbvisible = 'X'.
    rdhorz = 'X'.

    myevent-eventid = cl_gui_toolbar=>m_id_function_selected.
    myevent-appl_event = 'X'.
    APPEND myevent TO myevent_tab.
    myevent-eventid = cl_gui_toolbar=>m_id_dropdown_clicked.
    APPEND myevent TO myevent_tab.

    CREATE OBJECT evt_receiver.

    PERFORM create_horz_toolbar.
    mytoolbar = mytoolbar_h.

    b_init = 'X'.
  ENDIF.
ENDMODULE.                    "status_0100 OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE ok_code.
    WHEN 'DISPLAY_MODE'.
      IF rdhorz IS INITIAL.
        IF mytoolbar_v IS INITIAL.
          PERFORM create_vert_toolbar.
        ENDIF.
        mytoolbar = mytoolbar_v.
        CALL METHOD mycontainer_v->set_visible
          EXPORTING
            visible = 'X'.

        CALL METHOD mycontainer_h->set_visible
          EXPORTING
            visible = ''.
      ELSE.
        mytoolbar = mytoolbar_h.
        CALL METHOD mycontainer_h->set_visible
          EXPORTING
            visible = 'X'.

        IF not mytoolbar_v IS INITIAL.
          CALL METHOD mycontainer_v->set_visible
            EXPORTING
              visible = ' '.
        endif.
      ENDIF.

    WHEN 'BACK'.
      IF NOT b_init IS INITIAL.
        CALL METHOD mytoolbar_h->free
          EXCEPTIONS
            OTHERS = 1.
        FREE mytoolbar.

        CALL METHOD mycontainer_h->free
          EXCEPTIONS
            OTHERS = 1.
        FREE mycontainer_h.

        IF NOT mytoolbar_v IS INITIAL.
          CALL METHOD mytoolbar_v->free
            EXCEPTIONS
              OTHERS = 1.
          FREE mytoolbar.

          CALL METHOD mycontainer_v->free
            EXCEPTIONS
              OTHERS = 1.
          FREE mycontainer_v.
        ENDIF.

      ENDIF.
      LEAVE TO SCREEN 0.

    WHEN 'ADD_BUTTON'.
      CALL METHOD mytoolbar->add_button
        EXPORTING
          fcode            = edfcode
          icon             = edicon
          butn_type        = edtype
          text             = edtext
          quickinfo        = edtip
        EXCEPTIONS
          cntb_error_fcode = 1.
      IF sy-subrc = 1.
        PERFORM popup_nonunique_fcode.
      ENDIF.


    WHEN 'ADD_BUTTON_GROUP'.
      CLEAR buttongroup.
      PERFORM fill_data_table
        USING:
        'fc1' '@03@' cntb_btype_button 'button'
                          text-001,                         "#EC NOTEXT
        'fc2' '@04@' cntb_btype_check  'check'
                         text-002,                          "#EC NOTEXT
        ''    ''     cntb_btype_sep '' '',
        'fc3' '@05@' cntb_btype_group  'cg1'
                         text-003,                          "#EC NOTEXT
        'FC4' '@06@' cntb_btype_group  'cg2'
                          text-003,                         "#EC NOTEXT
        ''    ''     cntb_btype_sep '' '',
        'fc5' '@07@' cntb_btype_dropdown  'dropdown'
                          text-004,                         "#EC NOTEXT
        'fc6' '@07@' cntb_btype_menu  'menu'
                          text-005.                         "#EC NOTEXT

      CALL METHOD mytoolbar->add_button_group
        EXPORTING
          data_table       = buttongroup
        EXCEPTIONS
          cntb_error_fcode = 1.
      IF sy-subrc = 1.
        PERFORM popup_nonunique_fcode.
      ENDIF.

    WHEN 'DELETE_BUTTON'.
      CALL METHOD mytoolbar->delete_button
        EXPORTING
          fcode            = edfcode
        EXCEPTIONS
          cntb_error_fcode = 1.
      IF sy-subrc = 1.
        PERFORM popup_nonunique_fcode.
      ENDIF.

    WHEN 'DELETE_ALL'.
      CALL METHOD mytoolbar->delete_all_buttons
        EXCEPTIONS
          OTHERS = 1.
      IF sy-subrc = 1.
*        PERFORM popup_nonunique_fcode.
      ENDIF.

    WHEN 'SET_STATE'.
      CALL METHOD mytoolbar->set_button_visible
        EXPORTING
          fcode            = edfcode
          visible          = cbvisible
        EXCEPTIONS
          cntb_error_fcode = 1.

      CALL METHOD mytoolbar->set_button_state
        EXPORTING
          fcode            = edfcode
          enabled          = cbenabled
          checked          = cbchecked
        EXCEPTIONS
          cntb_error_fcode = 1.
      IF sy-subrc = 1.
*      PERFORM popup_nonunique_fcode.
      ENDIF.

    WHEN 'STATIC_CTXMENU'.

      edfcode = 'STATIC'.                                   "#EC NOTEXT
      edicon  = '@01@'.                                     "#EC NOTEXT
      edtip   = text-007.
      edtext  = 'static menu'.                              "#EC NOTEXT
      edtype = cntb_btype_menu.
      cbenabled = 'X'.

      CALL METHOD mytoolbar->add_button
        EXPORTING
          fcode            = edfcode
          icon             = edicon
          butn_type        = edtype
          text             = edtext
          quickinfo        = edtip
        EXCEPTIONS
          cntb_error_fcode = 1.
      IF sy-subrc = 1.
*        PERFORM popup_nonunique_fcode.
      ENDIF.

      IF menu_static IS INITIAL.
        CREATE OBJECT menu_static.
        CALL METHOD menu_static->add_function
          EXPORTING
            fcode = 'static0'
            text  = text-007.                               "#EC NOTEXT
        CALL METHOD menu_static->add_separator.

        CALL METHOD menu_static->add_function
          EXPORTING
            fcode = 'static1'
            text  = text-008.                               "#EC NOTEXT

        CALL METHOD menu_static->add_function
          EXPORTING
            fcode = 'static2'
            text  = text-009.                               "#EC NOTEXT

        CALL METHOD menu_static->add_function
          EXPORTING
            fcode       = 'static3'
            text        = text-010
            checked     = 'X'
            accelerator = 'A'.                              "#EC NOTEXT

      ENDIF.

      CLEAR tab_btnmnu.

      wa_btnmnu-function = edfcode.
      wa_btnmnu-ctmenu = menu_static.
      APPEND wa_btnmnu TO tab_btnmnu.

      CALL METHOD mytoolbar->assign_static_ctxmenu_table
        EXPORTING
          table_ctxmenu = tab_btnmnu.

    WHEN 'CTXMENU_CHANGE'.
      IF NOT menu_static IS INITIAL.
        CALL METHOD menu_static->add_separator.

        ADD 1 TO id_item.
        CONCATENATE 'item' id_item INTO fcode_item.
        CALL METHOD menu_static->add_function
          EXPORTING
            fcode = fcode_item
            text  = text-012.
      ENDIF.

    WHEN OTHERS.
      CALL METHOD cl_gui_cfw=>dispatch.
  ENDCASE.
  CLEAR ok_code.
ENDMODULE.                    "user_command_0100 INPUT


*   create a toolbar with horizonzal display mode
FORM create_horz_toolbar.
  CREATE OBJECT mycontainer_h
     EXPORTING
       container_name = 'CONTAINER'.                        "#EC NOTEXT

  CREATE OBJECT mytoolbar_h
     EXPORTING
       parent = mycontainer_h.

  CALL METHOD mytoolbar_h->set_registered_events
    EXPORTING
      events = myevent_tab.

  SET HANDLER evt_receiver->on_function_selected
              FOR mytoolbar_h.
  SET HANDLER evt_receiver->on_dropdown_clicked
              FOR mytoolbar_h.
ENDFORM.                    "create_horz_toolbar

*   create a toolbar with vertical display mode
FORM create_vert_toolbar.
*  DATA: evt_receiver_v TYPE REF TO lcl_my_event_handler.

  CREATE OBJECT mycontainer_v
     EXPORTING
       container_name = 'CONTAINER_V'.                      "#EC NOTEXT

  CREATE OBJECT mytoolbar_v
     EXPORTING
       parent = mycontainer_v
      display_mode = cl_gui_toolbar=>m_mode_vertical.

  CALL METHOD mytoolbar_v->set_registered_events
    EXPORTING
      events = myevent_tab.

  SET HANDLER evt_receiver->on_function_selected
              FOR mytoolbar_v.
  SET HANDLER evt_receiver->on_dropdown_clicked
              FOR mytoolbar_v.
ENDFORM.                    "create_vert_toolbar


*---------------------------------------------------------------------*
*       FORM FILL_DATA_TABLE                                          *
*---------------------------------------------------------------------*
FORM fill_data_table
         USING
               fcode  TYPE ui_func
               icon   TYPE iconname
               type   TYPE tb_btype
               text   TYPE text40
               tip    TYPE iconquick.

  CALL METHOD mytoolbar->fill_buttons_data_table
    EXPORTING
      fcode      = fcode
      icon       = icon
      butn_type  = type
      text       = text
      quickinfo  = tip
    CHANGING
      data_table = buttongroup.
ENDFORM.                    "fill_data_table

FORM popup_nonunique_fcode.
  CALL FUNCTION 'POPUP_WITH_WARNING'
    EXPORTING
      textline1 = text-006.
ENDFORM.                    "popup_nonunique_fcode

regards

vijay

0 Kudos

I am interested in create a import document from the system, like you can use it under crm system, in crmd_order, under label documents.

I am afraid I didnt explained correctly in the previous message.

thanx.

0 Kudos

Hi Vijay Babu Dudla

Since you have already mentioned the program name (standard) is there a reason for copy/pasting the code here.

Regards

Raja

0 Kudos

Hi Raja,

Some times the program might not be present in older versions, i don't know in which version he is in. So to avoid that i gave the code also.

nothing else.

regards

vijay

0 Kudos

Hi Hi Vijay Babu Dudla ,

You may be right! Hope you did take my comment in the right sense.

Regards

Raja

mandar_shete
Active Participant
0 Kudos

Hi,

Try following code to get the idea


REPORT  ZTEST_MSS8                              .

include <icon>.
DATA EDITOR TYPE REF TO CL_GUI_TEXTEDIT.
DATA: CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA: okcode type sy-ucomm,
      add_doc TYPE REF TO cl_gui_toolbar.



start-of-selection.

CREATE OBJECT CONT
    EXPORTING
      CONTAINER_NAME              = 'CCTRL'
      REPID                       = SY-REPID
      DYNNR                       = '8000'
    EXCEPTIONS
      CNTL_ERROR                  = 1
      CNTL_SYSTEM_ERROR           = 2
      CREATE_ERROR                = 3
      LIFETIME_ERROR              = 4
      LIFETIME_DYNPRO_DYNPRO_LINK = 5
      OTHERS                      = 6.

CREATE OBJECT ADD_DOC
  EXPORTING
    PARENT             = CONT .

CALL METHOD ADD_DOC->ADD_BUTTON
  EXPORTING
    FCODE            = 'OK'
    ICON             = ICON_CREATE
    BUTN_TYPE        = 2.

call screen 8000.

hymavathi_oruganti
Active Contributor
0 Kudos

hi,

u need to create a screen, place a custom container in that and named it.

cl_gui_toolbar object is a class to handle toolbar in grid i suppose,

so u need to first create a grid in the container of class cl_gui_alv_grid.

u need to call set_table_for_first display to display the grid.

u need to handle the methods for toolbar etc by declaring ur own classes

and then writing SET HANDLER s