SAP BLOG--Jack Wu

人生最要紧的是充实自己,让自己的视野更广阔,让自己的脑筋更灵活,让自己看事情更准确,让自己与别人相处更和谐,让自己对群体有越来越多的贡献..........

ABAP--OBJECTS ABAP的类的基础知识

一、Class Define
1) Basis Structure of Class
CLASS c1 DEFINITION.
  PUBLIC SECTION.
    DATA: a1 …
    METHODS: m1 …
    EVENTS: e1 …
  PROTECTED SECTION.
    DATA: a2 …
    METHODS: m2 …
    EVENTS: e2 …
  PRIVATE SECTION.
    DATA: a3 …
    METHODS: m3 …
    EVENTS: e3 …
ENDCLASS.

CLASS c1 IMPLEMENTATION.
  METHOD m1. …
  ENDMETHOD.
  METHOD m2. …
  ENDMETHOD.
  METHOD m3. …
  ENDMETHOD.
ENCLASS.

2) Components of Classes: Attributes' Type
CLASS ... DEFINITION
  ....
  ...SECTION.
    DATA... TYPE ... [READ-ONLY] ...
    CLASS-DATA... TYPE ... [READ-ONLY] ...
    CONSTANTS... TYPE ... VALUE ...
    ...
ENDCLASS.
DATA:                   Instance attributes
CLASS-DATA:    Staticattributes
CONSTANTS:    Constants


3)Components of Classes:Methods' type
CLASS ... DEFINITION
  ....
  ...SECTION.
    METHODS... IMPORTING [VALUE] ... TYPE ... [OPTIONAL]
      EXPORTING [VALUE] ... TYPE ...
      CHANGING [VALUE] ... TYPE ... [OPTIONAL]
      RETURNING VALUE(...) TYPE ...
      EXCEPTIONS ...
    CLASS-METHODS...
    ...
ENDCLASS.
METHODS:                Instance methods
CLASS-METHODS: Staticmethods

4)Constructors' type
CLASS ... DEFINITION
  ....
    PUBLIC SECTION.
      METHODS CONSTRUCTOR
        [IMPORTING arg1 TYPEtype... ].
      CLASS-METHODS CLASS_CONSTRUCTOR.
    ...
ENDCLASS.

二、Using Object Step
1)Declaring referencevariables

DATA: ref1 TYPE REF TO class,
            ref2 TYPE REFTO  class.

2)Creating objects
DATA: CREATE OBJECT: ref1,

3)Accessing attributes and methods
ref2.x = ref1->attr+ ref2->attr.
CALL METHOD ref1->methodEXPORTING ...

三、Accessing the components of classes
1)Instance components:           ref–>comp
Instance attribute:                   ref->attr
Instance method:                   call method ref->meth

2)Static components                 class=>comp
Static attribute:                        class=>attr
Static method:                         call method class=>meth

3)Special references in methods
Self reference:               ME->comp
Pseudo reference         SUPER->comp 

四、Class Inhireritance(abap只支持单继承)
1)Inheritance-Overview
CLASS c1 DEFINITION INHERITING FROM ...
   ...
ENDCLASS.

2)Redefining Methods
CLASS ... DEFINITION INHERITING FROM ...
   ... SECTION.
       METHODS ... REDEFINITON ...
   ......
ENDCLASS.

五) Interface(待续)

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CompassButton/article/details/1822006
个人分类: 10 SAP ABAP
所属专栏: SAP应用和开发
上一篇ABAP--REUSE_ALV_GRID_DISPLAY的i_callback_user_command的调用跟踪摘抄
下一篇ABAP--SAP UI的发展路线
想对作者说点什么? 我来说一句

ABAP基础知识

2008年06月17日 67KB 下载

abap基础知识(很适合初学者)

2009年11月08日 291KB 下载

sap abap 基础知识

2011年02月25日 123KB 下载

没有更多推荐了,返回首页

关闭
关闭