‎2011 Sep 22 12:39 PM
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
‎2011 Sep 23 6:56 AM
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.
‎2011 Sep 22 1:02 PM
‎2011 Sep 22 1:03 PM
‎2011 Sep 22 1:20 PM
@Florian Kemmer - in is showing as syntax error
@Volker Binder - but before modify itab i need to modify wa..how to achieve that
‎2011 Sep 22 1:27 PM
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.
‎2011 Sep 22 1:32 PM
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.
‎2011 Sep 22 2:00 PM
i m using 4.6 version...there is no " REPLACE ALL OCCURRENCES"
‎2011 Sep 22 2:05 PM
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.
‎2011 Sep 22 2:23 PM
‎2011 Sep 22 3:10 PM
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.
‎2011 Sep 22 7:26 PM
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.
‎2011 Sep 22 7:40 PM
I ran your original code and it worked fine. Are you sure your itab contains the strings?
Rob
‎2011 Sep 22 7:46 PM
Yes the only thing missing in the original code was the modify statement...
But ugly to read
m.
‎2011 Sep 22 7:54 PM
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
‎2011 Sep 23 5:44 AM
Hi,
Is your requirement to replace what ever comes in the tags <...> or are these strings fixed?
Keshav
‎2011 Sep 23 10:05 AM
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...
‎2011 Sep 23 10:25 AM
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.
‎2011 Sep 23 10:29 AM
@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
‎2011 Sep 23 10:50 AM
Yes Keshav, you are absolutely correct. Sorry I missed that.
Danish.
‎2011 Sep 23 6:56 AM
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.
‎2011 Sep 23 7:40 AM
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.