SAP DERIVED TYPES PRE TMP ABEXA



Get Example source ABAP code based on a different SAP table
  



Using %pre / %tmp / %pky
This example demonstrates the use of %pre , %tmp and %pky with an unmanaged RAP BO in a late numbering scenario.
Note that this example does not cover a production business scenario for late numbering. Instead it is intended to give an idea about the use of the BDEF derived type components.
Data model
The CDS data model consists of the root entity DEMO_UMANAGED_ROOT_LATE_NUM3.
Root entity:
DDLS DEMO_UMANAGED_ROOT_LATE_NUM3
Behavior definition
The RAP behavior definition DEMO_UMANAGED_ROOT_LATE_NUM3 is defined in RAP BDL as follows:
BDEF DEMO_UMANAGED_ROOT_LATE_NUM3
Behavior implementation
For the above RAP behavior definition, one ABP is created. The global class of the behavior pool is BP_DEMO_UMANAGED_ROOT_LATE_NU3. The actual behavior implementation takes place in local classes that are defined and implemented in the BP_DEMO_UMANAGED_ROOT_LATE_NU3CCIMP of the behavior pool.
The following class is relevant for the example:
lcl_buffer: Constitutes the transactional buffer which is an internal table in this example. It contains all fields of the database table and further fields that are used in the example, for example, the internal table also contains the components %pid and %cid. Furthermore, there are components representing flags like changed and final_key_assigned. The first one is used to flag whether an instance has been created or changed and thus should be saved. The second specifies whether final keys have been assigned to the instance.
The following methods are relevant for the example:
create: Creates the instances and writes them to the transactional buffer. In this case, a %pid as well as a preliminary value for %key is created for the instances.
update: Updates instances. Here, the use cases are covered when instances are updated that already have the final keys assigned and have not.
prep_root_buffer: Prepares the transactional buffer. In case of an update request on persisted instances, these instances are read from the database table into the transactional buffer.
adjust_numbers: Assigns the final keys. In this simple example, the final keys are assigned integers . Furthermore, the MAPPED LATE, which shows %pre and %tmp, and REPORTED LATE response structures are filled. For demonstration purposes, the entries for both structures are stored in two internal tables that are displayed in the output.
The save, cleanup and cleanup_finalize methods save the entries in the transactional buffer to the database table or clearing the entries respectively.

ABAP_SOURCE_CODE
DEMO CL_DEMO_RAP_DRVD_TYPES_LATENU2

ABAP_DESCRIPTION
Access with ABAP using EML
There are two ABAP_EML modify requests. The first creates multiple RAP BO instances and the second updates the new instances.
In the create request, %key is not specified. The create method creates %pid and %key for the instances.
The update request includes the modification of the previously created instances that have not yet been persisted to the database. The reference to the instances is made by using %pky. %pky contains %pid and the preliminary keys in %key. Note that this is a non-draft scenario, hence, %pky can be used. %tky could be used as well. It is even recommended that you use it since you are prepared for a potential switch to a draft scenario (here, %tky contains the same components as %pky but, if need be , it also includes %is_draft).
The save sequence is triggered using a COMMIT ENTITIES statement. In this case, the COMMIT ENTITIES variant is used with a CONVERT KEY OF statement to retrieve the preliminary keys of the instances for demonstration purposes.
The adjust_numbers method assigns the final keys to the instances. In this example, the method simply adds an integer to the key. Furthermore, the internal tables in the global class mentioned above are filled demonstrating how %pre and %tmp might be addressed. Finally, the save method saves the instances to the database table.
The output shows three tables: A table that displays the outcome of the RAP operations, i. e. the successfully saved entries in the database table. A table showing the MAPPED LATE information. A table showing the REPORTED LATE information. Both mapped and reported information were filled in the course of the adjust_numbers method.