Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3189

Table Comprehensions with Corresponding and Modifying

$
0
0

Hi,

 

I've written the following simple coding for demo purposes.

 

The intention is to copy an internal table into a target table and adding/modifying a member (field3) of each table line that gets copied.

 

TYPES:            BEGIN OF t_struct1,                  field1      TYPE i,                   field2      TYPE string,            END OF t_struct1,            BEGIN OF t_struct2,                  field1      TYPE i,                   field2      TYPE string,                   field3      TYPE i,            END OF t_struct2.   
DATA:           lt_source TYPE STANDARD TABLE OF t_struct1,           lt_target TYPE STANDARD TABLE OF t_struct2.    
* Initialize source table with some random values
lt_source = VALUE #(           ( field1 = 1 field2 = 'A' )           ( field1 = 2 field2 = 'B' ) ).     
* Now copy source lines to target table using corresponding
lt_target = VALUE #( FOR wa IN lt_source ( CORRESPONDING #( wa ) ) ).

The result is that lt_target contains two lines where field1 and field2 is populated. That's perfect.

 

Now I would like the same construct as in line 19 and have field3 assigned a value. I've tried to add a new statement like field3 = sy-tabix, however this results in a syntax error.

 

Questions is how can I still use table comprehensions, take advantage about the corresponding constructor and yet modify a target structure member?

 

Thanks,

Michael


Viewing all articles
Browse latest Browse all 3189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>