OO CLASS

*&---------------------------------------------------------------------*
*& Include ZBC404_HF_LCL_AIRPLANE *
*&---------------------------------------------------------------------*

******************************************
* Definition part
******************************************
CLASS lcl_airplane DEFINITION.
*------------------------------
* Public section
*------------------------------
PUBLIC SECTION.
TYPES: t_name(25) TYPE c.
METHODS:
constructor,
set_attributes IMPORTING p_name TYPE t_name
p_planetype TYPE saplane-planetype,
display_attributes,
display_n_o_airplanes.
*------------------------------
* Private section
*------------------------------
PRIVATE SECTION.
* Private attributes
DATA: name(25) TYPE c,
planetype TYPE saplane-planetype.
* Private static attribute
CLASS-DATA n_o_airplanes TYPE i.
ENDCLASS.
******************************************
* Implementation part
******************************************
CLASS lcl_airplane IMPLEMENTATION.
METHOD constructor.
* Counts number of instances
n_o_airplanes = n_o_airplanes + 1.
ENDMETHOD.

METHOD set_attributes.
name = p_name.
planetype = p_planetype.
ENDMETHOD.

METHOD display_attributes.
WRITE:/ 'Name:', name, 'Planetype:', planetype.
ENDMETHOD.

METHOD display_n_o_airplanes.
WRITE: / 'No. planes:', n_o_airplanes.
ENDMETHOD.

ENDCLASS.

*&---------------------------------------------------------------------*
*& Report ZBC404_HF_MAINTAIN_AIRPLANES *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT ZBC404_HF_MAINTAIN_AIRPLANES .
INCLUDE zbc404_hf_lcl_airplane.

* Create reference to class lcl_airplane
DATA: airplane1 TYPE REF TO lcl_airplane,
airplane2 TYPE REF TO lcl_airplane.

START-OF-SELECTION.

* Create instance
CREATE OBJECT airplane1.
CALL METHOD: airplane1->display_n_o_airplanes.

CREATE OBJECT airplane2.

* Setting attributes using a method with parameters
CALL METHOD airplane1->set_attributes EXPORTING p_name = 'Kurt'
p_planetype = 'MD80'.
END-OF-SELECTION.
* Using methods
CALL METHOD: airplane1->display_n_o_airplanes,
airplane1->display_attributes.

*The resulting report:
*Maintain airplanes
*No. planes: 1
*No. planes: 2
*Name: Kurt Planetype: MD80
*Use constructor to create an object with parameters
*CLASS lcl_airplane DEFINITION.
* PUBLIC SECTION.
* TYPES: t_name(25) TYPE c.
*METHODS:
* constructor importing p2_name type t_name
* p2_planetype TYPE saplane-planetype,
*..... more code .......
*CLASS lcl_airplane IMPLEMENTATION.
* METHOD constructor.
* name = p2_name.
* planetype = p2_planetype.
*..... more code .......
*START-OF-SELECTION.
* CREATE OBJECT airplane1 exporting p2_name = 'Hansemand'
* p2_planetype = 'Boing 747'.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值