ABAP for Cloud Development
AS ABAP Release 914, ©Copyright 2024 SAP SE. All rights reserved.
ABAP - Keyword Documentation → ABAP RAP Business Objects → ABAP for RAP Business Objects → ABAP for Consuming RAP Business Objects → ABAP EML - Consuming RAP BOs →
COMMIT ENTITIES
Syntax Forms
COMMIT ENTITIES
, Short Form1.
COMMIT ENTITIES
IN SIMULATION MODE RESPONSESresponse_param
.
COMMIT ENTITIES RESPONSE OF
, Long Form2.
COMMIT ENTITIES
IN SIMULATION MODE RESPONSE OF bdef1response_param
RESPONSE OF bdef2response_param
... .
COMMIT ENTITIES RESPONSES
, Dynamic Form3.
COMMIT ENTITIES
IN SIMULATION MODE RESPONSES OF dyn_tabresponse_param
.
COMMIT ENTITIES BEGIN, END
4.
COMMIT ENTITIES BEGIN
IN SIMULATION MODE
RESPONSE OF ... RESPONSES OF ...response_param
.
CONVERT KEY OF bdef
FROM TEMPORARY pre_key
TO final_key.
COMMIT ENTITIES END.
Description
Triggers the RAP save sequence and completes the RAP transaction. All transactional changes in the transactional buffer, that is, RAP BO instances created, modified, or deleted within the RAP transaction, are persisted to the database.
At the end of an ABAP session, the saving of changed or created data to the database must be triggered, which is done by COMMIT ENTITIES
statements. Otherwise, the changes are lost. COMMIT ENTITIES
terminates RAP transactions. If the RAP transactions include RAP modify operations, i. e. there were ABAP EML MODIFY
statements before a COMMIT ENTITIES
statement, an implicit COMMIT WORK
is triggered after processing the save sequence.
Therefore, all RAP BO instances that are present in the transactional buffer are persisted to the database. However, COMMIT ENTITIES
follows an all or nothing approach, i. e. either all instances are valid and correct and all can be saved or none can be saved if at least one instance is invalid.
COMMIT ENTITIES
statements can be used for RAP modify operations by RAP BO consumers to trigger the data persistency but they cannot be used in ABAP behavior pools in ABAP. In case of a natively supported RAP scenario (for example, an SAP Fiori app using OData), the COMMIT ENTITIES
call is not to be used since it is performed implicitly and automatically by the RAP transactional engine.
System Fields
COMMIT ENTITIES
statements set the system field sy-subrc
. Note that when using COMMIT ENTITIES
statements, it is not guaranteed that the implicit COMMIT WORK
will be carried out successfully. In the event of failures during the RAP save sequence, the RAP saver method cleanup_finalize
is called for all involved RAP business objects to ensure that the transactional buffer is cleared for the current RAP transaction. The RAP save sequence is then terminated without persisting the instances to the database. This is indicated by the value set for the system field sy-subrc
when executing COMMIT ENTITIES
statements.
Note: The following statements are only valid for COMMIT ENTITIES
statements terminating RAP transactions that include RAP modify operations.
sy-subrc | Meaning |
---|---|
0 | The implicit COMMIT WORK has been carried out successfully if a RAP transaction that is terminated by a COMMIT ENTITIES statement includes RAP modify operations. |
4 | The implicit COMMIT WORK has not been carried out successfully. An issue occurred in the early phase of the RAP save sequence (involved RAP saver methods: finalize , check_before_save ). The value 4 for sy-subrc means that there are responses returned by the failed parameter because of failures in the RAP save sequence. Transactional changes successfully executed in the RAP interaction phase remain in the transactional buffer. |
8 | The implicit COMMIT WORK has not been carried out successfully. An issue occurred in the late phase of the RAP save sequence (involved RAP saver methods: save or save_modified ). Such an issue can produce inconsistencies which triggers the clearing of the transactional buffer and a ROLLBACK WORK internally. A subsequent RAP modify operation can then lead to a runtime error. If the RAP BO consumer is to proceed after an issue in the late phase of the RAP save sequence, an explicit ROLLBACK ENTITIES is required. |
The following variants of the COMMIT ENTITIES
statement are available:
COMMIT ENTITIES
, Short Form- The short form of the
COMMIT ENTITIES
statement saves all instances of RAP BOs that are changed within the RAP transaction. COMMIT ENTITIES
, Long Form- The long form of the
COMMIT ENTITIES
statement saves all RAP BO instances that are changed within the RAP transaction and provides responses for individual RAP BO entities. COMMIT ENTITIES OPERATIONS
, Dynamic Form- The dynamic form of the
COMMIT ENTITIES
statement allows the root entities for which the commit should be executed to be specified dynamically. COMMIT ENTITIES BEGIN, END
- This form of the
COMMIT ENTITIES
statement is relevant forlate numbering
scenarios.
Hints
- Using a
COMMIT WORK
statement also triggers the RAP save sequence and saves RAP BO instances from the transactional buffer to the database. However, the use ofCOMMIT ENTITIES
statements is preferable in the context of RAP because they offer more features like the retrieval of responses information or key conversion. COMMIT ENTITIES
statements are not allowed in RAP BO providers.- ABAP EML statements should not be used in loops. Using them can have a performance impact because it can result in multiple single database accesses. There should be only one ABAP EML statement to read the necessary data, and then the data should be modified with an ABAP EML modify request.
- When using
COMMIT ENTITIES
statements, a check ofsy-subrc
should be included to avoid syntax warnings. If responses are retrieved, it is recommended that the response parameterfailed
is checked so as to react accordingly. - If in the RAP interaction phase only read operations are executed and a
COMMIT ENTITIES
statement is specified, only thecleanup
method is called. - Commits in the context of RAP projection behavior definitions (or RAP interface behavior definitions): RAP BO instances that fail to be committed in the RAP save sequence for the base RAP BO are returned to the RAP BO consumer. The messages in the
failed
RAP response parameter are automatically mapped to projections.
Executable Examples
The following executable examples demonstrate the use of the respective statements.