Start of Content Area

Background documentation Mapping  Locate the document in its SAP Library structure

Technically speaking, all objects in ABAP Objects – including persistent objects managed by the Persistence Service – exist only transiently in the internal session of an ABAP program. Conversely, SAP System data exists persistently in the database. The persistence of objects is achieved by mapping database tables and the attributes of persistent classes.

Mapping Assistant

Mapping bridges the gap between the relational database view and the object-oriented view. Mapping forms an important part of creating persistent classes. You perform mapping in the Mapping Assistant, a tool integrated in the Class Builder. In principle, you proceed as follows:

...

       1.      Create an object model and class design. If you want to apply object-oriented programming to existing database tables or database tables to be created are to follow the relational model, the object model results from the relational model.

       2.      Define each class in the Class Builder, choosing the Persistent Class attribute for each one. The system assigns a unique global GUID to each class (as it does for every class in the Class Builder) and generates the class-specific auxiliary classes for Object Services. The class GUID is of no significance in the application for normal classes, but it is important for persistent classes, since the Persistence Service works with this ID.

       3.      Define the persistence mapping in the Mapping Assistant.

...

                            a.      Choose one or more database tables, database views, or structures.

·         You may have to create new database tables, database views, or structures for the object model in the ABAP Dictionary. At present the system does not perform this function automatically.

·         There are three ways of creating the persistence mapping. These mapping types are based on the keys of the database tables or database views and their Ids. We differentiate between:

Mapping Using Business Keys
Mapping Using an Instance GUID
Mapping Using Instance GUID and Business Keys

All three mapping types require database tables, database views, or ABAP Dictionary structures that can be used to generate attributes and methods of the persistent class and its class actor.

                            b.      Assign all columns of the database tables, the database views, or components of structures to the attributes of the persistent class. This defines:

·         The mapping type

·         The value attributes

·         The reference attributes, made up of the class GUID and an instance GUID, which allow you to refer to persistent database objects.

Caution

You must map all columns of a database table to attributes. If you only want to manage some of the columns using Object Services, you must create a database view.

 

Single-Table Mapping

In the simplest form of mapping, you assign exactly one database table to one persistent class. This is known as single-table mapping. At runtime, the system links one persistent object of the persistent class to exactly one entry in this table. Within an internal session, the Persistence Service provides a unique connection between the object and the database.

This graphic is explained in the accompanying text

Multiple-Table Mapping

Alternatively, you can assign several database tables to one persistent class. This is known as multiple-table mapping. Then at runtime, the system links each persistent object of this class to an entry in each of the tables involved. The key of each of these tables must have the same type. Multiple-table mapping also supports all three types of mapping outlined.

This graphic is explained in the accompanying text

Structure Mapping

In this case, you map ABAP Dictionary structures, rather than database tables or database views to persistent objects. The application developer must therefore program the type of persistent data storage in the appropriate methods of the class actor.

You will need to map a structure (or structures) if you want a persistent object to contain table-like attributes. Database tables can only have flat structures, which prevents your mapping the object to a table in this case. You must still use structure mapping, even if you want to store the data in a different form – such as in a file on the application server.

 

 

End of Content Area