这个BAPI一直还活着,不知道为什么,可能SAP没工夫升级吧。。。
今天主要是GM_CODE的问题,对应如下,同时下面转一个同学的文章。。。
GM_CODE | Tcode | 描述 | MovementType |
01 | MB01 | 对采购订单收货 | 101/ |
02 | MB31 | 按生产订单收货 | 101/ |
03 | MB1A | 消耗出货 | 201/261/541/551 |
04 | MB1B | 转移过账 | 301/311/321/325/344 |
05 | MB1C | 其他收货 | Z67/Z68/501/511 |
06 | MB11 | 货物移动 | |
07 | MB04 | 委外调整 |
Movement Type:
101 仓库收料 102退料
201 工程领料 202工程退料 cost center
261 仓库发料 262退料
411 转仓 412退回 sales order GR/GI Slip No.
501 仓库without PO 收料 by G/L Account 502 退回
561 初始化库存 562退回
Movement Type
1.物料的移动在SAP中的反映,也可以理解为物流业务在SAP中的反映
2.移动类型可以根据物料类型的Quantity/Value属性,更新(数量(Stock)或价值(FI凭证/科目的确定)
3.移动类型的字段显示(Screen)可以在IMG中设置
4.MRP,ATP check 等计算的基础
5.链接SAP各模块
Mvt type Description
1xx GR from Pur/Prd and return
2xx GI for Consumption
3xx,4xx Transfer
5xx GR W/O ref to Pur/Prd Order
6xx LE-SHP movement types
7xx Physical inventory(IM:70x/WM:71x)
8xx Brazil
Customer 9xx,Xxx,Yxx,Zxx
MM模块通过移动类型来区分物料的移动,MB11可以处理工厂内所有的移动,而MB11不便于权限管理,因此在工厂往往使用MB1A,MB1B,MB1C来处理厂内物流。
MB1A通常用于发货类,例如201 成本中心消耗, 261 内部订单消耗,541 委外加工发货,551 库房报损均使用MB1A。
MB1B通常用于转储类,例如301 工厂间转储(一步) 311 存储地点间转储 309 编码转换 321-325 库存类为冻结/质检状态的记帐修改 移动
MB1C通常用于收货类,例如101 采购订单收货 103 采购订单收货至冻结状态 122 无采购订单退货 161 按退货采购订单退货 131 从生产订单501 无采购订单收货 511 免费收货
说明:采购订单、生产订单收货
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.
"执行操作
&n