| Variant/Addition | Notes |
| Short form of `COMMIT ENTITIES` |
The following snippet shows a create operation. This operation has only
an impact on the database with the `COMMIT ENTITIES` statement.
Triggering the save sequence means that the execution of the statement
triggers the calling of the saver methods available in the saver class
of a behavior implementation. In managed scenarios (except for some
special variants), the saving is done automatically without implementing
a dedicated saver method. Optionally, you can specify the `RESPONSES` addition followed by a data object of type `ABP_BEHV_RESPONSE_TAB` to retrieve information returned by the response parameters of RAP saver methods.
```abap MODIFY ENTITIES OF root_ent ENTITY root_ent CREATE FIELDS ( key_field field1 field2 ) WITH VALUE #( ( %cid = 'cid' key_field = 7 field1 = 'K' field2 = 'L' ) ) MAPPED DATA(mapped) FAILED DATA(failed) REPORTED DATA(rep). COMMIT ENTITIES. IF sy-subrc <> 0. ... ENDIF. ... "Some modifications DATA f_resp TYPE abp_behv_response_tab. DATA r_resp TYPE abp_behv_response_tab. "Note: Inline declarations for the data objects are also possible. COMMIT ENTITIES RESPONSES FAILED f_resp REPORTED r_resp. IF sy-subrc <> 0. ... ENDIF. ``` |
| Long form of `COMMIT ENTITIES` |
The long syntax form includes the retrieval of information for one or more RAP BO entities. Root entities must be specified.
``` abap COMMIT ENTITIES RESPONSE OF zdemo_abap_rap_ro_m FAILED DATA(f1) REPORTED DATA(r1) RESPONSE OF zdemo_abap_rap_draft_m FAILED DATA(f2) REPORTED DATA(r2). IF sy-subrc <> 0. ... ENDIF. ``` |
| Dynamic form of `COMMIT ENTITIES` |
The dynamic syntax form allows you to retrieve RAP responses from RAP saver methods by dynamically specifying one or more RAP BO root entities.
``` abap DATA: root_name1 TYPE abp_root_entity_name VALUE 'ZDEMO_ABAP_RAP_RO_M', root_name2 TYPE abp_root_entity_name VALUE 'ZDEMO_ABAP_RAP_DRAFT_M', failed_resp TYPE abp_behv_response_tab. DATA(dyn_tab) = VALUE abp_entity_name_tab( ( root_name1 ) ( root_name2 ) ). COMMIT ENTITIES RESPONSES OF dyn_tab FAILED failed_resp REPORTED DATA(reported_resp). IF sy-subrc <> 0. ... ENDIF. ``` |
| Specifying a commit scope |
- Especially used in late numbering scenarios to get the final keys from the preliminary keys (using the [`CONVERT KEY`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapconvert_key.htm) addition)
- The commit scope is opened by `COMMIT ENTITIES BEGIN ...` (`...` stands for further syntax options such as the specification of `RESPONSES ...` or `RESPONSE OF ...` ), and closed by `COMMIT ENTITIES END.`.
``` abap COMMIT ENTITIES BEGIN. ... "CONVERT KEY OF some_bo FROM ...-%pid TO DATA(some_key). "For example, converting the preliminary keys (e.g. %pid components) "based on entries in the MAPPED table of a RAP BO entity. "Using a CONVERT KEY statement, you can retrieve the final keys of "individual instances, and store them in a local variable. COMMIT ENTITIES END. ``` |
| Simulating a commit |
- The optional `IN SIMULATION MODE` addition can be specified with `COMMIT ENTITIES` statements allowing a RAP transaction to be checked.
- With this addition, only the RAP early save phase is processed without saving data, i.e. a final `COMMIT WORK` is not performed.
- The addition can be used to check the consistency of the transaction by evaluating, for example, the `sy-subrc` value as a result of executing the commit in simulation mode.
``` abap DELETE FROM zdemo_abap_rapt1. DO 2 TIMES. MODIFY ENTITIES OF zdemo_abap_rap_ro_m ENTITY root CREATE FIELDS ( key_field ) AUTO FILL CID WITH VALUE #( ( key_field = 100 ) ) MAPPED DATA(m1) FAILED DATA(f1) REPORTED DATA(r1). IF sy-index = 1. COMMIT ENTITIES IN SIMULATION MODE. ELSE. COMMIT ENTITIES. ENDIF. IF sy-subrc <> 0. ... ENDIF. "Data is not saved SELECT FROM zdemo_abap_rapt1 FIELDS key_field ORDER BY key_field INTO TABLE @DATA(tab). IF sy-index = 1. ASSERT tab IS INITIAL. "Clearing the transactional buffer ROLLBACK ENTITIES. ELSE. ASSERT lines( tab ) = 1. ASSERT tab[ 1 ]-key_field = 100. ENDIF. ENDDO. ``` |