Application Development and Automation 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: 
Read only

replace statement

Former Member
0 Likes
2,418

Hey ABAP, i have following Problem:

REPLACE ALL OCCURRENCES OF '.' IN SECTION OFFSET lv_offset of lv_kstbm.

when trying to compile this, it tells me that between "OFFSET" and "of" LENGTH is expected.

REPLACE ALL OCCURRENCES OF '.' IN SECTION OFFSET lv_offset LENGTH lv_length of lv_kstbm.

when compiling this one, it tells me "length lv_length" isnt expected to be there.

lv_length and LV-offset are both local variables of type i.

any ideas?

1 ACCEPTED SOLUTION
Read only

Former Member
909

i think you are combining two things in one...

by pattern replacing.

DATA: c4(4) TYPE C.

c4 = 'abab'.

REPLACE ALL OCCURRENCES OF 'ab' IN c4 WITH 'CCC'.

by position replacing...

DATA: text TYPE STRING.

text = 'abcdefgh'.

REPLACE SECTION OFFSET 4 OF text WITH 'XXXX'.

one of them can be used at a time..

regards

shiba dutta

3 REPLIES 3
Read only

Former Member
0 Likes
909

hi

i think you have to complete the statement with the WITH text addition

REPLACE ALL OCCURRENCES OF '.' IN SECTION OFFSET lv_offset LENGTH lv_length of lv_kstbm WITH 'something'.

if helpful, reward

Sathish. R

Read only

Former Member
910

i think you are combining two things in one...

by pattern replacing.

DATA: c4(4) TYPE C.

c4 = 'abab'.

REPLACE ALL OCCURRENCES OF 'ab' IN c4 WITH 'CCC'.

by position replacing...

DATA: text TYPE STRING.

text = 'abcdefgh'.

REPLACE SECTION OFFSET 4 OF text WITH 'XXXX'.

one of them can be used at a time..

regards

shiba dutta

Read only

Former Member
0 Likes
909
chk this example

Pattern-based replacement of all found location of the word "know" in the data objects text1 and text2 by "should know that". After the first REPLACE statement, text1 contains the complete content "I should know that You should know that ", and sy-subrc contains the value 0. The data objects cnt, off, and len contain the values 2, 23, and 16 respectively. After the second REPLACE statement, text2 contains the truncated content "I should know that" and sy-subrc contains the value 2. The data objects cnt, off, and len contain the values 1, 2, and 16. 

DATA: text1 TYPE string, 
      text2(18) TYPE c, 
      cnt TYPE i, 
      off TYPE i, 
      len TYPE i. 

text1 = text2 = 'I know you know'. 

REPLACE ALL OCCURRENCES OF 'know' IN: 
        text1 WITH 'should know that' 
              REPLACEMENT COUNT  cnt 
              REPLACEMENT OFFSET off 
              REPLACEMENT LENGTH len, 
        text2 WITH 'should know that' 
              REPLACEMENT COUNT  cnt 
              REPLACEMENT OFFSET off 
              REPLACEMENT LENGTH len.