Get Example source ABAP code based on a different SAP table
ABAP_RAP - BDEF Projection Extension, Field Extension This example demonstrates how extension fields are added and behavior-enabled in a projection BDEF extension scenario.
Original Base RAP BO DDIC data model> The DDIC data model consists of one database table: DEMO_ROOT_EXT>>: DDIC DEMO_ROOT_EXT This database table includes structure DEMO_EXTENSION>>. DDIC DEMO_EXTENSION CDS data model> The CDS data model consists of one root entity without child entities: DEMO_RAP_FIELD_EXT>>: DDLS DEMO_RAP_FIELD_EXT Behavior definition> The RAP behavior definition> DEMO_RAP_FIELD_EXT>> is defined in RAP BDL> as shown below. It defines global authorization control and adds field attributes to several fields. BDEF DEMO_RAP_FIELD_EXT Behavior implementation> For the RAP behavior definition, one ABAP behavior pool (ABP)> is created. The global class of the behavior pool is BP_DEMO_RAP_FIELD_EXT>>, see BP_DEMO_RAP_FIELD_EXT=========CCIMP>>. This global class implements two methods:
get_instance_features>: Implements dynamic feature control for field DataField>: If field CharField> has value A>, then field DataField> is read-only. If field CharField> has any other value, then field DataField> can be accessed without any restrictions.
get_global_auth>: Defines global feature control for the complete RAP BO: Update requests are generally authorized and delete requests are generally unauthorized.
Extension RAP BO DDIC data model extension> Extension fields are added to the DDIC data model via the structure extension DEMO_EXTEND_STR>>: DDIC DEMO_EXTEND_STR CDS data model extension> The extension fields are added to the CDS data model via the CDS view entity extension DEMO_EXTENSION_RAP_BO> >: DDLS DEMO_EXTENSION_RAP_BO BDEF extension> The BDEF extension DEMO_EXTENSION_RAP_BO >> adds field attributes to the extension fields. BDEF DEMO_EXTENSION_RAP_BO ABP extension> The ABP extension is implemented in the global class BP_DEMO_EXTENSION_RAP_BO>>, see BP_DEMO_EXTENSION_RAP_BO======CCIMP>>. This global class implements dynamic feature control for the extension field NumFieldExt>: If the value of field IntFieldExt> is greater than 1000, then field NumFieldExt> is read-only. If the value of field IntFieldExt > is less than or equal to 1000, access to field NumFieldExt> is unrestricted.
Projection Layer Data model projection> The projection view DEMO_RAP_PROJ_EXT_FIELD>> projects the root node: DDLS DEMO_RAP_PROJ_EXT_FIELD View entity extension> The CDS view entity extension DEMO_RAP_PV_EX>> extends the original CDS projection view. It includes the extension fields in the projection layer. DDLS DEMO_RAP_PV_EX Behavior projection> The RAP projection behavior definition DEMO_RAP_PROJ_EXT_FIELD>> projects the base BDEF. BDEF DEMO_RAP_PROJ_EXT_FIELD BDEF projection extension> The BDEF projection extension DEMO_RAP_PROJ_BDEF_EXT>> extends the projection behavior definition. Its adds field attributes to the extension fields. BDEF DEMO_RAP_PROJ_BDEF_EXT
ABAP_SOURCE_CODE DEMO CL_DEMO_RAP_PROJ_EXT_FIELD
ABAP_DESCRIPTION Access with ABAP using EML> The source code above uses ABAP EML> to access the RAP business object> from an ABAP class:
It inserts two entity instances using MODIFY ENTITIES CREATE>>.
It updates both entity instances using MODIFY ENTITIES UPDATE>>. Field attributes from the original base BO, from the projection BO, and from the extensions are respected. Fields declared as read-only on any layer must not be updated. CharFieldExt> is not available in the derived types, since it has been suppressed.