zoukankan      html  css  js  c++  java
  • SET HANDLER

    Syntax

    SET HANDLER handler1 handler2 ... FOR { oref |{ALL INSTANCES} } 
                                      [ACTIVATION act]

    Extras:

    1. ... FOR oref 

    2. ... FOR ALL INSTANCES 

    3. ... ACTIVATION act 

    Effect

    This statement registers the event handlers handler1 handler2 ... for the associated instance events of the objects specified after FOR. The addition ACTIVATION can be used to deregister event handlers or perform a dynamic registration.

    An event handler is raised if the associated instance event is raised using RAISE EVENT in an object for which it is registered. An event handler handler can be specified as follows, where the names have the same meaning as in the explicit method call:

    • meth 

    • oref->meth 

    • class=>meth 

    Methods meth can be specified from the same class or from other classes defined as instance event handlers using the addition FOR EVENT evt OF {class|intf} of the statements [CLASS-]METHODS. No event handlers for static events can be specified. At least one name must be specified.

    The type class or intf specified after FOR EVENT OF in the definition of an instance event handler defines the objects whose events it can handle. Single objects or all handleable objects can be specified after FOR. 

    Addition 1

    ... FOR oref 

    Effect

    This addition registers or deregisters the event handlers of the list handler1 handler2 ... for exactly one object. oref is an object reference that must point to an object whose events can be handled by the specified event handlers. The class of the object must be class or a subclass of class, or must implement the interface intf directly or through a superclass.

    oref is a functional operand position.

    Example

    Registers an event handler for an ALV event.

    CLASS demo DEFINITION. 
      PUBLIC SECTION. 
        METHODS main. 
      PRIVATE SECTION. 
        DATA itab TYPE TABLE OF scarr. 
        METHODS handle_double_click 
                FOR EVENT double_click OF cl_salv_events_table. 
    ENDCLASS. 
    
    CLASS demo IMPLEMENTATION. 
      METHOD main. 
        DATA alv TYPE REF TO cl_salv_table. 
        ... 
        TRY. 
            cl_salv_table=>factory( 
              IMPORTING r_salv_table = alv 
              CHANGING  t_table      = itab ). 
            SET HANDLER handle_double_click FOR alv->get_event( ). 
          CATCH cx_salv_msg. 
            ... 
        ENDTRY. 
      ENDMETHOD. 
      METHOD handle_double_click. 
         ... 
      ENDMETHOD. 
    ENDCLASS. 
    

      

    Addition 2

    ... FOR ALL INSTANCES 

    Effect

    This addition registers or deregisters the event handlers of the list handler1 handler2 ... for all objects whose events they can handle. These are all objects whose classes are either class or the subclass of class, or which implement the interface intf directly or through a superclass. A registration of this type is also valid for all raising instances created after the statement SET HANDLER.

    Note

    Registration with FOR ALL INSTANCES applies also in particular for temporary instances as they can be created when using the instantiaion operator NEW

    Addition 3

    ... ACTIVATION act 

    Effect

    A single-character text-like field act can be specified after the addition ACTIVATION. If act has the value "X" (the default value), the event handlers handler are registered. If act has the value " ", however, the registration of the event handlers handler is canceled. A single registration cannot, on the other hand, be deregistered using mass deregistration. Conversely, individual raising objects cannot be excluded from registration after a mass registration.

    Note

    As long as the registration of an instance method as an event handler for an instance event is not canceled using ACTIVATION " " or all raising instances are deleted, the associated object cannot be deleted by the garbage collector. This is because it is still used by the runtime environment. 

    Example

    Registers an event handler with FOR ALL INSTANCES. The events of all temporary instances created with NEW are handled until registration is stopped. The program can be executed as DEMO_SET_HANDLER_FOR_ALL.

    CLASS cls DEFINITION. 
      PUBLIC SECTION. 
        EVENTS evt 
          EXPORTING VALUE(p) TYPE string DEFAULT `nop`. 
        METHODS meth 
          IMPORTING p TYPE string. 
    ENDCLASS. 
    
    CLASS cls IMPLEMENTATION. 
      METHOD meth. 
        RAISE EVENT evt EXPORTING p = p. 
      ENDMETHOD. 
    ENDCLASS. 
    
    CLASS hdl DEFINITION. 
      PUBLIC SECTION. 
        METHODS meth FOR EVENT evt OF cls 
          IMPORTING p. 
    ENDCLASS. 
    
    CLASS hdl IMPLEMENTATION. 
      METHOD meth. 
        cl_demo_output=>write( p ). 
      ENDMETHOD. 
    ENDCLASS. 
    
    START-OF-SELECTION. 
      DATA(href) = NEW hdl( ). 
      SET HANDLER href->meth FOR ALL INSTANCES. 
    
      NEW cls( )->meth( `Ping 1`). 
      NEW cls( )->meth( `Ping 2`). 
      NEW cls( )->meth( `Ping 3`). 
    

      



      SET HANDLER href->meth FOR ALL INSTANCES ACTIVATION ' '. 

      NEW cls( )->meth( `Ping 4`). 
      NEW cls( )->meth( `Ping 5`). 
      NEW cls( )->meth( `Ping 6`). 

      cl_demo_output=>display( ). 

  • 相关阅读:
    IS上部署MVC网站,打开后ExtensionlessUrlHandler-
    深拷贝与浅拷贝
    python小技巧---打印出不同颜色的输出
    环境搭建之allure的安装配置,及简单使用
    Python进行JSON格式化输出,以及汉字显示问题
    无限遍历,Python实现在多维嵌套字典、列表、元组的JSON中获取数据
    环境准备—之—linux下安装svn--开机自启--及format权限问题
    环境准备—之—linux下安装python3和pip3
    环境准备—之—linux下安装jdk
    问题1——之Linux虚拟机ip地址消失
  • 原文地址:https://www.cnblogs.com/yjyongil/p/10722034.html
Copyright © 2011-2022 走看看