This section defines class initialization through the example given in the previous section.
*----------------------------------------------------------------------*
* Include z_sample_lcl_airplane *
*----------------------------------------------------------------------*
**************************************** **
* Definition part
**************************************** **
Class lcl_airplane definition.
*------------------------------
* Public Section
*------------------------------
Public section.
Types: t_name (25) type C.
Methods:
constructor importing p2_name type t_name
p2_planetype TYPE saplane-planetype,
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.
name = p2_name.
planetype = p2_planetype.
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.
Bytes ---------------------------------------------------------------------------------------------
Report zbobo_oo_011.
Include z_sample_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
Exporting p2_name = 'airp1'
P2_planetype = 'bobo '.
Call method: airplane1-> display_n_o_airplanes.
Create object airplane2
Exporting p2_name = 'airp1'
P2_planetype = 'bobo '.
* Setting attributes using a method with Parameters
* Attributes of plane1 are modified, but those of plane2 are not changed.
Call method airplane1-> set_attributes exporting p_name = 'kurt'
P_planetype = 'md80 '.
End-of-selection.
* Using methods
* Display attributes that have been modified
Call method: airplane1-> display_n_o_airplanes,
Airplane1-> display_attributes.
* Initialized attributes
Call method: airplane2-> display_n_o_airplanes,
Airplane2-> display_attributes.