Application Development 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: 

last occurance

former_member588853
Active Contributor
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

5 REPLIES 5

Former Member

former_member189059
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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.

varma_narayana
Active Contributor
0 Kudos

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>

Former Member
0 Kudos

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