Technical Articles
Step by step process of building Complex Type Entities in SAP Gateway
Hi All,
In this blog want to explain about Complex Entity Uses and how to create it in SAP Gateway Project.
Below is the scenario or use case of complex entity.
Scenario :
There can be cases where the data from Legacy system is to be inserted to SAP DB and the payload can not be modified so in order to adopt the same payload structure,complex types would be useful.
One example could be Address , let say it has 4 sub properties named as Street,City,State,Country.
So we can create a complex type of address comprising properties as Street,City,State,Country.
Another example that i had demonstrated below is for Meal that tells for which Flight Number what is the Meal Number , so it is designed like for sflight entity it has one attribute named as Meal which comprises of sub attribute mealnumber and flightnumber.
So lets proceed step wise to create such scenario.
Steps to build project for such cases are as below :
- Go to Transaction SEGW.
- Click on Create Project Icon.
- Give Project Name and description Save it in a Package.
- Right Click on Data Model and Click Complex Type
Alternatively, we can click Import and select the source (for structures , click import DDIC Structure) and select Radio button Complex Type and provide the ABAP structure name
- Provide name to complex Type
- After this either we can manually input properties or import it from structure. Here it is importing from structure SFLIMEAL
- Right click on entity name, click on Import Properties and select desired properties .
Note in complex type we don’t have to provide any properties as a key so it means
complex types are always optional.
- Now Create an entity that will have a nested type(complex type)
Right click on Data Model ,Select Create, click Entity Type. Provide name and ABAP structure.
- Select the required properties from the structure and opt for key property and then click on Finish.
- Now we have entity ready , Double click on entity name remove abap structure from there as we are going to introduce new field for complex type. If we will not remove it ,it will throw error mentioning field is not a part of structure.
- Once done open properties of entity and add new property and give complex type name as highlighted below
- Now click on Generate Icon.
- Once Successfully generated , register service and is ready to use , redefine the method in DPC EXT class as per your requirement.
- Structure in JSON format would be something like this , unless $select is supplied along with URL
{
"Carrid" : "",
"Connid" : "",
"Fldate" : "",
"Price" : "",
"Currency" : "",
"Planetype" : "",
"Meal" : {
"Mealnumber" : "",
"Connid": ""
}
}
- Please Note as it is mentioned earlier ,Complex Type are always optional so during post call we can skip it ,passing in payload ,if not required. Some valid sample payload are as below
( only Key need to be passed )
{
"Carrid" : "",
"Connid" : "",
"Fldate" : "",
"Price" : "",
"Currency" : "",
"Planetype" : ""
}
{
"Carrid" : "",
"Connid" : "",
"Fldate" : "",
"Price" : "",
"Currency" : "",
"Planetype" : "",
"Meal" : { }
}
{
"Carrid" : "",
"Connid" : "",
"Fldate" : "",
"Price" : "",
"Currency" : "",
"Planetype" : "",
"Meal" : { "Mealnumber" : "" }
}
{
"Carrid" : ""
}
Note – If you are importing from DDIC structure , the model will create the structure same as provided from import although EDM. will have only those properties which you had selected during import. In order to keep both EDM and GW Model same, remove structure name from entity after import .
References :
Hope this Blog will help…
Thank You.
Hi Krishna,
I try to add complex types but I get an error when generating. Am I skipping anything?
I ask for your help, best regards.
Error: ABAP field name '' is not part of the ABAP structure 'SFLIGHT'
entity properties
Hi
Please remove abap structure (SFLIGHT) if you have imported from structure as mentioned in para.
Now we have entity ready , Double click on entity name remove abap structure from there as we are going to introduce new field for complex type. If we will not remove it ,it will throw error mentioning field is not a part of structure.