‎2008 Jan 14 5:16 AM
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
‎2008 Jan 14 5:21 AM
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
‎2008 Jan 14 5:20 AM
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.
‎2008 Jan 14 5:21 AM
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
‎2008 Jan 14 5:45 AM
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
‎2008 Jan 14 5:48 AM
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