其他相关资料可点击:
HU相关配置 |
代码
输入参数:内向交货单号
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(INB_VBELN) TYPE VBELN
*" TABLES
*" ET_CREATED_HUS STRUCTURE BAPIHUIDENTIFICATION OPTIONAL
*" RETURN STRUCTURE BAPIRET2
*"----------------------------------------------------------------------
TYPE-POOLS: pdt.
DATA: lv_vbeln TYPE vbeln.
DATA: lv_error TYPE c,
lw_return TYPE bapiret2.
DATA: lw_koko TYPE vbkok,
lw_kopo TYPE vbpok,
lt_prot TYPE TABLE OF prott,
lw_prott TYPE prott,
lt_kopo TYPE TABLE OF vbpok,
lt_vsek TYPE TABLE OF verko,
lt_vsep TYPE TABLE OF verpo,
lv_pupd TYPE c.
DATA: lw_goods TYPE packgood,
lt_goods TYPE pdt_packgoods,
lw_object TYPE pdt_object,
lv_profile TYPE pdt_profile,
lv_application TYPE pdt_application.
DATA: lt_packitems TYPE pdt_packitems,
lt_packqty TYPE pdt_t_packqty,
lx_hus TYPE pdt_hus,
lt_hu_messages TYPE huitem_messages_t,
lv_objectkey TYPE pdt_objkey,
lv_packresult TYPE pdt_autopackresult.
DATA: lw_likp TYPE likp,
lw_lips TYPE lips,
lt_lips TYPE TABLE OF lips.
DATA: lv_vpobjkey TYPE vpobjkey,
ls_huhdr_proposal TYPE huhdr_proposal,
lw_huitm_prop TYPE huitm_proposal.
DATA: lw_vbkok TYPE vbkok,
lt_verpo TYPE TABLE OF verpo,
ls_verpo TYPE verpo,
lt_verko TYPE TABLE OF verko,
ls_verko TYPE verko,
lw_created_hus TYPE vekpvb,
lt_created_hus TYPE TABLE OF vekpvb,
lw_inb_hu TYPE bapihuidentification.
date:ls_likp type likp. FIELD-SYMBOLS TYPE huitm_proposal.
IF inb_vbeln IS NOT INITIAL.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = inb_vbeln
IMPORTING
output = lv_vbeln.
*&------------------------------------------------------------------
* Auto Packing
*&------------------------------------------------------------------
REFRESH: lt_packitems, lt_goods, lt_packqty, lt_hu_messages.
CLEAR: lv_packresult, lv_objectkey, lw_object,lx_hus.
SELECT * INTO TABLE lt_lips FROM lips WHERE vbeln = lv_vbeln.
select single * from likp into ls_likp vbeln = lv_vbeln..
IF sy-subrc <> 0.
CLEAR: lw_return.
lw_return-id = 'VL'.
lw_return-type = 'E'.
lw_return-number = '331'.
APPEND lw_return TO return.
EXIT.
ENDIF.
LOOP AT lt_lips INTO lw_lips.
CLEAR: lw_goods.
lw_goods-matnr = lw_lips-matnr.
lw_goods-kunag = lw_likp-kunag.
lw_goods-kunwe = lw_likp-kunnr.
lw_goods-vkorg = lw_likp-vkorg.
lw_goods-vtweg = lw_lips-vtweg.
lw_goods-spart = lw_lips-spart.
lw_goods-kunnr = lw_likp-kunnr.
lw_goods-ablad = lw_likp-ablad.
lw_goods-abrvw = lw_lips-abrvw.
lw_goods-route = lw_likp-route.
lw_goods-vstel = lw_likp-vstel.
lw_goods-versart = lw_likp-vsart.
lw_goods-werks = lw_lips-werks.
lw_goods-lgort = lw_lips-lgort.
lw_goods-charg = lw_lips-charg. lw_goods-lifnr = ls_likp-lifnr. "可能涉及到 HU 数量选择的优先级
SELECT SINGLE xchpf INTO lw_goods-xchpf
FROM marc
WHERE matnr = lw_goods-matnr
AND werks = lw_goods-werks.
IF lw_goods-xchpf = 'X'.
* IF lw_goods-charg IS INITIAL.
* lw_goods-charg = '9999999999'.
* ENDIF.
ENDIF.
lw_goods-maxqua = lw_lips-lfimg.
lw_goods-qunit_a = lw_lips-vrkme.
APPEND lw_goods TO lt_goods.
ENDLOOP.
lw_object-objtype = '03'.
lw_object-objkey = inb_vbeln.
lv_application = '1'.
* Assign packinstruction
CALL FUNCTION 'VHUPILE_ASSIGN_PACKINSTRUCTION'
EXPORTING
application = lv_application
object = lw_object
profile = '0001'
* PDPARA = PDPARA
packgoods = lt_goods
* DIALOG_FLAG = DIALOG_FLAG
IMPORTING
packitems = lt_packitems
t_packqty = lt_packqty
return_code = lv_packresult
EXCEPTIONS
failure = 1
profile_not_found = 2
profile_wrong = 3
creation_failed = 4
no_packgood_found = 5
packinstr_deleted = 6
packinstr_not_found = 7
OTHERS = 8.
IF sy-subrc <> 0.
CLEAR lw_return.
lw_return-id = sy-msgid.
lw_return-type = sy-msgty.
lw_return-number = sy-msgno.
lw_return-message_v1 = sy-msgv1.
lw_return-message_v2 = sy-msgv2.
lw_return-message_v3 = sy-msgv3.
lw_return-message_v4 = sy-msgv4.
PERFORM frm_build_msgtext CHANGING lw_return.
IF lw_return IS NOT INITIAL.
APPEND lw_return TO return.
ENDIF.
EXIT.
ENDIF.
**------------------------------------------
* get proposals
**------------------------------------------
CALL FUNCTION 'VHUPILE_CREATE_HU_PROPOSALS'
EXPORTING
application = lv_application
object = lw_object
profile = '0001'
* PDPARA = PDPARA
packitems = lt_packitems
IMPORTING
s_mmdata = lx_hus-s_mmdata
t_hd_prp = lx_hus-t_hd_prp
t_hd_cap = lx_hus-t_hd_cap
t_hd_add = lx_hus-t_hd_add
t_hd_tra = lx_hus-t_hd_tra
t_items = lx_hus-t_items
t_srlnr = lx_hus-t_srlnr
EXCEPTIONS
failure = 1
profile_not_found = 2
profile_wrong = 3
creation_failed = 4
no_packgood_found = 5
packinstr_deleted = 6
packinstr_not_found = 7
OTHERS = 8.
IF sy-subrc <> 0.
CLEAR lw_return.
lw_return-id = sy-msgid.
lw_return-type = sy-msgty.
lw_return-number = sy-msgno.
lw_return-message_v1 = sy-msgv1.
lw_return-message_v2 = sy-msgv2.
lw_return-message_v3 = sy-msgv3.
lw_return-message_v4 = sy-msgv4.
PERFORM frm_build_msgtext CHANGING lw_return.
IF lw_return IS NOT INITIAL.
APPEND lw_return TO return.
ENDIF.
EXIT.
ENDIF.
*...To clear the memory before calling WS_UPDATE_DELIVERY..........
CALL FUNCTION 'HU_PACKING_REFRESH'.
* General Header
CLEAR: lw_vbkok.
lw_vbkok-vbeln = lw_object-objkey.
lw_vbkok-vbeln_vl = lw_object-objkey.
lw_vbkok-vbtyp_vl = '7'. "Inbound Delivery
* Items
SORT lt_lips BY matnr.
LOOP AT lx_hus-t_items ASSIGNING .
READ TABLE lt_lips INTO lw_lips WITH KEY matnr = -matnr BINARY SEARCH.
IF sy-subrc = 0.
-belnr = lw_lips-vbeln.
-posnr = lw_lips-posnr.
ENDIF.
ENDLOOP.
REFRESH: lt_verpo.
LOOP AT lx_hus-t_items[] INTO lw_huitm_prop.
CLEAR: ls_verpo.
MOVE lw_huitm_prop-matnr TO ls_verpo-matnr.
MOVE lw_huitm_prop-velin TO ls_verpo-velin .
MOVE lw_huitm_prop-exidv TO ls_verpo-exidv_ob .
MOVE lw_huitm_prop-lgort TO ls_verpo-lgort.
MOVE lw_huitm_prop-belnr TO ls_verpo-rfbel.
MOVE lw_huitm_prop-belnr TO ls_verpo-vbeln.
MOVE lw_huitm_prop-posnr TO ls_verpo-rfpos.
MOVE lw_huitm_prop-posnr TO ls_verpo-posnr .
MOVE lw_huitm_prop-quantity TO ls_verpo-tmeng.
MOVE lw_huitm_prop-werks TO ls_verpo-werks.
MOVE lw_huitm_prop-charg TO ls_verpo-charg.
MOVE lw_huitm_prop-meins TO ls_verpo-vrkme.
APPEND ls_verpo TO lt_verpo.
ENDLOOP.
* Header
REFRESH: lt_verko.
LOOP AT lx_hus-t_hd_prp[] INTO ls_huhdr_proposal.
CLEAR: ls_verko.
MOVE-CORRESPONDING ls_huhdr_proposal TO ls_verko.
APPEND ls_verko TO lt_verko.
ENDLOOP.
REFRESH: lt_prot[], lt_created_hus[].
CLEAR: lv_error.
CALL FUNCTION 'WS_DELIVERY_UPDATE'
EXPORTING
vbkok_wa = lw_vbkok
synchron = 'X'
commit = 'X'
delivery = lw_vbkok-vbeln
nicht_sperren = space
if_no_generic_system_service = 'X'
TABLES
verko_tab = lt_verko
verpo_tab = lt_verpo
prot = lt_prot
et_created_hus = lt_created_hus
EXCEPTIONS
communication_failure = 1
system_failure = 2.
IF sy-subrc <> 0.
lv_error = 'X'.
ENDIF.
IF lt_prot IS NOT INITIAL.
LOOP AT lt_prot INTO lw_prott WHERE msgno IS NOT INITIAL.
ENDLOOP.
IF sy-subrc = 0.
lv_error = 'X'.
ENDIF.
ENDIF.
IF lv_error = 'X'.
CLEAR lw_return.
lw_return-id = sy-msgid.
lw_return-type = sy-msgty.
lw_return-number = sy-msgno.
lw_return-message_v1 = sy-msgv1.
lw_return-message_v2 = sy-msgv2.
lw_return-message_v3 = sy-msgv3.
lw_return-message_v4 = sy-msgv4.
PERFORM frm_build_msgtext CHANGING lw_return.
IF lw_return IS NOT INITIAL.
APPEND lw_return TO return.
ENDIF.
ROLLBACK WORK.
EXIT.
ELSE.
COMMIT WORK AND WAIT.
LOOP AT lt_created_hus INTO lw_created_hus.
CLEAR: lw_inb_hu.
lw_inb_hu-hu_id = lw_created_hus-venum.
lw_inb_hu-hu_exid = lw_created_hus-exidv.
APPEND lw_inb_hu TO et_created_hus.
ENDLOOP.
ENDIF.
ENDIF.