09-08-2008 6:34 AM
Folks,
I have a requirement where i want to split the string and place into the internal table which has the format (row,col,value).
example:
Table1
abc#def#ghi#
jkl#mno#pqr#
(In table1 )
I want above table to be splitted to below format
Table2
row col value
1 1 abc
1 2 def
1 3 ghi
2 1 jkl
2 2 mno
2 3 pqr
Please help me out in solving this.
09-08-2008 6:36 AM
hi,
check this example from sap.
DATA: NAMES(30) TYPE C VALUE 'Charly, John , Peter',
NAMES2 TYPE STRING,
ONE(10) TYPE C,
TWO(10) TYPE C,
THREE TYPE STRING,
FOUR(4) TYPE C VALUE 'FOUR',
DELIMITER(2) VALUE ','.
SPLIT NAMES AT DELIMITER INTO ONE TWO.
ONE contains 'Charly' and TWO contains 'John , Pet'.
SY-SUBRC is 4, because TWO was not large enough to
accommodate the whole of the remaining string
SPLIT NAMES AT ',' INTO ONE TWO THREE.
ONE contains 'Charly', TWO contains ' John',
THREE contains ' Peter'.
SPLIT NAMES AT ', ' INTO ONE THREE TWO.
ONE contains 'Charly', THREE contains 'John',
TWO contains 'Peter'.
CONCATENATE NAMES '' INTO NAMES2 SEPARATED BY SPACE.
SPLIT NAMES2 AT DELIMITER INTO ONE TWO THREE FOUR.
ONE contains 'Charly', TWO contains 'John',
THREE contains 'Peter ', FOUR is empty.
SPLIT NAMES2 AT DELIMITER INTO ONE FOUR THREE.
ONE contains 'Charly', FOUR contains 'John',
THREE contains 'Peter', SY-SUBRC is 4, since
FOUR was not large enough (spaces are significant
characters!)
09-08-2008 6:40 AM
09-08-2008 6:47 AM
Using below syntax it solved my problem.
SPLIT itab2-b AT '#' INTO TABLE ITAB.
09-08-2008 7:00 AM
just check this code outline..
this is just a outline and i guess its not bug free.
data:len type i.
data:i type i.
data:j type i.
data:k type i.
loop at table1.
i = 1.
j = 0.
k = 0.
table2-row = sy-tabix.
len = strlen( table1-field ).
len = len - 1.
while i <= len.
if table1-field+j(i) <> '#'.
table2-value = table1-field+j(i).
else.
k = k + 1.
table2-col = k.
append table2.
endif.
i = i + 1.
endwhile.
endloop.