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

Loading data from SAP AS

Former Member
0 Likes
834

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?

1 ACCEPTED SOLUTION
Read only

rameez_khan
Active Participant
0 Likes
757

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.
3 REPLIES 3
Read only

rameez_khan
Active Participant
0 Likes
758

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

DoanManhQuynh
Active Contributor
757

you could read it in binary mode and do the convert from xstring. I think there are some sample on internet.

Read only

SimoneMilesi
Active Contributor
757

You can rely on ABAP2XLSX to read Excel files both in foreground and background 🙂