Vous êtes sur la page 1sur 2

SAP R/3 Release 4.

7 Exercises: ABAP Objects Basic:

1. Create a class with name c1 and with three attributes declared in different sections as follows:Commondata in public section Protectdata in private section Privatedata in private section In the main program, create an object (obj1) of class c1 and attempt to display the protected and private attribute of class c1 using its object (obj1). 2. Create a program that contains a method tax_calc belonging to the class ctax. This method receives grade as IMPORTING parameter and salary as CHANGING parameter. Based on the grade, the EXPORTING parameter itax is calculated and the CHANGING parameter, salary is modified by deducting tax from it. 3. Create program that contains a class c1 with the following components:Component Type Static/Instance stnum Data static instnum Data Instance stmeth Method Static instmeth Method Instance Now write code inside both the static and instance methods to display values of the static and instance attributes: stnum and instnum. 4. Create a program that contains a class c1 with a constructor method which displays 'I am constructor' to indicate that it is triggered. Now in the START-OF-SELECTION block, create an object of the class c1, which triggers the instance constructor method and the text written inside the constructor is get displayed.

SAP Development ABAP Training

March 2005 Page 1

SAP R/3 Release 4.7 Exercises: ABAP Objects Advanced:

1. Create a program that contains superclass c1 and its subclass c2. Class c1 has the following components:Compon Nature Section of Significance/action ent Existence num Attribute public Value = 6 meth1 Method Public Displays value of NUM meth2 Method Protected Displays:- I am meth2 num2 Attribute Protected Value = 7 And Subclass c2 contains the following new components:Com Nature Section of Significance/action pon Existence ent m1 Method public Calls method meth1. Calls method meth2 Displays value of variable num2. In the START-OF-SELECTION block, create an object (oref) of class c2 and called the method m1 .In the definition of the method m1 of class c2 call the methods meth1, meth2 and display variable num2. 2. Create a class c1 that contains an event e1, for which the triggering method is t1. Event handler method for event e1 is m1, and it is defined in another class c2. Register the event e1 with the event handler method m1 at runtime. Create an object of class c1 and call the triggering method t1, which raises the event and ultimately calls event handler method m1 in class c2. 3. Create a class c2 with a private method m2 and a private attribute num and using CREATE PRIVATE option. That means, only the class itself and its friends can instantiate this class. Now create another class c1 that is friend of class c2. And show that methods of class c1 can access private components of c2 as well as can instantiate class c2.

SAP Development ABAP Training

March 2005 Page 2