Application Development and Automation 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: 

Import from file JSON

0 Kudos
7,586

Hello experts 🙂

I need to import data from the * .JSON file into the internal SAP table.
I tried to use the "GUI_UPLOAD" CALL FUNCTION, but the * JSON file has too long entries.
The fields are max 128 characters, but the file has no enteres.
And "GUI_UPLOAD is trying to put everything on one line ...
What to do?

11 REPLIES 11

FredericGirod
Active Contributor
3,661

your internal table has a structure, or you just want to insert the whole file directly, like a text ?

3,661

My internal table and function:

TYPES: BEGIN OF ty_up,
wiersz type c LENGTH 256,
END OF ty_up.
DATA: it_up TYPE TABLE OF ty_up.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

TABLES

data_tab = it_up[]

This file *.json is big (200 MB).

I want to put every new entry in the field on a new line.

Is it possible to set a new line after some character?

0 Kudos
3,661

Sample of file which I need to import to SAP and what is importing to table.file.jpgimport.jpg

FredericGirod
Active Contributor
3,661

replace the function module by the class/method cl_gui_frontend_services=>gui_upload

there is no size limit

raphael_almeida
Active Contributor
0 Kudos
3,661

Hi tomasz.piwowarski ,

Try to upload your json using the stringtab type (it's a unlimited string structure).

BR,

Pacheco.

raphael_almeida
Active Contributor
3,661

Also, you can use the /ui2/cl_json=>deserialize static class to pass this string to your internal tab.

Example:

/ui2/cl_json=>deserialize( EXPORTING json = <your json string> pretty_name = /ui2/cl_json=>pretty_mode-camel_case CHANGING data = <internal tab> ).

BR,

Pacheco.

FredericGirod
Active Contributor
3,661

raphael.almeida you should transform your comment into an answer (button Actions)

GK817
Active Contributor
0 Kudos
3,661

Hi,

I suggest to use class /ui2/cl_json. For sample code and to see how it works, please refer below links:

https://wiki.scn.sap.com/wiki/display/Snippets/One+more+ABAP+to+JSON+Serializer+and+Deserializer

Check comments too.

Sandra_Rossi
Active Contributor
0 Kudos
3,661

I see exactly the same contents in notepad and in ABAP. So it's not an ABAP question. Why do you think there should be a "newline characters" at the places you show? What is the logic for a program to determine the places where the "newline characters" should be inserted?

DoanManhQuynh
Active Contributor
0 Kudos
3,661

I think you go into wrong direction. GUI_UPLOAD just up your text file as it is so your screenshot is correct. if you still want to use that fm, just change the table it_up to string table type.

if what you want is convert the json to itab, you could search "convert JSON" or "JSON to ABAP"...you will find a lot of threads, or try yourself with SAP sXML library, asJSON...

0 Kudos
3,661

Thank you all for your help

Now i use this code:

DATA : v_file TYPE string.
DATA tab1 TYPE TABLE OF string.

cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = v_file
filetype = 'ASC'
has_field_separator = '#'
read_by_line = 'X'
CHANGING
data_tab = tab1
).

And now I have problems with size of the file...

error - DP_OUT_OF_MEMORY

I shoud first put the file on the application server.

Basic will help me with putting the file.

But how i can read the file?

Can I put application server file path into cl_gui_frontend_services=>gui_upload ?