创建交货单/外向交货BAPI_OUTB_DELIVERY_CREATE_SLS/STO
FUNCTION Z_SD_CREATE_DN.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IM_SHIP_TYPE) TYPE LIKP-VSART DEFAULT '01'
*" VALUE(IM_DUE_DATE) TYPE DATUM DEFAULT '99991231'
*" EXPORTING
*" VALUE(E_DN) TYPE CHAR10
*" VALUE(E_STATUS) TYPE CHAR1
*" VALUE(E_MESSAGE) TYPE CHAR40
*" TABLES
*" T_DATA STRUCTURE ZSDS0008
*" IT_RETURN STRUCTURE BAPIRET2 OPTIONAL
*" IT_DN STRUCTURE VBAK OPTIONAL
*"----------------------------------------------------------------------
DATA : LV_SHIP_POINT TYPE BAPIDLVCREATEHEADER-SHIP_POINT,
LV_DUE_DATE TYPE BAPIDLVCREATEHEADER-DUE_DATE,
LV_DELIVERY TYPE BAPISHPDELIVNUMB-DELIV_NUMB,
LT_SO_ITEMS LIKE TABLE OF BAPIDLVREFTOSALESORDER,
LS_SO_ITEM LIKE BAPIDLVREFTOSALESORDER,
LT_STO_ITEMS LIKE TABLE OF BAPIDLVREFTOSTO,
LS_STO_ITEM LIKE BAPIDLVREFTOSTO,
LT_RETURN LIKE TABLE OF BAPIRET2,
LS_RETURN LIKE BAPIRET2. DATA : LV_TYPE(). "PO / SO
DATA : LV_SUCCESS.
DATA : LV_MATNR TYPE VBAP-MATNR.
DATA : LV_VBELN TYPE VBELN.
DATA : LV_TABIX TYPE SY-TABIX.
DATA : LV_CONTINUE. DATA : LT_LIPS TYPE TABLE OF LIPS,
LS_LIPS TYPE LIPS. DATA : BEGIN OF LS_DATA,
DEL.
INCLUDE STRUCTURE ZSDS0008.
DATA : END OF LS_DATA. DATA : LT_DATA LIKE TABLE OF LS_DATA. DATA : BEGIN OF LT_VBFA OCCURS ,
VBELV TYPE VBFA-VBELV, "先前凭证
POSNV TYPE VBFA-POSNV,
VBELN TYPE VBFA-VBELN, "后续凭证
POSNR TYPE VBFA-POSNN,
END OF LT_VBFA. DATA : LV_MAX TYPE I VALUE '',
LV_COUNT TYPE I. LOOP AT T_DATA.
MOVE-CORRESPONDING T_DATA TO LS_DATA.
APPEND LS_DATA TO LT_DATA.
ENDLOOP. PERFORM FRM_DATA_CHECK TABLES LT_DATA CHANGING E_MESSAGE. IF E_MESSAGE IS NOT INITIAL.
E_STATUS = 'E'.
EXIT.
ENDIF. REFRESH : LT_STO_ITEMS,
LT_SO_ITEMS,
IT_RETURN. SORT LT_DATA BY VBELN POSNR. LV_DUE_DATE = IM_DUE_DATE. CLEAR LS_DATA.
READ TABLE LT_DATA INTO LS_DATA INDEX .
SELECT SINGLE * FROM EKKO WHERE EBELN = LS_DATA-VBELN.
IF SY-SUBRC EQ ."PO - STO.
LV_TYPE = 'PO'.
LV_SHIP_POINT = ''.
* LV_DUE_DATE = '99991230'.
ELSE.
LV_TYPE = 'SO'.
LV_SHIP_POINT = ''.
* LV_DUE_DATE = '99991230'.
ENDIF. * 判断行项目是否产生过交货单
SELECT VGBEL AS VBELV VGPOS AS POSNV VBELN POSNR
FROM LIPS
INTO TABLE LT_VBFA
WHERE VGBEL = LS_DATA-VBELN. * 控制交货单最大的项目数
DO. CLEAR LV_CONTINUE. LOOP AT LT_DATA INTO LS_DATA WHERE DEL EQ ''. * IF LV_MAX = LV_COUNT.
* CLEAR LV_COUNT.
* EXIT.
* ENDIF.
* 排除掉已经创建过交货单的行项目
READ TABLE LT_VBFA WITH KEY VBELV = LS_DATA-VBELN POSNV = LS_DATA-POSNR.
IF SY-SUBRC EQ .
E_DN = LT_VBFA-VBELN.
IT_DN-VBELN = E_DN.
COLLECT IT_DN.
CONTINUE.
ENDIF. CLEAR E_DN. ADD TO LV_COUNT. IF LV_TYPE = 'PO'.
CLEAR LS_STO_ITEM.
LS_STO_ITEM-REF_DOC = LS_DATA-VBELN.
LS_STO_ITEM-REF_ITEM = LS_DATA-POSNR.
APPEND LS_STO_ITEM TO LT_STO_ITEMS.
ELSE.
CLEAR LS_SO_ITEM.
LS_SO_ITEM-REF_DOC = LS_DATA-VBELN.
LS_SO_ITEM-REF_ITEM = LS_DATA-POSNR.
APPEND LS_SO_ITEM TO LT_SO_ITEMS.
ENDIF. LV_CONTINUE = 'X'. LS_DATA-DEL = 'X'.
MODIFY LT_DATA FROM LS_DATA TRANSPORTING DEL.
ENDLOOP. IF LV_CONTINUE EQ ''.
EXIT.
ENDIF. IF LV_DUE_DATE NE ''.
FREE MEMORY ID 'DUE_DATE'.
EXPORT LV_DUE_DATE TO MEMORY ID 'DUE_DATE'.
ENDIF. IF LT_SO_ITEMS IS NOT INITIAL.
* Call BAPI to Create DN
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
EXPORTING
SHIP_POINT = LV_SHIP_POINT
DUE_DATE = LV_DUE_DATE
IMPORTING
DELIVERY = LV_DELIVERY
TABLES
SALES_ORDER_ITEMS = LT_SO_ITEMS
RETURN = LT_RETURN. ELSEIF LT_STO_ITEMS IS NOT INITIAL.
* Call BAPI to Create DN
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_STO'
EXPORTING
SHIP_POINT = LV_SHIP_POINT
DUE_DATE = LV_DUE_DATE
IMPORTING
DELIVERY = LV_DELIVERY
TABLES
STOCK_TRANS_ITEMS = LT_STO_ITEMS
RETURN = LT_RETURN. ENDIF. APPEND LINES OF LT_RETURN TO IT_RETURN. LOOP AT LT_RETURN TRANSPORTING NO FIELDS WHERE TYPE = 'A' OR
TYPE = 'E' OR
TYPE = 'X'.
EXIT.
ENDLOOP. IF SY-SUBRC EQ .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. PERFORM FRM_CONVERT_MESSAGE TABLES LT_RETURN CHANGING E_MESSAGE. E_STATUS = 'E'.
EXIT.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'. E_STATUS = 'S'.
E_DN = LV_DELIVERY.
ENDIF. DO TIMES.
SELECT *
FROM LIPS
INTO TABLE LT_LIPS
WHERE VBELN = LV_DELIVERY. IF SY-SUBRC EQ .
EXIT.
ENDIF.
ENDDO. * --->请求交货数量 与交货数量不一致 20152417
IF LT_STO_ITEMS IS NOT INITIAL AND LINES( LT_STO_ITEMS ) NE LINES( LT_LIPS ).
* WAIT UP TO 1 SECONDS.
PERFORM FRM_DELETE_DELIVERY TABLES IT_RETURN USING LV_DELIVERY.
CLEAR IT_RETURN.
IT_RETURN-ID = ''.
IT_RETURN-NUMBER = ''.
IT_RETURN-TYPE = 'E'.
IT_RETURN-MESSAGE = '交货数量与请求交货数量不一致,停止交货'.
IT_RETURN-MESSAGE_V1 = '交货数量与请求交货数量不一致'.
IT_RETURN-MESSAGE_V2 = ',停止交货'.
IT_RETURN-MESSAGE_V3 = LV_DELIVERY.
IT_RETURN-MESSAGE_V4 = ''.
APPEND IT_RETURN. CLEAR: E_STATUS,E_DN.
EXIT.
ELSEIF LT_SO_ITEMS IS NOT INITIAL AND LINES( LT_SO_ITEMS ) NE LINES( LT_LIPS ).
* WAIT UP TO 1 SECONDS.
PERFORM FRM_DELETE_DELIVERY TABLES IT_RETURN USING LV_DELIVERY.
CLEAR IT_RETURN.
IT_RETURN-ID = ''.
IT_RETURN-NUMBER = ''.
IT_RETURN-TYPE = 'E'.
IT_RETURN-MESSAGE = '交货数量与请求交货数量不一致,停止交货'.
IT_RETURN-MESSAGE_V1 = '交货数量与请求交货数量不一致'.
IT_RETURN-MESSAGE_V2 = ',停止交货'.
IT_RETURN-MESSAGE_V3 = LV_DELIVERY.
IT_RETURN-MESSAGE_V4 = ''.
APPEND IT_RETURN. CLEAR: E_STATUS,E_DN.
EXIT.
ENDIF.
* <---请求交货数量 与交货数量不一致 20150427 IT_DN-VBELN = LV_DELIVERY.
APPEND IT_DN. * REFRESH : GT_DN_ITEM.
*
* LOOP AT LT_LIPS INTO LS_LIPS.
* LV_TABIX = SY-TABIX.
*
* CLEAR GS_DN_ITEM.
* GS_DN_ITEM-DELIV_NUMB = LS_LIPS-VBELN.
* GS_DN_ITEM-DELIV_ITEM = LS_LIPS-POSNR.
* GS_DN_ITEM-MATERIAL = LS_LIPS-MATNR.
* GS_DN_ITEM-DLV_QTY = LS_LIPS-LGMNG.
* GS_DN_ITEM-FACT_UNIT_NOM = LS_LIPS-UMVKZ.
* GS_DN_ITEM-FACT_UNIT_DENOM = LS_LIPS-UMVKN.
*
* READ TABLE LT_DATA INTO LS_DATA WITH KEY VBELN = LS_LIPS-VGBEL POSNR = LS_LIPS-VGPOS.
* IF SY-SUBRC EQ 0 AND LS_DATA-CHARG IS NOT INITIAL AND LS_LIPS-CHARG NE LS_DATA-CHARG.
* GS_DN_ITEM-BATCH = LS_DATA-CHARG.
* APPEND GS_DN_ITEM TO GT_DN_ITEM.
*
* LS_LIPS-CHARG = LS_DATA-CHARG.
* ELSE.
* DELETE LT_LIPS INDEX LV_TABIX.
* CONTINUE.
* ENDIF.
*
* CLEAR GS_DN_ITEM_CTR.
* GS_DN_ITEM_CTR-DELIV_NUMB = LS_LIPS-VBELN.
* GS_DN_ITEM_CTR-DELIV_ITEM = LS_LIPS-POSNR.
* GS_DN_ITEM_CTR-CHG_DELQTY = 'X'.
* APPEND GS_DN_ITEM_CTR TO GT_DN_ITEM_CTR.
*
* MODIFY LT_LIPS FROM LS_LIPS TRANSPORTING CHARG.
* ENDLOOP. * CHECK GT_DN_ITEM IS NOT INITIAL. * GS_DN_HEADER-DELIV_NUMB = LV_DELIVERY.
* GS_DN_HEADER_CTR-DELIV_NUMB = LV_DELIVERY.
* GS_DN_HEADER-SHIP_COND = IM_SHIP_COND."Ship condition
* GS_DN_HEADER_CTR-SHIP_COND_FLG = 'X'."Ship condition
* GV_DN_NUMBER = LV_DELIVERY. * Update Batch to DN
* CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
* EXPORTING
* HEADER_DATA = GS_DN_HEADER
* HEADER_CONTROL = GS_DN_HEADER_CTR
* DELIVERY = GV_DN_NUMBER
* TABLES
* ITEM_DATA = GT_DN_ITEM
* ITEM_CONTROL = GT_DN_ITEM_CTR
* RETURN = GT_RETURN. * LV_VBELN = LV_DELIVERY.
* CALL FUNCTION 'Z_SD_CHANGE_DN'
* EXPORTING
* IM_DELIVERY = LV_VBELN
* IM_SHIP_TYPE = IM_SHIP_TYPE
* TABLES
* IT_ITEM = LT_LIPS
* IT_RETURN = GT_RETURN.
*
*
* LOOP AT GT_RETURN TRANSPORTING NO FIELDS WHERE TYPE = 'A' OR
* TYPE = 'E' OR
* TYPE = 'X'.
* EXIT.
* ENDLOOP.
*
* IF SY-SUBRC EQ 0.
* CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
*
* APPEND LINES OF GT_RETURN TO IT_RETURN.
*
* PERFORM FRM_CONVERT_MESSAGE TABLES GT_RETURN CHANGING E_MESSAGE.
** Delete Delivery Note
* PERFORM FRM_DELETE_DELIVERY USING LV_VBELN.
*
* E_STATUS = 'E'.
* ELSE.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT = 'X'.
*
* E_STATUS = 'S'.
* E_DN = LV_DELIVERY.
* ENDIF.
*
* REFRESH: LT_SO_ITEMS,
* LT_STO_ITEMS,
* LT_LIPS.
*
* APPEND LINES OF GT_RETURN TO IT_RETURN.
*
* IT_DN-VBELN = LV_DELIVERY.
* APPEND IT_DN.
ENDDO. ENDFUNCTION. ZSDS0008结构:
KUNNR 类型 KUNNR
VBELN 类型 VBELN
POSNR 类型 POSNR
CHARG 类型 CHARG_D
创建交货单/外向交货BAPI_OUTB_DELIVERY_CREATE_SLS/STO的更多相关文章
- 销售订单、外向交货单、交货 bapi
转自[http://www.cnblogs.com/elegantok/archive/2009/10/18/1585398.html]***********SALES ORDER INPUT CRE ...
- SAP 参照sto订单创建外向交货BAPI
DATA: SHIP_POINT TYPE TVST-VSTEL, "装运点/接收点 NUM_DELIVERIES TYPE VBNUM, STOCK_TRANS_ITEMS WITH HE ...
- 『诡异的』VL10B创建外向交货单出错解决全过程
一直觉得SAP STO的业务模式配置起来还是挺简单的,无非就是关联一下采购单与交货单的关系,以及相应工厂的装运数据,其他像主数据的设置也没有什么特别的.相比ICS模式,它少了IDOC的配置,所以还是很 ...
- 「SAP技术」A项目关联公司间退货STO流程
[SAP技术]A项目关联公司间退货STO流程 1)创建公司间退货STO单据. 如下图示的公司间退货STO 4500000572, 2),VL10B, 创建交货单. 如下图交货单号:80044918, ...
- SAP MM 公司间STO发货单输出报错 - 合并工厂AUC1和存储位置6002没有货物收货地点 - 之对策
SAP MM 公司间STO发货单输出报错 - 合并工厂AUC1和存储位置6002没有货物收货地点 - 之对策 昨天收到客户业务部门报错,说是业务对交货单0080022298做POD失败.相关交货单的输 ...
- 成套销售交货组与BOM 546719 - FAQ: Delivery group and BOM in the delivery
交货组:将需要同时交互给客户的项目捆绑在一起,按行项目中最后交货日期做完交货组的计划行日期 1.如果销售订单标记为完全交货,则所有行项目都会分配到同一个交货组中 删除交货单是会给出警告 2.为母键行项 ...
- BAPI
MM模块 1. BAPI_MATERIAL_SAVEDATA 创建物料主数据 注意参数EXTENSIONIN的使用,可以创建自定义字段 例如:WA_BAPI_TE_MARA-MATERIAL = IT ...
- SAP 各模块常用的BAPI
MM模块 1. BAPI_MATERIAL_SAVEDATA 创建物料主数据 注意参数EXTENSIONIN的使用,可以创建自定义字段 例如:WA_BAPI_TE_MARA-MATERIAL = IT ...
- 常用tcode
SAP常用TCODE 1 MMBE 查询库存 2 CO01 生产订单创建 3 ME2N-按采购订单编号 ME2B/ME2M/ME2C/ME2W 采购订单查询 清单范围ALV 4 MB51 物料凭证清单 ...
随机推荐
- EntityFramework 开始小试
1 Install-Package EntityFramework 2 创建实体类 public class Blog { public int BlogId { get; set; } public ...
- ctrl+z暂停任务
(1) CTRL+Z挂起进程并放入后台 (2) jobs 显示当前暂停的进程 (3) bg %N 使第N个任务在后台运行(%前有空格) (4) fg %N 使第N个任务在前台运行 默认bg,fg不带% ...
- Protractor AngularJS测试框架教程
Protractor是一个建立在WebDriverJS基础上的端到端(E2E)的AngularJS JavaScript Web应用程序测试框架.Protractor全自动化真实的模拟用户在真正的浏览 ...
- JMS【三】--ActiveMQ简单的HelloWorld实例
第一篇博文JMS[一]--JMS基本概念,我们介绍了JMS的两种消息模型:点对点和发布订阅模型,以及消息被消费的两个方式:同步和异步,JMS编程模型的对象,最后说了JMS的优点. 第二篇博文JMS[二 ...
- 常用的邮箱服务器(SMTP、POP3)地址、端口
常用的邮箱服务器(SMTP.POP3)地址.端口 参考网址:http://wenku.baidu.com/link?url=IPv15rPRkd0nsuGH0Dm0A5kFyRaeHJY2_gYpDW ...
- Python学习笔记day5
模块 1.自定义模块 自定义模块就是在当前目录下创建__init__.py这个空文件,这样外面的程序才能识别此目录为模块包并导入 上图中libs目录下有__init__.py文件,index.py程序 ...
- maven环境快速搭建(转)
主要介绍maven在本地安装使用 http://www.cnblogs.com/fnng/archive/2011/12/02/2272610.html 使用Eclipse构建Maven项目 (s ...
- 修改Mac]Bringing interface etch0:Device
OS版本:Red Hat Enterprise Linux AS4/5 网上有很多关于linux下修改MAC地址的方法,大多依葫芦画瓢,似乎都没验证过,达不到修改的目的. 经过我的详细测试,最终成功解 ...
- An unknown server-side error occurred while processing the command.处理
在调用resetAPP()时,报错:An unknown server-side error occurred while processing the command. 怎么解决呢?请看: 额,Ap ...
- Unity5 新功能解析--物理渲染与standard shader
Unity5 新功能解析--物理渲染与standard shader http://blog.csdn.net/leonwei/article/details/48395061 物理渲染是UNITY5 ...