‎2019 May 28 9:11 PM
Hi everyone, i'm facing the following situation: i made a report which need data input (excel tables) but i must consider the case the report is executed in background, so it must load the data input from tha application server, i could load the data from a local folder of my pc, i load the excel, and i save it in an internal table, the problem is when i want to load it from application server, with the sentence READ DATASET, i must save it into a char type struct (INTO f, and f must be char type) the problem is my struct is not type char, because it is wa of the table where i want to save the excel table, is there some way i can do this? or maybe exists some other easier way to do that?
‎2019 May 29 12:48 AM
Hello Juan,
Try to read values from dataset into a string variable and then split the string variable into respective columns of your WA.
Also depending on file format select the separator.
For example
Tab Delimited = cl_abap_char_utilites=>horizontal_tab.
Similarly if file is Pipe or Comma seperated then use "|" or ",".
Example:
DATA : lv_str(255) TYPE c.
*Read the data from application server
OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
MESSAGE e009(zz) WITH p_file.
ENDIF.
DO.
**Writing the data into internal table
READ DATASET p_file INTO lv_str.
IF sy-subrc = 0.
SPLIT lv_str AT cl_abap_char_utilites=>horizontal_tab INTO
gwa_file-f1
gwa_file-f2
gwa_file-f3
gwa_file-f4
gwa_file-f5
append gwa_file to it_file.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET p_file.
‎2019 May 29 12:48 AM
Hello Juan,
Try to read values from dataset into a string variable and then split the string variable into respective columns of your WA.
Also depending on file format select the separator.
For example
Tab Delimited = cl_abap_char_utilites=>horizontal_tab.
Similarly if file is Pipe or Comma seperated then use "|" or ",".
Example:
DATA : lv_str(255) TYPE c.
*Read the data from application server
OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
MESSAGE e009(zz) WITH p_file.
ENDIF.
DO.
**Writing the data into internal table
READ DATASET p_file INTO lv_str.
IF sy-subrc = 0.
SPLIT lv_str AT cl_abap_char_utilites=>horizontal_tab INTO
gwa_file-f1
gwa_file-f2
gwa_file-f3
gwa_file-f4
gwa_file-f5
append gwa_file to it_file.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET p_file.
‎2019 May 29 9:20 AM
you could read it in binary mode and do the convert from xstring. I think there are some sample on internet.
‎2019 May 29 9:29 AM
You can rely on ABAP2XLSX to read Excel files both in foreground and background 🙂