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 error

Former Member
0 Likes
2,268

hi,

i want to replace the following code:

loop at itab into v_data1.

replace '<?xml version="1.0" encoding="utf-8" ?>' with ' ' into

v_data1-data .

replace '- <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02">'

with ' ' into v_data1-data.

endloop.

but here the code is not getting replace...kindly suggest where to change the code...

and i am getting su-subrc = 4...

The v_data1 will contain around 1000 characters..i need to search whole v_data1

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,191

Hi,

Try this. This should work perfectly.



DATA: v1 TYPE string VALUE '- <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02">'.

LOOP AT itab INTO v_data1.
* Eg. v_data1-data = '- <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02"> test'.

  REPLACE v1 WITH space INTO v_data1-data.
  MODIFY itab FROM v_data1 TRANSPORTING data.
ENDLOOP.

OR...... A simpler example is given below.

DATA: v1 TYPE string VALUE '- <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02"> test'.
DATA: v2 TYPE string VALUE '- <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02">'.

REPLACE v2 WITH space INTO v1.

WRITE: / v1,
       / v2.

Regards,

Danish.

20 REPLIES 20
Read only

Former Member
0 Likes
2,191

instead of into i had expected in.

Read only

former_member226519
Active Contributor
0 Likes
2,191

forgotten MODIFY ITAB?

Read only

0 Likes
2,191

@Florian Kemmer - in is showing as syntax error

@Volker Binder - but before modify itab i need to modify wa..how to achieve that

Read only

0 Likes
2,191

Hi,

This statement is obsolete, please check documentation for new REPLACE statement syntax...


1. REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF] 
pattern 
IN [section_of] dobj WITH new 
[IN {BYTE|CHARACTER} MODE] 
[{RESPECTING|IGNORING} CASE] 
[REPLACEMENT COUNT rcnt] 
{ {[REPLACEMENT OFFSET roff] 
[REPLACEMENT LENGTH rlen]} 
| [RESULTS result_tab|result_wa] }.

Something like:


FIELD-SYMBOLS: <fs> TYPE ty_ch.
CONSTANTS: gc_pattern(100) TYPE c VALUE '<?xml versio = ...'.
LOOP AT itab ASSIGNING <fs>.
   REPLACE gc_pattern IN <fs>-data WITH space IN CHARACTER MODE.
ENDLOOP.

Kr,

m.

Read only

Former Member
0 Likes
2,191

Hi,

Try this.



REPLACE ALL OCCURRENCES OF '- <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02">' 
IN v_data1-data WITH ' '.

Regards,

Danish.

Read only

0 Likes
2,191

i m using 4.6 version...there is no " REPLACE ALL OCCURRENCES"

Read only

0 Likes
2,191

OK then try something like:


FIELD-SYMBOLS: <fs> TYPE ty_ch.   "Type of you v_data1 structure
CONSTANTS: gc_pattern(100) TYPE c VALUE '<?xml versio = ...'.
LOOP AT itab ASSIGNING <fs>.
   REPLACE gc_pattern WITH space INTO <fs>-data.
ENDLOOP.

Read only

0 Likes
2,191

No Manu...it is not working...

Read only

0 Likes
2,191

Manu..canu let me know..if i need to add modify itab to below code to replicate to itab?

LOOP AT itab ASSIGNING <fs>.

REPLACE c1 WITH space INTO <fs>-data.

REPLACE c2 WITH space INTO <fs>-data.

REPLACE c3 WITH space INTO <fs>-data.

REPLACE c4 WITH space INTO <fs>-data.

REPLACE c5 WITH space INTO <fs>-data.

ENDLOOP.

Read only

0 Likes
2,191

No you don't have to use the MODIFY statement since you're using a referenced field-symbol.

I think you miscreated your constant, sorry was'nt so clear about that... the length must be the exact length of the string enclosed..

I mean:


CONSTANTS: c1(15) TYPE c VALUE 'thisisaconstant'.  "Exact length = 15

Kr,

m.

Read only

Former Member
0 Likes
2,191

I ran your original code and it worked fine. Are you sure your itab contains the strings?

Rob

Read only

0 Likes
2,191

Yes the only thing missing in the original code was the modify statement...

But ugly to read

m.

Read only

0 Likes
2,191

But he got sy-subrc = 4 which tells me the string was not found.

Now that I think of it, the sy-subrc = 4 would apply to the last loop pass where the string was not found, so if the modify were added, it would likely work (assuming the strings are actually in prior records).

Rob

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,191

Hi,

Is your requirement to replace what ever comes in the tags <...> or are these strings fixed?

Keshav

Read only

0 Likes
2,191

Thanks for ur help..it really helped...i have given exact length in the constants..

one more thing...now i want to add 1 line to the existing itab..exactly at the begining..and 1 at the end...

i have tried with append..it always append at the bottom..but i want to add at the begining of itab...

Read only

0 Likes
2,191

Hi,

Try this for adding line at the beginning.

Create another Internal table say ITAB1 of the same type as ITAB. Clear and fill the existing work area i.e. v_data1.


APPEND v_data1 TO itab1.
APPEND LINES OF itab[] TO itab1[].

Regards,

Danish.

Read only

0 Likes
2,191

@OP - Please answer my previous question for my understanding. A simple regex statement might solve it.

@ danish

Try this for adding line at the beginning.

Create another Internal table say ITAB1 of the same type as ITAB. Clear and fill the existing work area i.e. v_data1.

APPEND v_data1 TO itab1.

APPEND LINES OF itab[] TO itab1[].

No need of such big logic...Just a insert with index 1 will do.

kesav

Read only

0 Likes
2,191

Yes Keshav, you are absolutely correct. Sorry I missed that.

Danish.

Read only

Former Member
0 Likes
2,192

Hi,

Try this. This should work perfectly.



DATA: v1 TYPE string VALUE '- <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02">'.

LOOP AT itab INTO v_data1.
* Eg. v_data1-data = '- <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02"> test'.

  REPLACE v1 WITH space INTO v_data1-data.
  MODIFY itab FROM v_data1 TRANSPORTING data.
ENDLOOP.

OR...... A simpler example is given below.

DATA: v1 TYPE string VALUE '- <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02"> test'.
DATA: v2 TYPE string VALUE '- <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02">'.

REPLACE v2 WITH space INTO v1.

WRITE: / v1,
       / v2.

Regards,

Danish.

Read only

Former Member
0 Likes
2,191

Hi,

loop at itab into v_data1.

clear v_data1-data .

modify itab from v_data1-data index sy-tabix transporting v_data1-data .

clear v_data1.

endloop.

Ram.