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

Splitting string

Former Member
0 Likes
659

Hi,

I have a string. Length can vary b/w 0 and 900. I would like to split this string into variables l1,l2,l3,l4. l1,l2,l3,l4 are of length 250. Please tell me how this can be done.

Thanks,

Prasy

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
633

Hi Prasy,

You can split the string with use of

String+offset(length).

here offset is the starting position and length is no. of characters starting from offset.

For example string is X and other 3 fields are l1, l2, l3.

l1 = X+0(10).

l2 = X+10(12).

l3 = X+22(4)

or

Do Like tHis..

Data: string(28) .

itab-field1 = string+0(10).

itab-field2 = string+10(12).

itab-field3 = string+22(4).

append itab.

clear itab.

Otherwise if any seperaters are there in the string u can do like this...

split string at '/' itab-f1 itab-f2 itab-f3.

Regards,

Chandru

4 REPLIES 4
Read only

Former Member
0 Likes
633

Hi,

Use SPLIT statement as below

SPLIT f AT g INTO TABLE itab.

data : begin of itab occurs 0,

text(250) type c,

end of itab.

SPLIT string1 AT ',' INTO TABLE itab.

loop at itab.

write : / itab-text.

endloop.

each value will be stored as seperate record in the itab.

Read only

Former Member
0 Likes
634

Hi Prasy,

You can split the string with use of

String+offset(length).

here offset is the starting position and length is no. of characters starting from offset.

For example string is X and other 3 fields are l1, l2, l3.

l1 = X+0(10).

l2 = X+10(12).

l3 = X+22(4)

or

Do Like tHis..

Data: string(28) .

itab-field1 = string+0(10).

itab-field2 = string+10(12).

itab-field3 = string+22(4).

append itab.

clear itab.

Otherwise if any seperaters are there in the string u can do like this...

split string at '/' itab-f1 itab-f2 itab-f3.

Regards,

Chandru

Read only

Former Member
0 Likes
633

Hi,

You can split the string as follows.

*step1: create a required structure

TYPES: BEGIN OF ty_split_string,

l1(250) TYPE c,

l2(250) TYPE c,

l3(250) TYPE c,

l4(250) TYPE c,

END OF ty_split_string.

DATA: l_string(900) TYPE c,

ls_split_string TYPE ty_split_string.

*step2: Initialize the string which is to be splitted.

l_string = '101 Mary Jones UK 2000$'.

*step3: work area ls_split_string will now containg the string which is splitted at required positions

ls_split_string = l_string.

write: ls_split_string-l1, ls_split_string-l2, ls_split_string-l3, ls_split_string-l4.

Check the below example:

TYPES: BEGIN OF ty_split_string,

l1(25) TYPE c,

l2(25) TYPE c,

l3(25) TYPE c,

l4(25) TYPE c,

END OF ty_split_string.

DATA: l_string(90) TYPE c,

ls_split_string TYPE ty_split_string.

  • Initialize the string: for Example:

l_string = 'aaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccddddddddddddddd'.

ls_split_string = l_string.

WRITE /: 'l1:', ls_split_string-l1.

WRITE /: 'l2:', ls_split_string-l2 .

WRITE /: 'l3:', ls_split_string-l3 .

WRITE /: 'l4:', ls_split_string-l4.

Pls do reward if useful.

Regards,

Farheen

Edited by: Farheen Fatima on Jan 14, 2008 7:03 AM

Read only

Former Member
0 Likes
633

HI

Check the possible String operations..

  • shifting up to a given string

DATA: t2(10) TYPE c VALUE 'abcdefghij',

string2 LIKE t2,

str2(2) TYPE c VALUE 'ef'.

string2 = t2.

WRITE string2.

SHIFT string2 UP TO str2.

WRITE / string2.

string2 = t2.

SHIFT string2 UP TO str2 LEFT.

WRITE / string2.

string2 = t2.

SHIFT string2 UP TO str2 RIGHT.

WRITE / string2.

string2 = t2.

SHIFT string2 UP TO str2 CIRCULAR.

WRITE / string2.

SKIP.

ULINE.

  • shifting a string depending on the first or last sign

DATA: t3(14) TYPE c VALUE ' abcdefghij',

string3 LIKE t3,

str3(6) TYPE c VALUE 'ghijkl'.

string3 = t3.

WRITE string3.

SHIFT string3 LEFT DELETING LEADING space.

WRITE / string3.

string3 = t3.

SHIFT string3 RIGHT DELETING TRAILING str3.

WRITE / string3.

SKIP.

ULINE.

Thanks

Praveen