SAP SHEET RAP CALC DR LN M ABEXA



Get Example source ABAP code based on a different SAP table
  



RAP Calculator: Managed, Draft-Enabled RAP BO with Late Numbering
This example represents a calculator using RAP concepts, i. e. using ABAP_EML in the context of a managed and draft-enabled RAP business object with RAP late numbering to carry out simple calculations. Here, a RAP BO instance consists of a calculation ID (which is the key that is finally set not until the RAP save sequence), two operands (having integer values), the arithmetic operator and the result plus other draft-related fields.
Data model
The CDS data model consists of the root entity DEMO_CS_RAP_DRAFT_M :
DDLS DEMO_CS_RAP_DRAFT_M
Behavior definition
The RAP behavior definition DEMO_CS_RAP_DRAFT_M is defined in RAP BDL as follows:
BDEF DEMO_CS_RAP_DRAFT_M
Behavior implementation
For the above RAP behavior definition, one ABP is created. The global class of the behavior pool is BP_DEMO_CS_RAP_DRAFT_M. The actual behavior implementation takes place in local classes that are defined and implemented in the BP_DEMO_CS_RAP_DRAFT_M========CCIMP of the behavior pool. See comments in the code for more information on the implementation.

ABAP_SOURCE_CODE
DEMO CL_DEMO_CS_RAP_DRAFT_LN_M

ABAP_DESCRIPTION
RAP Calculator within a class
The above source code uses EML to access the RAP business object from an ABAP class.
The class that acts as RAP BO consumer here demonstrates the following:
Creating instances and saving to the database First, five instances are created using an ABAP_EML MODIFY statement, i. e. five calculations are triggered. All of them use a different arithmetic operator. They all return a valid result. To show the effect of the statement, the entries of the draft table and the database table are retrieved and displayed. At this stage, the entries are not yet available in the database table. Then, the activate action is executed so that the entries in the draft table are persisted to the database table. The table entries are retrieved again showing that the draft table has no entries. All instances have been persisted to the database.
Creating invalid entries Three instances are created using an ABAP_EML MODIFY statement , i. e. three calculations are carried out. All of them fail either by using a wrong operator or because of a division by 0 or an arithmetic overflow issue. Consequently, the FAILED and REPORTED response parameters are filled with these instances. In the same way as above, the table entries are retrieved and displayed before and after executing the activate method. Here, the invalid entries are not persisted to the database.
Correcting and updating invalid entries The three invalid entries are updated so that the calculation is successful and a valid result is returned. Finally, the now valid instances are saved to the database table.
RAP Calculator using an SAP Fiori Elements app
You can test the RAP Calculator using the preview version of an SAP Fiori Elements app as follows: In ADT, search for and open the service binding DEMO_RAP_CALC_DR_SB. It is contained in the same package as the class mentioned above. Make sure that the Local Service Endpoint in the Service Version Details section is published. Select the entity set DEMO_CS_RAP_DRAFT_M and choose Preview . An app is opened in a browser. If you are prompted, provide the system credentials to log on. The app and the managed, draft-enabled RAP BO can be explored. The late numbering aspects comes into the picture when you, for example, create a new instance, i. e. create a new calculation, and you keep a draft version of it instead of saving it to the database. The calculation ID which represents the key of the instance has an initial value. The final key is only set when you save the instance to the database.
See comments in the code for more information.