Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
jyothi7
Explorer
0 Kudos
431

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 

jyothi7_0-1724390350045.png

 

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: -  

jyothi7_1-1724390438294.png

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

For this flow we can do some modification. 

jyothi7_2-1724390552656.png

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. 

jyothi7_3-1724391035960.png

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 

  1. Create a Database table For required fields 
  2. Create Interface CDS view  
  3. Create Consumption CDS view 
  4. Add metadata extension to the consumption view 
  5. Create Behavior definition 
  6. Create a service definition 
  7. Create a service binding 
  8. Create a  Behavior implementation  

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

jyothi7_4-1724391369390.png

2. Create Interface CDS view (ZI_JBM_USER) 

jyothi7_5-1724391369391.png

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

jyothi7_6-1724391369392.png

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

jyothi7_7-1724391369393.png

5. Create a behavior definition of consumption view 

jyothi7_8-1724391369394.png

6. Now create a service definition 

jyothi7_9-1724391369394.png

 7. Create a service binding 

jyothi7_10-1724391369395.png

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 

jyothi7_11-1724391369396.png

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. 

jyothi7_12-1724391369396.png

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. 

jyothi7_13-1724391369397.png

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. 

jyothi7_14-1724391369398.png

Now execute the code in ABAP CONSOLE 

jyothi7_15-1724391369399.png

Now we can see the database table Updated record 

jyothi7_16-1724391369399.png 

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 

jyothi7_17-1724391369400.png

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

jyothi7_18-1724391369400.png

In Database table we can see the changes in Updated data  

jyothi7_19-1724391369401.png 

Now we can go for SAMPLE_READ method Implementation. 

This logic inside a interface method 

jyothi7_20-1724391369401.png

Output in console: 

jyothi7_21-1724391369402.png

Now am doing SAMPLE_DELETE method implementation. 

Inside a SAMPLE_DELETE method logic 

jyothi7_22-1724391369402.png

Calling SAMPLE_DELETE method in a interface  

jyothi7_23-1724391369403.png

Output: - 

jyothi7_24-1724391369403.png

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 

jyothi7_25-1724393006029.png

Inside a SAMPLE_CREATE METHOD Logic 

jyothi7_26-1724393006030.png

Create a object in a report level. 

jyothi7_27-1724393006031.png

In CDS table we can see the inserted DATA 

jyothi7_28-1724393006032.png

Now we can implement the sample_update method. 

jyothi7_29-1724393006033.png

We can see the Updated record in Table 

jyothi7_30-1724393006033.png

Now we can do for SAMPLE_DELETE Implementation 

jyothi7_31-1724393006034.png

In report we need to call those method and use it 

jyothi7_32-1724393006035.png

Output: - 

jyothi7_33-1724393006036.png

Labels in this area