• ABAPHow to use controls


    How to use controls
     

    How to:

    General
    Synchronization/Flush
    Set up event handling for controls
    Declare a reference variable before the class has been defined
    Set focus to a control


     Control Framework and enheritance hierarchy
    The control framework consists of 2 parts:

    CL_GUI_CFW contains methods that provide services for communication with the frontend, and can be used both by control wrapper calsses and by control progtrammers
    The CL_GUI_OBJECT encapsulates ActiveX or JavaBeans methods, while CL_GUI_CONTROL is responsible for displaying the control on the screen.
    CL_GUI_OBJECT -> CL_GUI_CONTROL -> CL_GUI_* (Wrapper class)

    These classes contains methods that are enherited by subsequent classes in the enheritance tree. 

    RFC calls is used to synchronize the front and backend. This synchronization takes palce at some predifined points in the program flow. However you should not rely entirely on automatic synchronization, but force synchronization with the Flush method when necessary.

    Bear in mind that the synchronization/RFC calls represenmts a bottleneck, so you should keep the not use the Flush method to a minimum.

    Syntax:

    CALL METHOD cl_gui_cfw=>FLUSH 

    There are two types of events:

    Application events. T

    The flow logic of the screen is processed after the event (The PAI module is processed).

    In the events table the event must be registred as an application event by setting then field appl_event to 'X':

    wa_events-eventid = cl_gui_textedit=>event_double_click.
    wa_events-appl_event = 'X'.
    append wa_events to i_events.

    Important: The dispatch method of cl_gui_cfw must be called in the PAI module:

    CALL METHOD cl_gui_cfw=>dispatch.

    System events.

    For system events the flow-logic of the screen is not executed. That means that the PAI and PBO modules are not processed.

    In the events table the the field appl_event must be set to SAPCE:

    wa_events-eventid = cl_gui_textedit=>event_double_click.
    wa_events-appl_event = space.
    append wa_events to i_events.

    The dispatch method of cl_gui_cfw must NOT be called.

    Example

    It is presumed that a SAP toolbar control named go_toolbar of class cl_gui_toolbar has been defined. To see a complete example of how to handle events, refer to The SAP toolbar control.

    Data:
    * 1.  Define and instance of the eventhandler class.
    *      If the event handler class is defined after the data decalaration
    *      the class must be declared as DEFERRED in the top of the program:  CLASS cls_event_handler DEFINITION DEFERRED.
      go_event_handler TYPE REF TO cls_event_handler,
    * 2. Define table 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
      gi_events TYPE cntl_simple_events,
    * Workspace for table gi_events
      g_event TYPE cntl_simple_event.
    * 3. Define and implement eventhandler class
    CLASS cls_event_handler DEFINITION.
      PUBLIC SECTION.
        METHODS:
    *     Syntax:
    *     <method name> FOR EVENT <event of control - see the control documentation>
    *         OF <class of object> <importing parameters l - see the control documentation>
          on_function_selected
            FOR EVENT function_selected OF cl_gui_toolbar
              IMPORTING fcode,
    ENDCLASS.
    CLASS cls_event_handler IMPLEMENTATION.
       METHOD on_function_selected.
    *     Do something when the event is raised
      ENDMETHOD.
    ENDCLASS.
    * 4. Append events to the events table
    *     The Event Id  can be found in the control documentation. Note that The event below is registred as an application event
     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.
    .... append more events i necessary...
    * 5. Use the events table to register events for the control
        CALL METHOD go_toolbar->set_registered_events
            EXPORTING
               events = gi_events.
    * 6. Create event handler
    CREATE OBJECT   go_event_handler.
    * Syntax:
    * SET HANDLER <event handler class> -> <Event handler method>
    *   FOR <control>
    SET HANDLER go_event_handler->on_function_selected
          FOR go_toolbar.
    Scenario: DATA: o_my_class TYPE REF TO lcl_myclass.

    CLASS lcl_myclass.....
    ENDCLASS.

    This will cause an error because the definition of class lcl_myclass is after the declaration.

    Solution:

    Define the class in the beginning of the program with DEFINITION DEFERRED:

    CLASS lcl_myclass DEFINITION DEFERRED.

    DATA: o_my_class TYPE REF TO lcl_myclass.

    CLASS lcl_myclass.....
    ENDCLASS. 

    Set the focus to a control named go_grid:

    CALL METHOD cl_gui_control=>set_focus
      EXPORTING control = go_grid.
     

  • 相关阅读:
    利用iframe实现ajax 跨域通信的解决方案
    C++中事件机制的简洁实现
    java远程类加载与轻客户端
    iOS开发那些事性能优化–内存泄露问题的解决
    Asp.net项目的开发流程
    LVS配置教程
    PowerShell之东扯西谈
    响应式设计专题
    2013年最值得关注的网页设计流行趋势
    HTTP Live Streaming直播技术分析与实现
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157300.html
Copyright © 2020-2023  润新知