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

Looking for some clarification on Datasets

Former Member
0 Likes
1,016

Alright, I need to read in a csv file that contains several lines. The delimiter is ^. This file holds one line that has the header information for a sales order. The subsequent lines are individual line items (1-many). How can I read one line at a time and end when I reach the end of the file? I would be reading the line into a string and split it from there.

Regards,

Davis

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
987

Hello,

LOOP AT ITAB.   " this contains your file.
at first.
*  split and  move  records to header
continue.
endat.

split and move records to item

endloop.

Regards,

Naimesh Patel

Alright, I need to read in a csv file that contains several lines. The delimiter is ^. This file holds one line that has the header information for a sales order. The subsequent lines are individual line items (1-many). How can I read one line at a time and end when I reach the end of the file? I would be reading the line into a string and split it from there.

Regards,

Davis

8 REPLIES 8
Read only

naimesh_patel
Active Contributor
0 Likes
988

Hello,

LOOP AT ITAB.   " this contains your file.
at first.
*  split and  move  records to header
continue.
endat.

split and move records to item

endloop.

Regards,

Naimesh Patel

Read only

0 Likes
987

I should add that this is a background job, or will be a background job. That means that I will be using datasets and can't use anything related to the GUI.

Davis

Read only

0 Likes
987

Hi,

In that case, you can read the lines of file in Text mode. Get the line into a string and then use SPLIT command to split the values at '^' into the table fields.

ashish

Read only

0 Likes
987

Do I just do something like this?

do.
   read dataset filepath into filestring.
   if sy-subrc <>0.
      exit.
   endif.

*split string*

enddo.

Davis

Read only

0 Likes
987

Yes, but you have to use the OPEN DATASET command before trying to read it.

If you search the forum, you'll see many examples of exactly how to do this.

Rob

Read only

0 Likes
987

Hi,

Check this sample program which will give you an idea -

http://www.sapfans.com/sapfans/alex.htm

ashish

Read only

Former Member
0 Likes
987

Hi,

Use function module GUI_UPLOAD, pass 'X' to parameter HAS_FIELD_SEPARATOR.

Check the documentation for more details.

ashish

Read only

Former Member
0 Likes
987

Hi,

You can use these FM RKD_WORD_WRAP or SWA_STRING_SPLIT.

Regards,

Ferry Lianto