ABAP 面向对象_创建类及实例对象
作者:互联网
*&---------------------------------------------------------------------*
*& Report ZCLASSTEST_CPF
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZCLASSTEST_CPF.
"定义类 其中definition为定义类的变量及方法名,
"implementation为方法的实现代码
CLASS DOG DEFINITION.
PUBLIC SECTION.
DATA: NAME TYPE C LENGTH 10,
AGE TYPE N LENGTH 2.
METHODS:SET_INFO IMPORTING i_NAME TYPE C
i_AGE TYPE N,
GET_INFO IMPORTING i_NAME TYPE C
EXPORTING e_NAME TYPE C
e_AGE TYPE N,
RUN .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS DOG IMPLEMENTATION.
METHOD GET_info.
E_NAME = NAME.
E_AGE = AGE.
ENDMETHOD.
METHOD SET_info.
AGE = I_AGE.
NAME = I_NAME.
ENDMETHOD.
METHOD RUN.
WRITE :/ NAME,'is Running'.
ENDMETHOD.
ENDCLASS.
DATA GV_DOG TYPE REF TO DOG. "定义一个实例变量
DATA GV_NAME(20) TYPE C.
DATA GV_AGE(2) TYPE N.
START-OF-SELECTION.
CREATE OBJECT GV_DOG. "实例变量实例化
CALL METHOD GV_DOG->SET_INFO
EXPORTING
I_NAME = '旺财'
I_AGE = '5'.
CALL METHOD GV_DOG->GET_INFO
EXPORTING
I_NAME = '旺财'
IMPORTING
E_NAME = GV_NAME
E_AGE = GV_AGE.
WRITE :/ GV_NAME,GV_AGE.
CALL METHOD GV_DOG->RUN.
标签:GV,NAME,AGE,DOG,面向对象,ABAP,类及,TYPE,METHOD 来源: https://www.cnblogs.com/smarttony/p/16186569.html