Application Development 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: 

combine two internal table using function module table output

Former Member
0 Kudos

Hi there

Let me apologize in advance if I'm breaking any guidelines. I'm quite new to this. I'm usually the type that ones to figure things out myself but I've invested to mush time in this problem. I've looked trough the archive but couldn't find anything that meets my criteria.

This is my situation :

1. I've one function module that does a select on my Z_table and returns an internal table with the fallowing fields (the fields are based on abap table "vttk" ) :

  • shipment_number (tknum in vttk)
  • planning_date (dpreg in vttk)
  • time_in (uareg in vttk)
  • time_out (uatend in vttk)
  • remarks (custom field)

Lets call this internal table returned by our function module it_shipm_data. The data elements are the same as that of vttk.

2. I've an custom internal table structure with the fallowing fields (again based on vttk)

  • tknum
  • dpreg
  • uareg
  • uaten
  • tplst
  • erdat
  • fabkl (field from another table made possible by doing a join).

Lets call this internal table structure ls_shipm

3. I've also made an internal table structure that contains all the above fields. I got this tip from you guys.

Lets call this in internal table structure ls_final_shipm

This is my problem:

As you may have noticed internal table it_shipm more fields then internal table it_shipm_data


WHAT I WANT

I need to get all these data together in one table:

The field value in it_shipm_data MOST overwrite the corresponding field values in it_shipm

if I was working with a regular abap/Z-table a simple join would have done the job.

Some codes:

DATA: it_shipm TYPE TABLE OF ls_shipm,  "custom internal table
      wa_shipm TYPE ls_shipm,
      it_shipm_data TYPE TABLE OF z_table, "returned internal table from FM
      wa_shipm_data TYPE z_table,
      it_final TYPE TABLE OF ls_final_shipm,
      wa_final TYPE ls_final_shipm.      

What I've tried so far that came close to what I was looking for thanks to you guys

LOOP AT it_shipm_data INTO wa_shipm_data 
  READ TABLE it_shipm INTO wa_shipm 
                           WITH KEY tknum = wa_shipm_data-shipment_number 
  IF sy-subrc =0.
     MOVE-CORRESPONDING wa_shipm TO wa_final.
     MOVE_CORRESPONDING wa_shipm_data to wa_final.
     APPEND wa_final to it_final.
     CLEAR  wa_final.
  ENDIF.
ENDLOOP.

Result problems:

When i loop over it_final to see what it has stored i noticed the fallowing

  • Only the tknum (shipment number are the same)
  • All the other values are from it_shipm

So basicly no value of it_shipm_data (my Z-table values) are being passed.

Am I asking the impossible ?

I know this is a long post.

I just want to provide a mush information as possible to make it easier to debug.

3 REPLIES 3

former_member221827
Active Participant

My guess would be the names of the z_table fields and the internal table don't match up exactly and the data is not being passed in the second move-corresponding wa_shipm_data to wa_final. Have you tried mapping the fields manually to see if that's the problem? (i.e. wa_final-dpreg = wa_shipm_data-dpreg?

If that works then you could use the CORRESPONDING component operator to get what you're looking for and replace the move-corresponding.

http://help.sap.com/abapdocu_740/en/index.htm?file=abapmove-corresponding.htm

Former Member
0 Kudos

Hey there thanks for your input.

To answer your question, yes you're right data wasn't being passed correctly so i had to remove everything and start over.
this time making sure that I checked every step. Eventually noticed that I was looking at it the wrong way after browsing trough this site. I saw something unrelated to my problem and decided to try it after a (long) while it hit me.

After re-evaluating this is the solution i came up with to fix my problem for combining the two tables. Again my apologize for any confusion I may have caused.

I not to sure if my solution is performance friendly because I've read somewhere on this site that you should try to avoid using a select in a loop. So if anyone knows how I can make this more performance friendly I'm all ears (please no OOP my knowledge isn't on point for that).

LOOP AT it_shipm_data into wa_ship_data  "this is the internal table returned by my function module 
  wa_final-field1  =  wa_ship_data       "pushing all the field from my final internal table
    .....
  SELECT * FROM vttk INTO CORRESPONDING FIELDS OF wa_final   "getting the remaining fields that i need 
WHERE tknum = wa_ship_data-tknum. ENDSELECT. APPEND wa_final TO it final.
ENDLOOP

0 Kudos

Yes, avoid this latest code. Use the earliest code (LOOP + READ TABLE).

If your only issue is with the 2 "overlapping" MOVE-CORRESPONDING, then just indicate the fields one by one.