移动代码
01 -- MB01
02 -- MB31
03 -- MB1A
04 -- MB1B
05 -- MB1C
06 -- MB11
07 -- MB04
一、收货(101)
说明:采购订单、生产订单收货
form recvfromord tables pt_tran structure zwttran.
"移库定义
data: goodsmvt_header type bapi2017_gm_head_01,
goodsmvt_code type bapi2017_gm_code,
goodsmvt_headret type bapi2017_gm_head_ret,
materialdocument type bapi2017_gm_head_ret-mat_doc,
matdocumentyear type bapi2017_gm_head_ret-doc_year,
goodsmvt_item type standard table of /afs/bapi2017_gm_item_create,
return type standard table of bapiret2,
w_creturn type bapiret2,
w_goodsmvt_item type /afs/bapi2017_gm_item_create,
w_return type bapiret2.
data:lt_retmsg like table of bapiret2 with header line,
lt_return like table of bapiret2 with header line.
data:l_tran_nbr like zwttran-tran_nbr,
l_tranpo like zwttran-tranpo,
l_matdoc like zwttran-matdoc,
l_flag like zwttran-flag,
l_line_id type i.
data:l_asn_nbr type ze_ref_field, "asn号
l_po type ze_ref_field,"po号
l_po_line(5) type n,"po行号
l_matnr type matnr."货号
data:l_type type char1,"类型
l_afpo type afpo,"生产订单
l_j_3abssi type j_3abssi,"生产订单计划行
l_eket type eket,"采购订单计划行
l_ekpo type ekpo."采购订单行项目
data:lt_bom like table of zwmbom with header line.
refresh:t_tran_nbr.
loop at pt_tran.
clear :t_tran_nbr.
t_tran_nbr-tran_nbr = pt_tran-tran_nbr.
if pt_tran-tran_type = '603' and pt_tran-tran_code = '02' and pt_tran-proc_stat_code = '10' and pt_tran-ref_field_6 = 'P'.
t_tran_nbr-po = pt_tran-ref_field_3.
endif.
append t_tran_nbr.
endloop.
sort t_tran_nbr by tran_nbr po.
delete adjacent duplicates from t_tran_nbr.
loop at t_tran_nbr.
clear:l_tran_nbr,l_matdoc,l_matnr,l_asn_nbr,l_po,l_matnr,l_type,l_afpo,l_j_3abssi,l_eket,l_ekpo,l_tranpo,lt_retmsg,lt_return,pt_tran.
refresh:lt_return.
clear:goodsmvt_header,goodsmvt_code,goodsmvt_headret,materialdocument,matdocumentyear, goodsmvt_item ,return,w_return.
refresh:goodsmvt_item ,return.
"头
goodsmvt_header-pstng_date = sy-datum.
goodsmvt_header-doc_date = sy-datum.
"明细
loop at pt_tran where tran_type = '603' and tran_code = '02' and proc_stat_code = '10' and units_rcvd > 0
and tran_nbr = t_tran_nbr-tran_nbr and ref_field_3 = t_tran_nbr-po.
if pt_tran-ref_field_6 = 'P'.
l_tran_nbr = pt_tran-tran_nbr.
"获取asn号
l_asn_nbr = pt_tran-ref_field_1.
l_po = pt_tran-ref_field_3.
concatenate l_tran_nbr l_po into l_tranpo.
if pt_tran-ref_field_4 is not initial.
l_po_line = pt_tran-ref_field_4.
else.
clear l_po_line.
endif.
l_matnr = pt_tran-matnr.
clear:lt_retmsg.
refresh:lt_retmsg.
call function 'ZLC_GET_PREMOVE101'
EXPORTING
p_matnr = l_matnr
p_po = l_po
p_po_line = l_po_line
IMPORTING
p_type = l_type
p_afpo = l_afpo
p_j_3abssi = l_j_3abssi
p_ekpo = l_ekpo
p_eket = l_eket
TABLES
pt_retmsg = lt_retmsg.
read table lt_retmsg with key type = 'E'.
if sy-subrc <> 0.
case l_type.
when 'E'.
"事务代码
goodsmvt_code-gm_code = '02'. "mb31
"明细
w_goodsmvt_item-line_id = w_goodsmvt_item-line_id + 1.
w_goodsmvt_item-move_type = '101'."移动类型
w_goodsmvt_item-material = l_j_3abssi-matnr."大货号
w_goodsmvt_item-grid_value = l_j_3abssi-j_3asize."网格值
w_goodsmvt_item-plant = g_plant."工厂
w_goodsmvt_item-stge_loc = g_stge_loc."地点
w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd."数量
w_goodsmvt_item-orderid = l_j_3abssi-j_3absnr."订单号
w_goodsmvt_item-order_itno = l_j_3abssi-j_3ahbsp."行项目
w_goodsmvt_item-sched_line_sku = l_j_3abssi-j_3aebsp."计划行项目
w_goodsmvt_item-mvt_ind = 'F'."生产订单
w_goodsmvt_item-stck_type = 'E'.
w_goodsmvt_item-gr_rcpt = pt_tran-user_id.
append w_goodsmvt_item to goodsmvt_item.
when 'F'.
"事务代码
goodsmvt_code-gm_code = '01'. "mb01
"明细
w_goodsmvt_item-line_id = w_goodsmvt_item-line_id + 1.
l_line_id = w_goodsmvt_item-line_id.
w_goodsmvt_item-move_type = '101'."移动类型
w_goodsmvt_item-material = l_ekpo-matnr."大货号
w_goodsmvt_item-grid_value = l_eket-j_3asize."网格值
w_goodsmvt_item-plant = g_plant."工厂
w_goodsmvt_item-stge_loc = g_stge_loc."地点
clear w_goodsmvt_item-vendor.
w_goodsmvt_item-entry_qnt = pt_tran-units_rcvd."数量
clear w_goodsmvt_item-batch.
w_goodsmvt_item-po_number = l_eket-ebeln."采购订单
w_goodsmvt_item-po_item = l_eket-ebelp."采购订单行号
w_goodsmvt_item-sched_line_sku = l_eket-etenr."计划行
clear:w_goodsmvt_item-parent_id,w_goodsmvt_item-line_depth.
w_goodsmvt_item-mvt_ind = 'B'."采购订单
w_goodsmvt_item-stck_type = 'E'."库存类型
w_goodsmvt_item-gr_rcpt = pt_tran-user_id.
append w_goodsmvt_item to goodsmvt_item.
refresh:lt_bom.
call function 'ZLC_GET_BOM'
EXPORTING
p_ebeln = l_eket-ebeln
p_ebelp = l_eket-ebelp
p_etenr = l_eket-etenr
TABLES
pt_bom = lt_bom.
if lines( lt_bom ) > 0.
loop at lt_bom.
w_goodsmvt_item-line_id = w_goodsmvt_item-line_id + 1.
w_goodsmvt_item-move_type = '543'."移动类型
w_goodsmvt_item-material = lt_bom-matnr."货号
if lt_bom-grdv is not initial.
w_goodsmvt_item-grid_value = lt_bom-grdv.
else.
clear w_goodsmvt_item-grid_value.
endif.
w_goodsmvt_item-plant = '1000'."工厂
clear w_goodsmvt_item-stge_loc.
w_goodsmvt_item-vendor = lt_bom-vendor."供应商
w_goodsmvt_item-entry_qnt = lt_bom-entry_qnt * pt_tran-units_rcvd."数量
if lt_bom-charg is not initial.
w_goodsmvt_item-batch = lt_bom-charg.
else.
clear w_goodsmvt_item-batch.
endif.
w_goodsmvt_item-parent_id = l_line_id.
w_goodsmvt_item-line_depth = 1.
w_goodsmvt_item-mvt_ind = 'B'."采购订单
w_goodsmvt_item-stck_type = 'E'."库存类型
w_goodsmvt_item-gr_rcpt = pt_tran-user_id.
append w_goodsmvt_item to goodsmvt_item.
endloop.
endif.
endcase.
else.
append lines of lt_retmsg to lt_return.
endif.
endif.
endloop.
read table lt_return with key type = 'E'.
if sy-subrc <> 0.
if goodsmvt_item[] is not initial.
"删除日志
perform deletepixtranlog using l_tranpo.
"执行操作
call function '/AFS/BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = goodsmvt_header
goodsmvt_code = goodsmvt_code
IMPORTING
goodsmvt_headret = goodsmvt_headret
materialdocument = materialdocument
matdocumentyear = matdocumentyear
TABLES
afs_goodsmvt_item = goodsmvt_item
return = return.
read table return with key type = 'E' into w_return.
if sy-subrc <> 0.
"提交