ABAP面向对象之EVENT处理

原创 2011年01月22日 16:38:00

CLASS counter DEFINITION.
  PUBLIC SECTION.
    METHODS increment_counter.
    EVENTS  critical_value EXPORTING value(excess) TYPE i.
  PRIVATE SECTION.
    DATA: count     TYPE i,
          threshold TYPE i VALUE 10.
ENDCLASS.

CLASS counter IMPLEMENTATION.
  METHOD increment_counter.
    DATA diff TYPE i.
    ADD 1 TO count.
    IF count > threshold.
      diff = count - threshold.
      RAISE EVENT critical_value EXPORTING excess = diff.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

CLASS handler DEFINITION.
  PUBLIC SECTION.
    METHODS handle_excess FOR EVENT critical_value OF counter
            IMPORTING excess.
ENDCLASS.

CLASS handler IMPLEMENTATION.
  METHOD handle_excess.
    WRITE: / 'Excess is', excess.
  ENDMETHOD.
ENDCLASS.

DATA: r1 TYPE REF TO counter,
      h1 TYPE REF TO handler.

START-OF-SELECTION.

  CREATE OBJECT: r1, h1.

  SET HANDLER h1->handle_excess FOR ALL INSTANCES.

  DO 20 TIMES.
    CALL METHOD r1->increment_counter.
  ENDDO.

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

SAP ABAP OO Event

1. Define Event: Event would be defined at the time of class declaration. When using standard SAP ...

BC404学习笔记-ABAP面向对象编程(三)-CAST 向上、向下转型问题.

1.向上、向下中的上下,可以理解成父类和子类。 2.向上转型(up-cast或者narrowing cast)指子类型引用实例化父类型对象,这样父类引用指向子类引用。这样之后父类的引用是访问不了子类的...

BC404学习笔记-ABAP面向对象编程(一)-基础

只摘录注意事项和难以理解的地方。总的来说和JAVA、C++面向对象编程技术差不太多。类、继承、封装之类的概念在abapoo中也都有体现。面向对象的对象简单理解就是现实世界的事物,到编程世界就用类来表现...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)