08-31-2007 11:30 AM
HI,
If I have
<b>WRITE : ' " ' , ' " ' . " sample code.</b>
I am taking this line into an internal table.
I need to find LAST OCCURANCE OF <b>"</b>.
There may be as many as <b>"</b> in a write statement, I need to get last occurance of <b>"</b>
regards,
nazeer
08-31-2007 11:44 AM
Hello Nazeer,
Using index and offset concept we can do it.
lets suppose we got this string into itab.
data: pos type i.
do.
if itab+pos(1) eq '"'.
clear occurance.
move sy-tabix to occurance.
endif.
add 1 to pos.
enddo.
write: occurance.
Reward If Helpful.
Regards
--
Sasidhar Reddy Matli.
08-31-2007 11:34 AM
Hi,
Check this,
http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db996e35c111d1829f0000e829fbfe/content.htm
Reward if useful!
08-31-2007 11:36 AM
Hello,
See this code, it does what you want
data: currentchar.
data: full_value type string value 'JEREMY"20yrs"'.
data: length type i.
data: count type i.
length = STRLEN( full_value ).
count = length - 1.
do count times.
length = length - 1.
currentchar = full_value+length.
write:/ currentchar.
IF CURRENTCHAR = '"'.
exit.
endif.
enddo.
length = length + 1.
write:/ full_value+length.
08-31-2007 11:44 AM
Hello Nazeer,
Using index and offset concept we can do it.
lets suppose we got this string into itab.
data: pos type i.
do.
if itab+pos(1) eq '"'.
clear occurance.
move sy-tabix to occurance.
endif.
add 1 to pos.
enddo.
write: occurance.
Reward If Helpful.
Regards
--
Sasidhar Reddy Matli.
08-31-2007 11:48 AM
Hi..
this is the Code to find the Last occurrence.
DATA : V_STR(10) VALUE 'INDIA'.
DATA : V_SUB(1) VALUE 'I'.
DATA : V_LEN TYPE I,
V_POS TYPE I.
V_LEN = STRLEN( V_STR ).
V_POS = V_LEN - 1.
DO V_LEN TIMES..
IF V_STR+V_POS(1) = V_SUB.
WRITE: / 'LAST OCCU = ', V_POS.
EXIT.
ENDIF.
SUBTRACT 1 FROM V_POS.
ENDDO.
<b>reward if Helpful</b>
08-31-2007 12:30 PM
Hi Nazeer
Try this program.
DATA f(50).
DATA v_pos LIKE sy-fdpos.
DATA v_pos2 LIKE sy-fdpos.
MOVE 'Sample " Sam " Sa' TO f.
v_pos = 1.
DO.
SEARCH f FOR '"' STARTING AT v_pos.
IF sy-subrc = 0 .
IF sy-index = 1.
v_pos2 = v_pos + sy-fdpos .
v_pos = sy-fdpos + 2.
ELSE.
v_pos2 = v_pos + sy-fdpos .
v_pos = v_pos + sy-fdpos + 2.
ENDIF.
ELSE.
IF sy-index = 1.
WRITE : 'not found'.
EXIT.
ELSE.
WRITE : v_pos2.
EXIT.
ENDIF.
ENDIF.
ENDDO.
Best Regards
Wiboon