注
- 这个BAPI r3没有,ecc有
- 自带commit,执行完bapi里update aufk的的更新模块会被触发
- 写入wbs报错 61 261,是bapi bug,早期有个note1677892 ,s4 依旧有bug,参考lijun解决办法CO_KO1_CHECK_PROJN中
**begin add by dlj 20190415 通过清空特殊库存类型来解决bapi创建和前台不一致问题
*wbs元素前台创建成功,BAPI创建则报错
DEFINE mc_range.
&1-sign = &2.
&1-option = &3.
&1-low = &4.
APPEND &1.
CLEAR:&1.
END-OF-DEFINITION.
DATA:lt_tvarvc TYPE TABLE OF tvarvc,
lr_typ TYPE RANGE OF t003o-auart WITH HEADER LINE.
SELECT * FROM tvarvc
INTO TABLE lt_tvarvc
WHERE name = 'ZPP_ORDER_TYPE_Q'.
LOOP AT lt_tvarvc INTO DATA(ls_tvarvc).
mc_range lr_typ ls_tvarvc-sign ls_tvarvc-opti ls_tvarvc-low.
ENDLOOP.
IF i_order_type IN lr_typ.
CLEAR:e_sobkz.
ENDIF.
*end add by dlj 20190415
DEMO
*BAPI
data:
ls_bapi_pp_order_create type bapi_pp_order_create,
ls_return type bapiret2,
lv_order_number type bapi_order_key-order_number.
loop at gt_alv where sel = 'X' and aufnr = ''.
data(lv_tabix) = sy-tabix.
clear:ls_return,lv_order_number,ls_bapi_pp_order_create.
ls_bapi_pp_order_create-order_type = gt_alv-auart."订单类型
ls_bapi_pp_order_create-material = gt_alv-matnr."订单物料号
* ls_bapi_pp_order_create-plant = gt_alv-werks."订单工厂
ls_bapi_pp_order_create-plant = '1021'."订单工厂
* ls_bapi_pp_order_create-planning_plant = gt_alv-werks."计划工厂
ls_bapi_pp_order_create-planning_plant = '1021'."计划工厂
ls_bapi_pp_order_create-prod_version = gt_alv-verid."生产版本
ls_bapi_pp_order_create-basic_start_date = gt_alv-mbdat."基本开始日期
ls_bapi_pp_order_create-basic_end_date = gt_alv-mbdat."基本完成日期
ls_bapi_pp_order_create-quantity = gt_alv-psmng."订单数量
ls_bapi_pp_order_create-quantity_uom = gt_alv-vrkme. "单位
* ls_bapi_pp_order_create-sales_order = gt_alv-vbeln. "销售订单
* ls_bapi_pp_order_create-sales_order_item = gt_alv-posnr. "销售订单项目
ls_bapi_pp_order_create-storage_location = gt_alv-lgort_out. "产出库存地点
call function 'CONVERSION_EXIT_ABPSP_INPUT'
exporting
input = gt_alv-posid
importing
output = ls_bapi_pp_order_create-wbs_element
exceptions
not_found = 1.
* ls_bapi_pp_order_create-QUANTITY_UOM = gt_alv-MEINS."单位
* ls_bapi_pp_order_create-goods_recipient = gt_alv-wempf."收货方
* ls_bapi_pp_order_create-GOODS_RECIPIENT = gt_alv-MEINS.
ls_bapi_pp_order_create-order_type = gt_alv-auart.
set update task local.
call function 'BAPI_PRODORD_CREATE'
exporting
orderdata = ls_bapi_pp_order_create
importing
return = ls_return
order_number = lv_order_number.
if lv_order_number is not initial.
gt_alv-rtype = 'S'.
gt_alv-rtmsg = '订单创建成功'.
gt_alv-aufnr = lv_order_number.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
*线体
update aufk
set zzvbeln = gt_alv-vbeln zzposnr = gt_alv-posnr zzline = gt_alv-xianb
where aufnr = lv_order_number.
commit work and wait.
*修改消耗库存地点
perform frm_pro_change using lv_order_number gt_alv-lgort_consu.
else.
call function 'BAPI_TRANSACTION_ROLLBACK'.
gt_alv-rtype = 'E'.
message id ls_return-id type ls_return-type number ls_return-number
with ls_return-message_v1 ls_return-message_v2
ls_return-message_v3 ls_return-message_v4
into gt_alv-rtmsg.
endif.
move-corresponding gt_alv to lt_zppd0011.
lt_zppd0011-menge = gt_alv-menge + gt_alv-psmng . "订单已开立数量
if lt_zppd0011-menge = gt_alv-kwmeng_meins.
lt_zppd0011-complete = 'X'.
endif.
lt_zppd0011-aenam = sy-uname.
lt_zppd0011-aedat = sy-datum.
lt_zppd0011-aezet = sy-uzeit.
append lt_zppd0011.
modify gt_alv index lv_tabix.
endloop.
if sy-subrc ne 0.
message e001(00) with '至少选择一行未创建成功的单据'.
endif.