BAPI_OUTB_DELIVERY_CHANGE
注:
1.不能修改拣配数量,拣配可以用 WS_DELIVERY_UPDATE
DEMO
form change_po_dn .
data:
lv_bukrs type ekko-bukrs,
lv_kunnr(40),
lv_type(10),
lv_p17.
data:begin of ls_ekpo2,
bsart type ekko-bsart,
lifnr type ekko-lifnr,
bukrs type ekko-bukrs,
inco2 type ekko-inco2,
ebelp type ekpo-ebelp,
retpo type ekpo-retpo,
end of ls_ekpo2.
data:
lv_vbeln type likp-vbeln,
ls_items like line of gt_items,
ls_ekpo type ekpo,
lt_ekpo type table of ekpo,
ls_lips type lips,
lt_lips type table of lips,
lv_subrc like sy-subrc.
*po
data:
ls_po_item type bapimepoitem ,
lt_po_item type table of bapimepoitem ,
ls_po_itemx type bapimepoitemx,
lt_po_itemx type table of bapimepoitemx.
*dn
data:
ls_header_data type bapiobdlvhdrchg,
ls_header_control type bapiobdlvhdrctrlchg,
ls_item_data type bapiobdlvitemchg ,
lt_item_data type table of bapiobdlvitemchg ,
ls_item_control type bapiobdlvitemctrlchg,
lt_item_control type table of bapiobdlvitemctrlchg.
*判断p17
select count(*) from ztmm_po_lis2 where ebeln = gv_ebeln and bsart = 'EB'.
if sy-subrc = 0.
select single
ekko~bsart ekko~lifnr ekko~bukrs ekko~inco2
ekpo~retpo
into corresponding fields of ls_ekpo2
from ekko
inner join ekpo on ekko~ebeln = ekpo~ebeln
where ekko~ebeln = gv_ebeln.
split ls_ekpo2-inco2 at '+' into lv_bukrs lv_kunnr lv_type.
shift lv_kunnr left by 2 places.
if ls_ekpo2-bsart = 'EB' and ls_ekpo2-lifnr = '0000010142'
and ls_ekpo2-bukrs+0(2) = '23' and ls_ekpo2-bukrs ne '2300' and ls_ekpo2-bukrs ne '2330'
and lv_bukrs+0(2) = '23' and lv_bukrs ne '2300' and lv_bukrs ne '2330'
and ( lv_type = '寄售' or lv_type = '样机' )
and ls_ekpo2-retpo is initial.
lv_p17 = 'X'.
endif.
endif.
check lv_p17 = 'X'.
select ebeln ebelp menge
into corresponding fields of table lt_ekpo
from ekpo
where ebeln = gv_ebeln.
select max( vbeln ) into lv_vbeln from lips where vgbel = gv_ebeln.
select vbeln posnr lfimg vrkme meins charg umvkz umvkn
into corresponding fields of table lt_lips
from lips
where vbeln = lv_vbeln.
ls_header_data-deliv_numb = lv_vbeln.
loop at gt_items into ls_items.
*po
read table lt_ekpo into ls_ekpo with key ebelp = ls_items-posnr.
ls_po_item-po_item = ls_items-posnr.
ls_po_item-quantity = ls_ekpo-menge - ls_items-product_amount.
append ls_po_item to lt_po_item.
ls_po_itemx-po_item = ls_items-posnr.
ls_po_itemx-quantity = 'X'.
append ls_po_itemx to lt_po_itemx.
*dn
read table lt_lips into ls_lips with key posnr = ls_items-posnr.
ls_item_data-deliv_numb = lv_vbeln.
ls_item_data-deliv_item = ls_items-posnr.
ls_item_data-dlv_qty = ls_lips-lfimg - ls_items-product_amount.
ls_item_data-dlv_qty_imunit = ls_item_data-dlv_qty. "下面的字段都要传,否则会报错“vlbapi 004”
ls_item_data-sales_unit = ls_lips-vrkme.
ls_item_data-base_uom = ls_lips-meins.
ls_item_data-batch = ls_lips-charg.
ls_item_data-fact_unit_nom = ls_lips-umvkz.
ls_item_data-fact_unit_denom = ls_lips-umvkn.
append ls_item_data to lt_item_data.
if ls_item_data-dlv_qty = 0.
ls_item_control-del_item = 'X'.
else.
ls_item_control-chg_delqty = 'X'.
endif.
ls_item_control-deliv_numb = lv_vbeln.
ls_item_control-deliv_item = ls_items-posnr.
append ls_item_control to lt_item_control.
endloop.
refresh gt_return.
call function 'BAPI_OUTB_DELIVERY_CHANGE'
exporting
header_data = ls_header_data
header_control = ls_header_control
delivery = lv_vbeln
tables
item_data = lt_item_data
item_control = lt_item_control
return = gt_return.
perform frm_populate_message changing lv_subrc.
if lv_subrc ne 0.
gs_xi_log-zztextcode = '003'.
gs_xi_log-zzstatus_msg = 'ERROR'.
concatenate gs_xi_log-zzwrong_msg '(交货单' lv_vbeln '数量更改未成功)'
into gs_xi_log-zzwrong_msg.
call function 'BAPI_TRANSACTION_ROLLBACK'.
else.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
gs_xi_log-zztextcode = '002'.
concatenate '交货单' lv_vbeln '数量更改成功'
into gs_xi_log-zzwrong_msg.
gs_xi_log-zzstatus_msg = 'OK'.
endif.
check gs_xi_log-zztextcode = '002'.
refresh gt_return.
clear lv_subrc.
call function 'BAPI_PO_CHANGE'
exporting
purchaseorder = gv_ebeln
no_authority = 'X'
tables
return = gt_return
poitem = lt_po_item
poitemx = lt_po_itemx.
perform frm_populate_message changing lv_subrc.
if lv_subrc ne 0.
call function 'BAPI_TRANSACTION_ROLLBACK'.
gs_xi_log-zztextcode = '003'.
concatenate gs_xi_log-zzwrong_msg '(采购订单' gv_ebeln '数量更改未成功)'
into gs_xi_log-zzwrong_msg.
gs_xi_log-zzstatus_msg = 'ERROR'.
return.
else.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
concatenate gs_xi_log-zzwrong_msg '/采购订单' gv_ebeln '数量更改成功'
into gs_xi_log-zzwrong_msg.
endif.
endform. " CHANGE_PO_DN
form frm_populate_message changing p_subrc.
data: lv_error type string,
ls_msg type t100.
clear: p_subrc, gt_return.
loop at gt_return where type = 'E' or type = 'A' or type = 'X'.
if gt_return-message is initial.
select single * from t100 into ls_msg
where sprsl = sy-langu
and arbgb = gt_return-id
and msgnr = gt_return-number.
replace '&1' with gt_return-message_v1(10) into ls_msg-text.
replace '&2' with gt_return-message_v2(10) into ls_msg-text.
replace '&3' with gt_return-message_v3(10) into ls_msg-text.
replace '&4' with gt_return-message_v4(10) into ls_msg-text.
replace '&' with gt_return-message_v1(10) into ls_msg-text.
replace '&' with gt_return-message_v2(10) into ls_msg-text.
replace '&' with gt_return-message_v3(10) into ls_msg-text.
replace '&' with gt_return-message_v4(10) into ls_msg-text.
concatenate lv_error ls_msg-text into lv_error.
else.
concatenate lv_error gt_return-message into lv_error.
endif.
p_subrc = 4.
endloop.
if p_subrc = 4 and gs_xi_log-zzwrong_msg is initial.
gs_xi_log-zztextcode = '003'.
gs_xi_log-zzstatus_msg = 'ERROR'.
gs_xi_log-zzwrong_msg = lv_error.
elseif p_subrc = 4 and gs_xi_log-zzwrong_msg is not initial.
gs_xi_log-zztextcode = '003'.
gs_xi_log-zzstatus_msg = 'ERROR'.
concatenate gs_xi_log-zzwrong_msg lv_error into gs_xi_log-zzwrong_msg
separated by '/'.
endif.
endform. " FRM_POPULATE_MESSAGE