zoukankan      html  css  js  c++  java
  • ABAP Help Document(11):4.数据对象定义

    4.Declarations

        ABAP定义数据类型(Data Types)和数据对象(Data objects)。数据类型只是描述信息,除描述管理内存外不占用额外内存,数据对象根据数据类型为模板占用内存空间。

    4.1数据类型

        ABAP使用TYPES定义数据类型

    示例:

    "数据定义
    FORM f_declar_data_type.
      "定义数据类型
      "语法:
      "使用ABAP类型
      "1. TYPES { {dtype[(len)] TYPE abap_type [DECIMALS dec]}
      "   | {dtype TYPE abap_type [LENGTH len] [DECIMALS dec]} }.
      "C,N,P,X必须指定长度,其他类型不用指定长度
      "b,s类型不能使用,仅ABAP内部使用
      TYPES: type1(10) TYPE C.
      TYPES: type2 TYPE C LENGTH 10.
    
      "使用已定义数据类型
      "2. TYPES dtype { {TYPE [LINE OF] type}
      "         | {LIKE [LINE OF] dobj}  }.
      TYPES: type3 TYPE type1.
    
      "类,接口使用引用
      "3. TYPES dtype { {TYPE REF TO type}
      "  | {LIKE REF TO dobj} }.
    *  INTERFACE i1.
    *   ...
    *  ENDINTERFACE.
    *  CLASS c1 DEFINITION.
    *    PUBLIC SECTION.
    *      INTERFACES i1.
    *  ENDCLASS.
    *  TYPES: iref TYPE REF TO i1,
    *         cref TYPE REF TO c1,
    *         dref TYPE REF TO iref.
    
       "使用结构体定义
       "4. TYPES BEGIN OF struc_type.
       "...
       " TYPES comp ...
       " TYPES comp TYPE struc_type BOXED.
       " INCLUDE {TYPE|STRUCTURE} ...
       " ...
       "TYPES END OF struc_type.
        TYPES: BEGIN OF street_type,
               name TYPE c LENGTH 40,
               no   TYPE c LENGTH 4,
             END OF street_type.
        TYPES: BEGIN OF address_type,
               name TYPE c LENGTH 30,
               street TYPE street_type,
               BEGIN OF city,
                 zipcode TYPE n LENGTH 5,
                 name TYPE c LENGTH 40,
               END OF city,
             END OF address_type.
        TYPES:zipcode_type TYPE address_type-city-zipcode.
    
        "table类型
        "5. TYPES dtype { {TYPE tabkind OF [REF TO] type}
        "         | {LIKE tabkind OF dobj} }
        "         [tabkeys] [INITIAL SIZE n].
    
        "tabkind:
        "{ {[STANDARD] TABLE}
        "| {SORTED TABLE}
        "| {HASHED TABLE}
        "| {ANY TABLE}
        "| {INDEX TABLE} }
        "standard,sorted table使用primary table index
        "hashed table使用hash公式
    
        "tabkeys
        "[ WITH key ]
        "指定主键
        "[ WITH secondary_key1 ] [ WITH secondary_key2 ]
        "最多15个次要键
        "[ {WITH|WITHOUT} FURTHER SECONDARY KEYS ]
    
        "key
        "[UNIQUE | NON-UNIQUE]
        "{ {KEY [primary_key [ALIAS key_name] COMPONENTS] comp1 comp2 ...}
        "| {DEFAULT KEY} }
        
        "secondary_key
        "{UNIQUE HASHED}|{UNIQUE SORTED}|{NON-UNIQUE SORTED} 
        "KEY key_name COMPONENTS comp1 comp2.
    
        "[INITIAL SIZE n],指定初始时内表内存占用大小
    
        "OCCURS已经弃用
        TYPES:tab1 TYPE STANDARD TABLE OF type1.
        TYPES:tab2 TYPE TABLE OF type1.
        TYPES:tab3 TYPE SORTED TABLE OF type1.
        TYPES:tab4 TYPE HASHED TABLE OF type1.
        "standard table使用NON-UNIQUE key
        TYPES:tab5 TYPE STANDARD TABLE OF spfli WITH NON-UNIQUE KEY carrid connid.
        "sorted table都可以,hashed table只能是UNIQUE key
        TYPES:tab6 TYPE SORTED TABLE OF spfli WITH UNIQUE KEY carrid connid.
        "使用primary_key,通过alias指定别名
        TYPES:tab7 TYPE SORTED TABLE OF spfli
          WITH UNIQUE KEY PRIMARY_KEY
          ALIAS pri_key1
          COMPONENTS carrid connid.
    
        "range table类型
        "6. TYPES dtype {TYPE RANGE OF type}|{LIKE RANGE OF dobj}
        "         [INITIAL SIZE n].
        "range table 是标准表
    *    TYPES: BEGIN OF linetype,
    *         sign   TYPE c LENGTH 1,
    *         option TYPE c LENGTH 2,
    *         low    {TYPE type}|{LIKE dobj},
    *         high   {TYPE type}|{LIKE dobj},
    *       END OF linetype.
        TYPES:rtab1 TYPE RANGE OF type1.
    
        "LOB Handle type
        "7. TYPES dtype TYPE dbtab lob_handle_type FOR lob_handle_columns
        "  [lob_handle_type FOR lob_handle_columns ].
        "lob_handle_type
        "{ READER|LOCATOR|{LOB HANDLE} } | { WRITER|LOCATOR }
        "lob_handle_columns
        "{ COLUMNS blob1 blob2 ... clob1 clob2 ... } | { ALL [OTHER] [BLOB|CLOB] COLUMNS }
        "示例:DEMO_TYPES_LOB_HANDLE
    ENDFORM

    4.2数据对象

    示例:

    "数据对象
    FORM f_declar_data_object.
      "使用ABAP已定义类型
      "1. DATA { {var[(len)] TYPE abap_type [DECIMALS dec]}
      "| {var TYPE abap_type [LENGTH len] [DECIMALS dec]} }
      "    [VALUE  val|{IS INITIAL}]
      "     [READ-ONLY].
      DATA:lv_var1(10) TYPE C.
      DATA:lv_var2 TYPE P LENGTH 8 DECIMALS 2.
    
      "使用已有数据对象类型
      "2.DATA var { {TYPE [LINE OF] type}
      "| {LIKE [LINE OF] dobj} }
      " [VALUE  val|{IS INITIAL}]
      " [READ-ONLY].
      DATA:lv_var3 LIKE lv_var1.
    
      "类对象定义
      "3.DATA ref { {TYPE REF TO type}
      "| {LIKE REF TO dobj} }
      " [VALUE IS INITIAL]
      " [READ-ONLY].
    *  CLASS c1 DEFINITION.
    *    PUBLIC SECTION.
    *      DATA a1 TYPE i VALUE 1.
    *  ENDCLASS.
    *
    *  DATA: oref  TYPE REF TO c1,
    *        dref1 LIKE REF TO oref,
    *        dref2 TYPE REF TO i.
    *  CREATE OBJECT oref.
    *  GET REFERENCE OF oref INTO dref1.
    *  CREATE DATA dref2.
    *  dref2->* = dref1->*->a1.
    
       "结构体对象
       "4. DATA BEGIN OF struc [READ-ONLY].
       "DATA comp ...
       "INCLUDE {TYPE|STRUCTURE} ...
       " ...
       "DATA END OF struc.
       DATA:BEGIN OF struc1.
       DATA:lv_var1 TYPE C LENGTH 4.
       DATA:lv_var2 TYPE I.
       INCLUDE TYPE spfli.
       DATA:END OF struc1.
    
       DATA:BEGIN OF struc2,
         lv_var1 TYPE C LENGTH 4,
         lv_var2 TYPE I,
            END OF struc2.
    
       "定义内表对象
       "5. DATA itab { {TYPE tabkind OF [REF TO] type}
       "| {LIKE tabkind OF dobj} }
       "        [tabkeys] [INITIAL SIZE n]
       "        [WITH HEADER LINE]
       "        [VALUE IS INITIAL]
       "        [READ-ONLY].
       "[WITH HEADER LINE] 已经弃用
       DATA:itab1 TYPE TABLE OF spfli.
    
       "定义range table对象
       "6. DATA rtab {TYPE RANGE OF type}|{LIKE RANGE OF dobj}
       "[INITIAL SIZE n]
       "[WITH HEADER LINE]
       "[VALUE IS INITIAL]
       "[READ-ONLY].
       DATA:rtab1 TYPE RANGE OF C.
    
       "LOB对象
       "7. DATA dtype TYPE dbtab [READ-ONLY]
       "lob_handle_type FOR lob_handle_columns
       "[lob_handle_type FOR lob_handle_columns ].
    
       "Boxed对象
       "DATA struc TYPE struc_type BOXED.
       "只定义在类,接口定义部分
    *   CLASS c1 DEFINITION.
    *      PUBLIC SECTION.
    *        TYPES: BEGIN OF t_struc,
    *                 comp1 TYPE c LENGTH 100,
    *                 comp2 TYPE n LENGTH 100,
    *               END OF t_struc.
    *      PRIVATE SECTION.
    *        CLASS-DATA struc1 TYPE t_struc BOXED.
    *        DATA       struc2 TYPE t100    BOXED.
    *   ENDCLASS.
    ENDFORM.

    4.3 Class类对象

        Tcode:SE24,Class Builder创建类,接口。这样定义的类接口称为全局的类,也可以在程序(除type groups,interface pools)定义本地类,接口。

        Classes组成:Attributes,Methods,Events,Types and Constants;

        Classes定义可见性:Public,Protected,Private。Public,类本身,友类,子类any objects都可以访问;Protected,类本身,友类,子类可以访问;Private,类本身,友类可以访问。

        Attributes:1.Static Attributes,静态变量,CLASS-DATA定义;2.普通变量使用DATA定义;

        Methods:1.Instance Methods,使用Methods定义;2.Static methods,静态方法,使用CLASS-METHODS定义;3.Constructors,构造方法,分为静态构造,实例构造方法;

        Events:1.Static Events,只有静态Events可以在静态方法触发;2.Instance events,实例触发事件;

        Types和Constants:定义数据类型,常量;

    类继承:

        子类可以继承父类public,protected部分属性,方法。通过REDEFINITION复位义方法。

    示例1:

    "定义类
    *1. CLASS class DEFINITION [class_options].
    *    [PUBLIC SECTION.
    *    [components]]
    *    [PROTECTED SECTION.
    *    [components]]
    *    [PRIVATE SECTION.
    *    [components]]
    *  ENDCLASS.
    "class_options
    *[PUBLIC]  "全局类,只能定义在global Class pool
    *[INHERITING FROM superclass]  "指定父类
    *[ABSTRACT] "抽象类
    *[FINAL]  "终结类,不能被继承
    *[CREATE {PUBLIC|PROTECTED|PRIVATE}]
    *[SHARED MEMORY ENABLED] "共享内存
    *[FOR TESTING] "测试类
    *[[GLOBAL] FRIENDS class1 class2 ...    "友类,接口
    *                  intf1  intf2  ...].
    
    "实现类
    *2. CLASS class IMPLEMENTATION.
    *    ...
    *    METHOD ...
    *      ...
    *    ENDMETHOD.
    *    ...
    *  ENDCLASS.
    
    "抽象类
    CLASS c2 DEFINITION ABSTRACT.
      PUBLIC SECTION.
      PROTECTED SECTION.
        METHODS m1.
      PRIVATE SECTION.
        DATA:a1 TYPE string VALUE 'class c2,value a1'.
    ENDCLASS.
    "终结类,继承c2
    CLASS c3 DEFINITION FINAL INHERITING FROM c2.
      PUBLIC SECTION.
        METHODS m2.
    ENDCLASS.
    "类实现
    CLASS c2 IMPLEMENTATION.
      METHOD m1.
        WRITE:/ a1.
      ENDMETHOD.
    ENDCLASS.
    CLASS c3 IMPLEMENTATION.
     METHOD m2.
       m1( ).
     ENDMETHOD.
    ENDCLASS.
    
    FORM f_class_object.
      "子类可以访问父类public,protect特性,方法
      DATA: lo_c3 TYPE REF TO c3.
      CREATE OBJECT lo_c3.
      lo_c3->m2( ).
    ENDFORM.

    示例2:

    CREATE PUBLIC:无限制;

    CREATE PROTECTED:只能在子类,本身方法,友类方法中实例化;

    CREATE PRIVATE:只能在本身方法,友类方法中实例化;

    "接口
    INTERFACE i2.
    ENDINTERFACE.
    "指定友类接口,
    CLASS c4 DEFINITION CREATE PRIVATE FRIENDS i2.
      PRIVATE SECTION.
        DATA:lv_c4 TYPE string VALUE 'c4 private value'.
    ENDCLASS.
    
    CLASS c5 DEFINITION.
      PUBLIC SECTION.
        "实现接口
        INTERFACES i2.
        METHODS m1.
    ENDCLASS.
    
    CLASS c5 IMPLEMENTATION.
      METHOD m1.
        "当c4指定friend类接口,就可以在c5中实例化
        "否则c4只能在自己内部实例化
        DATA:lo_c4 TYPE REF TO c4.
        CREATE OBJECT lo_c4.
        WRITE:/ lo_c4->lv_c4.
      ENDMETHOD.
    ENDCLASS.

    示例3:定义抽象父类,接口,子类实现,复位义

    INTERFACE i3.
      METHODS m1.
    ENDINTERFACE.
    "如果抽象类中有非抽象方法,必须要有实现类
    CLASS c6 DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS m1 ABSTRACT.
    ENDCLASS.
    CLASS c7 DEFINITION INHERITING FROM c6.
      PUBLIC SECTION.
        INTERFACES i3.
        "复位义
        METHODS m1 REDEFINITION.
        METHODS m2.
    ENDCLASS.
    "实现类c7
    CLASS c7 IMPLEMENTATION.
      METHOD m1.
        WRITE:/ 'c6 method m1复位义'.
      ENDMETHOD.
      METHOD m2.
        WRITE:/ 'c7 method m2'.
      ENDMETHOD.
      METHOD i3~m1.
        WRITE:/ 'i3 mthod m1'.
      ENDMETHOD.
    ENDCLASS.
    
    FORM f_class_object1.
      "子类可以访问父类public,protect特性,方法
      DATA: lo_c7 TYPE REF TO c7.
      CREATE OBJECT lo_c7.
      lo_c7->m1( ).
      lo_c7->m2( ).
      lo_c7->i3~m1( ).
    ENDFORM.

    示例4:类继承,方法复位义

    "复位义
    "构造方法不能复位义
    "METHODS meth [FINAL] REDEFINITION.
    CLASS c8 DEFINITION.
      PUBLIC SECTION.
        METHODS: constructor IMPORTING name TYPE string age TYPE I.
        METHODS: m1.
      PRIVATE SECTION.
        DATA:lv_name TYPE string.
        DATA:lv_age TYPE I.
    ENDCLASS.
    CLASS c8 IMPLEMENTATION.
      METHOD constructor.
        lv_name = name.
        lv_age = age.
        WRITE:/ name,age.
      ENDMETHOD.
      METHOD m1.
        WRITE:/ 'c8 method m1'.
      ENDMETHOD.
    ENDCLASS.
    
    "子类
    CLASS c9 DEFINITION INHERITING FROM c8.
      PUBLIC SECTION.
        "构造方法不能复位义
        "METHODS:constructor REDEFINITION.
        METHODS:m1 REDEFINITION.
    ENDCLASS.
    CLASS c9 IMPLEMENTATION.
      METHOD m1.
        "调用父类方法
        super->m1( ).
        WRITE:/ 'c9 method m1'.
      ENDMETHOD.
    ENDCLASS.
    FORM f_class_object2.
      DATA:lo_c8 TYPE REF TO c8.
      DATA:lo_c9 TYPE REF TO c9.
      "创建对象
      CREATE OBJECT lo_c8 EXPORTING name = 'tom' age = 10.
      CREATE OBJECT lo_c9 EXPORTING name = 'any' age = 11.
      lo_c8->m1( ).
      "会调用c8的m1方法,和c9的m1方法
      lo_c9->m1( ).
    ENDFORM.

    示例5:类声明,定义友类

    "类声明
    "语法:CLASS class DEFINITION DEFERRED [PUBLIC]. 
    
    "友类
    "CLASS class DEFINITION 
    "    LOCAL FRIENDS class1 class2 ... 
    "                  intf1  intf2  ... .  

    4.4接口

        接口定义,接口声明

    示例:

    "接口声明,定义
    "语法:接口定义
    *1. INTERFACE intf [PUBLIC]. 
    *  [components] 
    *  ENDINTERFACE. 
    "语法:接口声明
    *2. INTERFACE intf DEFERRED [PUBLIC].  

    4.5类与接口中Components

    类和接口中Components

    1.TYPES;

    2.DATA;

    3.CONSTANTS,常量;

    语法:CONSTANTS const [options].

    4.CLASS-DATA,类静态变量;

    语法:CLASS-DATA attr [options].

    5.METHODS,方法;

    示例:

    "5.METHODS
    "语法:
    "通用实例方法
    *1. METHODS meth [ABSTRACT|FINAL]
    *  [IMPORTING parameters [PREFERRED PARAMETER p]]
    *    [EXPORTING parameters]
    *    [CHANGING  parameters]
    *    [{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}
    *    |{EXCEPTIONS exc1 exc2 ...}].
    "IMPORTING, EXPORTING and CHANGING 参数
    "输入,输出,可变参数
    "RETURNING不能和EXPORTING,CHANGING一起使用
    "[PREFERRED PARAMETER p]
    "只在所有参数可选有效,隐式设置参数可选
    "RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2)
    "基于类的异常,类直接捕捉抛出,RESUMABLE表明可恢复异常
    "EXCEPTIONS exc1 exc2
    "方法捕捉异常后,抛出自定义异常
    "ABSTRACT
    "抽象方法,抽象类或Final类中定义抽象方法
    "FINAL
    "定义final方法,Final类中所有方法为Final,不需重新定义
    
    "Functional Method
    *2.METHODS meth [ABSTRACT|FINAL]
    *  [IMPORTING parameters [PREFERRED PARAMETER p]]
    *    RETURNING VALUE(r) typing
    *    [{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}
    *    |{EXCEPTIONS exc1 exc2 ...}].
    "构造方法
    *3. METHODS constructor [FINAL]
    *  [IMPORTING parameters [PREFERRED PARAMETER p]]
    *    [{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}
    *    |{EXCEPTIONS exc1 exc2 ...}].
    "event handler
    *4. METHODS meth [ABSTRACT|FINAL]
    *     FOR EVENT evt OF {class|intf}
    *     [IMPORTING p1 p2 ... [sender]].
    "复位义方法
    *5. METHODS meth [FINAL] REDEFINITION.
    "测试方法
    *6. METHODS meth [ABSTRACT|FINAL]
    *    FOR TESTING
    *    [{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}].

    示例:

    CLASS c10 DEFINITION.
      PUBLIC SECTION.
        METHODS div_zero IMPORTING iv_op1 TYPE I
                                   iv_op2 TYPE I
                         EXPORTING ov_op1 TYPE I
                         RAISING cx_sy_arithmetic_error.
        METHODS div_re IMPORTING iv_op1 TYPE I
                                 iv_op2 TYPE I
                       RETURNING VALUE(re1) TYPE I.
        METHODS div_exception EXCEPTIONS meth_excep.
        "ztom_tspfli为table type,返回内表
        METHODS get_spfli EXPORTING ot_op1 TYPE ztom_tspfli.
    ENDCLASS.
    
    CLASS c10 IMPLEMENTATION.
      "使用exporting
      METHOD div_zero.
        ov_op1 = iv_op1 / iv_op2.
      ENDMETHOD.
      "使用return
      METHOD div_re.
        re1 = iv_op1 / iv_op2.
      ENDMETHOD.
      "抛出exception
      METHOD div_exception.
        TRY.
          DATA:lv_num1 TYPE I VALUE 1.
          DATA:lv_num2 TYPE I VALUE 0.
          lv_num1 = lv_num1 / lv_num2.
        CATCH cx_sy_arithmetic_error.
          RAISE meth_excep.
        ENDTRY.
      ENDMETHOD.
      "返回table
      METHOD get_spfli.
        SELECT * INTO TABLE ot_op1 FROM spfli.
      ENDMETHOD.
    ENDCLASS.
    
    FORM f_class_object3.
      DATA:lo_c10 TYPE REF TO c10.
      DATA:lo_exception TYPE REF TO cx_sy_arithmetic_error.
      DATA:lv_ov1 TYPE I.
      DATA:lv_string TYPE string.
      DATA:lt_spfli TYPE ztom_tspfli.
      DATA:ls_spfli LIKE LINE OF lt_spfli.
      "创建对象
      CREATE OBJECT lo_c10.
      TRY.
        "try catch捕捉异常,类自动抛出异常
        lo_c10->div_zero( EXPORTING iv_op1 = 1 iv_op2 = 0 IMPORTING ov_op1 = lv_ov1 ).
        WRITE:/ 'exporting value:',lv_ov1.
      CATCH cx_sy_arithmetic_error INTO lo_exception.
        lv_string = lo_exception->get_text( ).
        WRITE:/ lv_string.
      ENDTRY.
      "return value
      "当只有输入参数,不需要EXPORTING
      lv_ov1 = lo_c10->div_re( iv_op1 = 10 iv_op2 = 2 ).
      WRITE:/ 'return value:',lv_ov1.
      "exception
      lo_c10->div_exception( EXCEPTIONS meth_excep = 1 ).
      IF sy-subrc = 0.
        WRITE:/ 'no exception'.
      ELSE.
        WRITE:/ 'some exception'.
      ENDIF.
      "获取table
      lo_c10->get_spfli( IMPORTING ot_op1 = lt_spfli ).
      LOOP AT lt_spfli INTO ls_spfli.
        WRITE:/ ls_spfli-carrid,ls_spfli-connid,ls_spfli-countryfr.
      ENDLOOP.
    ENDFORM.

    6.CLASS-METHODS,类静态方法;

    示例:

    "6.类静态方法
    "General Static Methods
    *1. CLASS-METHODS meth
    *  [IMPORTING parameters [PREFERRED PARAMETER p]]
    *    [EXPORTING parameters]
    *    [CHANGING parameters]
    *    [{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}
    *    |{EXCEPTIONS exc1 exc2 ...}].
    "Functional Static Methods
    *2. CLASS-METHODS meth
    *  [IMPORTING parameters [PREFERRED PARAMETER p]]
    *    RETURNING VALUE(r) typing
    *    [{RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...}
    *    |{EXCEPTIONS exc1 exc2 ...}].
    "Static Constructors
    *3. CLASS-METHODS class_constructor.
    "Event Handlers
    *4. CLASS-METHODS meth
    *     FOR EVENT evt OF {class|intf}
    *     [IMPORTING p1 p2 ... [sender]].

    7.Events and Class Events;

    示例:

    "7.Events and Class-Events
    "事件
    "语法:EVENTS evt [EXPORTING parameters].
    "静态事件
    "语法:CLASS-EVENTS evt [EXPORTING parameters].
    "parameters:
    "VALUE(p1) typing [OPTIONAL|{DEFAULT def1}]
    "VALUE(p2) typing [OPTIONAL|{DEFAULT def2}]
    CLASS c11 DEFINITION.
      PUBLIC SECTION.
        METHODS m_raise_event.
        CLASS-METHODS cm_raise_event.
        EVENTS e_1 EXPORTING VALUE(p1) TYPE I
                    VALUE(p2) TYPE string OPTIONAL.
        CLASS-EVENTS ce_1.
        "event handler
        METHODS m_handler_event FOR EVENT e_1 OF c11.
        "class event handler
        METHODS m_handler_cevent FOR EVENT ce_1 OF c11.
    ENDCLASS.
    
    CLASS c11 IMPLEMENTATION.
      METHOD m_raise_event.
        RAISE EVENT e_1 EXPORTING p1 = 1 p2 = 'raise event'.
      ENDMETHOD.
    
      METHOD cm_raise_event.
        RAISE EVENT ce_1.
      ENDMETHOD.
    
      METHOD m_handler_event.
        WRITE:/ 'hanlder event'.
      ENDMETHOD.
    
      METHOD m_handler_cevent.
        WRITE:/ 'handler class event'.
      ENDMETHOD.
    ENDCLASS.
    
    FORM f_class_object4.
      DATA:lo_c11 TYPE REF TO c11.
      CREATE OBJECT lo_c11.
      "注册handler
      SET HANDLER lo_c11->m_handler_event FOR lo_c11.
      SET HANDLER lo_c11->m_handler_cevent.
      "触发event
      lo_c11->m_raise_event( ).
      c11=>cm_raise_event( ).
    ENDFORM.

    8.类接口实现

    示例:

    "8.类接口实现
    "接口实现
    *1. INTERFACES intf
    *    { {[ABSTRACT METHODS meth1 meth2 ... ]
    *       [FINAL METHODS meth1 meth2 ... ]}
    *    | [ALL METHODS {ABSTRACT|FINAL}] }
    *    [DATA VALUES attr1 = val1 attr2 = val2 ...].
    "接口声明
    *2. INTERFACES intf.
    INTERFACE i4.
      METHODS i4_meth1.
    ENDINTERFACE.
    INTERFACE i5.
      INTERFACES i4.
      METHODS i5_meth1.
    ENDINTERFACE.
    CLASS c12 DEFINITION.
      PUBLIC SECTION.
        "声明实现接口
        INTERFACES: i4,i5.
        "别名方法
        ALIASES m1 FOR i5~i5_meth1.
        METHODS m2.
    ENDCLASS.
    CLASS c12 IMPLEMENTATION.
      METHOD i4~i4_meth1.
        WRITE:/ 'interface i4 method1'.
      ENDMETHOD.
      METHOD m1.
        WRITE:/ 'aliase interface i5 method1'.
      ENDMETHOD.
      METHOD m2.
        WRITE:/ 'method 2'.
      ENDMETHOD.
    ENDCLASS.

    4.6 Field Symbols

    示例:

    "Field Symbols
    "语法:FIELD-SYMBOLS <fs> { typing }
    FORM f_field_symbol.
      FIELD-SYMBOLS:<fs_tab> TYPE ANY TABLE.
      FIELD-SYMBOLS:<fs_wa> TYPE spfli.
      DATA:lt_spfli TYPE TABLE OF spfli.
      SELECT * INTO TABLE lt_spfli FROM spfli.
      "field symbol赋值
      ASSIGN lt_spfli TO <fs_tab>.
    ENDFORM.

     

  • 相关阅读:
    java lambda表达式学习笔记
    一个奇妙的java坑:Long 类型的比较
    要不要冗余字段
    mysql找回密码
    mysql创建触发器
    【转】Java 8十个lambda表达式案例
    ThreadLocal类学习笔记
    mybatis generator使用总结
    【转】Java 项目UML反向工程转化工具
    PostMan做接口自动化测试
  • 原文地址:https://www.cnblogs.com/tangToms/p/14691045.html
Copyright © 2011-2022 走看看