Get Example source ABAP code based on a different SAP table
Example for CL_ABAP_BEHAVIOR_SAVER_FAILED> This example demonstrates the RAP saver class CL_ABAP_BEHAVIOR_SAVER_FAILED>> using a simple managed RAP BO with unmanaged save >. Data model> The CDS data model consists of the root entity DEMO_SAVE_F_UNM_S_M >. Root entity: DDLS DEMO_SAVE_F_UNM_S_M Behavior definition> The RAP behavior definition> DEMO_SAVE_F_UNM_S_M>> is defined in RAP BDL> as follows: BDEF DEMO_SAVE_F_UNM_S_M Behavior implementation> For the above RAP behavior definition, one ABP> is created. The global class of the behavior pool is BP_DEMO_SAVE_F_UNM_S_M>>. The actual behavior implementation takes place in local classes that are defined and implemented in the BP_DEMO_SAVE_F_UNM_S_M========CCIMP>> of the behavior pool. The ABP includes the implementation of a validation. In this simple example, the validation fails if particular fields have particular values. The class LSC_DEMO_SAVE_F_UNM_S_M> is the RAP saver class that inherits from CL_ABAP_BEHAVIOR_SAVER_FAILED>. The SAVE_MODIFIED> saver method is implemented in a way that a save is denied for a RAP BO instance if particular fields have particular values in a RAP create operation.
ABAP_SOURCE_CODE DEMO CL_DEMO_RAP_SAVER_FAILED
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 different ABAP_EML requests. Among them, there are modify requests including a create operation to create one instance in most cases. COMMIT ENTITIES> statements trigger the save sequence. These statements include the retrieval of the RAP response parameters> failed > and reported>. After most modify requests, the responses - if there are any - are displayed. A SELECT> statement retrieves the entries on the database table to show the effect of the RAP operations. The following is covered: Successful saving of a RAP BO instance Demonstrates a successful RAP create operation. The validation and the saving is carried out successfully. The value of sy-subrc> is 0 after the COMMIT ENTITIES> statement. There are no early and late responses. Failure in the RAP interaction phase Demonstrates a failure in the RAP interaction phase. The RAP create operation includes two RAP BO instances. One of these includes a key value that is already available in the database table. Hence, the creation of this instance fails. The early failed response includes an entry. A subsequent read operation shows that the erroneous instance is not present in the transactional buffer. The other instance is then saved to the database. Failure in the early save phase Demonstrates a failure in the early phase of the RAP save sequence (the validation fails). The value of sy-subrc> is 4 after the COMMIT ENTITIES> statement. A read operation demonstrates that the RAP BO instance that has failed is still available in the RAP transactional buffer>. A RAP update operation is carried out on the failed instance to correct the issue. Failure in the late save phase Demonstrates a failure in the late phase of the RAP save sequence (in the SAVE_MODIFIED> method). Due to the implementation mentioned above, the saving of the RAP BO instance is denied. The response parameters are filled in the SAVE_MODIFIED> method. The value of sy-subrc> is 8 after the COMMIT ENTITIES > statement. A read operation demonstrates that the RAP BO instance that has failed is not available in the transactional buffer. RAP BO consumer proceeds after a failure in the late save phase After an issue occurred earlier in the late save phase, sy-subrc > was set to 8. The RAP BO consumer cannot continue unless there is an explicit rollback. Therefore, the example includes a ROLLBACK ENTITIES> statement that precedes another RAP create operation. If the statement is not specified, the runtime error CX_SADL_DUMP_APPL_MODEL_ERROR> will be raised.