SAP Controls - Workshops

15
SAP Controls Workshop Techniques to simplify the development of essential lists and applications Step-by-step guidance on how to use all container and application controls Benefit immediately from extensively commented, reusable code Harald Röser 10 SAP ® PRESS Essentials ®

description

SAP CONTROLS

Transcript of SAP Controls - Workshops

  • SAP Controls Workshop

    Techniques to simplify the development of essential lists and applications

    Step-by-step guidance on how to use all container and application controls

    Bene t immediately from extensively commented, reusable code

    SAP

    PR

    ESS Essentials 10SA

    P C

    ontrols Workshop

    Harald Rser

    10SA

    P P

    RESS Essentials

    ISBN 1-59229-073-6

    073_cover.indd 1073_cover.indd 1 05.12.2005 17:07:2805.12.2005 17:07:28

  • www.sap-press.com 1

    SAP Controls Workshop

    Harald Rser

    Contents

    1 Introduction ............................................. 3

    2 Classical Controls ................................... 52.1 Tabstrip Control ................................... 5

    2.2 Table Control ....................................... 7

    3 Control Framework ( CFW ) ................. 113.1 Architecture ......................................... 11

    3.2 Automation Queue .............................. 12

    3.3 Event Handling .................................... 14

    3.4 Lifetime Management .......................... 15

    3.5 Class Hierarchy .................................... 15

    3.6 Testing an Application .......................... 16

    4 Custom Containers with Picture Controls ..................................................... 174.1 Basic Program ...................................... 17

    Summary ............................................. 20

    4.2 Controls for Container and Picture ....... 21

    4.3 Method Call ........................................ 24

    Summary ............................................. 26

    4.4 Event Handling .................................... 26

    System Event ...................................... 31

    Summary ............................................. 32

    5 Container Controls ................................. 355.1 Custom Container Control ................... 35

    5.2 Dialog Box Container Control .............. 37

    5.3 Docking Container Control .................. 40

    5.4 Splitter Container Control .................... 42

    5.5 Easy Splitter Container Control ............ 45

    6 SAP HTML Viewer .................................. 49

    7 SAP TextEdit ............................................. 57

    8 SAP Toolbar .............................................. 61

    9 SAP Tree and Tree Model ..................... 699.1 SAP Simple Tree ................................... 70

    9.2 SAP Column Tree ................................. 79

    9.3 SAP List Tree ........................................ 87

    9.4 SAP Tree Model ................................... 92

    10 SAP ALV Grid ........................................... 9910.1 ALV Grid with Prede ned Structure in

    the ABAP Dictionary ............................ 100

    Some Notes on the

    Standard Functions ............................. 103

    10.2 ALV Grid with Display Variant .............. 103

    10.3 ALV Grid with Selectable

    Data Area Layout ................................. 104

    10.4 ALV Grid with Toolbar ......................... 107

    10.5 ALV Grid with Field Catalog ................. 112

    10.6 ALV Grid with Double-Click Event

    and Hotspot ........................................ 116

    11 Context Menu ......................................... 12111.1 Context Menu for the Picture

    Control ................................................ 121

    11.2 Context Menu for Tree Control and

    Tree Model .......................................... 125

    11.3 Context Menu for the ALV Grid

    Control ................................................ 127

  • 2 Galileo Press 2006. All rights reserved.

    Content

    12 Drag&Drop ............................................... 13112.1 The Drag&Drop Operation ................... 132

    12.2 Events of the Drag&Drop Operation .... 132

    12.3 Creating a Sample Application .............. 133

    13 Desktop Of ce Integration ................. 14313.1 Integrating Of ce Applications .............. 144

    13.2 Integrating MS Excel Functions ............. 155

    A Appendix ................................................... 161A.1 Sample Programs .................................... 161

    A.2 Test Data in the Front-End PC ................ 162

    A.3 Online Documentation ........................... 162

    Index ................................................................... 163

  • www.sap-press.com 3

    1 Introduction

    This workshop provides you with a step-by-step intro-

    duction to programming GUI controls. It is intended for

    ABAP developers who have a basic knowledge of dialog

    programming and ABAP Objects. However, if you are not

    yet familiar with object-oriented programming, youll

    soon learn that it is relatively easy to use GUI controls to

    create dialog programs. Furthermore, since GUI controls

    are available exclusively as instances and interfaces, and

    the functions must therefore be called via methods, you

    will nd that this is a very practical exercise that should

    prove helpful to you in your work.

    One of the most common areas of application in which

    controls are used is in the output of controllable lists. You

    probably know that you can create lists in a report using

    the WRITE statement, and even create interactive lists us-ing the HIDE statement. Perhaps youre also familiar with the step loop technique for outputting screen lists in a

    dynpro. During the course of this workshop, you will

    learn about many other ways in which to output data in

    hierarchical and non-hierarchical lists.

    Chapter 2 describes the classical controls. These con-

    trols are encapsulated to such an extent that they can be

    called with the corresponding ABAP statements. Unfor-

    tunately, the request is quite complex with regard to the

    ow logic and the ABAP program, which is why the user

    is supported by a wizard during the implementation pro-

    cess. Nevertheless, this information on the underlying

    concepts should prove useful to you in your work.

    Chapter 3 contains some basic information on the use

    of GUI controls. Since GUI controls are used to develop

    technically sophisticated client/server applications, it is

    critical that you pay attention to certain aspects of these

    controls, so you can enjoy the full range of their function-

    alities. Client/server applications make extensive use of

    the event control from ABAP Objects.

    Chapter 4 shows you howstep by stepto create a

    basic dialog program, which is used as a basis for all sam-

    ple programs in this workshop. You should create this ba-

    sic program in your SAP system as a template. Then, we'll

    use a very simple control to create our rst sample pro-

    gram. We'll also highlight the various event-handling op-

    tions for you.

    Chapter 5 deals with the container concept. Because a

    GUI control cannot be executed on its own, it must al-

    ways be wrapped by a container. SAP provides many dif-

    ferent types of containers, which we'll show you in a

    sample program.

    Chapters 6 through 8 describe various GUI controls

    such as SAP HTML Viewer, SAP TextEdit, and SAP Tool-

    bar. For each of these controls, we'll create a sample pro-

    gram to demonstrate the different functions.

    Chapter 9 deals with the various controls used to out-

    put hierarchical lists. If youre an experienced developer,

    youll already be familiar with this type of output from

    Object Navigator (Transaction SE80). For an easier navi-

    gation, the list is often output in a tree structure contain-

    ing nodes that you can expand and collapse. At the end

    of this chapter, you should be able to implement these

    tree structures in your own applications.

    Chapter 10 revisits the description of screen list out-

    puts. After instancing the necessary objects, youll see

    that you can output very powerful lists with just one

    method call. By default, these lists contain nearly every

    detail you will need. If you previously used many com-

    plex function modules to obtain the same result, this part

    of your life has just become much easier.

    In Chapter 11, you'll be introduced to the controls for

    the context menu. This function is very useful for SAP us-

    ers because it provides context-sensitive support for the

    operation of the system. Unfortunately, all too often, we

    (as developers) simply forget to provide this useful aide in

    our applications. But you'll see that you can easily use

    GUI controls to compensate for this faux pas and make a

    lot of new friends in the user departments.

  • 4 Galileo Press 2006. All rights reserved.

    1 Introduction

    In Chapter 12, we'll describe the Drag&Drop concept

    and use an example to demonstrate the possibilities that

    are available once this functionality is implemented.

    Finally, in Chapter 13, we'll demonstrate that the GUI

    controls concept cannot only be used to integrate con-

    trols provided by SAP, but that the Desktop Of ce Inte-

    gration (DOI) interface enables you to integrate any

    OLE2-enabled external application. The provided inter-

    faces enable you to transfer data directly into of ce ap-

    plications such as MS Word or Excel, or into your own

    Visual Basic programs. In most cases, this data can also be

    retransferred into the SAP system.

    The Appendix contains a list of all sample programs.

    You can download these programs from www.sap-press.

    com/go/essentials, which will save you editing time when

    you reprogram the examples. In any case, you should try

    to create the sample programs yourself. When preparing

    them, we tried to keep the necessary coding effort to a

    minimum. The instancings to classes and the method calls

    can be generated via the Pattern function. Needless to

    say, the programs won't be free of errors initially, how-

    ever, it is precisely this troubleshooting process that in-

    creases the mastery of learning and your understanding

    of the functionality involved. You should copy only the

    source code of the sample solution into your modules if

    you get stuck and no longer know how to proceed. Fur-

    thermore, you should try to identify the cause of the er-

    ror again.

    The online documentation contains a comprehensive

    description of the GUI controls introduced in this book. If

    you want to indulge further into a certain subject, refer-

    ring to the online documentation would be your best

    bet. Unfortunately, sometimes its dif cult to nd the in-

    dividual topics. Therefore, the Appendix contains a de-

    tailed description of the directory paths for Releases 4.6

    and 4.7.

    Before we start, I'd like to provide you with some

    additional information on the sample programs: To obtain a clear design, we'll use the following

    include statements:

    Include Description

    _TOP Data de nitions

    _PAI PAI module

    Include Description

    _PBO PBO module

    _UP FORM routines

    _CL Local classes

    The module pool lists only the include statements,

    with the exception of the include statement for local

    classes, since this statement is always implemented in

    the TOP include. The examples are structured in such a way that you

    can activate the modules between the individual

    steps without causing any syntax errors. You should

    always execute these activation steps to facilitate

    troubleshooting. You will often create sample programs due to copies

    of existing examples or copies of the basic dialog pro-

    gram. The creation of this basic program is described

    in Section 4.1. Section 4.4 describes the procedure of

    copying dialog programs. When copying sample programs, you should note

    that the _CL include statement for local classes will

    not be copied because it is not integrated in the

    module pool, but rather in the TOP include state-

    ment. If you use the copy process to generate sample pro-

    grams, remember that you must create a transaction

    code for the newly-generated program and that you

    should adapt the GUI title. For the examples, we'll use only text literals to im-

    prove the readability of the programs. However, we

    dont recommend that a programmer engage in this

    behavior. Instead, we advise that text elements be

    used. In most of the examples, we'll use the following pro-

    cedure: First, well integrate the module call into the

    ow logic, or the call of the subroutine into the ABAP

    program respectively. Then, you can easily create the

    module or subroutine to be added by simply double-

    clicking on the name. It is imperative that you per-

    form this action in the correct include statement. We'll use the colon (:) as an indicator for program-

    ming code that has been omitted for the purposes of

    clarity and readability.

  • www.sap-press.com 61

    8 SAP Toolbar

    In our last example, we saw that the TextEdit control pro-

    vides an application toolbar. The SAP Toolbar Control

    ( class CL_GUI_TOOLBAR ) enables you to integrate such application toolbars into your own applications, but this

    Toolbar Control must also be embedded into a con-

    tainer.

    You can integrate the following objects in your appli-

    cation toolbar: Button ( with icon and name ) Button ( with dropdown menu )

    If you click on the button, the assigned function is

    triggered. If you click on the arrow next to the but-

    ton, a menu is expanded. Menu

    If you click on the button, a menu is displayed. Splitter bar/separator Button group ( similar to checkboxes ) Toggle buttons ( similar to radio buttons )

    You can arrange the buttons in the application toolbar

    horizontally or vertically. As soon as you click on a but-

    ton, the control framework carries out the event control,

    and simultaneously, the assigned function code is trans-

    ferred to the control framework.

    Note The SAP Toolbar Control assumes that the

    Microsoft Common control is present. The latter is in-

    stalled by the Microsoft Internet Explorer.

    In our example, we'll create a horizontal application tool-

    bar in the dynpro. To respond to the activation of the in-

    dividual buttons, we'll output a corresponding message.

    First create a dialog program called ZCFW_32_TOOL-

    BAR as described in Section 4.1. Assign an appropriate

    GUI title to the program and check whether the program

    is executable.

    Figure 8.1 SAP Toolbar Control

    First, we have to create an area called DYNPRO_CON-

    TAINER with row height 1 for the custom control in the

    dynpro. We'll use the Screen Painter to do that. Then, we

    have to complement the TOP include with the object ref-

    erence variables for the container and the toolbar. Press-

    ing the function key will trigger an event. Therefore, we'll

    provide an internal table and a work area for the registra-

    tion. For event handling, we'll create a local class with a

    handling method. For better readability, we'll encode the

    local class in a separate include statement. We also need

    an object reference variable to instance this class. The in-

    dividual buttons of the application toolbar will be de-

    scribed as elements of an internal table. For the row

    structure and the table type, SAP provides type de ni-

    tions in the type pool CNTB. Since we'll also output an

    icon on the button, we'll use the type pool ICON that

    contains the de nitions for all SAP icons.

    This results in the following implementation for our

    TOP include:

    *&--------------------------------------**& Include ZCFW_32_TOOLBAR_TOP*&--------------------------------------*PROGRAM ZCFW_32_TOOLBAR.

    *&--------------------------------------** Definition for the control framework*&--------------------------------------*

  • 62 Galileo Press 2006. All rights reserved.

    8 SAP Toolbar

    CLASS cl_gui_cfw DEFINITION LOAD.

    *&--------------------------------------** Object reference variables (user* control)*&--------------------------------------*DATA: obj_custom_container TYPE REF TO cl_gui_custom_container, obj_toolbar TYPE REF TO cl_gui_toolbar.

    *&--------------------------------------** Event table*&--------------------------------------*DATA: t_events TYPE cntl_simple_events, wa_event TYPE cntl_simple_event.

    *&--------------------------------------** Define class for event handler and * object reference*&--------------------------------------*INCLUDE ZCFW_32_TOOLBAR_CL.

    DATA: obj_event_receiver TYPE REF TO cl_event_receiver, fcode TYPE ui_func.

    *&--------------------------------------** User action*&--------------------------------------*DATA: okcode TYPE sy-ucomm, save_okcode TYPE sy-ucomm.

    *&--------------------------------------** Table for toolbar buttons*&--------------------------------------*TYPE-POOLS: CNTB.DATA: s_toolbar_button TYPE stb_button, t_toolbar_button TYPE ttb_button.

    *&--------------------------------------** Names of icons* Overview of all icons with report

    * SHOWICON*&--------------------------------------*TYPE-POOLS: icon.

    We can create the include statement for de ning and im-

    plementing the local class by double-clicking on the in-

    clude name. In order to be able to activate the TOP in-

    clude we'll implement the local class as follows:

    *---------------------------------------** INCLUDE ZCFW_32_TOOLBAR_CL*---------------------------------------*

    ****************************************** CLASS cl_event_receiver* DEFINITION*****************************************CLASS cl_event_receiver DEFINITION.ENDCLASS.****************************************** CLASS cl_event_receiver* IMPLEMENTATION*****************************************CLASS cl_event_receiver IMPLEMENTATION.ENDCLASS.

    We'll use three additional PBO modules in our ow logic.

    The PBO module CREATE_OBJECTS will be used to create

    the container and toolbar objects. For registering the

    events at the front-end PC, creating the event handler,

    and registering the events we'll provide the PBO module

    REGISTER_EVENTS. You should already be familiar with

    these steps from the previous examples. The individual

    buttons will now be created in the PBO module CRE-

    ATE_TOOLBAR.

    Create the following ow logic:

    PROCESS BEFORE OUTPUT. MODULE status_0100. MODULE create_objects. MODULE register_events. MODULE create_toolbar.*PROCESS AFTER INPUT.

  • www.sap-press.com 63

    8 SAP Toolbar

    MODULE user_command_0100. MODULE exit_command_0100.

    Then create the PBO modules by double-clicking on the

    module names. In the PBO module CREATE_OBJECTS,

    we'll query whether the custom container object already

    exists. If it doesn't exist, we'll create it and connect it to

    the area in the dynpro. In the next step, we'll instance the

    toolbar control and connect it to the custom container.

    You can use the DISPLAY_MODE parameter to specify

    the orientation of the application toolbar. A horizontal

    application toolbar must have a height of at least one

    row, and a vertical application toolbar should be at least

    four columns wide. Listing 8.1 shows the result.

    *&---------------------------------------------------------**& Module create_objects OUTPUT*&---------------------------------------------------------** Create instances*&---------------------------------------------------------*MODULE create_objects OUTPUT. IF NOT obj_custom_container IS INITIAL. EXIT. ENDIF.*&---------------------------------------------------------** Create instance for custom container*&---------------------------------------------------------* CREATE OBJECT obj_custom_container EXPORTING* PARENT = CONTAINER_NAME = 'DYNPRO_CONTAINER'* STYLE =* LIFETIME = lifetime_default* REPID =* DYNNR =* NO_AUTODEF_PROGID_DYNNR = EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 CREATE_ERROR = 3 LIFETIME_ERROR = 4 LIFETIME_DYNPRO_DYNPRO_LINK = 5 others = 6. IF SY-SUBRC 0. MESSAGE i398(00) WITH 'Error' sy-subrc 'when creating the custom container control'. ENDIF.*&---------------------------------------------------------** Create instance for toolbar control* Note:

    Listing 8.1 PBO Module CREATE_OBJECTS

  • 64 Galileo Press 2006. All rights reserved.

    8 SAP Toolbar

    We recommend that you activate the development ob-

    jects periodically to facilitate troubleshooting in the event

    of an error.

    Now we'll create the PBO module REGISTER_EVENTS

    ( see Listing 8.2 ). To register the event, the static attribute

    M_ID_FUNCTION_SELECTED is available for the EVEN-

    TID parameter in the class CL_GUI_TOOLBAR. To handle the event, we'll use the on_function_selected method.

    * Horizontal application toolbar: >= 1 row* Vertical application toolbar: >= 4 columns*&---------------------------------------------------------* CREATE OBJECT obj_toolbar EXPORTING PARENT = obj_custom_container* SHELLSTYLE =* LIFETIME = DISPLAY_MODE = cl_gui_toolbar=>m_mode_horizontal* DISPLAY_MODE = cl_gui_toolbar=>m_mode_vertical* NAME = EXCEPTIONS CNTL_INSTALL_ERROR = 1 CNTL_ERROR = 2 CNTB_WRONG_VERSION = 3 others = 4. IF SY-SUBRC 0. MESSAGE i398(00) WITH 'Error' sy-subrc 'when creating the toolbar control'. ENDIF.ENDMODULE. " create_objects OUTPUT

    Listing 8.1 PBO Module CREATE_OBJECTS (cont.)

    *&---------------------------------------------------------**& Module register_events OUTPUT*&---------------------------------------------------------** Event handling*&---------------------------------------------------------*MODULE register_events OUTPUT.*&---------------------------------------------------------** Register events as system events at CFW*&---------------------------------------------------------* CLEAR wa_event. CLEAR t_events. wa_event-eventid = CL_GUI_TOOLBAR=>M_ID_FUNCTION_SELECTED. wa_event-appl_event = ' '.

    Listing 8.2 PBO Module REGISTER_EVENTS

  • www.sap-press.com 65

    8 SAP Toolbar

    At this point, we can also create the de nition for the

    handling method. The CL_GUI_TOOLBAR class provides the FUNCTION_SELECTED event. The function code of

    the selected button or menu item is transferred in the

    FCODE parameter. Therefore, we obtain the following

    de nition for the local class:

    CLASS cl_event_receiver DEFINITION. PUBLIC SECTION. METHODS on_function_selected FOR EVENT function_selected OF cl_gui_toolbar IMPORTING fcode sender.ENDCLASS.

    As a response to the user action, we will merely output a

    noti cation message, therefore, we'll create the following

    de nition for our handling method:

    CLASS cl_event_receiver IMPLEMENTATION.*----------------------------------------* Triggering event: function_selected

    * Handling method: on_function_selected*---------------------------------------- METHOD on_function_selected. IF sender = obj_toolbar. CASE fcode. WHEN 'FCODE_CANCEL'. MESSAGE i398(00) WITH 'button CANCEL' 'was pressed !'. WHEN 'FCODE_CREATE'. MESSAGE i398(00) WITH 'button CREATE' 'was pressed !'. WHEN 'FCODE_CHANGE'. MESSAGE i398(00) WITH 'button CHANGE' 'was pressed !'. WHEN 'FCODE_DELETE'. MESSAGE i398(00) WITH 'button DELETE' 'was pressed !'. WHEN 'FCODE_SEARCH'.

    APPEND wa_event TO t_events. CALL METHOD obj_toolbar->set_registered_events EXPORTING EVENTS = t_events EXCEPTIONS CNTL_ERROR = 1 others = 2. IF SY-SUBRC 0. MESSAGE i398(00) WITH 'Error' sy-subrc 'when registering the events'. ENDIF.*&---------------------------------------------------------** Create event handler and register events*&---------------------------------------------------------* IF obj_event_receiver IS INITIAL. CREATE OBJECT obj_event_receiver. SET HANDLER obj_event_receiver->on_function_selected FOR obj_toolbar. ENDIF.ENDMODULE. " register_events OUTPUT

    Listing 8.2 PBO Module REGISTER_EVENTS

  • 66 Galileo Press 2006. All rights reserved.

    8 SAP Toolbar

    MESSAGE i398(00) WITH 'button SEARCH' 'was pressed !'. ENDCASE. ENDIF .*--- Trigger PAI and transfer * function code (system event) ---* CALL METHOD cl_gui_cfw=>set_new_ok_code EXPORTING new_code = fcode. ENDMETHOD.ENDCLASS.

    If you recall, when an event is handled as a system event

    by the control framework, no PAI processing takes place.

    If, in addition to the transferred function code, the con-

    tent of other dynpro elements is required for further pro-

    cessing, the event must either be handled as an applica-

    tion event, or the PAI processing must be explicitly trig-

    gered, by using the set_new_ok_code method in the handling method, for the system event to transfer the

    function code to the PAI modules. In our example, we'll

    use the latter technique.

    In the last PBO module of our ow logic, we must de ne

    the application toolbar. To do this, we must rst de ne

    the individual buttons in an internal table. Then, this list

    of buttons must be added to the toolbar.

    To ll this internal table with the buttons of the appli-

    cation toolbar, the fill_data_buttons_table method is provided with the following parameters:

    Parameter Data type Meaning

    fcode ui_func Function code

    icon c Name of an icon

    disabled c Active/inactive status of button

    butn_type tb_btype Toolbar button type

    text text40 Text on button

    quickinfo iconquick Tooltip for icon

    checked c Button has/has not been selected

    data_table ttb_button Internal table with buttons

    Table 8.1 Parameters for FILL_DATA_BUTTONS_TABLE Method

    To ll the internal table with the individual buttons, we'll

    create a subroutine as shown in Listing 8.3.

    *&---------------------------------------------------------**& Form fill_buttons_data_table*&---------------------------------------------------------** Fill a table * for creating several buttons*&---------------------------------------------------------*FORM fill_buttons_data_table USING p_fcode TYPE ui_func "function code p_icon TYPE c "name of an icon p_type TYPE tb_btype "toolbar button type p_text TYPE text40 "text on buttons p_tip TYPE iconquick "tooltip for icon CHANGING p_ttb_button TYPE ttb_button. "toolbar buttons* Define button and enter in table CALL METHOD cl_gui_toolbar=>fill_buttons_data_table EXPORTING FCODE = p_fcode ICON = p_icon* DISABLED = BUTN_TYPE = p_type

    Listing 8.3 Subroutine for Filling Internal Tables

  • www.sap-press.com 67

    8 SAP Toolbar

    In the PBO module CREATE_TOOLBAR, we'll rst create

    the individual buttons and provide them in the internal

    table. You can obtain a clear and quick overview of the

    existing icons and their names by starting the SHOW-

    ICON report . The following table contains possible but-

    ton types:

    Value Meaning

    cntb_btype_button Button

    cntb_btype_dropdown Button with menu

    cntb_btype_menu Menu

    cntb_btype_sep Splitter bars/separators

    cntb_btype_group Button group

    cntb_btype_check Toggle button

    Table 8.2 Possible Values for the BUTN_TYPE Parameter

    Once we have built up the internal table with the but-

    tons, we must add it to the toolbar. To do this, we'll use

    the add_button_group method. This results in the fol-lowing implementation:

    *&--------------------------------------**& Module create_toolbar OUTPUT*&--------------------------------------** Add list of buttons to* toolbar*&--------------------------------------*

    MODULE create_toolbar OUTPUT. IF NOT t_toolbar_button IS INITIAL. EXIT. ENDIF.*&--------------------------------------** Create table with buttons*&--------------------------------------* PERFORM fill_buttons_data_table USING: 'FCODE_CANCEL' ICON_CANCEL cntb_btype_button 'Cancel' 'Cancel' t_toolbar_button, 'FCODE_CREATE' ICON_CREATE cntb_btype_button 'Create' 'Create' t_toolbar_button, 'FCODE_CHANGE' ICON_CHANGE cntb_btype_button 'Change' 'Change' t_toolbar_button, 'FCODE_DELETE' ICON_DELETE cntb_btype_button 'Delete' 'Delete' t_toolbar_button, 'FCODE_SEARCH' ICON_SEARCH cntb_btype_button 'Search' 'Search' t_toolbar_button.

    TEXT = p_text QUICKINFO = p_tip* CHECKED = CHANGING DATA_TABLE = p_ttb_button EXCEPTIONS CNTB_BTYPE_ERROR = 1 others = 2. IF SY-SUBRC 0. MESSAGE i398(00) WITH 'Error' sy-subrc 'at method fill_buttons_data_table. ENDIF.ENDFORM. " fill_buttons_data_table

    Listing 8.3 Subroutine for Filling Internal Tables (cont.)

  • 68 Galileo Press 2006. All rights reserved.

    8 SAP Toolbar

    *&--------------------------------------** Add list of buttons to* toolbar*&--------------------------------------* CALL METHOD obj_toolbar->add_button_group EXPORTING DATA_TABLE = t_toolbar_button EXCEPTIONS DP_ERROR = 1 CNTB_ERROR_FCODE = 2 others = 3. IF SY-SUBRC 0. MESSAGE i398(00) WITH 'Error' sy-subrc 'at method' 'ADD_BUTTON_GROUP'. ENDIF.ENDMODULE. " create_toolbar OUTPUT

    We'll use the free method again to release the instances. The object reference variables will be initialized with the

    ABAP statement FREE. Therefore, we'll create a subrou-tine that contains the necessary calls. Before the subrou-

    tine ends, the automation queue should be synchronized

    with the cl_gui_cfw=>flush method. Make sure that the subroutine is always called before the application

    exits.

    Furthermore, we'll query the SAP Toolbar function

    codes in the PAI module USER_COMMAND_0100. As a

    prerequisite for this step, we have already implemented

    the cl_gui_cfw=>set_new_ok_code method in the handling method. And nally, to respond to the user ac-

    tion, we'll output a corresponding message again.

    *&--------------------------------------**& Module USER_COMMAND_0100 INPUT*&--------------------------------------** Query user action*---------------------------------------*MODULE user_command_0100 INPUT. save_okcode = okcode. CLEAR okcode.

    CASE sy-dynnr. WHEN 0100. CASE save_okcode. WHEN 'EXIT'. PERFORM free_objects. LEAVE PROGRAM. WHEN 'BACK'. LEAVE TO SCREEN 100.*--- PAI processing upon completion of* handling method ---* WHEN 'FCODE_CANCEL'. MESSAGE i398(00) WITH 'CANCEL PAI processing' 'for button'. WHEN 'FCODE_CREATE'. MESSAGE i398(00) WITH 'CREATE PAI processing' 'for button'. WHEN 'FCODE_CHANGE'. MESSAGE i398(00) WITH 'CHANGE PAI processing' 'for button'. WHEN 'FCODE_DELETE'. MESSAGE i398(00) WITH 'DELETE PAI processing' 'for button'. WHEN 'FCODE_SEARCH'. MESSAGE i398(00) WITH 'SEARCH PAI processing' 'for button'. ENDCASE. ENDCASE.ENDMODULE. " USER_COMMAND_0100 INPUT

    We have now completed our second sample application.

    We should be able to activate all modules without en-

    countering any problems. Start the transaction and click

    on one of the buttons in the SAP Toolbar. You should see

    two sequential messages displayed. The rst message is

    output by the handling method for the system event; the

    second message is output by the PAI module. Where you

    want to program the functionality for the selected button

    depends entirely on your own speci c requirements.

  • www.sap-press.com 163

    Index

    AActiveX Controls 11

    Application event 15, 32

    Automation Controller 11

    Automation Queue 12

    Automation Trace 16

    BBasic program 17

    Business Document Server 26

    CCALL SUBSCREEN 7

    CFW 11

    CFW services 11

    CL_GUI_CFW 13, 15

    CL_GUI_CONTROL 15

    CL_GUI_DIALOGBOX_CONTAINER 39

    CL_GUI_HTML_VIEWER 49

    CL_GUI_OBJECT 15

    CL_GUI_TEXTEDIT 57

    Class Builder 25

    Class hierarchy 15, 35

    CNTL 28

    CNTL_ERROR 13

    Communication 12

    Container control 35

    Control event 32

    Control Framework 11

    Copy 26

    Custom container control 35

    DDebugging 16

    Dialog box container control 37

    Dialog transaction 18

    Docking container control 40

    EEasy splitter container control 45

    Event handling 14

    EXIT_COMMAND_0100 20

    FFlow logic 5

    Flush 12

    FLUSH_ERROR 13

    Flush call 12

    Functional type 20

    GGUI status 18

    GUI title 18

    HHandling method 15

    HTML pages 49

    HTML Viewer control 49

    IInput checks 20

    Internet browser 49

    JJava Beans 11

    LLifetime Management 15

    MMIME documents 49

    Modeless dialog box 37

    OObject Navigator 17

    OK field 5, 14

    Online documentation 8, 24, 37

    PParent parameter 23

    PBO processing 12

    Performance optimization 12

    Picture Control 17

    Process After Input 5

    Process Before Output 5

    RRe-link 36

    Representative classes 12

    Representative object 12, 15

    Result parameters 12

    RFC calls 12

    RFC connection 12

    SSAP HTML Viewer 49

    SAP TextEdit 57

    SAP Toolbar 61

    Screen Painter 5, 21

    SENDER 30

    SET_HANDLER 14

    SET_NEW_OK_CODE 15

    SET_REGISTERED_EVENTS 15

    SHOWICON report 67

    Splitter container control 42

    Start dynpro 17

    Statement pattern 23

    Step loop technique 8

    Subscreen area 5

    Subscreen dynpro 5

    sy-ucomm 14

  • 164 Galileo Press 2006. All rights reserved.

    Index

    Synchronization 12

    Synchronization time 12

    System event 15, 31

    TTable Control 7

    TabStrip 5

    Tabstrip control 5

    Testing 16

    TextEdit Control 57

    TOP include 17

    Trace file 16

    Type group 28

    Type pool 61

    UUP include 18

    URL address 51

    USER_COMMAND_0100 20

    WWizard 8, 9

    Wordwrap 59

    Wrapping 12

    Extract SAP PRESS ESSENTIALSSAP Controls Workshop- Harald Rser---------------------ContentsIntroduction---------------------8 SAP Toolbar---------------------Index---------------------www.sap-press.de(C) Galileo Press GmbH 2005