2012 Aug 09 10:52 AM
Hi Experts,
Is it possible to replace a patten just in one column in the internal table?
For example:
DATA: BEGIN OF ITAB OCCURS 0,
TEST1(20) TYPE C,
TEST2(20) TYPE C,
END OF ITAB.
DATA: P_LINE TYPE I.
DATA: P_LOW.
ITAB-TEST1 = 'AN20'.
ITAB-TEST2 = 'AN20AN20AN20'.
APPEND ITAB.
APPEND ITAB.
APPEND ITAB.
After update the table should be changed to below.
| TEST1 | TEST2 |
|---|---|
| AN20 | EG20EG20EG20 |
AN20 | EG20EG20EG20 |
AN20 | EG20EG20EG20 |
I would like to update second column TEST2 that value change from AN20AN20AN20 to EG20EG20EG20.
How can I use replace table command to update it? NO LOOP PLEASE.
Thanks,
Leon
2012 Aug 09 1:20 PM
Hi
U can use MODIFY statament:
ITAB-TEST2 = 'EG20EG20EG20'.
MODIFY ITAB TRANSPORTING TEST2 WHERE TEST2 = 'AN20AN20AN20'.
Max
2012 Aug 09 11:32 AM
Yes, it's possible (use <f1> for further info).
Is it an exam question?
2012 Aug 09 12:15 PM
Hi
Leon
Replacw table command works only when your itab is declarred as
DATA itab TYPE TABLE OF string.
Regards
Aaradhana
2012 Aug 09 1:10 PM
HI Leon,
Please use the below line of code.
data: off TYPE i,
lin TYPE i,
off1 TYPE i,
lin1 TYPE i,
lin2 type i.
lin = 1.
lin1 = 2.
lin2 = 3.
off = 5.
off1 = 0.
REPLACE ALL occurences of 'AN20'
IN TABLE itab from lin offset off to lin1 offset off1 WITH 'EG20'
RESPECTING CASE.
REPLACE ALL occurences of 'AN20'
IN TABLE itab from lin1 offset off to lin2 offset off1 WITH 'EG20'
RESPECTING CASE.
REPLACE ALL occurences of 'AN20'
IN TABLE itab from lin2 offset off WITH 'EG20'
RESPECTING CASE.
Thanks
Pooja.
2012 Aug 09 1:20 PM
Hi
U can use MODIFY statament:
ITAB-TEST2 = 'EG20EG20EG20'.
MODIFY ITAB TRANSPORTING TEST2 WHERE TEST2 = 'AN20AN20AN20'.
Max