Accessing RAP objects via EML (Entity Manipulation Language)

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Access RAP Business Objects using Entity Manipulation Language (EML)

Access RAP business objects via EML (Entity Manipulation Language)

Entity Manipulation Language (EML)

The Entity Manipulation Language (EML) is a part of the ABAP language that enables access to RAP business objects.

Because the consumption of business objects via the OData protocol requires a Fiori UI or a web API, EML enables type-safe access to business objects directly by using ABAP. EML interacts with business objects by triggering their operations for specified entities. An operation can only be triggered by EML if the operation is specified for the relevant entity in the behavior definition and if it is implemented accordingly.

Use Cases of EML

Accessing RAP Business Objects with EML

The following EML statements represent those that can be used for interacting with business objects:

READ

The READ statement provides read access to entity instances and returns the requested instances and fields. This statement can be used as a basic operation that provides necessary data to work with in subsequent business logic.  

Code Example

Code snippet
READ ENTITIES OF /DMO/R_Travel_D IN LOCAL MODE 
ENTITY Travel 
FIELDS ( BeginDate EndDate TravelID ) 
WITH CORRESPONDING #( keys ) 
RESULT DATA(travels) 
FAILED DATA (failed) 
REPORTED DATA (reported). 
Copy code

The above statement reads the begin date, the end date, and the semantic ID of travel instances identified by the importing parameter keys. In the behavior pool of the reference business object, this READ statement is used in the validation validateDates to provide the data to be validated in subsequent checks.

The READ statement is introduced by the keywords READ ENTITIES OF followed by the behavior definition of the business object the statement refers to.

Since this statement is contained in the behavior pool of the business object it refers to, the keywords IN LOCAL MODE are used. They ensure privileged access to the underlying CDS views that returns all data sets even if access controls are defined in a DCL.

The statement at hand reads the data of travel instances, hence the ENTITY Travel is specified. Here, we use the alias specified for the entity in the behavior definition.

The next line states the fields whose values are to be included in the read result.

The keywords WITH CORRESPONDING #( keys ) indicate that the read operation will be performed on instances with the primary keys contained in the internal table keys. This internal table is provided as an importing parameter of the validation method.

The internal table specified after the keyword RESULT acts as a response parameter that contains the result of the read operation. The type of this response parameter is derived from the specified entity and from the triggered read operation by the framework.

READ BY Association

The READ BY association statement uses an association of the entity specified in the EML statement in order to read instances of an associated entity.

Code Example

Code snippet
READ ENTITIES OF /DMO/R_Travel_D IN LOCAL MODE 
ENTITY Booking BY \_Travel 
FIELDS ( TravelUUID ) 
WITH CORRESPONDING #( keys ) 
RESULT DATA(travels) 
LINK DATA(link) 
FAILED DATA(failed) 
REPORTED DATA(reported). 
Copy code

Since this read statement is contained in the behavior pool of the business object it refers to, the keywords IN LOCAL MODE are used. They ensure privileged access to the underlying CDS views that returns all data sets even if access controls are defined in a DCL.

The statement at hand reads the data of travel instances, but the association specified for the booking entity is used. Hence, the ENTITY Booking is specified. Here, we use the alias specified for the entity in the behavior definition.

To indicate that the read operation is to be performed by an association, the syntax BY \ is used. After that, the name of the association specified in the according CDS entity is used.

The next line states that only the value of the field TravelUUID is to be included in the read result.

The keywords WITH CORRESPONDING #( keys ) indicate that the read operation will be performed for instances with those primary keys that are contained in the internal table keys. This internal table is provided as an importing parameter of the determination method.

The internal table specified after the keyword RESULT acts as a response parameter which contains the result of the read operation. The type of this response parameter is derived from the specified entity and from the triggered read operation by the framework.

The internal table declared after the keyword LINK acts as another response parameter. It contains the primary keys of the source and the target entity instances involved in the read-by-association operation. Since the association _Travel is used in this case, the source is a booking instance and the target is a travel instance. The type of this response parameter is derived from the specified entity and from the triggered read operation by the framework. The response parameter LINK is not used in the determination mentioned above.

Similar to the above, there are other EML statements described below for accessing the Business Objects with EML:

  • MODIFY

  • GET PERMISSIONS

  • SET LOCKS

  • COMMIT ENTITIES

  • ROLLBACK ENTITIES

  • Common Response Parameters

Check out this SAP Help link for further information - Examples for Accessing Business Objects with EML

You will be using the EML statement to trigger the Purchase Requisition API in the upcoming exercise.

Save progress to your learning plan by logging in or creating an account