SAP DERIVED TYPES ISDRAFT ABEXA



Get Example source ABAP code based on a different SAP table
  



Using %is_draft
This example demonstrates the use of the draft indicator %is_draft with an unmanaged RAP BO in a draft scenario.
Data model
The CDS data model consists of the root entity DEMO_UNMANAGED_ROOT_DRAFT and its child entity DEMO_UNMANAGED_CHILD_DRAFT. The child entity is not used in the example.
Root entity:
DDLS DEMO_UNMANAGED_ROOT_DRAFT
Behavior definition
The RAP behavior definition DEMO_UNMANAGED_ROOT_DRAFT is defined in RAP BDL as follows:
BDEF DEMO_UNMANAGED_ROOT_DRAFT
Behavior implementation
For the above RAP behavior definition, one ABP is created. The global class of the behavior pool is BP_DEMO_UNMANAGED_ROOT_DRAFT. The actual behavior implementation takes place in local classes that are defined and implemented in the BP_DEMO_UNMANAGED_ROOT_DRAFT==CCIMP of the behavior pool. See a detailed description of the RAP handler methods in this topic: Example for RAP Handler Methods.

ABAP_SOURCE_CODE
DEMO CL_DEMO_RAP_DRVD_TYPES_ISDRAFT

ABAP_DESCRIPTION
Access with ABAP using EML
There are two ABAP_EML modify requests that cover RAP modify operations: The first ABAP_EML modify request covers a create operation to create new RAP BO instances and an update operation on those newly created instances. In this case, the RAP operations are executed on active instances since the draft indicator %is_draft is disabled for all instances. For demonstration purposes, the instances in the update operation are referred to using %tky . Within %tky, the key is referred in different ways just to visualize the component groups. All options have the same effect and refer to the same. With a COMMIT ENTITIES statement, the instances are saved to the database. The output shows the database table entries as well as the mapped responses for the root entity to visualize the mapping of %cid and the keys, including the draft indicator. The second ABAP_EML modify request covers the creation of draft instances. In this case, the draft indicator %is_draft is enabled for all instances. With a COMMIT ENTITIES statement, the draft instances are saved to the draft table. The draft action activate which is followed by a COMMIT ENTITIES statement that finally saves the instances to the database table. The output shows the following:
Mapped responses after the RAP create operation and after the execution of the activate action, but before committing. It shows the change of the draft indicator, i. e. it is changed from disabled to enabled.
Tables are displayed that demonstrate the effect on the draft and database tables. The first two tables show the state of the draft and database table before the activation, i. e. new draft instances are created and, thus, available in the draft table. The data fields are changed due to the implementations in the ABAP behavior pool. At this stage, there have not been any changes to the database table. The next two tables show the state of the draft and database tables after the activation. The database table now includes the former draft instances that have been persisted to the database. The draft table is empty.