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

Read line and split into different fields

Former Member
0 Likes
1,100

I have a flat file with space (multiple spaces between different fields) as a delimiter. The problem is, file is coming from 3rd party and they don't want to change the separator as comma or tab delimited CSV file. I have to load data in ODS (BW 3x).

Now I am thinking to load line by line and then split data into different objects in Transfer rules.

The Records looks like:

*009785499 BC 2988 244 772 200

*000000033 AB 0 0 0 0

*000004533 EE 8 3 2 4

Now I want data to split like:

Field1 = 009785499

Field2 = BC

Field3 = 2988

Field4 = 244

Field5 = 772

Field6 = 200

After 1st line load, go to 2nd line and split the data as above and so on. Could you help me with the code pleaseu2026?

Is it a good design to load data? Any other idea?

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
930

Hi Mau,

First capture the data into the internal table (say itab).

Loop at itab.

it_final-field1 = itab+1(9).

it_final-field2 = itab+12(2).

it_final-field1 = itab+16(4).

it_final-field1 = itab+21(3).

it_final-field1 = itab+25(3).

it_final-field1 = itab+29(3).

Append it_final.

Endloop.

&*********** Reward Point if helpful**********&

8 REPLIES 8
Read only

naimesh_patel
Active Contributor
0 Likes
930

I think, you have to split the records, record by record.

Like:


LOOP AT ITAB.
SPLIT ITAB-TEXT AT SPACE INTO IT_DATA-FLD1 IT_DATA-FLD2.
APPEND IT_DATA.
ENDLOOP.

Regards,

Naimesh Patel

Read only

0 Likes
930

SPLIT command works between single space. What about for multiple spaces as in my case spaces are multiple and there are no fixed spaces between fields?

Read only

Former Member
0 Likes
930

you probably have to upload this into a 1 field itab (let's say 1000char length).

loop at your itab into an work area

split work_area-field at space into f1 f2 f3 f4 etc...

move those fields to another itab for processing.

Read only

Former Member
0 Likes
930

Will you always have exactly six fields (five spaces)?

Rob

Read only

0 Likes
930

Yes, I will have exactly six fields but different spaces between fields.

Read only

Former Member
0 Likes
931

Hi Mau,

First capture the data into the internal table (say itab).

Loop at itab.

it_final-field1 = itab+1(9).

it_final-field2 = itab+12(2).

it_final-field1 = itab+16(4).

it_final-field1 = itab+21(3).

it_final-field1 = itab+25(3).

it_final-field1 = itab+29(3).

Append it_final.

Endloop.

&*********** Reward Point if helpful**********&

Read only

Former Member
0 Likes
930

check this..

DATA: BEGIN OF ITAB OCCURS 10,

WORD(20),

END OF ITAB.

SPLIT 'STOP Two STOP Three STOP ' AT 'STOP' INTO TABLE ITAB.

Now, ITAB has three lines. The first line is blank, the second contains 'Two' and the third contains 'Three' .

Read only

0 Likes
930

Solved using CONDENSE STR and then used SPLIT statement.