Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
MohamedMedhat
Explorer
20,733

In this blog, We will learn how to create a simple RAP OData V2 API and use it to achieve a Deep entity set creation operation which is requested in lot of projects and Custom services especially in complex integration scenarios without need to Create normal CDS entity with selection from DB Tables .

In this example,  CDS Custom entity views for Header and Items , Unmanaged Behavior definition, Service definition, Service Binding . 

Step #1 - > Create Custom Entity - Root Header

 

@EndUserText.label: 'Custom Entity - Root Header'
define root custom entity ZCE_R_Header
{
   key hdr_Key   : land1;
       hdr_field1: landx;
       hdr_field2: natio;
       
    _item : composition [1..*] of ZCE_I_Items ;    
}

 

Step #2 - > Create Custom Entity - for Items 

 

@EndUserText.label: 'Custom Entity - Items'
define custom entity ZCE_I_Items
{
  key hdr_Key      : land1;
  key itm_key      : bukrs;
      Company_name : butxt;
  
   _header : association to parent ZCE_R_Header on $projection.hdr_Key = _header.hdr_Key;
}

 

Step #3 - > Right Click on Custom Entity ZCE_R_Header and Create Behavior Definition 

MohamedMedhat_0-1723901628430.png

Step #4 -> Unmanaged Behaviour creation as below with Unmanaged Class implementation 

 

unmanaged implementation in class zCL_bp_ce_r_header unique;
//strict ( 2 ); //Uncomment this line in order to enable strict mode 2. The strict mode has two variants (strict(1), strict(2)) and is prerequisite to be future proof regarding syntax and to be able to release your BO.

define behavior for ZCE_R_Header //alias <alias_name>
//late numbering
lock master
authorization master ( instance )
//etag master <field_name>
{
  create;
  update;
  delete;
  field ( readonly : update ) hdr_Key;
  association _item { create; }
}

define behavior for ZCE_I_Items //alias <alias_name>
//late numbering
lock dependent by _header
authorization dependent by _header
//etag master <field_name>
{
  update;
  delete;
  field ( readonly ) hdr_Key,itm_key;
  association _header;
}

 

Step #5 -> Create Behaviour Implementation Class Save it and Activate .

Step #6 -> Implement Method cba_itm

MohamedMedhat_0-1723902215388.png

Step #7 ->  Create Service Definition 'ZCE_R_Service_Defination'

 

@EndUserText.label: 'Service Defination'
define service ZCE_R_Service_Defination {
  expose ZCE_R_Header as header;
  expose ZCE_I_Items  as items;
}

 

Step #8 -> Create Service Binding

MohamedMedhat_0-1723902712844.png

Step #9 -> Publishing Service 

MohamedMedhat_0-1723902873431.png

Step #10 -> Register and Activate SICF Node 

Step #11 -> Use below Json Payload - with Post Operation

{
  "hdr_Key"     : "T" ,
  "hdr_field1"  : "hdr_field1" ,
  "hdr_field2"  : "hdr_field2",
  "to_item" :
    [
      {
        "hdr_Key" : "01" ,
        "itm_key" : "01" ,
        "Company_name" : "Company_name1"
      },
      {
         "hdr_Key" : "02" ,
         "itm_key" : "02" ,
         "Company_name" : "Company_name2"
      }
    ]
}

Conclusion :  

we Will Find Our Deep structure data inside ENTITIES_CBA

MohamedMedhat_0-1723924897676.pngMohamedMedhat_1-1723924916335.png

 

 

5 Comments