ABAP – Get handling units in a Shipment

SAPIn this code snippet I’ll show how you can get info about all the handling units in a shipment delivery.A shipment can contain 1..* deliveries. S first of all you need to get all deliveries in the shipment:

DATA:
  lt_vbeln    TYPE TABLE OF vbeln,
  iv_shipment TYPE vttp-tknum VALUE '1234567'.  "Your shipment number

SELECT vbeln 
  INTO TABLE lt_vbeln
  FROM vttp 
  WHERE tknum = iv_shipment.

To view a shipment, go to TCode VT03N and use your shipment number.

To view deliveries contained in the shipment, go to Top Menu -> GoTo -> Shipments and Deliveries and double click on a delivery you want to see (or use directly Tcode VL03N and enter the delivery number).

To view handling units in the delivery, press Ctrl+F6 (or the “box” icon in the top toolbar).

…this was the SAPGUI approach to inspect the HU’s in a delivery…now comes the coding part

At first I’ll show the approach using the standard function module to get all the necessary information about HU’s in a delivery:

DATA: 
  iv_delivery TYPE vbeln VALUE '2016280854' "Your delivery number from shipment.
  ls_object   TYPE hum_object.

  lt_hus      TYPE hum_hu_header_t,
  lt_hupos    TYPE hum_hu_item_t,
  lt_serialno TYPE vsep_t_rserob.

ls_object-object = '01'. "Delivery
ls_object-objkey = lv_delivery.

CALL FUNCTION 'HU_GET_HUS'
  EXPORTING
    if_lock_hus      = 'X'
    if_with_text     = ' '
    is_objects       = ls_object
  IMPORTING
    et_header        = lt_hus
    et_items         = lt_hupos
    et_item_serialno = lt_serialno
  EXCEPTIONS
    hus_locked       = 1
    no_hu_found      = 2
    fatal_error      = 3
    OTHERS           = 4.

The above code is great if you need information about one delivery.

Maybe you ask why I used the “magic constant” 01 for the ls_object-object. This field is connected to the VEKP-VPOBJ field which can contain the following values

VEKP_VPOBJ

But what if you need to get information about all HU’s in all deliveries of one shipment?

  1. You can loop over all deliveries in a shipment and call the standard FM above
  2. You can use custom SQL command
DATA:
  iv_tknum TYPE tknum VALUE '1234567',  "Your shipment number
  lt_venum TYPE TABLE OF venum.         "table of HU numbers

SELECT DISTINCT vekp~venum
  INTO TABLE lt_venum
  FROM vttp
  INNER JOIN vekp ON vekp~vpobjkey = vttp~vbeln
                 AND vekp~vpobj    = '01'
  WHERE vttp~tknum = iv_tknum.

... get further info about selected VENUM's

Leave a Reply

Your email address will not be published. Required fields are marked *