Get Example source ABAP code based on a different SAP table
Example for RAP Saver Methods This example demonstrates RAP saver methods within a RAP saver class using a simple unmanaged RAP BO. Data model> The CDS data model consists of the root entity DEMO_UNMANAGED_ROOT > and its child entity DEMO_UNMANAGED_CHILD>. Root entity: DDLS DEMO_UNMANAGED_ROOT Child entity: DDLS DEMO_UNMANAGED_CHILD Behavior definition> The RAP behavior definition> DEMO_UNMANAGED_ROOT>> is defined in RAP BDL> as follows: BDEF DEMO_UNMANAGED_ROOT Behavior implementation> For the above RAP behavior definition, one ABP> is created. The global class of the behavior pool is BP_DEMO_UNMANAGED_ROOT>>. The actual behavior implementation takes place in local classes that are defined and implemented in the BP_DEMO_UNMANAGED_ROOT========CCIMP>> of the behavior pool. Note >: The ABP purposely includes only few handler method implementations since the focus is on the saver methods. The class lsc_demo_unmanaged_root> is the RAP saver class that includes the following RAP saver methods: Method>Details> finalize> Triggers any final calculations involving all BOs in the current LUW before the data gets saved to the database. In this example, the method is implemented in a way to do a calculation on a data field. field3> should be divided by 2. Since the field is of type i>, a division by 2 with uneven numbers results in an error. In case of an error, the FAILED> and reported> parameters get filled. If the division is successful, field3> receives the result and a success message is included in the reported> parameter for the particular instance. A log table ( DEMO_TAB_SAVELOG>>) is then filled with content of the failed> (if available) and reported> structures. The purpose of this log table is to show the returned messages of the finalize>, check_before_save> and save > methods in the output. check_before_save> Contains a consistency check. An instance should only get saved if the value of data field field4> does not exceed 100>. Furthermore, the failed> and reported> parameters as well as the log table DEMO_TAB_SAVELOG>> are filled. save> Saves the data from the transactional buffer to the database. The method is only called if the finalize>, check_before_save> and adjust_numbers> methods have been processed successfully. Once the data has been saved, a success message is included in the reported> parameter and the log table DEMO_TAB_SAVELOG>>. cleanup> Clears the transactional buffer. The method is called if the save> method has been processed. cleanup_finalize> Clears the transactional buffer. The method is called if issues arise in the finalize> and check_before_save > methods.
ABAP_SOURCE_CODE DEMO CL_DEMO_RAP_UNM_SAVER_MTHDS
ABAP_DESCRIPTION Access with ABAP using EML> The above source code uses EML> to access the RAP business object from an ABAP class. The example demonstrates three different ABAP_EML MODIFY> requests. Each of the MODIFY> requests includes CREATE> operations to create three instances. COMMIT ENTITIES> statements trigger the save sequence. First MODIFY> request: The finalize> method is not processed successfully which prevents the data from being saved. Second MODIFY> request: The finalize> method is processed successfully while the check_before_save> method is not. The data is not saved. Third MODIFY> request: Both finalize> and check_before_save> method are processed successfully. As a consequence, the save> method is called and the data is saved to the database table. The output shows three sections for each MODIFY> request:
A log table including the saver methods that have been called.
A log table including information that has been returned for failed > and reported>.
A table including the database table entries after the CREATE> operations. However, the output of the first two MODIFY> statements does not show the table since the CREATE> operations cannot be processed successfully on purpose.