| Terms | Notes |
| RAP business objects (RAP BO) | - A RAP BO is based on a special, tree-like hierarchical structure of [CDS entities](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm "Glossary Entry") of a data model - Such a structure of entities can consist of [parent entities](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenparent_entity_glosry.htm "Glossary Entry") and [child entities](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenchild_entity_glosry.htm "Glossary Entry") that are themselves defined using [CDS compositions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_composition_glosry.htm "Glossary Entry") and [to-parent associations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abento_parent_association_glosry.htm "Glossary Entry"). - The top parent entity of a [CDS composition tree](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_composition_tree_glosry.htm "Glossary Entry") is the root entity that represents the business object. With a large composition tree, RAP BOs can be fairly complex. Or they can be very simple by just consisting of one root entity alone. - Note: There is a special syntax for the [CDS root entity](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenroot_entity_glosry.htm) of a RAP BO: [`define root view entity`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_define_root_view_v2.htm) |
| [RAP behavior definition](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_behavior_definition_glosry.htm "Glossary Entry") (BDEF) | - RAP BOs are described by the definitions specified in a special [DDIC](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_glosry.htm "Glossary Entry") artifact: RAP behavior definition (BDEF) - A BDEF defines the [RAP business object behavior](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_bo_behavior_glosry.htm "Glossary Entry") (i. e. the transactional behavior of a RAP BO) - Transactional behavior means a BDEF defines [behavior characteristics](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_properties_glosry.htm "Glossary Entry") and [RAP BO operations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_bo_operation_glosry.htm "Glossary Entry") i. e. [RAP BO standard operations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_standard_operation_glosry.htm "Glossary Entry") ([CRUD operations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencrud_glosry.htm "Glossary Entry")), [non-standard operations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_nstandard_operation_glosry.htm "Glossary Entry") like specific [RAP actions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_action_glosry.htm "Glossary Entry") and [functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_function_glosry.htm "Glossary Entry"), and more. - There are many other things that can be included impacting the RAP BO behavior like [RAP feature control](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_feature_control_glosry.htm "Glossary Entry"), for example, defining which data is mandatory and which is read-only, or [determinations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_determination_glosry.htm "Glossary Entry") and [validations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_validation_glosry.htm "Glossary Entry"). - BDEFs use [Behavior Definition Language](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbdl_glosry.htm "Glossary Entry") (BDL) for the definitions. Find more information on the topic and various options to define the transactional behavior in section [BDL for Behavior Definitions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbdl.htm) in the ABAP Keyword Documentation. |
| Transactional buffer and implementation types | - A BDEF defines the behavior of a RAP BO and, thus, how to handle its data. This data is available in the [RAP transactional buffer](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentransactional_buffer_glosry.htm "Glossary Entry"). - It is a storage for a RAP BO's data that is used and worked on during an [SAP LUW](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensap_luw_glosry.htm). - This data includes [RAP BO instances](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_bo_instance_glosry.htm "Glossary Entry") (i. e. concrete data sets of an entity). This is where EML enters the picture: EML is used, among others, to access this data in the transactional buffer. - Currently, there are two kinds of RAP BOs: [managed](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenmanaged_rap_bo_glosry.htm "Glossary Entry") and [unmanaged RAP BOs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenunmanaged_rap_bo_glosry.htm "Glossary Entry"). - Managed and unmanaged are implementation types that are also specified in the BDEF. - The implementation type determines the [RAP BO provider](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_bo_provider_glosry.htm "Glossary Entry"), i. e. how the transactional buffer is provided and how the behavior of a RAP BO is implemented. |
| Managed RAP BOs | - The managed RAP BO provider fully or partly provides the transactional buffer and RAP BO behavior (for standard operations only). In this case, the developers need not cater for the transactional buffer and implement the standard operations. This implementation is mostly relevant for greenfield scenarios when starting from scratch. - Example: Regarding CRUD operations in managed RAP BOs, developers need not cater for an implementation at all. The standard operations work out of the box. For example, in case of an update operation, RAP BO instance data that is to be updated is automatically read into the transactional buffer, and then updated accordingly there. Finally, when triggering the saving, the updated instance in the transactional buffer is automatically saved to the database without any custom development needed. - The transactional buffer is provided, too. You do not need to create the buffer yourself. - Note: Usually, the behavior of a RAP BO requires some additional implementations also in the context of managed RAP BOs. For example, non-standard operations or feature controls must be self-implemented in [ABAP behavior pools](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbehavior_pool_glosry.htm "Glossary Entry") (see the details further down). |
| Unmanaged RAP BOs | - Everything must be provided by the [unmanaged RAP BO provider](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenunmanaged_rap_bo_prov_glosry.htm "Glossary Entry"), i. e. the transactional buffer and all RAP BO operations must be provided or self-implemented by developers in an ABAP behavior implementation - Unmanaged RAP BOs are, for example, relevant for brownfield scenarios, i. e. in scenarios in which transactional buffers and application logic is already available and should be embedded in the RAP world. Note that it is possible to have a managed RAP BO with unamanged parts, e.g. unamanged save or additional save. Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbdl_rap_bo.htm). |
| ABAP behavior implementation in an ABAP behavior pool (ABP) | - An [ABAP behavior pool](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbehavior_pool_glosry.htm "Glossary Entry") is a special [class pool](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclass_pool_glosry.htm "Glossary Entry") for an ABAP behavior implementation that implements the unmanaged RAP BO provider based on definitions in a BDEF. The class pool's name is specified in the BDEF. - The [global class](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenglobal_class_glosry.htm "Glossary Entry") of a behavior pool does not implement the behavior itself. It is empty on creation apart from the declaration and implementation part skeletons. The behavior implementation is coded in local [RAP handler classes](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabp_handler_class_glosry.htm "Glossary Entry") and a [RAP saver class](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabp_saver_class_glosry.htm "Glossary Entry") in the [CCIMP include](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenccimp_glosry.htm "Glossary Entry") of the behavior pool. These classes are called by the [RAP runtime engine](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_runtime_engine_glosry.htm "Glossary Entry") when the RAP BO is accessed. This is covered in more detail further down. - Usually, saver classes are not needed in managed RAP BOs (except for special variants of managed RAP BOs such as [RAP additional save](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_add_save_glosry.htm) and [RAP unmanaged save](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_unman_save_glosry.htm)). Local handler classes are usually needed in managed RAP BOs if implementations are required that go beyond standard operations. - Note: In more complex scenarios, with RAP BOs that consist of many entities, you can define behavior pools for individual entities by adding the syntax to the [`define behavior for`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbdl_define_beh.htm) notation. There is not a saver class for each entity but only one saver class for the BO as a whole. Any number of behavior pools can be assigned to a BDEF allowing applications a structuring into multiple units. |
| 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. 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. ``` |