2023 Apr 19 3:51 PM
Hello.
In my application I have an inbound delivery, where I have to:
I have looked at and tried various examples in the forums, the code below is a (horrible) work-in-progress of the best result I have until now: split is correct, packing is done BUT the numbering of the HU is internal and the assigned type is A (even if I pass B in the proposal).
Correct would be for example: 435958083154001398 type B, actual is:
The code looks like this:
FORM pack_pallet
CHANGING ps_pallet TYPE ty_pallet.
CONSTANTS: lc_inbound_del TYPE c LENGTH 2 VALUE '03',
lc_delnotif TYPE c VALUE '7'.
DATA: ls_erefid TYPE vpobjkey,
lt_eheader TYPE hum_hu_header_t,
lt_eitem TYPE hum_hu_item_t,
lt_emsg TYPE huitem_messages_t,
lt_ehus TYPE STANDARD TABLE OF vekpvb,
lt_ret TYPE bapirettab,
l_packmat TYPE matnr,
l_clenum LIKE rlmob-clenum.
DATA: ls_vbkok_wa TYPE vbkok,
lt_verko TYPE STANDARD TABLE OF verko,
lt_verpo TYPE STANDARD TABLE OF verpo,
lt_repack TYPE STANDARD TABLE OF hum_repack,
lt_prot TYPE TABLE OF prott.
* Custom function here: looks up packing material and changes l_packmat
* Lot numbers: required for packing, optional for posting
* In case of packing, we must create it else it will fail.
CALL FUNCTION 'BAPI_BATCH_CREATE'
EXPORTING
material = ps_pallet-matnr
batch = ps_pallet-charg
plant = ps_pallet-werks
IMPORTING
batch = ps_pallet-charg
TABLES
return = lt_ret[].
IF ps_pallet-charg IS INITIAL.
gs_msg-msgid = lt_ret[ type = 'E' ]-id.
gs_msg-msgno = lt_ret[ type = 'E' ]-number.
gs_msg-msgv1 = lt_ret[ type = 'E' ]-message_v1.
gs_msg-msgv2 = lt_ret[ type = 'E' ]-message_v2.
gs_msg-msgv3 = lt_ret[ type = 'E' ]-message_v3.
gs_msg-msgv4 = lt_ret[ type = 'E' ]-message_v4.
* Custom error handling goes here
ENDIF.
ls_vbkok_wa-vbeln_vl = ps_pallet-vbeln.
ls_vbkok_wa-vbtyp_vl = 7.
* ls_vbkok_wa-wabuc = 'X'. "FIXME posting will be done later!
* ls_vbkok_wa-spe_auto_gr = 'X'. "FIXME posting will be done later!
ls_vbkok_wa-kzebu = 'X'.
INSERT INITIAL LINE INTO lt_verko INDEX 1 ASSIGNING FIELD-SYMBOL(<fs_verko>).
<fs_verko>-venum = ps_pallet-exidv.
<fs_verko>-exidv = ps_pallet-exidv.
* FIXME this may NOT be empty, else the packing fails!
<fs_verko>-exida = 'B'. "Number assigned by customer (no HU management)
FIXME test if internal number assignment depends on material type...
SELECT SINGLE magrv
INTO <fs_verko>-magrv
FROM mara
WHERE matnr = l_packmat.
<fs_verko>-werks = ps_pallet-werks.
<fs_verko>-status = '0010'.
<fs_verko>-vhilm = l_packmat.
INSERT INITIAL LINE INTO lt_verpo INDEX 1 ASSIGNING FIELD-SYMBOL(<fs_verpo>).
<fs_verpo>-venum = ps_pallet-exidv."FIXME no effect
<fs_verpo>-exidv_ob = ps_pallet-exidv."FIXME removing this is a bad idea, "HU not found"
<fs_verpo>-exidv = ps_pallet-exidv.
<fs_verpo>-velin = '1'.
<fs_verpo>-vbeln = ps_pallet-vbeln.
<fs_verpo>-posnr = '900001'. "FIXME was: ps_pallet-posnr.
<fs_verpo>-tmeng = ps_pallet-lfimg.
<fs_verpo>-vrkme = ps_pallet-vrkme.
<fs_verpo>-matnr = ps_pallet-matnr.
<fs_verpo>-charg = ps_pallet-charg.
<fs_verpo>-werks = ps_pallet-werks.
CALL FUNCTION 'WS_DELIVERY_UPDATE_2'
EXPORTING
vbkok_wa = ls_vbkok_wa
delivery = ps_pallet-vbeln
update_picking = abap_true
no_messages_update_1 = abap_true
synchron = abap_true
commit = space
nicht_sperren_1 = 'Y'
if_database_update_1 = '1'
if_error_messages_send = space
TABLES
prot = lt_prot
verko_tab = lt_verko
verpo_tab = lt_verpo
* FIXME enable block to suppress visible errors
* EXCEPTIONS
* error_message = 1
* OTHERS = 2
.
IF sy-subrc = 0.
* FIXME notify results
ELSE.
ROLLBACK WORK.
* FIXME custom error handling
ENDIF.
ENDFORM.
Since this is an unreleased function (thanks SAP! /s) I have tried fiddling with the input parameters but I couldn't get rid of this last issue.
The functional consultant for the customer is checking for possible issues regarding the customizing, in the meanwhile my question is: does the numbering / type error depend on some wrong coding on my part?
Thanks,
Andrea.
2023 Apr 19 9:55 PM
Hi Andrea,
I implemented an (almost) identical scenario using function "GN_DELIVERY_CREATE", with some small differences. In my case f.e. the delivery is packed into new handling units (HU will be created by the function itself).
On item level I only fill the following fields: EXIDV_OB (same value as Exidv on verko), VELIN, VBELN, POSNR, TMENG and VRKME. I dont enter a batch and material as the HU item is linked to the batch split item.
On header I use the fields "vhilm, exidv, and exidv2, where exidv2 is filled with a temporary number (starting with $ followed by a couner).
When checking your code, the venum field (internal HU number) is filled with the etxernal number, maybe this is causing your issue. What happens when you remove this assigment on verko and verpo level?
2023 Apr 20 8:07 AM
At the item level, I have tried removing the assignment and it had no effect. I must try at the header level, today I am letting the users tests the preliminary version but I will update the comment once I have tested your suggestion, thank you.
2023 Apr 21 7:57 AM
Hello c5e08e0478aa4727abc4482f5be390b2
Calling WS_DELIVERY_UPDATE_2 function is inherently complex as there is no official documentation. The approach that works for me is to use Delivery Interface IDocs to update deliveries. The IDocs are processed by WS_DELIVERY_UPDATE_2. So once I get the result I need with the IDocs, I can put a break point in the function and figure out how it should be called for a specific scenario.
I might not be able to give you a full solution, but let me share a couple comments on how you call the function:
Best regards
Dominik Tylczynski
2023 Apr 24 9:48 AM
Thanks for the tips, I am going to work on this today and try them out. (edit: nope, no time... after freeze is over)
My initial solution was autopack with a batch input recording but it was rejected because they wanted the ability to only pack one item line and partial quantities. Regarding IDOCS, unfortunately in this situation I believe we have neither the capacity (in terms of headcount) nor the flexibility (because of bureaucracy) to explore this route.
2024 Aug 24 8:42 AM
Hi abo,
I have the same kind of requirement can you please provide me the code or guidenece how do you acheive this.