Skip to Content
-1

JSON to ABAP Conversion

Nov 16, 2017 at 08:02 AM

237

avatar image
Former Member

Hi Experts

I am trying to Upload JSON file into SAP internal table and perform some actions on it.

I have referred already to these links:

https://blogs.sap.com/2013/01/07/abap-and-json/

https://answers.sap.com/questions/195916/complex-json-structure-to-abap.html and

https://archive.sap.com/discussions/thread/3817827

However, there is no information on how to UPLOAD a json file directly into an internal table.

Any pointers will be appreciated.


Regards

Dinesh

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member Nov 20, 2017 at 07:13 AM
0

Hi..

Thanks for helping.. Solved the issue on own by reading character by character. In actual the json file was pretty complex and Standard SAP was taking a lot of time to deserialize.

Thanks

Show 1 Share
10 |10000 characters needed characters left characters exceeded

For complexity, I can understand, but for performance a test of custom ABAP versus kernel had shown that ABAP is slower than kernel (performance ratio was 1.7 for ABAP versus 1 for Kernel - https://wiki.scn.sap.com/wiki/display/Snippets/Performance+of+JSON+from+scratch+-+sXML+versus+ZCL_MDP_JSON )

0
avatar image
Former Member Nov 16, 2017 at 04:29 PM
1

Hi dear.

Follow this example, if it's what I imagined.

First, you have to create a structure like your json response;


TYPES:

TY_T_NAMES TYPE TABLE OF STRING WITH EMPTY KEY,

BEGIN OF TY_ROOT,
MESSAGE TYPE STRING,
NAMES   TYPE TY_T_NAMES,
END OF TY_ROOT.

DATA RESULT TYPE TY_ROOT.

  DATA(_JSON) = '{' &&
                   '"Message":"Hello",' &&
                   '"Names":["John","Julie","Mark","Juan"]' &&
                '}'.

After that, you can use this method to deserialize the data;

/UI2/CL_JSON=>DESERIALIZE( 
 EXPORTING 
   JSON = _JSON 
 CHANGING 
   DATA = RESULT ).

Check it

Enio,

Regards;


print-1.png (10.5 kB)
print-2.png (13.1 kB)
Share
10 |10000 characters needed characters left characters exceeded