Statisches Menu

Aufbau eines Statischen Menüs mithilfe des Toolbar-Controls. Das Beispielprogramm ist weitestgehend objektorientiert programmiert. Der Aufbau des Menüs und die Reaktion auf die Funktionen sind in einer lokalen Klasse implementiert. Es zeigt zu einem Vertriebsbeleg alle verfügbaren Texte an.

Der ausgewählte Text wird markiert und ausgegraut, so dass er nicht erneut ausgewählt werden kann.

Dynpro

CustomControl „Toolbar“

Bitte ein Customcontainer mit Namen „CC_TOOLBAR“ anlegen. Einmal quer oben ins Dynpro.

CustomControl „Text“

Bitte ein Customcontainer mit Namen „CC_TEXT“ für das TextControl anlegen. Etwas größer unter CC_TOOLBAR.

OK-Code

Im OK-Codefeld bitte SY-UCOMM eintragen.

GUI-Status

Ein GUI-Status ist nicht notwendig; es wird ein Standard-GUI-Status verwendet.

Ablauflogik

PROCESS BEFORE OUTPUT.
 MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
 MODULE USER_COMMAND_0100.

Coding

REPORT  zz_textauswahl.
TYPE-POOLS icon.
CLASS lcl_my_toolbar_class DEFINITION DEFERRED.
DATA gr_toolbar TYPE REF TO lcl_my_toolbar_class.

PARAMETER p_vbeln TYPE vbeln DEFAULT ‚0000076543‘.

START-OF-SELECTION.

  CALL SCREEN 100.


*———————————————————————-*
*       CLASS lcl_my_toolbar_class DEFINITION
*———————————————————————-*
CLASS lcl_my_toolbar_class DEFINITION.

  PUBLIC SECTION.
    DATA gv_tdid      TYPE tdid.
    DATA gv_vbeln     TYPE vbeln.
    DATA menu_static  TYPE REF TO cl_ctmenu.
    DATA mytoolbar    TYPE REF TO cl_gui_toolbar.
    DATA lt_ttxern    TYPE STANDARD TABLE OF ttxern.
    DATA lt_ttxid     TYPE STANDARD TABLE OF ttxid.
    DATA lt_ttxit     TYPE STANDARD TABLE OF ttxit.
    DATA gr_textedit           TYPE REF TO cl_gui_textedit.

    METHODS: constructor
                 IMPORTING fi_toolbar_container TYPE c
                           fi_text_container    TYPE c
                           fi_vbeln             TYPE vbeln
                           fi_auart             TYPE auart,
             on_function_selected
               FOR EVENT function_selected OF cl_gui_toolbar
                 IMPORTING fcode,

             add_entry
                 IMPORTING fi_fcode TYPE ui_func
                           fi_ftext TYPE text40,
             read_texts
                 IMPORTING fi_vbeln TYPE vbeln
                           fi_auart TYPE auart,
             set_button_title
                 IMPORTING fi_fcode TYPE ui_func PREFERRED PARAMETER fi_fcode,
             build_toolbar,
             build_menu.

ENDCLASS.                    „lcl_my_event_handler DEFINITION

*———————————————————————-*
*       CLASS lcl_my_toolbar_class IMPLEMENTATION
*———————————————————————-*
CLASS lcl_my_toolbar_class IMPLEMENTATION.

  METHOD constructor.

    DATA myevent_tab           TYPE cntl_simple_events.
    DATA myevent               TYPE cntl_simple_event.
    DATA my_toolbar_container  TYPE REF TO cl_gui_custom_container.
    DATA my_text_container     TYPE REF TO cl_gui_custom_container.

***___________________________________________________________________
***
*** TextControl
***___________________________________________________________________
***

    CREATE OBJECT my_text_container
      EXPORTING
        container_name = fi_text_container.                 „#EC NOTEXT
    CREATE OBJECT gr_textedit
      EXPORTING
        wordwrap_mode     = cl_gui_textedit=>wordwrap_at_windowborder
        wordwrap_position = -1
        parent            = my_text_container
      EXCEPTIONS
        OTHERS            = 6.

    CALL METHOD gr_textedit->set_readonly_mode
      EXPORTING
        readonly_mode = 1.

***___________________________________________________________________
***
*** ToolbarControl
***___________________________________________________________________
***

    CREATE OBJECT my_toolbar_container
      EXPORTING
        container_name = fi_toolbar_container.              „#EC NOTEXT

    CREATE OBJECT mytoolbar
      EXPORTING
        parent = my_toolbar_container.

    myevent-eventid    = cl_gui_toolbar=>m_id_function_selected.
    myevent-appl_event = ‚X‘.
    APPEND myevent TO myevent_tab.

    CALL METHOD mytoolbar->set_registered_events
      EXPORTING
        events = myevent_tab.

    SET HANDLER on_function_selected  FOR mytoolbar.

***___________________________________________________________________
***
*** Set Toolbar
***___________________________________________________________________
***

    gv_vbeln = fi_vbeln.

    CALL METHOD read_texts
      EXPORTING
        fi_vbeln = fi_vbeln
        fi_auart = fi_auart.
    CALL METHOD set_button_title( space ).

 

  ENDMETHOD.                    „constructor

  METHOD read_texts.

    FIELD-SYMBOLS <ttxern> TYPE ttxern.
    FIELD-SYMBOLS <ttxit>  TYPE ttxit.
    FIELD-SYMBOLS <ttxid>  TYPE ttxid.
    DATA lv_txtgr TYPE tvak-txtgr.
    DATA lv_auart TYPE auart.
    DATA ls_ttxit TYPE ttxit.

    IF fi_vbeln IS NOT INITIAL.
      SELECT SINGLE auart FROM vbak INTO lv_auart WHERE vbeln = fi_vbeln.
    ELSE.
      lv_auart = fi_auart.
    ENDIF.

    SELECT SINGLE txtgr FROM tvak INTO lv_txtgr
     WHERE auart = lv_auart.

    IF lv_txtgr <> space.
      SELECT * FROM ttxern INTO TABLE lt_ttxern
       WHERE txtob    = ‚A‘
         AND tdobject = ‚VBBK‘
         AND txtgr    = lv_txtgr.
      IF sy-subrc = 0.
        SELECT * FROM ttxid INTO TABLE lt_ttxid
          FOR ALL ENTRIES IN lt_ttxern
         WHERE tdobject = lt_ttxern-tdobject
           AND tdid     = lt_ttxern-tdid.

        LOOP AT lt_ttxid ASSIGNING <ttxid>.
          SELECT SINGLE * FROM ttxit INTO ls_ttxit
           WHERE tdobject = <ttxid>-tdobject
             AND tdid     = <ttxid>-tdid
             AND tdspras  = sy-langu.
          IF sy-subrc > 0.
            ls_ttxit-tdobject = <ttxid>-tdobject.
            ls_ttxit-tdid     = <ttxid>-tdid.
            ls_ttxit-tdspras  = sy-langu.
            ls_ttxit-tdtext   = <ttxid>-tdid.
          ENDIF.
          APPEND ls_ttxit TO lt_ttxit.
        ENDLOOP.
      ENDIF.
    ENDIF.

    READ TABLE lt_ttxit ASSIGNING <ttxit> INDEX 1.
    IF sy-subrc = 0.
      gv_tdid = <ttxit>-tdid.
    ENDIF.

  ENDMETHOD.                    „read_texts

  METHOD on_function_selected.


*    MESSAGE s000(oo) WITH ‚Funktion‘ fcode.
    gv_tdid = fcode.
    CALL METHOD set_button_title( fcode ).

  ENDMETHOD.                    „lcl_my_event_handler

  METHOD set_button_title.
    FIELD-SYMBOLS <ttxit>  TYPE ttxit.

    DATA lv_text  TYPE text40.
    DATA lv_info  TYPE iconquick.
    DATA lv_icon  TYPE iconname.
    DATA lv_fcode TYPE ui_func.
    DATA lv_tname TYPE thead-tdname.
    DATA lt_lines TYPE STANDARD TABLE OF tline.

    IF fi_fcode IS INITIAL.
      lv_fcode = gv_tdid.
    ELSE.
      lv_fcode = fi_fcode.
    ENDIF.

    READ TABLE lt_ttxit ASSIGNING <ttxit> WITH KEY tdid = lv_fcode.
    CHECK sy-subrc = 0.
    CONCATENATE ‚Text‘ <ttxit>-tdid <ttxit>-tdtext INTO lv_text SEPARATED BY space.
    CALL METHOD build_toolbar.
    lv_icon = icon_column_right.
    CALL METHOD mytoolbar->set_button_info
      EXPORTING
        fcode = ‚TEXT‘
        icon  = lv_icon
        text  = lv_text.

    IF gv_vbeln IS NOT INITIAL.
      lv_tname = gv_vbeln.
      CLEAR lt_lines.
      CALL FUNCTION ‚READ_TEXT‘
        EXPORTING
          id       = gv_tdid
          language = sy-langu
          name     = lv_tname
          object   = ‚VBBK‘
        TABLES
          lines    = lt_lines
        EXCEPTIONS
          OTHERS   = 8.
      CALL METHOD gr_textedit->set_text_as_r3table
        EXPORTING
          table = lt_lines.

    ENDIF.

  ENDMETHOD.                    „set_button_title

  METHOD build_menu.

    DATA tab_btnmnu TYPE ttb_btnmnu.
    DATA wa_btnmnu  TYPE stb_btnmnu.
    DATA lv_fcode   TYPE ui_func.
    DATA lv_ftext   TYPE text40.

    CHECK mytoolbar IS BOUND.
    FIELD-SYMBOLS <ttxit>  TYPE ttxit.


    IF  menu_static IS INITIAL.
      CREATE OBJECT menu_static.
    ELSE.
      CALL METHOD menu_static->clear.
    ENDIF.

    LOOP AT lt_ttxit ASSIGNING <ttxit>.
      lv_fcode = <ttxit>-tdid.
      lv_ftext = <ttxit>-tdtext.
      CALL METHOD add_entry
        EXPORTING
          fi_fcode = lv_fcode
          fi_ftext = lv_ftext.
    ENDLOOP.

    CLEAR tab_btnmnu.

    wa_btnmnu-function = ‚TEXT‘.
    wa_btnmnu-ctmenu   = menu_static.
    APPEND wa_btnmnu TO tab_btnmnu.

    CALL METHOD mytoolbar->assign_static_ctxmenu_table
      EXPORTING
        table_ctxmenu = tab_btnmnu.
  ENDMETHOD.                    „build_menu

  METHOD add_entry.
    DATA lv_mark TYPE c.
    IF gv_tdid = fi_fcode.
      lv_mark = ‚X‘.
    ELSE.
      lv_mark = space.
    ENDIF.
    CALL METHOD menu_static->add_function
      EXPORTING
        fcode    = fi_fcode
        text     = fi_ftext
        checked  = lv_mark
        disabled = lv_mark.
  ENDMETHOD.                    „add_entry

  METHOD build_toolbar.
    IF mytoolbar IS BOUND.
      CALL METHOD mytoolbar->delete_all_buttons.
    ENDIF.

    CALL METHOD mytoolbar->add_button
      EXPORTING
        fcode            = ‚TEXT‘
        icon             = icon_display_text
        butn_type        = cntb_btype_menu
        text             = ‚Texte‘
        quickinfo        = ‚Texte anzeigen‘
      EXCEPTIONS
        cntb_error_fcode = 1.
    CALL METHOD build_menu.


  ENDMETHOD.                    „build_toolbar

ENDCLASS.                    „lcl_my_event_handler IMPLEMENTATION


*&———————————————————————*
*&      Module  STATUS_0100  OUTPUT
*&———————————————————————*
MODULE status_0100 OUTPUT.

  SET PF-STATUS ‚STLI‘ OF PROGRAM ‚SAPMSSY0‘.

  IF gr_toolbar IS INITIAL.
    CREATE OBJECT gr_toolbar
      EXPORTING
        fi_toolbar_container = ‚CC_TOOLBAR‘
        fi_text_container    = ‚CC_TEXT‘
        fi_auart             = space                        „‚ZDO1‘
        fi_vbeln             = p_vbeln.
  ENDIF.

ENDMODULE.                 “ STATUS_0100  OUTPUT

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

  CASE sy-ucomm.
    WHEN ‚BACK‘ OR ‚%EX‘ OR ‚RW‘.
      SET SCREEN 0.
      LEAVE SCREEN.
  ENDCASE.

ENDMODULE.                 “ USER_COMMAND_0100  INPUT

 

Enno Wulff
follow me