Ansicht
Dokumentation

ABENCDS_SIMPLE_BO_ABEXA - CDS SIMPLE BO ABEXA

ABENCDS_SIMPLE_BO_ABEXA - CDS SIMPLE BO ABEXA

PERFORM Short Reference   General Data in Customer Master  
This documentation is copyright by SAP AG.
SAP E-Book

- Simple Unmanaged RAP Business Object

This example demonstrates a simple unmanaged RAP business object and different ways of accessing it.

Note that this example rather shows technical aspects of an unmanaged business objects than correct semantical behavior. The business case - increase the price of selected flights - is achieved in a way that would not be followed in a real life scenario. Here, it is shown that the methods of an ABAP behavior pool can also be freely implemented and that this implementation can be called using EML as well as from outside an AS ABAP using an exposed service and the RAP transactional engine.

Data model

The CDS data model consists of one single root entity without child entities:

Behavior definition

The CDS behavior definition DEMO_CDS_SIMPLE_ROOT_ENTITY is defined in CDS BDL as follows:

One CRUD operation is specified with create and one additional operation is specified with action. The action expects a parameter that must be typed with a structured CDS entity, for which the following CDS abstract entity is defined:

Behavior implementation

For the above CDS behavior definition, one ABAP behavior pool (ABP) is created. The global class of the behavior pool is BP_DEMO_CDS_SIMPLE_ROOT_ENTITY. The actual behavior implementation takes place in local classes that are defined and implemented in the BP_DEMO_CDS_SIMPLE_ROOT_ENTITYCCIMP of the behavior pool. The global class has two private static attributes:

  • BUFFER, an internal table with the structured line type of the root entity DEMO_CDS_SIMPLE_ROOT_ENTITY that holds the business data.
  • LOG, an internal table of line type i, that logs the lines that were changed by the behavior implementation.

There are two local classes:

  • LHC_DEMO_SIMPLE_BO
The handler class of the behavior pool. The methods of this class implement the following operations:
  • A method MODIFY implements the create operation and the additional operation including an error handling.

  • A method READ implements the read operation.

  • LSC_DEMO_SIMPLE_BO
The saver class of the behavior pool. The methods of this class implement the actual update of the persistent data from the processed business data.

Business service

The business service DEMO_SD_SIMPLE_ROOT_ENTITY exposes the root entity DEMO_CDS_SIMPLE_ROOT_ENTITY. a service binding DEMO_SB_SIMPLE_ROOT_ENTITY binds this service to the OData protocol.

Source Code

Execute

Description

Access with ABAP using EML

The above source code uses EML to access the RAP business object from an ABAP program:

  • A create operation is executed with the statement MODIFY ENTITY.
By using the addition CREATE FROM, the method MODIFY of the handler class LHC_DEMO_SIMPLE_BO is called and an internal table is passed to the parameter create_tab. The data type of the internal table is derived with the special addition TYPE TABLE FOR CREATE of the TYPES statement. The method creates data in the static attribute BUFFER of the ABAP behavior pool by selecting from the root entity.
  • A read operation is executed with the statement READ ENTITY.
This calls the method READ of the handler class LHC_DEMO_SIMPLE_BO. Appropriate internal tables for passing the query parameters and receiving the result are again created by using special additions to the TYPES statement. The method reads those data from the static attribute BUFFER of the ABAP behavior pool that are specified by the query parameters.
  • An update operation is executed with the statement MODIFY ENTITY.
By using the addition EXECUTE, the method MODIFY of the handler class LHC_DEMO_SIMPLE_BO is called and an internal table is passed to the parameter action_tab. The internal table is constructed using the value parameter VALUE and type inference. The method modifies lines of the static attribute BUFFER of the ABAP behavior pool as specified in action_tab. Additionally, the modified lines are logged in the static attribute LOG.
  • A read operation is executed with the statement READ ENTITY.
Same as the above read operation, but the internal tables are created by the value parameter VALUE and type inference and by an inline declaration. If no error occurred, the result shows the modified data in the static attribute BUFFER of the ABAP behavior pool.
  • The changes are saved with the statement COMMIT ENTITIES.
This calls the methods FINALIZE, CHECK_BEFORE_SAVE and SAVE of the saver class LSC_DEMO_SIMPLE_BO.
  • In FINALIZE, the static attribute BUFFER of the ABAP behavior pool is reduced to the modified lines.

  • In CHECK_BEFORE_SAVE, a condition is checked.

  • In SAVE, the actual ABAP SQL UPDATE takes place on the respective DDIC database table.

Access with OData using SAP Gateway OSCI

The program DEMO_ODATA_SIMPLE_BO_GATEWAY shows, how the ICF node /sap/opu/odata/sap/demo_sb_simple_root_entity/ of the service binding DEMO_SB_SIMPLE_ROOT_ENTITY mentioned above can be accessed by an utility method of the OData Services Consumption and Integration (OSCI) component of SAP Gateway.

An appropriate HTTP request header and body is constructed and passed to method GET_INSTANCE of class /IWFND/CL_SUTIL_CLIENT_PROXY. This method passes the HTTP request as an HTTP post request to the OData service. By setting external breakpoints in the BP_DEMO_CDS_SIMPLE_ROOT_ENTITYCCIMP of the behavior pool, you can track how the behavior implementation is called by the RAP runtime framework that handles the HTTP request on the AS ABAP.

The respective DDIC database table is accessed by ABAP SQL before and after accessing the OData service in order to show the effect.

In real live applications, an HTTP request as shown here would be send by web based frameworks as SAPUI5.

Access with OData using ICF directly

The program DEMO_ODATA_SIMPLE_BO_ICF drills down the access to the OData service to using classes and methods of ICF.

The same HTTP request body is constructed as in the example above. But here, the class CL_HTTP_CLIENT is directly used to create a client object for the OData service, which is used to pass appropriate values for the HTTP request header and the HTTP request body as a post request to the OData service.

The result is the same as by using the utility method of SAP Gateway. This example serves the purpose to show a glimpse of the underlying well-known techniques of frameworks like SAP Gateway that again is part of the RAP runtime framework.






TXBHW - Original Tax Base Amount in Local Currency   ABAP Short Reference  
This documentation is copyright by SAP AG.

Length: 11831 Date: 20240425 Time: 113023     sap01-206 ( 151 ms )