SAP ABAP OO面向对象入门实例
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
*& Report Y_TEST_A * *&---------------------------------------------------------------------* *& 简单ABAP对象 * *&---------------------------------------------------------------------*
REPORT y_test_a .
*&---------------------------------------------------------------------* *& Class simpleobj
*&---------------------------------------------------------------------* * Text
*----------------------------------------------------------------------* CLASS simpleobj DEFINITION.
PUBLIC SECTION.
METHODS: show_text.
PRIVATE SECTION.
DATA text(100) TYPE c VALUE 'This is my first ABAP object.'. ENDCLASS. "simpleobj
*&---------------------------------------------------------------------* *& Class (Implementation) SIMPLEOBJ
*&---------------------------------------------------------------------* * Text
*----------------------------------------------------------------------* CLASS simpleobj IMPLEMENTATION.
METHOD show_text.
WRITE text.
ENDMETHOD. "show_text
ENDCLASS. "SIMPLEOBJ
* Global Data Declaratioin
DATA ob_app TYPE REF TO simpleobj.
START-OF-SELECTION.
CREATE OBJECT ob_app.
CALL METHOD ob_app->show_text.
*& Report Y_TEST_A_1 * *& * *&---------------------------------------------------------------------* *& * *& 类的静态属性 * *&---------------------------------------------------------------------*
REPORT y_test_a_1 .
*&---------------------------------------------------------------------* *& Class vehicle
*&---------------------------------------------------------------------* * Text
*----------------------------------------------------------------------* CLASS vehicle DEFINITION.
PUBLIC SECTION.
CLASS-DATA class_name(10) VALUE 'Vehicle'.
METHODS:accelerate,show_speed.
PROTECTED SECTION.
DATA speed TYPE i.
CONSTANTS: pi TYPE p DECIMALS 2 VALUE '3.14'.
ENDCLASS. "vehicle
*&---------------------------------------------------------------------* *& Class (Implementation) vehicle
*&---------------------------------------------------------------------* * Text
*----------------------------------------------------------------------* CLASS vehicle IMPLEMENTATION.
METHOD accelerate.
speed = speed + 1.
ENDMETHOD. "accelerate
METHOD show_speed.
WRITE: / 'Speed:' ,speed.
ENDMETHOD. "show_speed
ENDCLASS. "vehicle
DATA ob_app1 TYPE REF TO vehicle.
DATA ob_app2 TYPE REF TO vehicle.
DATA ob_app3 TYPE REF TO vehicle.
DATA o_vehicle TYPE REF TO z_cl_vehicle. "引用全局类
START-OF-SELECTION.
CREATE OBJECT ob_app1.
CREATE OBJECT ob_app2.