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

Issue with SPLIT statement

Former Member
0 Likes
717

Hi There,

VALUE = ' 1 2 3 4'.

sPLIT VALUE AT SPACE INTO BLANK1 ACTUAL1 BLANK2 ACTUAL2 BLANK3 ACTUAL3 BLANK4 ACTUAL4

O/P IS

BLANK1 =

ACTUAL1 = 1

BLANK2 = 2

ACTUAL2 = 3

BLANK3 = 4

ACTUAL3 =

BLANK4 =

ACTUAL4 =

VALUE = ' 1 3 4'.

sPLIT VALUE AT SPACE INTO BLANK1 ACTUAL1 BLANK2 ACTUAL2 BLANK3 ACTUAL3 BLANK4 ACTUAL4

O/P IS

BLANK1 =

ACTUAL1 = 1

BLANK2 =

ACTUAL2 =

BLANK3 = 3

ACTUAL3 = 4

BLANK4 =

ACTUAL4 =

I'm getting strange results

Actual this is what im trying to achieve

I have 4 words(1 or more characters) separted by single space some times the words may be space(just 1space) by itself.

So i expect to get my words in to actuals

For ex :

1 case

I expected the output to be

ACTUAL1 = 1

ACTUAL2 = 2

ACTUAL3 = 3

ACTUAL4 = 4

2 case

I expected the output to be

ACTUAL1 = 1

ACTUAL2 =

ACTUAL3 = 3

ACTUAL4 = 4

Can anyone tell me as to where i'm missing the trick

Thanks

Edited by: kajol sindi on Feb 18, 2010 9:51 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
666

Hi,

I think you got confused with SPILT Statement.

SPLIT command is used to split a string into different varaibles.This is will be done on the basis character which you specify as pivot point.

For ex:str = "This is text for example".

SPLIT AT SPACE into VAR1 VAR2 VAR3 VAR4 VAR5.

Which will split into:

THIS into VAR1, IS into VAR2, TEXT into VAR3, FOR into VAR4, EXAMPLE into VAR5.

it will not consider space for splitting into any varaible.SPACE is just considered as a point where should the split occurs.

Your Split statement should look like this.

VALUE = '1 2 3 4'.

SPLIT VALUE AT SPACE INTO ACTUAL1 ACTUAL2 ACTUAL3 ACTUAL4.

This will have the required output.

Thanks & Regards,

Vamsi.

4 REPLIES 4
Read only

Former Member
0 Likes
666

I don´t understand the second case

You say the words are separated by a space and a word can be a space.

In that case, to get the result you are expecting I would imply that the value you are looking is

VALUE = ' 1  3 4'.

note the two spaces between 1 and 3.

Read only

Former Member
0 Likes
667

Hi,

I think you got confused with SPILT Statement.

SPLIT command is used to split a string into different varaibles.This is will be done on the basis character which you specify as pivot point.

For ex:str = "This is text for example".

SPLIT AT SPACE into VAR1 VAR2 VAR3 VAR4 VAR5.

Which will split into:

THIS into VAR1, IS into VAR2, TEXT into VAR3, FOR into VAR4, EXAMPLE into VAR5.

it will not consider space for splitting into any varaible.SPACE is just considered as a point where should the split occurs.

Your Split statement should look like this.

VALUE = '1 2 3 4'.

SPLIT VALUE AT SPACE INTO ACTUAL1 ACTUAL2 ACTUAL3 ACTUAL4.

This will have the required output.

Thanks & Regards,

Vamsi.

Read only

Former Member
0 Likes
666

VALUE = ' 1 2 3 4'.

sPLIT VALUE AT SPACE INTO BLANK1 ACTUAL1 BLANK2 ACTUAL2 BLANK3 ACTUAL3 BLANK4 ACTUAL4

in your case Split statement splits the string when the space occurs.

that is why you are getting the wrong result.

Modify your statement as follows:

VALUE = ' 1 2 3 4'.

SPLIT VALUE AT SPACE INTO ACTUAL1 ACTUAL2 ACTUAL3 ACTUAL4.

Now you will get the output as you want i.e.

ACTUAL1 = 1

ACTUAL2 = 2

ACTUAL3 = 3

ACTUAL4 = 4

For more details of split statement read F1 help.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
666

You can just split it into internal table.

split lv_string at space into table itab.