*&---------------------------------------------------------------------*
*& 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'.