目录
报错
1.报错:客户xx不在工厂xx中
原因:填错了抬头中的 供应商、供应工厂,项目中的供应库存地点
报错:06 218,净价格必须大于0 et price must be greater than 0
原因:
1.没有自动带出净价(维护供应商条件价格),或者带出的采购信息记录价格不大于0
2.多次调用缓存问题,清缓存
**清空缓存
* perform mepo_refresh(saplmepo).
* data: mem_optn like csdata-xfeld value '0'.
* export mem_optn to memory id 'CSIO_MEM_OPTN'.
2.有多个外协消耗组件时报错
Change indicators could not be uniquely determined in material mapping
原因:没有填 pocomponents-item_no或采购订单行传入了重复行
删除自动从bom带出来的外协组件的方法:参考 lg zflg_po_create
pocond-change_id = 'U'.更新价格,I表示新增价格(I新增价格时先加一行D删除采购信息记录的价格)
pocondx-change_id = 'X'.
3.
ls_poheader-item_intvl = 'X'. "项目编号间隔
ls_poheaderx-item_intvl = 'X'. "项目编号间隔
必须传这两个参数,不然行项目不支持指定项目号
4.供货工厂是根据供应商取的,如果供货工厂不对会报错“净价计算错误”
5.Numerical entry is not supported for extrnal item(外部条目标识不支持编号条目),行项目号问题,比如项目号传重复了
6.UB转出单报错:06 215 请输入净价格。
原因:item传了GT_ID IR_ID
7.no_price_from_po = 'X' 不带用户的价格过来,但是会带采购信息记录
可以删采购信息记录,也可以item-po_price = 2,这样就不会带采购信息记录了,但要注意,如果item里写了采购信息记录(比如先跑了testrun返回进item了),就删不掉了。
注意事项
1.创建po带过来多个重复的价格
原因:配置问题,用户参数 EVO
或 no_price_from_po = 'X' 不带价格过来
2.如果物料维护了舍入值,则生成的采购订单的数量可能和传入的值不一样
比如舍入值为30的时候,传入100会生成120的订单
3 如果有采购信息记录,会自动带出价格条件,此时如果chang_id = 'I',会在原来的价格条件的基础上再加一条条件
正确的做法应该是,先传一行D,再传一行 I
4 转储采购订单没有库存也可以创建,但是创建交货单就会失败了(可用库存,不是非限制使用库存),可以先用BAPI_MATERIAL_AVAILABILITY检查可用库存
5.物料有多个单位,生成的采购订单单位和传入的单位不一样,并且自动转换了数量。
修改采购信息记录的订单单位之后就可以了。
6.EKPO-KZTLF 值为'B',前台ME21N创建为空值,bapi创建有默认值 B
原因是标准代码判断bapi进来取了配置表赋值
配置点这里,SM30维护视图是/SPE/V_TDELVAUTO
DEMO
BOE ZSDB010
代码片段
function zmm_01_po_create2 .
*"----------------------------------------------------------------------
*"*"局部接口:
*" IMPORTING
*" VALUE(IV_FROM_60_SO) TYPE XFELD DEFAULT ' '
*" VALUE(IV_FROM_60_PO) TYPE XFELD DEFAULT ' '
*" VALUE(IV_FROM_47_SO) TYPE XFELD DEFAULT ' '
*" VALUE(IV_FROM_47_PO) TYPE XFELD DEFAULT ' '
*" VALUE(IV_UPDATE_LOG) TYPE XFELD DEFAULT ' '
*" VALUE(IV_TEXT) TYPE CHAR255 OPTIONAL
*" EXPORTING
*" VALUE(ES_OUTPUT) TYPE ZSMM_RET_MES
*" TABLES
*" ET_RETURN STRUCTURE BAPIRET2 OPTIONAL
*" IT_PO_FILE STRUCTURE ZSMM_ME21N_FILE
*" CT_CORDER_LOG STRUCTURE ZTMM_CORDER_LOG OPTIONAL
*"----------------------------------------------------------------------
data: ls_poheader type bapimepoheader,
ls_poheaderx type bapimepoheaderx,
ls_poitem type bapimepoitem,
lt_poitem type table of bapimepoitem,
ls_poitemx type bapimepoitemx,
lt_poitemx type table of bapimepoitemx,
ls_poschedule type bapimeposchedule,
lt_poschedule type table of bapimeposchedule,
ls_poschedulex type bapimeposchedulx,
lt_poschedulex type table of bapimeposchedulx,
lt_pocond type table of bapimepocond,
ls_pocond type bapimepocond,
lt_pocondx type table of bapimepocondx,
ls_pocondx type bapimepocondx,
ls_exppurchaseorder type ebeln,
lt_corder_log type table of ztmm_corder_log,
ls_corder_log type ztmm_corder_log,
ls_header type zsmm_me21n_file,
lt_header type table of zsmm_me21n_file,
ls_item type zsmm_me21n_file,
lt_item type table of zsmm_me21n_file,
ls_return type bapiret2,
lt_return type bapiret2_t,
lv_itemno type ebelp,
lv_dummy type string,
lv_value type p,
lv_tabix type sy-tabix.
clear: ls_poheader,ls_poheaderx,lv_itemno,ls_exppurchaseorder.
refresh: lt_poitem,lt_poitemx,lt_poschedule, lt_poschedulex,lt_return.
append lines of it_po_file to lt_header.
append lines of it_po_file to lt_item.
*取得采购订单表头
sort lt_header by seqno.
delete adjacent duplicates from lt_header comparing seqno. "此号用来区分行项目是否在同一个采购订单下。
read table lt_header into ls_header index 1.
move-corresponding ls_header to ls_poheader.
* 取得公司代码
if ls_poheader-comp_code is initial.
select single bukrs
into ls_poheader-comp_code
from t001k
where bwkey = ls_header-plant.
endif.
ls_poheaderx-doc_type = 'X'.
ls_poheaderx-comp_code = 'X'.
ls_poheaderx-purch_org = 'X'.
ls_poheaderx-pur_group = 'X'.
if ls_poheader-suppl_plnt is not initial.
ls_poheaderx-suppl_plnt = 'X'.
endif.
ls_poheaderx-vendor = 'X'.
if ls_poheader-ref_1 is not initial.
ls_poheaderx-ref_1 = 'X'.
endif.
if ls_poheader-customer is not initial.
ls_poheaderx-customer = 'X'.
endif.
*构建采购订单行项目
loop at lt_item into ls_item where seqno = ls_header-seqno.
lv_tabix = sy-tabix.
move-corresponding ls_item to ls_poitem.
lv_itemno = lv_itemno + 10.
ls_poitem-po_item = lv_itemno.
append ls_poitem to lt_poitem.
ls_poitemx-po_item = lv_itemno.
ls_poitemx-material = 'X'.
ls_poitemx-quantity = 'X'.
ls_poitemx-po_unit = 'X'.
ls_poitemx-plant = 'X'.
ls_poitemx-stge_loc = 'X'.
if ls_poitem-suppl_stloc is not initial.
ls_poitemx-suppl_stloc = 'X'.
endif.
ls_poitemx-batch = 'X'.
ls_poitemx-ret_item = 'X'.
* ls_poitemx-INFO_UPD = 'X'. "去掉更新采购信息记录的勾 chenyl for dengld 24.07.2017 12:07:41
append ls_poitemx to lt_poitemx.
ls_poschedule-po_item = lv_itemno.
ls_poschedule-delivery_date = ls_item-delivery_date.
append ls_poschedule to lt_poschedule.
ls_poschedulex-po_item = lv_itemno.
ls_poschedulex-delivery_date = 'X'.
append ls_poschedulex to lt_poschedulex .
do 2 times.
pocond-itm_number = items-ebelp.
pocond-cond_type = items-kschl.
pocond-cond_value = items-kbetr.
pocond-currency = items-koein.
pocond-cond_p_unt = items-kpein.
pocond-change_id = 'D'.
if sy-index = 2.
pocond-change_id = 'I'.
endif.
append pocond. clear pocond.
pocondx-itm_number = items-ebelp.
pocondx-cond_type = 'X'.
pocondx-cond_value = 'X'.
pocondx-currency = 'X'.
pocondx-cond_p_unt = 'X'.
pocondx-change_id = 'X'.
append pocondx. clear pocondx.
enddo.
ls_item-ebelp = lv_itemno.
modify lt_item from ls_item index lv_tabix
transporting ebelp.
clear: ls_poitem, ls_poitemx,
ls_poschedule, ls_poschedulex.
endloop.
*---------------------------------------------------------------------*
data lt_headtext like table of bapimepotextheader with header line.
*备注进长文本 chenyl for dengld 25.07.2017 18:39:48
lt_headtext-po_item = '00000'.
lt_headtext-text_id = 'F01'.
lt_headtext-text_form = '*'.
lt_headtext-text_line = iv_text(132).
append lt_headtext.
lt_headtext-po_item = '00000'.
lt_headtext-text_id = 'F01'.
lt_headtext-text_form = '*'.
lt_headtext-text_line = iv_text+132(123).
append lt_headtext.
*---------------------------------------------------------------------*
*创建采购订单
call function 'BAPI_PO_CREATE1'
exporting
poheader = ls_poheader
poheaderx = ls_poheaderx
importing
exppurchaseorder = ls_exppurchaseorder
tables
potextheader = lt_headtext
return = et_return
poitem = lt_poitem
poitemx = lt_poitemx
poschedule = lt_poschedule
poschedulex = lt_poschedulex
pocond = lt_pocond
pocondx = lt_pocondx.
*如果失败,回滚事务,并输出错误信息.
if ls_exppurchaseorder is initial.
call function 'BAPI_TRANSACTION_ROLLBACK'.
loop at et_return into ls_return where type = 'E' or type = 'A'.
concatenate es_output-ret_text ls_return-message into es_output-ret_text.
endloop.
es_output-ret_id = 'E'.
else.
*如果成功,提交事务,并输出采购订单号.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
es_output-ret_id = 'S'.
es_output-ret_number = ls_exppurchaseorder.
concatenate ls_header-seqno
'号 采购订单'
ls_exppurchaseorder
'创建成功'
into es_output-ret_text.
*更新采购订单号到内标中
ls_header-ebeln = ls_exppurchaseorder.
modify it_po_file from ls_header
transporting ebeln
where seqno = ls_header-seqno.
*更新创建订单日志表
check iv_update_log = 'X'.
if iv_from_60_so = 'X'.
loop at ct_corder_log into ls_corder_log.
lv_tabix = sy-tabix.
ls_corder_log-r_order = ls_exppurchaseorder.
ls_corder_log-r_item = ls_corder_log-i_item.
read table lt_item into ls_item with key
i_order = ls_corder_log-i_order
i_item = ls_corder_log-i_item
ks_client = ls_corder_log-ks_client.
if sy-subrc = 0.
ls_corder_log-r_kunnr = ls_item-vendor.
endif.
ls_corder_log-r_netwr = ls_corder_log-i_netwr.
modify ct_corder_log from ls_corder_log index lv_tabix
transporting r_order r_item r_kunnr r_netwr.
endloop.
elseif iv_from_60_po = 'X'.
loop at lt_item into ls_item.
move-corresponding ls_item to ls_corder_log.
ls_corder_log-matnr = ls_item-material.
ls_corder_log-i_werks = ls_item-plant.
ls_corder_log-i_lgort = ls_item-stge_loc.
ls_corder_log-charg = ls_item-batch.
ls_corder_log-menge = ls_item-quantity.
ls_corder_log-i_order = ls_exppurchaseorder.
ls_corder_log-i_item = ls_item-ebelp.
read table lt_poitem into ls_poitem
with key po_item = ls_item-ebelp.
if sy-subrc = 0.
ls_corder_log-vrkme = ls_poitem-po_unit.
ls_corder_log-retpo = 'X'.
ls_corder_log-i_kunnr = ls_poitem-customer.
ls_corder_log-i_netwr = ls_poitem-net_price.
ls_corder_log-i_waerk = ls_poitem-orderpr_un.
endif.
append ls_corder_log to ct_corder_log.
endloop.
elseif iv_from_47_so = 'X'.
loop at ct_corder_log into ls_corder_log.
lv_tabix = sy-tabix.
ls_corder_log-r_order = ls_exppurchaseorder.
ls_corder_log-r_item = ls_corder_log-i_item.
read table lt_item into ls_item with key
i_order = ls_corder_log-i_order
i_item = ls_corder_log-i_item
ks_client = ls_corder_log-ks_client.
if sy-subrc = 0.
ls_corder_log-r_kunnr = ls_item-vendor.
endif.
ls_corder_log-r_netwr = ls_corder_log-i_netwr.
modify ct_corder_log from ls_corder_log index lv_tabix
transporting r_order r_item r_kunnr r_netwr.
endloop.
elseif iv_from_47_po = 'X'.
loop at lt_item into ls_item.
move-corresponding ls_item to ls_corder_log.
ls_corder_log-matnr = ls_item-material.
ls_corder_log-i_werks = ls_item-plant.
ls_corder_log-i_lgort = ls_item-stge_loc.
ls_corder_log-charg = ls_item-batch.
ls_corder_log-menge = ls_item-quantity.
ls_corder_log-i_order = ls_exppurchaseorder.
ls_corder_log-i_item = ls_item-ebelp.
ls_corder_log-i_kunnr = ls_item-vendor.
read table lt_poitem into ls_poitem
with key po_item = ls_item-ebelp.
if sy-subrc = 0.
ls_corder_log-vrkme = ls_poitem-po_unit.
ls_corder_log-retpo = 'X'.
ls_corder_log-i_netwr = ls_poitem-net_price.
ls_corder_log-i_waerk = ls_poitem-orderpr_un.
endif.
append ls_corder_log to ct_corder_log.
endloop.
endif.
endif.
endfunction.