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 table command in one column

Former Member
0 Likes
761

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.

   

TEST1TEST2
AN20EG20EG20EG20

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


1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
709

Hi

U can use MODIFY statament:

ITAB-TEST2 = 'EG20EG20EG20'.

MODIFY ITAB TRANSPORTING TEST2 WHERE TEST2 =  'AN20AN20AN20'.

Max

4 REPLIES 4
Read only

UweFetzer_se38
Active Contributor
0 Likes
709

Yes, it's possible (use <f1> for further info).

Is it an exam question?

Read only

Former Member
0 Likes
709

Hi

     Leon

      Replacw table command works only when your itab is declarred as

          DATA itab TYPE TABLE OF string.

Regards

     Aaradhana

Read only

Former Member
0 Likes
709

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.

Read only

Former Member
0 Likes
710

Hi

U can use MODIFY statament:

ITAB-TEST2 = 'EG20EG20EG20'.

MODIFY ITAB TRANSPORTING TEST2 WHERE TEST2 =  'AN20AN20AN20'.

Max