Mentor SAP
automatically generates methods for getting and setting its attributes. In addition, the system also generates other repository objects, including the class actor (also known as the class agent) ZCA_<name>. Programs must call the methods of this class to manage the instances of persistent classes, that is, persistent objects. The class actor also performs the actual database access. It automatically inherits the required methods from the basis class ZCB_<name>. You can redefine these methods, if necessary. For example, extend database accesses. The class actor is a singleton instance and has a friendship relationship with the persistent class.

 

Creation of Persistent Objects

In the program, you need to define a reference variable with the type of the class actor and fill it with the reference from the static attribute AGENT. You can then create a new instance of the persistent class using its method CREATE_PERSISTENT. The ABAP developer creates its interface from the definition of the key attributes of the persistent class. If a persistent object of the same persistence class with the same key attributes already exists in the program, the class-based exception CX_OS_OBJECT_EXISTING is triggered. By default, the data is saved by an asynchronous update. You must start this process by using the COMMIT WORK statement. Thus, the instances of the persistent class do not become persistent objects until after that point.

 

 

To Create Persistent Classes

Steps

  1. Model the class for your persistent objects.
  2. Find or create a suitable transparent table that has a field for each attribute of the class. If necessary, adapt the attributes of the class to match the technical field attributes of the transparent table.
  3. In the Class Builder, create a persistent class as described in the SAP Library. Define the persistence mapping to the table.

OO Transaction

In transaction maintenance, you can create transaction code as an OO transaction. This means that you link the transaction code either to the transaction service of the ABAP Objects Services for persistent objects or a public method in a global or local class of a program. When calling this type of OO transaction, which is linked to an instance method, the system automatically creates an instance of the class in its own internal session and then executes this instance method.

 

You still require procedural framework programs for screen fields.

 

If the OO Transaction Model flag is set, the system links the transaction code to the transaction service of the ABAP Objects Services. Conversely, if it is not set, you can call any method in a global or local class.

 

Users, therefore, now have the opportunity to call methods themselves in the usual way (using menu options, command field entries, and so on).

 

Global classes in ABAP Objects cannot contain screen definitions.

 

Therefore, when you create a link to a global class, note the following points:

 

Breaking these rules will not cause a syntax error or message from the Extended Syntax Check. Instead, you will either cause a runtime error or there will be no display.

 

Therefore, you may have to resort to using methods in local program classes. Naturally, you can then use all the conventional dialog programming techniques.

 

 

You can create an OO transaction by using the following steps:

Steps

  1. In the Create Transaction dialog box, enter a description in the Short Text
  2. Choose the Method of a Class (OO Transaction) option as an Initial Object.
  3. If you want to link the transaction code to a normal instance method, leave the OO Transaction Model checkbox unselected.
  4. Enter the Class Name and Method. If you are using a local class, select the Local in Program checkbox and enter the program name.
  5. Save the transaction code.