Sie sind auf Seite 1von 4

SAP R/3 Release ECC 5.

Exercises: Fundamentals of ABAP Objects

SAP Development ABAP Training

Exercise 1:
Objectives:
Create a Local Class with different components in different visibility sections
Define and implement Methods
Show how to instantiate the class
Access the instance and static components of the Class
Steps:
1. Create include program YOOPI_XX_LCL_AIRPLANE. (Replace XX with the last 2 digits of
your SAP User ID)
2. Create a class lcl_airplane in the above include program.
3. Create two private instance attributes: name (type C, length 25) & planetype (Type
saplane-planetyp).
4. Create a private static attribute: n_o_airplanes (type I)
5. Create a public instance method: set_attributes to set the private instance attributes name
and plane type. Enter two corresponding importing parameters for the declaration of the
method in the definition part. The definition of these parameters should be analogous to the
two attributes.
6. Implement the method in the implementation part. Each time the method is called, the static
attribute n_o_airplanes should increase by one.
7. Add another public instance method display_attributes to display the instance attributes.
8. Declare and implement a public static method display_n_o_airplanes to display the static
attribute n_o_airplanes.
9. Create program YOOPR_XX_LCL_MTN_AIRPLANES. (Replace XX with the last 2 digits of
your SAP User ID)
10. Use the INCLUDE statement to include program YOOPI_XX_LCL_AIRPLANE.
11. Create a reference to class lcl_airplane.
12. Call the static method display_n_o_airplanes (before instantiating an object in class
lcl_airplane).
13. Create an object in class lcl_airplane.
14. Set the object attributes using the set_attributes method. Invent an airplane name and
airplane type and pass them as text literal.
15. Display the object attributes using the display_attributes method.
16. Call the static method display_n_o_airplanes for a second time.

Jan 2007
Page 1

SAP R/3 Release ECC 5.0

Exercises: Fundamentals of ABAP Objects

SAP Development ABAP Training

Exercise 2:
Objectives:
Create a Constructor for a class
Create an object using the Constructor
Steps:
1. Copy include program YOOPI_XX_LCL_AIRPLANE to YOOPI_XX_LCL_AIRPLANE_C.
2. Create a constructor for class lcl_airplane. The constructor must have two importing
parameters that fill the instance attributes name and planetype.
3. Increment the static attribute n_o_airplanes in sequence of one inside the constructor.
4. Delete the set_attributes method definition and implementation,
5. Copy the main program YOOPR_XX_LCL_MAINTAIN_AIRPLANES to
YOOPR_XX_LCL_MAINTAIN_AIRPLANES_C and extend creation of the object with the
constructor interface.
6. Fill the constructor interface parameters with the same values you used when calling the
set_attributes method.
7. Delete the set_attributes method call.

Jan 2007
Page 2

SAP R/3 Release ECC 5.0

Exercises: Fundamentals of ABAP Objects

SAP Development ABAP Training

Exercise 3:
Objectives:
Define Functional Methods
Call Functional Methods
Steps:
1. Copy include program YOOPI_XX_LCL_AIRPLANE to YOOPI_XX_LCL_AIRPLANE_FM.
2. Inside class lcl_airplane define the public static functional method get_n_o_airplanes.
The signature must consist of the returning parameter re_count, which must be a whole
number.
3. Assign n_o_airplanes to re_count inside functional method get_n_o_airplanes.
4. Copy the main program YOOPR_XX_LCL_MAINTAIN_AIRPLANES to
YOOPR_XX_LCL_MAINTAIN_AIRPLANES_FM and call get_n_o_airplanes to display
number of airplanes, instead of using display_n_o_airplane.

Jan 2007
Page 3

SAP R/3 Release ECC 5.0

Exercises: Fundamentals of ABAP Objects

SAP Development ABAP Training

Exercise 4:
Objectives:
Define & call Private Methods.
Use keyword ME
Using Static Constructor
Raising and handling Exceptions for methods.
Steps:
1. Copy include program YOOPI_XX_LCL_AIRPLANE_C to YOOPI_XX_LCL_AIRPLANE_PM.
2. Inside class lcl_airplane Define and Implement a Class Constructor to populate the internal
table list_of_planetypes (type ty_planetypes) from SAPLANE.
3. Define the private method get_technical_attributes. The signature must consist of the
import parameter for the airplane type and the two export parameters for weight & tank
capacity. Refer to transparent table SAPLANE as a guide for specifying the types of these
formal parameters.
4. Inside method get_technical_attributes fill up the export parameters by single record
access to the internal table i_list_of_planetypes. If the reading of airplane type in the
method get_technical_attributes is not successful, the exception wrong_planetype should
be raised.
5. Call the method get_technical_attributes from the method display_attributes to obtain the
additional technical data. Upon retrieval print them inside the display_attributes method, if
retrieval is unsuccessful handle the exception raised by get_technical_attributes method.
6. Copy the main program YOOPR_XX_LCL_MAINTAIN_AIRPLANES_C to
YOOPR_XX_LCL_MAINTAIN_AIRPLANES_PM and try to call method
get_technical_attributes in the program flow. Also create a new object of class lcl_airplane
and pass an invalid planetype to the constructor.

Jan 2007
Page 4

Das könnte Ihnen auch gefallen