Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

JSON data fetching and populating in internal table in SAP

Former Member
0 Kudos

Hi Team,

I have a requirement where in I want to feed data from JSON file into SAP. JSON contains a number of arrays or entities with different fields.

For eg: [ "A" { "AF1" : "AV1" , "AF2": "AV2"} , "B" { "BF1" : "BV1" , "BF2" : "BV2" , "BF3" : "BV3"} , C... and so on.

I now want to read all these data for A, B, C.. and enter it into SAP. I created a deep structure having A,B,C as structures which in turn contains all the fields. Now, how do I add all these data into the internal table? Also, there are multiple values of A, B ,C like after C we again have another set of data A.B,C and so on.

I tried with some logic by checking characters and then for brackets and accordingly adding data. But I facing many issues.

It would of great help if you all can help me with the pointers on how to achieve this.

Thank you.

12 REPLIES 12

kiran_k8
Active Contributor
0 Kudos

Dharmin,

You get a JSON file on the app server which you have to read and get the data into the deep structure ? May be if possible you can attach the screenshot of the file so that we can see how the data is in the file.

K.Kiran

Former Member
0 Kudos

Hi Kiran,

I am calling the API service and getting the JSON data.

The file looks like this ->

kiran_k8
Active Contributor
0 Kudos

Dharmin,

Let me try.....

Usually we create an RFC FM with a deep structure getting passed as ROOT in the changing tab of the FM.This FM will be integrated within the Portal by the UI team so that whenever the Portal is run, it triggers the FM and passes the data to the ROOT structure ie it is PARSING the data from the Portal to FM and this part will be usually handled by the UI team.Only while VIEW and SAVE we manipulate the data and pass it back to the ROOT structure and which will be again be handled by UI team for display on the Portal.This is what the set up that I am currently working with since a few months.

But,I am at loss of words when you say you get an file as input.Is it really the requirement to read the data from the file ? Won't the UI team integrate the FM with the required setting such that data gets passed to the ROOT structure during PARSING.


Let's await replies from the experts.


K.Kiran.

Former Member
0 Kudos

Hi Kiran,

Thanks for the inputs. However, the data that will be received from the non SAP software through API's need to be fed in SAP through the JSON file obtained through the API.

And as per the requirement the data from this file needs to be read and update the database. So yes, that is what the requirement that has come up.

kiran_k8
Active Contributor
0 Kudos

Dharmin,

I think utlimately you have to reach to the guys handling the Non-SAP software to place the file in an mutually agreeable format so that the data can be processed further in SAP.

Seems SAP is working on FMs to handle data from JSON but not yet released for customer usage.May be you can check if the following FMs are there or search in SE37/SE24 with keyword  " *JSON*  "

FG : /RTC/COM_GUI_FG

FM : /RTC/COM_GUI_FG_GET_PROV_JSON

FG : /RTC/LIB_REPORTING_FG

FM : /RTC/LIB_REPORTING_FG_GET_JSON

FG : /RTC/LIB_REPORTING_FG_WS

FM : /RTC/LIB_REP_FG_WS_GET_JSON

K.Kiran.

Former Member
0 Kudos

Hi Kiran,

I tried building my code as per this URL . Very trusting JSON to (deep) ABAP data structure mapper · GitHub

However, it is working only for one structure as it holds only one string. I tried to append the data after one complete iteration but am not able to. The actual parameter used is a structure, while formal parameter passed is of type any. This parameter contains the entire data after first iteration , but since it is of type any, I am not able to assign or append or move it to my structure or work area.

( Line 130 - 139 .. if you would refer. )

former_member388328
Active Contributor
0 Kudos

Hi Dharmin,

Try to use this class /IWCOR/CL_DS_EP_READER_JSON.

thanking you

Vengaiah

0 Kudos

Hi Vengaiah,

It says the class does not exist.

0 Kudos

Hi Dharmin,

What is the version of the SAP. It should have gateway component.

Thanking you

Vengiaah

0 Kudos

HI,

I am using SAP 7.3, EHP 5

0 Kudos

Hello Dharmin,

I did a similar scenario using Transformation(Transformations - ABAP Development - SCN Wiki).

A similar detailed example is http://scn.sap.com/community/developer-center/netweaver-gateway/blog/2015/06/06/hybrid-odata-impleme...

Let me know in case of questions.

BR.

Former Member
0 Kudos

Search for, How to 'Deserialize JSON to ABAP'.. Use the following class.. CL_TREX_JSON_SERIALIZER