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: 
Read only

Import from file JSON

Former Member
0 Likes
11,889

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?

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
Read only

FredericGirod
Active Contributor
7,964

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

Read only

Former Member
7,964

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?

Read only

Former Member
0 Likes
7,964

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

Read only

FredericGirod
Active Contributor
7,964

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

there is no size limit

Read only

raphael_almeida
Active Contributor
0 Likes
7,964

Hi tomasz.piwowarski ,

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

BR,

Pacheco.

Read only

raphael_almeida
Active Contributor
7,964

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.

Read only

FredericGirod
Active Contributor
7,964

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

Read only

GK817
Active Contributor
0 Likes
7,964

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.

Read only

Sandra_Rossi
Active Contributor
0 Likes
7,964

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?

Read only

DoanManhQuynh
Active Contributor
0 Likes
7,964

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...

Read only

Former Member
0 Likes
7,964

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 ?