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: 

Corresponding operator - map a constant value

former_member314455
Participant
0 Kudos
3,220

Hi Guys,

Is there a single statement to achieve the below?

1) itab1 = itab2

2) Replace value of field1 (of all entries) in itab1 with a constant value 'X'.

I was trying to use Corresponding operator, but only allows mapping values from itab2.

Thanks,

Ajith

1 ACCEPTED SOLUTION

Juwin
Active Contributor
1,700

If you are using new ABAP statements, then, I could find the following 'single' statement. But, due to the complexity of this statement, I wouldn't recommend this.

tabl2 = value #( for entry in tabl1

               ( corresponding #( value ty2( base corresponding #( entry ) field1 = 'X' ) ) ) ).

Rather, split it into 3 statements and the program becomes much more readable.

tabl2        = corresponding #( tabl1 ).

strc2-field1 = 'X'.

modify tabl2 from strc2 transporting field1 where field1 ne strc2-field1.

Thanks,

Juwin

3 REPLIES 3

Juwin
Active Contributor
1,701

If you are using new ABAP statements, then, I could find the following 'single' statement. But, due to the complexity of this statement, I wouldn't recommend this.

tabl2 = value #( for entry in tabl1

               ( corresponding #( value ty2( base corresponding #( entry ) field1 = 'X' ) ) ) ).

Rather, split it into 3 statements and the program becomes much more readable.

tabl2        = corresponding #( tabl1 ).

strc2-field1 = 'X'.

modify tabl2 from strc2 transporting field1 where field1 ne strc2-field1.

Thanks,

Juwin

0 Kudos
1,700

Thanks !

Simplified it a bit and seems to work.

  itab1 =

      VALUE #( FOR wa IN itab1

               ( VALUE #( BASE CORRESPONDING #( wa )

                 field1 = 'X' ) ) ).

Juwin
Active Contributor
0 Kudos
1,700

Hi Ajith, I tried that in my system and it gives me a syntax error. May be you are on a later version of support pack, which includes the fix for this bug.

Thanks,

Juwin