Skip to Content
0
Jul 21, 2016 at 05:59 PM

Combine two select statements - VTRKH

2119 Views

Hello,

We are currently modifying a BADI provided to us by a 3rd party. Handling unit numbers and delivery numbers flow into this BADI into two different internal tables (it_delivery and it_hu)

We need to get tracking number data which is stored in VTRKH. Tracking information on the delivery takes precedence over handling unit so we have written our code as such:

We delete duplicates from it_delivery

SELECT vbtyp vbeln xsitd trackncoun

FROM vtrkh

INTO CORRESPONDING FIELDS OF TABLE it_vtrkh

FOR ALL ENTRIES IN it_delivery

WHERE vbtyp = 'J'

AND vbeln = it_delivery-vgbel.

We then fill it_vtrkh into a separate final table which includes HU number. Then we compare entries in the original HU table to see what doesn't have tracking data. If there is no tracking data, we fill it into it_final2 and go back to VTRKH.

SELECT vbtyp vbeln xsitd trackn

FROM vtrkh

INTO CORRESPONDING FIELDS OF TABLE it_vtrkh

FOR ALL ENTRIES IN it_final2

WHERE vbtyp = 'X'

AND vbeln = it_final2-venum.


TRACKNCOUN is the tracking number we want for delivery level and TRACKN is the number we want for HU level.


However, this program is incredibly slow and I think it is because we are accessing into VTRKH twice. Does anyone have a better way to do this?