EML CREATE BY ASSOCIATION in RAP

  • EML (Entity Manipulation Language) is used in RAP to programmatically create, read, update, and delete data in your business object.
  • When you want to create child entities (composition nodes) in RAP, you often use CREATE BY ASSOCIATION.
  • Why?
    • Because the child entity needs to be linked to the parent entity (the association).
                        Refer - Working with Large objects(LOB) in RAP
                                        Download the file into local machine.
                                        File type validations in RAP
                                             
Step 1: Create a class and declare interface- if_oo_adt_classrun and implement the main method.

CLASS zcl_ab_eml_crea DEFINITION

PUBLIC

FINAL

CREATE PUBLIC .


PUBLIC SECTION.

INTERFACES if_oo_adt_classrun.

PROTECTED SECTION.

PRIVATE SECTION.

ENDCLASS.


CLASS zcl_ab_eml_crea IMPLEMENTATION.

METHOD if_oo_adt_classrun~main.

DATA: lt_students TYPE TABLE FOR CREATE ziv_ab_hdr_stu13,

lt_attchments TYPE TABLE FOR CREATE ziv_ab_hdr_stu13\_attach,

ls_attchments LIKE LINE OF lt_attchments,

lt_target LIKE ls_attchments-%target.


lt_students = VALUE #( ( %cid = 'Header' StuName = 'Vinod' StuAge = '35' StuCourse = 'CSE'

StuCourDur = 4 StuStatus = ' ' StuGender = 'M' StuDob = sy-datum

%control = VALUE #(

StuName = if_abap_behv=>mk-on

StuAge = if_abap_behv=>mk-on

StuCourse = if_abap_behv=>mk-on

StuCourDur = if_abap_behv=>mk-on

StuStatus = if_abap_behv=>mk-on

StuGender = if_abap_behv=>mk-on

StuDob = if_abap_behv=>mk-on

) ) ).

lt_target = VALUE #( ( %cid = 'Item' AttchId = 11 Comments = 'test file' Attchment = 'test.txt'

%control = VALUE #(

AttchId = if_abap_behv=>mk-on

Comments = if_abap_behv=>mk-on

Filename = if_abap_behv=>mk-on

) ) ).

lt_attchments = VALUE #( ( %cid_ref = 'Header' %target = lt_target ) ).


"Save data

MODIFY ENTITIES OF ziv_ab_hdr_stu13

ENTITY Student

CREATE FROM lt_students

CREATE BY \_attach FROM lt_attchments

MAPPED DATA(lt_mapped)

FAILED DATA(lt_failed)

REPORTED DATA(lt_reported).


IF lt_failed IS INITIAL.

COMMIT ENTITIES.

out->write( EXPORTING data = 'Records created sucessfully' ).

ENDIF.

ENDMETHOD.

ENDCLASS.


Step 2: Check and activate.
Step 3: Run as abap application console.
                                                        
Testing: 
         * Preview the application.
        * Click on go to see all records.
        * Click on create record to see object details.



********************************Thank you*****************************

Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).