What Is Entity Manipulation Language and How to use EML operation during CRUD

Estimated read time 14 min read

In This Blog We Will Discussed About What Is EML Operation In RAP And How To Create a EML Operation.  

EML stands for Entity manipulating language. 

EML is a part of ABAP and using which user can access the data of RAP business objects in an ABAP Program. 

EML statements allow the data content of a RAP Business object to be read and modified. 

It is a part of ABAP to manage to read, create, update, delete the data into the DB Table 

In which version EML is available?  

EML – Entity Manipulation Language is available after 1902 Cloud release and 1909 on-premise release.

EML Flow 

 

Generally where is EML used ?  

Usually, Business objects that are implemented with the ABAP RESTful architecture based on the behavior definition and implementation of the interaction phase and save sequence in behavior pools can be consumed by means of OData protocol (Fiori UIs, or Web APIs). 

Now to access them through ABAP code EML syntax is used. 

First we can check Flow of EML operation With Fun analogy: –  

Birthday party house  Cake preparing Shop Baker will preparing a cake Once that person prepares cake, he needs to give it to Delivery Delivery boy will send that cake to Birthday boy House Once birthday boy received a cake then they will celebrate a birthday 

For this flow we can do some modification. 

ROOT ENTITY, EML, SAVE SEQUENCE, FINAL DATA, DATABASE, how these 5 components interact with our ABAP Rap. 

First baker man will prepare a cake whatever they need to add it in cake like Cherry, Cream, once he prepares a cake baker man will Give it to Delivery person. 

Here baker man Indicates EML 

Once The delivery person will deliver the cake to the  Birthday party house, House will be representing the database, and final data will be representing the Cake.

Final data means cake will be entered to the DB table that is Birthday Boy. 

And a few more concepts we can analogy with this concept The SAVE SEQUENCE can take a multiple Routes. 

Once cake is delivered to home Then we can celebrate a birthday. 

Save sequence can have multiple Routes Save such as, 

Un-managed save —> Customization of SQL Query or BAPI CALL FUNCTION MODULE to perform save the data to the DATABASE. Save with additional save –-> Apart from the standard save, internally or runtime custom code will run before the final save is called. Save with modify –> complete overriding code with a existing save at runtime and completely modifying in managed scenario itself. 

By this fun analogy we can get to know, When the commit is triggered then only, we can do the crud operation to the Database table Using EML concept. 

COMMIT ENTITIES: –  

Commit entities Triggered ABAP RAP framework When save sequence RAP Business object is changed using Modify statement is saved in Transactional buffer, the saving of changed or created data to the DATABASE must be triggered which is done by COMMIT ENTITIES. 

Now let us see what are steps we need to follow while creating a EML operation In RAP: –  

Steps to create EML 

Create a Database table For required fields Create Interface CDS view  Create Consumption CDS view Add metadata extension to the consumption view Create Behavior definition Create a service definition Create a service binding Create a  Behavior implementation  

1. Create a database table with the name of (ZJBM_DT_USER)

2. Create Interface CDS view (ZI_JBM_USER) 

3. Created a Consumption CDS view and also add @Metadata.allowExtensions: true Annotation (ZC_JBM_USER) 

4. Create a metadata extension to the consumption view (ZC_JBM_USER) 

5. Create a behavior definition of consumption view 

6. Now create a service definition 

 7. Create a service binding 

8. Select a consumption view and click on preview, we can see field in Front end And we can see there is no data is Present 

Now we need to Create a data with the help of EML operation 

For behavior definition we need to create a behavior implementation after we need to Do crud operation.  In behavior implementation write a crud operation. 

For this purpose, am taking instance method like SAMPLE_CREATE, SAMPLE_READ,  SAMPLE_UPDATE, SAMPLE_DELETE. 

 First am starting with SAMPLE_CREATE method implementation. 

We need to declare an interface as IF_OO_ADT_CLASSRUN  

This interface is used to do CRUD operation in Business object. 

First am going to implement Sample_create method. 

Declaring the internal table for root entity view 

%CONTROL this will tells like which are the fields you want to store to the DB table 

IF_ABAP_BEHV this interface helps to insert the data to the DB table,  

If you don’t want to insert the data for the particular fields we can make it as  

IF_ABAP_ BEHV=>MK-OFF 

Here am  inserting the data to the Database so am using IF_ABAP_BEHV=>MK-ON. 

Modify entities this statement will saves the data to the Transactional Buffer. 

After am taking MAPPED DATA, FAILED DATA, REPORTED DATA now i will explain what are those. 

Mapped data: – contains key mapping information (contains table key value) only available for modify entity or modify entities). 

Failed data: – Contains details about operation which is not successful or that cloud not be processed. 

Reported data: –  contains any error message as result of failed operation  

Inside a interface method we need to call the sample_create method. After method we need to use COMMIT_ENTITIES Statement once the commit entity statement is triggered then only data will be updated into the data base table. 

Now execute the code in ABAP CONSOLE 

Now we can see the database table Updated record 

 

Now I will do SAMPLE_UPDATE method to update the data. 

Here we need to mention which fields we are going to update in DB table 

Inside a Interface method calling the SAMPLE_UPDATE method and Commit entities Statement 

In Database table we can see the changes in Updated data  

 

Now we can go for SAMPLE_READ method Implementation. 

This logic inside a interface method 

Output in console: 

Now am doing SAMPLE_DELETE method implementation. 

Inside a SAMPLE_DELETE method logic 

Calling SAMPLE_DELETE method in a interface  

Output: – 

Refer the code below for the whole program inside a behavior implementation class.   

 

 

CLASS zbp_c_jbm_user DEFINITION PUBLIC FINAL CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES : if_oo_adt_classrun.
METHODS : sample_read,
sample_update,
sample_delete,
sample_create.
ENDCLASS.

CLASS zbp_c_jbm_user IMPLEMENTATION.
METHOD sample_create.
DATA : lt_user TYPE TABLE FOR CREATE zc_jbm_user.
lt_user = VALUE #( ( userid = 2
userName = ‘Jyothi’
userage = 22
%control = VALUE #(
userid = if_abap_behv=>mk-on
username = if_abap_behv=>mk-on
userage = if_abap_behv=>mk-on )
) ) .
MODIFY ENTITIES OF zc_jbm_user ENTITY user CREATE FROM lt_user
MAPPED DATA(lt_mapped)
FAILED DATA(lt_failed)
REPORTED DATA(Lt_reported).
ENDMETHOD.

METHOD sample_update.
MODIFY ENTITY zc_jbm_user
UPDATE FIELDS ( Username UserAge )
WITH VALUE #( (
UserId = 1
UserName = ‘Swathi’
UserAge = 28 ) ).
ENDMETHOD.

METHOD sample_read.
* READ ENTITY zc_jbm_user ALL FIELDS WITH VALUE #( (
* UserId = 1 ) )
* RESULT DATA(lt_read_data).
ENDMETHOD.

METHOD sample_delete.
MODIFY ENTITY zc_jbm_user
DELETE FROM VALUE #( (
UserId = 2 ) ).
ENDMETHOD.

METHOD if_oo_adt_classrun~main.
“===========Sample create method calling inside a interface Main
sample_create( ).
COMMIT ENTITIES.
IF sy-subrc = 0.
WRITE : / ‘Data Is Inseted In Database Table’.
ELSE.
WRITE : / ‘No data Inserted’.
ENDIF.
“============Sample update method===========
sample_update( ).
COMMIT ENTITIES.
IF sy-subcs = 0 .
WRITE : / ‘Record update to The DB table’.
ELSE.
WRITE : / ‘No Record update to the DB table’.
ENDIF.
“=====================sample_read method=======
READ ENTITY zc_jbm_user ALL FIELDS WITH
VALUE #( (
UserId = 1 ) )
RESULT DATA(lt_result).
out->write( lt_result ).

” ================Sample delete method
sample_delete( ).
COMMIT ENTITIES.
IF sy-subcs = 0 .
WRITE : / ‘Record Deleted to The DB table’.
ELSE.
WRITE : / ‘No Record Deleted to the DB table’.
ENDIF.
ENDMETHOD.
ENDCLASS.

 

 

 

Without using behavior implementation how can we use EML in Report program 

Inside a SAMPLE_CREATE METHOD Logic 

Create a object in a report level. 

In CDS table we can see the inserted DATA 

Now we can implement the sample_update method. 

We can see the Updated record in Table 

Now we can do for SAMPLE_DELETE Implementation 

In report we need to call those method and use it 

Output: – 

 

​ In This Blog We Will Discussed About What Is EML Operation In RAP And How To Create a EML Operation.  EML stands for Entity manipulating language. EML is a part of ABAP and using which user can access the data of RAP business objects in an ABAP Program. EML statements allow the data content of a RAP Business object to be read and modified. It is a part of ABAP to manage to read, create, update, delete the data into the DB Table In which version EML is available?  EML – Entity Manipulation Language is available after 1902 Cloud release and 1909 on-premise release.EML Flow  Generally where is EML used ?  Usually, Business objects that are implemented with the ABAP RESTful architecture based on the behavior definition and implementation of the interaction phase and save sequence in behavior pools can be consumed by means of OData protocol (Fiori UIs, or Web APIs). Now to access them through ABAP code EML syntax is used. First we can check Flow of EML operation With Fun analogy: –  Birthday party house  Cake preparing Shop Baker will preparing a cake Once that person prepares cake, he needs to give it to Delivery Delivery boy will send that cake to Birthday boy House Once birthday boy received a cake then they will celebrate a birthday For this flow we can do some modification. ROOT ENTITY, EML, SAVE SEQUENCE, FINAL DATA, DATABASE, how these 5 components interact with our ABAP Rap. First baker man will prepare a cake whatever they need to add it in cake like Cherry, Cream, once he prepares a cake baker man will Give it to Delivery person. Here baker man Indicates EML Once The delivery person will deliver the cake to the  Birthday party house, House will be representing the database, and final data will be representing the Cake.Final data means cake will be entered to the DB table that is Birthday Boy. And a few more concepts we can analogy with this concept The SAVE SEQUENCE can take a multiple Routes. Once cake is delivered to home Then we can celebrate a birthday. Save sequence can have multiple Routes Save such as, Un-managed save —> Customization of SQL Query or BAPI CALL FUNCTION MODULE to perform save the data to the DATABASE. Save with additional save –> Apart from the standard save, internally or runtime custom code will run before the final save is called. Save with modify –> complete overriding code with a existing save at runtime and completely modifying in managed scenario itself. By this fun analogy we can get to know, When the commit is triggered then only, we can do the crud operation to the Database table Using EML concept. COMMIT ENTITIES: –  Commit entities Triggered ABAP RAP framework When save sequence RAP Business object is changed using Modify statement is saved in Transactional buffer, the saving of changed or created data to the DATABASE must be triggered which is done by COMMIT ENTITIES. Now let us see what are steps we need to follow while creating a EML operation In RAP: –  Steps to create EML Create a Database table For required fields Create Interface CDS view  Create Consumption CDS view Add metadata extension to the consumption view Create Behavior definition Create a service definition Create a service binding Create a  Behavior implementation  1. Create a database table with the name of (ZJBM_DT_USER)2. Create Interface CDS view (ZI_JBM_USER) 3. Created a Consumption CDS view and also add @Metadata.allowExtensions: true Annotation (ZC_JBM_USER) 4. Create a metadata extension to the consumption view (ZC_JBM_USER) 5. Create a behavior definition of consumption view 6. Now create a service definition  7. Create a service binding 8. Select a consumption view and click on preview, we can see field in Front end And we can see there is no data is Present Now we need to Create a data with the help of EML operation For behavior definition we need to create a behavior implementation after we need to Do crud operation.  In behavior implementation write a crud operation. For this purpose, am taking instance method like SAMPLE_CREATE, SAMPLE_READ,  SAMPLE_UPDATE, SAMPLE_DELETE.  First am starting with SAMPLE_CREATE method implementation. We need to declare an interface as IF_OO_ADT_CLASSRUN  This interface is used to do CRUD operation in Business object. First am going to implement Sample_create method. Declaring the internal table for root entity view %CONTROL this will tells like which are the fields you want to store to the DB table IF_ABAP_BEHV this interface helps to insert the data to the DB table,  If you don’t want to insert the data for the particular fields we can make it as  IF_ABAP_ BEHV=>MK-OFF Here am  inserting the data to the Database so am using IF_ABAP_BEHV=>MK-ON. Modify entities this statement will saves the data to the Transactional Buffer. After am taking MAPPED DATA, FAILED DATA, REPORTED DATA now i will explain what are those. Mapped data: – contains key mapping information (contains table key value) only available for modify entity or modify entities). Failed data: – Contains details about operation which is not successful or that cloud not be processed. Reported data: –  contains any error message as result of failed operation  Inside a interface method we need to call the sample_create method. After method we need to use COMMIT_ENTITIES Statement once the commit entity statement is triggered then only data will be updated into the data base table. Now execute the code in ABAP CONSOLE Now we can see the database table Updated record  Now I will do SAMPLE_UPDATE method to update the data. Here we need to mention which fields we are going to update in DB table Inside a Interface method calling the SAMPLE_UPDATE method and Commit entities Statement In Database table we can see the changes in Updated data   Now we can go for SAMPLE_READ method Implementation. This logic inside a interface method Output in console: Now am doing SAMPLE_DELETE method implementation. Inside a SAMPLE_DELETE method logic Calling SAMPLE_DELETE method in a interface  Output: – Refer the code below for the whole program inside a behavior implementation class.     CLASS zbp_c_jbm_user DEFINITION PUBLIC FINAL CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES : if_oo_adt_classrun.
METHODS : sample_read,
sample_update,
sample_delete,
sample_create.
ENDCLASS.

CLASS zbp_c_jbm_user IMPLEMENTATION.
METHOD sample_create.
DATA : lt_user TYPE TABLE FOR CREATE zc_jbm_user.
lt_user = VALUE #( ( userid = 2
userName = ‘Jyothi’
userage = 22
%control = VALUE #(
userid = if_abap_behv=>mk-on
username = if_abap_behv=>mk-on
userage = if_abap_behv=>mk-on )
) ) .
MODIFY ENTITIES OF zc_jbm_user ENTITY user CREATE FROM lt_user
MAPPED DATA(lt_mapped)
FAILED DATA(lt_failed)
REPORTED DATA(Lt_reported).
ENDMETHOD.

METHOD sample_update.
MODIFY ENTITY zc_jbm_user
UPDATE FIELDS ( Username UserAge )
WITH VALUE #( (
UserId = 1
UserName = ‘Swathi’
UserAge = 28 ) ).
ENDMETHOD.

METHOD sample_read.
* READ ENTITY zc_jbm_user ALL FIELDS WITH VALUE #( (
* UserId = 1 ) )
* RESULT DATA(lt_read_data).
ENDMETHOD.

METHOD sample_delete.
MODIFY ENTITY zc_jbm_user
DELETE FROM VALUE #( (
UserId = 2 ) ).
ENDMETHOD.

METHOD if_oo_adt_classrun~main.
“===========Sample create method calling inside a interface Main
sample_create( ).
COMMIT ENTITIES.
IF sy-subrc = 0.
WRITE : / ‘Data Is Inseted In Database Table’.
ELSE.
WRITE : / ‘No data Inserted’.
ENDIF.
“============Sample update method===========
sample_update( ).
COMMIT ENTITIES.
IF sy-subcs = 0 .
WRITE : / ‘Record update to The DB table’.
ELSE.
WRITE : / ‘No Record update to the DB table’.
ENDIF.
“=====================sample_read method=======
READ ENTITY zc_jbm_user ALL FIELDS WITH
VALUE #( (
UserId = 1 ) )
RESULT DATA(lt_result).
out->write( lt_result ).

” ================Sample delete method
sample_delete( ).
COMMIT ENTITIES.
IF sy-subcs = 0 .
WRITE : / ‘Record Deleted to The DB table’.
ELSE.
WRITE : / ‘No Record Deleted to the DB table’.
ENDIF.
ENDMETHOD.
ENDCLASS.    Without using behavior implementation how can we use EML in Report program Inside a SAMPLE_CREATE METHOD Logic Create a object in a report level. In CDS table we can see the inserted DATA Now we can implement the sample_update method. We can see the Updated record in Table Now we can do for SAMPLE_DELETE Implementation In report we need to call those method and use it Output: –    Read More Application Development Blog Posts articles 

#SAP

You May Also Like

More From Author

+ There are no comments

Add yours