‎2007 Feb 15 2:19 AM
Hi ,
In my previous thread..I got a solvation..but I just overlooked somethings in that.
Prease anyone answer my requirement.
I get the field values like this :
14.8KG g
13.1 KG g
now I need to split these into 2 parts giving14.8 & 13.1 into one field F1 of an ITAB and KG g into F2 of ITAB
Please tell me the code
‎2007 Feb 15 2:38 AM
Check out this sample code.
REPORT zrich_0001.
data: str type string.
data: p1 type string.
data: p2 type string.
data: offset type i.
data: len type i.
data: lowercase type sy-abcde.
lowercase = sy-abcde.
translate lowercase to LOWER CASE.
str = '14.8KG g'.
TRANSLATE str using ' %'.
len = strlen( str ).
len = len - 1.
do len times.
offset = offset + 1.
if str+offset(1) ca '0123456789.'.
concatenate p1 str+offset(1) into p1.
elseif ( str+offset(1) ca sy-abcde
or str+offset(1) ca lowercase
or str+offset(1) = '%' ).
concatenate p2 str+offset(1) into p2.
endif.
enddo.
TRANSLATE p2 using '% '.
write:/ p1, p2.
Regards,
Rich Heilman
‎2007 Feb 15 2:31 AM
See the last reply which worked for you...
If u split at SPACE taht is enough it will work, I tried it in an example.
DATA: string(20) TYPE c VALUE 'st ri ng120',
string1(10) TYPE c ,
string2(10) TYPE c .
SPLIT string AT space INTO string1 string2.
Write string2.
Thanks
‎2007 Feb 15 2:38 AM
Check out this sample code.
REPORT zrich_0001.
data: str type string.
data: p1 type string.
data: p2 type string.
data: offset type i.
data: len type i.
data: lowercase type sy-abcde.
lowercase = sy-abcde.
translate lowercase to LOWER CASE.
str = '14.8KG g'.
TRANSLATE str using ' %'.
len = strlen( str ).
len = len - 1.
do len times.
offset = offset + 1.
if str+offset(1) ca '0123456789.'.
concatenate p1 str+offset(1) into p1.
elseif ( str+offset(1) ca sy-abcde
or str+offset(1) ca lowercase
or str+offset(1) = '%' ).
concatenate p2 str+offset(1) into p2.
endif.
enddo.
TRANSLATE p2 using '% '.
write:/ p1, p2.
Regards,
Rich Heilman
‎2007 Feb 15 2:52 AM
Ramana,
Just clicked a good solution for your problem.
Use the below code:
IF itab-f1 CS 'KG'.
IF sy-subrc = 0.
MOVE itab-f1+sy-fdpos(4) TO itab-f2.
itab-f1 = itab-f1+0(sy-fdpos).
ENDIF.
ENDIF.
This will definitely work.
Thanks
‎2007 Feb 15 3:36 AM
Ramana,
DATA : POS TYPE I.
DATA : VAR TYPE STRING VALUE '14.8KG g',
v_num(10),
v_char(10).
LOOP.
IF VAR+0(SY-INDEX) BETWEEN 0 AND 9.
concatenate v_num VAR+0(SY-INDEX) to v_num.
ELSE
concatenate v_char VAR+0(SY-INDEX) to v_char.
EXIT.
ENDIF.
ENDLOOP.
Pls. mark if useful.
VAR1 = VAR+0(SY-INDEX).
VAR2 = VAR+SY-INDEX(LENGTH OF THE STRING).
‎2007 Feb 15 4:11 AM
pls close the thread if your problem is solved
regards
shiba dutta