CALL FUNCTION 'BAPI_GOODSMVT_CREATE'-(物料凭证创建)
*&---------------------------------------------------------------------*
*& Report YTST_RAINY015_03
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ytst_rainy015_03.
*----------------------------------------------------------------------
* TYPES
*----------------------------------------------------------------------
TYPES: BEGIN OF ty_output,
lifnr TYPE ekko-lifnr, "供應商
ebeln TYPE ekpo-ebeln, "採購文件號碼
ebelp TYPE ekpo-ebelp, "採購文件的項目號碼
txz01 TYPE ekpo-txz01, "短文
matnr TYPE ekpo-matnr, "物料號碼
werks TYPE ekpo-werks, "地點
lgort TYPE ekpo-lgort, "庫存地點
menge TYPE ekpo-menge, "採購單數量
meins TYPE ekpo-meins, "單位
wenge TYPE ekpo-menge, "未清數量
benge TYPE ekpo-menge, "本次收料數量
txt(50) TYPE c, "備註
sel TYPE c, "選擇標誌
END OF ty_output.
TYPES: ty_tab_output TYPE ty_output OCCURS 0.
TYPES: BEGIN OF ty_error,
pstng_date TYPE budat,
doc_date TYPE bldat,
gm_code TYPE gm_code,
plant TYPE werks_d,
stge_loc TYPE lgort_d,
move_type TYPE bwart,
entry_qnt TYPE erfmg,
entry_uom TYPE erfme,
po_number TYPE bstnr,
po_item TYPE ebelp,
mvt_ind TYPE kzbew,
message(100) TYPE c,
txt(50) TYPE c,
row TYPE bapi_line,
END OF ty_error.
TYPES: ty_tab_error TYPE ty_error OCCURS 0.
DATA:gt_error TYPE ty_tab_error,
wa_error TYPE ty_error.
DATA:gt_output TYPE ty_tab_output,
wa_output TYPE ty_output.
DATA:l_tabix TYPE sy-tabix,
l_row TYPE bapi_line,
wa_output_tmp TYPE ty_output.
DATA:l_flag_create_success TYPE c.
DATA:lw_bapi_goodsmvt_header TYPE bapi2017_gm_head_01,
lw_bapi_goodsmvt_code TYPE bapi2017_gm_code,
lw_bapi_goodsmvt_headret TYPE bapi2017_gm_head_ret,
l_bapi_materialdocument TYPE bapi2017_gm_head_ret-mat_doc,
l_bapi_matdocumentyear TYPE bapi2017_gm_head_ret-doc_year,
lt_bapi_goodsmvt_item TYPE STANDARD TABLE OF bapi2017_gm_item_create,
wa_bapi_goodsmvt_item TYPE bapi2017_gm_item_create,
lt_bapi_return TYPE STANDARD TABLE OF bapiret2,
wa_bapi_return TYPE bapiret2.
*&G0.整理取得数据
SORT gt_output BY ebeln ebelp.
LOOP AT gt_output INTO wa_output.
wa_output_tmp = wa_output.
AT NEW ebeln.
CLEAR:lw_bapi_goodsmvt_header, lw_bapi_goodsmvt_code,
lw_bapi_goodsmvt_headret, l_bapi_materialdocument,
l_bapi_matdocumentyear, lt_bapi_goodsmvt_item,
lt_bapi_return.
*&G1.bapi_goodsmvt_hear 赋值(at new)
lw_bapi_goodsmvt_header-pstng_date = sy-datum.
lw_bapi_goodsmvt_header-doc_date = sy-datum.
lw_bapi_goodsmvt_code-gm_code = '01'.
ENDAT.
CLEAR wa_bapi_goodsmvt_item.
*&G2.bapi_goodsmvt_item 赋值()
wa_bapi_goodsmvt_item-plant = wa_output_tmp-werks.
wa_bapi_goodsmvt_item-stge_loc = wa_output_tmp-lgort.
wa_bapi_goodsmvt_item-move_type = '101'.
wa_bapi_goodsmvt_item-entry_qnt = wa_output_tmp-benge.
wa_bapi_goodsmvt_item-entry_uom = wa_output_tmp-meins.
wa_bapi_goodsmvt_item-po_number = wa_output_tmp-ebeln.
wa_bapi_goodsmvt_item-po_item = wa_output_tmp-ebelp.
wa_bapi_goodsmvt_item-mvt_ind = 'B'.
APPEND wa_bapi_goodsmvt_item TO lt_bapi_goodsmvt_item.
AT END OF ebeln.
*&G3flag打上
l_flag_create_success = 'Y'.
*&G4 CALL BAPI
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = lw_bapi_goodsmvt_header
goodsmvt_code = lw_bapi_goodsmvt_code
* TESTRUN = ' '
* GOODSMVT_REF_EWM =
IMPORTING
goodsmvt_headret = lw_bapi_goodsmvt_headret
materialdocument = l_bapi_materialdocument
matdocumentyear = l_bapi_matdocumentyear
TABLES
goodsmvt_item = lt_bapi_goodsmvt_item
return = lt_bapi_return.
* GOODSMVT_SERIALNUMBER =
* GOODSMVT_SERV_PART_DATA =
* EXTENSIONIN =
* AFS_GOODSMVT_SKU =
*&G5.如果失败,改flag 为‘N’.
LOOP AT lt_bapi_return INTO wa_bapi_return WHERE type = 'A'
OR type = 'E'.
l_flag_create_success = 'N'.
EXIT.
ENDLOOP.
*&G6 BAPI后处理
IF l_flag_create_success = 'Y'.
*&G6.1成功commit work,并形成日志
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
LOOP AT lt_bapi_goodsmvt_item INTO wa_bapi_goodsmvt_item.
wa_error-pstng_date = lw_bapi_goodsmvt_header-pstng_date.
wa_error-doc_date = lw_bapi_goodsmvt_header-doc_date.
wa_error-gm_code = lw_bapi_goodsmvt_code-gm_code.
MOVE-CORRESPONDING wa_bapi_goodsmvt_item TO wa_error.
CONCATENATE '生成物料凭证编号为:' l_bapi_materialdocument INTO wa_error-message.
MOVE '更新成功!' TO wa_error-txt.
APPEND wa_error TO gt_error.
CLEAR wa_error.
ENDLOOP.
ELSE.
*&6.2 失败rollback,并形成日志GT_ERROR
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
CLEAR l_row.
LOOP AT lt_bapi_goodsmvt_item INTO wa_bapi_goodsmvt_item.
l_row = l_row + 1.
wa_error-pstng_date = lw_bapi_goodsmvt_header-pstng_date.
wa_error-doc_date = lw_bapi_goodsmvt_header-doc_date.
wa_error-gm_code = lw_bapi_goodsmvt_code-gm_code.
MOVE-CORRESPONDING wa_bapi_goodsmvt_item TO wa_error.
MOVE '更新失败!' TO wa_error-txt.
wa_error-row = l_row.
READ TABLE lt_bapi_return INTO wa_bapi_return WITH KEY row = wa_error-row.
IF sy-subrc = 0.
wa_error-message = wa_bapi_return-message.
ENDIF.
APPEND wa_error TO gt_error.
CLEAR wa_error.
ENDLOOP.
ENDIF.
IF l_flag_create_success = 'Y'.
* IMPORTING
* RETURN =
ELSE.
* IMPORTING
* RETURN =
ENDIF.
ENDAT.
ENDLOOP.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'-(物料凭证创建)的更多相关文章
- BAPI_GOODSMVT_CREATE物料凭证增强字段
项目MSEG 的 BAPI 表增强结构 BAPI_TE_XMSEG 抬头MKPF 的 BAIP 表增强 BAPI_TE_XMKPF 1. 在结构BAPI_TE_XMSEG中appending str ...
- 查看物料凭证MB03 /MIGO A04-显示,R02-物料凭证
当货物移动操作后,可以使用事物码MB03.MIGO查询最近一次生成的物料凭证, 如果未知凭证号,Table:MKPF / AUFM/EKBE MKPF 抬头:物料凭证 KEY: MBLNR 物料凭证编 ...
- SAP MM 启用批次管理的物料MB21创建预留单据时批次号可以为空!
SAP MM 启用批次管理的物料MB21创建预留单据时批次号可以为空! 如下预留, 批次号字段为空. 实际上该物料是有激活batch management的, For MB21, it is just ...
- 【MM系列】SAP 物料凭证增强
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]在SAP里查看数据的方法 前言部 ...
- 【ABAP系列】SAP ABAP 物料凭证增强
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 物料凭证增强 ...
- Object和Function谁先被创建
http://bbs.csdn.net/topics/390772104#post-397284029
- SAP 订单状态跟踪
*&--------------------------------------------------------------------- *& Program name: *& ...
- SAP_FICO常用事务代码
1.会计科目维护: FS00:总账科目主记录维护 FSP0:科目表中总账科目主记录维护 FSS0:公司代码中总账科目主记录维护 2.会计凭证创建 FB01:创建凭证 F-02:总账凭证创建(在FB01 ...
- 从new Function创建函数联想到MVC模式
我们知道任何一个自定义函数都是Function构造器的实例,所以我们可以通过new Function的方式来创建函数,使用语法很简单, new Function(形参1, 形参2, ..., 形参N, ...
随机推荐
- 报“ Got minus one from a read call”的错误
在部署应用的时候,有时候应用可以直接启动,但偶尔应用却无法启动,报错信息是: java.sql.SQLRecoverableException: IO Error: Got minus one fro ...
- http://preshing.com/
http://preshing.com/ http://mechanical-sympathy.blogspot.com/
- Andriod 自动化测试研究方向
前言 孔子曰:"工欲善其事,必先利其器",我来云:"工欲利其器,必先知其理".我们无论学习任何新事物,都要尽量做到"知其然知其所以然",对于 ...
- 记一个发HTML格式邮件的问题
很早做了一个自动发邮件的程序,前一向发现Notes升级后反而CSS样式都没有了. 起初不以为意,反正格式数据在,客户也没说啥,后来觉得这样的态度要不得,小洞不补,大洞吃苦. 于是查查资料,发现浏览器里 ...
- hibernate 数据缓存
http://www.cnblogs.com/wean/archive/2012/05/16/2502724.html,
- JavaScript replace 回调函数用法
params.query = params.query.replace(/[\+\-\&\|\!\(\)\{\}\[\]\^\"\~\*\?\:\\]/g,function(a){ ...
- 面试题:使用finalkeyword修饰一个变量时,是引用不能变,还是引用的对象不能变?
/* * 问题:使用finalkeyword修饰一个变量时,是引用不能变,还是引用的对象不能变 * 答: * 使用finalkeyword修饰一个变量时,是指引用变量不能变,引用变量所指向的对象中的内 ...
- Allegro中解决鼠标放在走线上网络名、走线长度显示不出来的问题
一些PCB设计者在使用allegro时,由于一些误操作 导致当鼠标放在走线(cline)和网络(net)上面时,软件没有显示该走线的所属网络,或者相关的长度信息.本人经过help文档发现,以下方法可以 ...
- Qt中的对象类型转换
char * 与 const char *的转换 char *ch1="hello11"; const char *ch2="hello22"; ch2 = c ...
- js将字符串转变成数字
方法主要有三种 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数,后者把值转换成浮点数.只有 ...