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

internal table

Former Member
0 Likes
303

hello,

I have 2 internal tables which i am supposed to merge as 1. the problem here is that the the relation is 1: N

table A table B

key 1 desc Key 1 Value1

Key 1 Value 2

key 1 Value 3

And my final output should be

key 1 desc value1 value2 value3. One thing I know is there wont be more than 9 values in table b for every one in table a. Any quick ideas?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
271

quick idea.. use loop at B and read from A

now a simple code

data:  gt_final type table of string,
          gs_final like line of gt_final.

sort table_b by key.
loop at table_b into wa_b.
at new key.
 clear : gs_final, wa_a.
 read table table_a into wa_a with key KEY = wa_b-KEY. 
   if sy-subrc = 0.
      concatenate wa_a-key wa_a-desc into gs_final separated by space.
   endif.
endat.

concatenate gs_final wa_b-value into gs_final  separated by space.

at end of key. 
 append gs_final to gt_final.
  clear gs_final.
endat.

endloop.

one more option is to use field symbols. search to see how it is used.

Edited by: Soumyaprakash Mishra on Oct 2, 2009 3:59 PM

1 REPLY 1
Read only

Former Member
0 Likes
272

quick idea.. use loop at B and read from A

now a simple code

data:  gt_final type table of string,
          gs_final like line of gt_final.

sort table_b by key.
loop at table_b into wa_b.
at new key.
 clear : gs_final, wa_a.
 read table table_a into wa_a with key KEY = wa_b-KEY. 
   if sy-subrc = 0.
      concatenate wa_a-key wa_a-desc into gs_final separated by space.
   endif.
endat.

concatenate gs_final wa_b-value into gs_final  separated by space.

at end of key. 
 append gs_final to gt_final.
  clear gs_final.
endat.

endloop.

one more option is to use field symbols. search to see how it is used.

Edited by: Soumyaprakash Mishra on Oct 2, 2009 3:59 PM