2019 Dec 19 10:07 AM
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?
2019 Dec 19 10:09 AM
your internal table has a structure, or you just want to insert the whole file directly, like a text ?
2019 Dec 19 10:25 AM
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?
2019 Dec 19 11:43 AM
Sample of file which I need to import to SAP and what is importing to table.file.jpgimport.jpg
2019 Dec 19 11:57 AM
replace the function module by the class/method cl_gui_frontend_services=>gui_upload
there is no size limit
2019 Dec 19 11:58 AM
Hi tomasz.piwowarski ,
Try to upload your json using the stringtab type (it's a unlimited string structure).
BR,
Pacheco.
2019 Dec 19 12:01 PM
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.
2019 Dec 19 12:36 PM
raphael.almeida you should transform your comment into an answer (button Actions)
2019 Dec 19 1:34 PM
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.
2019 Dec 19 2:39 PM
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?
2019 Dec 20 12:24 AM
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...
2019 Dec 20 9:02 AM
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 ?