Hello Fellow SCNers,

I am writing this blog to demonstrate an example of how we can use Hybrid Odata in our Backend Developments for a POST(create) scenario.

This demonstration uses NetWeaver Gateway Foundation 7.4 SP 0008.

What is Hybrid OData?

Generally when we need to create/post multiple data records in a single backend table(like create multiple Sales Orders, multiple Purchase Orders, etc.) we use a ‘Batch’ and encapsulate multiple POST request payloads in it. When there are few records say around 1K then also due to huge data traffic the UI user can sense the latency in processing. Imagine what will be the case when its something like mass creation on materials, users, etc. in the system where data records can easily exceed by at least 10 times.

For such cases we can also explore the Hybrid OData development approach. It means sending the huge data (may be an entire file contents with thousands of records) to a single string property in an OData entity. This can be done by stringifying the data from file into JSON format and sending. Then a single POST on this entity can create all the records.

Example

Scenario: Here I have a flat file which has user details which the end user can upload from user interface and at backend the users (records from that file) should be created. They should be visible in SU01 transaction. Also for every user we need to assign/revoke authorizations for multiple applications.

OData Service –

Create a service (here ZCDP_ASSESSMENT_MANAGE_USERS).


SEGW - OData Service.png

Create an entity(here UserUpload)

SEGW - Entity Details.png

The entity has a single property of data type ‘String’. This will hold the stringified JSON sent from user interface.This is shown below-

SEGW - Entity Property Details.png


The corresponding data dictionary structure is (here ZCDP_ASSMNT_S_USER_DET) is

Entity Structure.png

Now one needs to read this Stringified JSON data and convert its contents to Internal Table so that further processing can be undertaken.

This can be done by using Transformations (http://help.sap.com/abapdocu_70/en/abapcall_transformation.htm))


Code as below –

In the Data Provider Extension Class, in the Create method of entity code as

DPC_EXT code.png

The data should look like below in debug mode –

Debug Data.png

[I will give payload details below]

Till this step we have read the data sent from UI. Now as mentioned we need to convert this to the Internal table so that normal ABAP processing can be done.

The type ZCDP_ASSMNT_S_USER_LIST will be shown below.

Convert Stringified JSON to Internal Table.png

Now we will see the parsed data in debug mode. Also, I have used a nested scenario that is every user record has multiple applications records whose access can be given/withdrawn from the user.

Table Contents.png

Nested Internal Table.png

and nested table contents for a user

Nested Internal Table contents.png

The actual table structures used above is ZCDP_ASSMNT_S_USER_LIST shown below

Actual File structure 1.png

and nested table structure is

Actual File structure 2.png

Post this all the contents in an internal table and normal ABAP processing can be done.

In case one needs to re-convert the internal table to stringified JSON and pass to UI, use below transformation code –

Declare the object of XML Writer class


Data Declartion Rev Trans 1.png

Instantiate the object


Instantiate  Rev Trans 2.png

Do the reverse transformation and parse the internal table into XString.


Then convert the XString to a string and pass back to UI.

Code Rev Trans 3.png

*——————————————————————— That’s It Folks —————————————————————–*

The Payload used for testing is

{

“UsersDetails”: “{\”USER_DET\“:[{\”BNAME\“: \”EMP9000\“,\”MANAGER\“: \”ABCD111\“,\”KOSTL\“: \”1100110011\“,\”T_LEVEL\“: \”EMP\“,\”FIRSTNAME\“: \”Employee\“, \”LASTNAME\“: \”9000\“,\”FULLNAME\“: \”Employee9000\“,\”SMTP_ADDR\“: \”EMP9000@DUMMY.COM\“,\”LOCATION\“: \”GURGAON\“,\”DISABLED\“: \”X\“,\”PROCESSING_STATUS\“: \”\“,\”ERROR_TEXT\“: \”\“,\”APPLICATIONS\“: [{\”BNAME\“: \”EMP9000\“,\”APP_ID\“: \”MANAGE_CATEGORIES\“,\”APP_MODE_INDICATOR\“: \”X\“,\”PROCESSING_STATUS\“: \”\“,\”ERROR_TEXT\“: \”\“},{\”BNAME\“: \”EMP9000\“,\”APP_ID\“: \”ASSIGN_EVALUATORS\“,\”APP_MODE_INDICATOR\“: \”X\“,\”PROCESSING_STATUS\“: \”E\“,\”ERROR_TEXT\“: \”Error ASSIGN_EVALUATORS\“}]},{\”BNAME\“: \”EMP9901\“,\”MANAGER\“: \”ABCD111\“,\”KOSTL\“: \”1100110011\“,\”T_LEVEL\“: \”EXE\“,\”FIRSTNAME\“: \”Employee\“, \”LASTNAME\“: \”9901\“,\”FULLNAME\“: \”Employee9901\“,\”SMTP_ADDR\“: \”EMP9901@DUMMY.COM\“,\”LOCATION\“: \”GURGAON\“,\”DISABLED\“: \”X\“,\”PROCESSING_STATUS\“: \”\“,\”ERROR_TEXT\“: \”\“,\”APPLICATIONS\“: [{\”BNAME\“: \”EMP9901\“,\”APP_ID\“: \”MANAGE_CATEGORIES\“,\”APP_MODE_INDICATOR\“: \”X\“,\”PROCESSING_STATUS\“: \”\“,\”ERROR_TEXT\“: \”\“},{\”BNAME\“: \”EMP9901\“,\”APP_ID\“: \”ASSESSMENT_RESULTS\“,\”APP_MODE_INDICATOR\“: \”X\“,\”PROCESSING_STATUS\“: \”E\“,\”ERROR_TEXT\“: \”Error in user 2 ASSIGN_EVALUATORS\“}]}]}”

}

* Points to note – The double quotes is a special character in JSON and it needs to be escaped. This is done by backslash character(\).

Hope this infuses some new development ideas. Looking forward for valuable feedback.

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Jagesh Lakdawala

    Hi Ankit,

    Very good approach. Thank you!

    one more add on to this is we can also upload the Excel/Text File containing the number of records to be updated in back end system, here we have to define the Entity Type as Media Type and within the UPDATE_STRAEM method we can convert the input XSTRING value to STRING and there by parsing the STRING value we can update the records in Back end system.

    Regards,

    Jagesh

    (0) 
    1. Ankit Maskara Post author

      Thanks Jagesh.

      Yes media operations (file download and upload) both are possible.

      PS: Please edit the STREAM typo in ‘UPDATE_STRAEM’.

      Best Regards,

      Ankit Maskara.

      (0) 

Leave a Reply