根据采购/销售订单创建STO/SO
FUNCTION Z_SD_CREATE_DN.
*"----------------------------------------------------------------------
*"*"本地接口:
*" 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,
LV_DELIVERYS TYPE BAPIDLVCREATEHEADER-NUM_DELIVERIES, "TUS-2015-12-04
LT_DELIVERIES TYPE BAPISHPDELIVNUMB OCCURS WITH HEADER LINE, "TUS-2015-12-04
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.
***********CHANGED BY JAHLEEL 20160328 BEGIN**************************
*CHANGE THE WAY OF SEARCHING THE DELIVERY FROM SALES ORDERS. ** 判断行项目是否产生过交货单
* SELECT VGBEL AS VBELV VGPOS AS POSNV VBELN POSNR
* FROM LIPS
* INTO TABLE LT_VBFA
* WHERE VGBEL = LS_DATA-VBELN. IF LV_TYPE EQ 'SO'. SELECT VBELV POSNV VBELN POSNN AS POSNR
FROM VBFA
INTO TABLE LT_VBFA
WHERE VBELN EQ LS_DATA-VBELN
AND VBTYP_N EQ 'J'. ELSEIF LV_TYPE EQ 'PO'. SELECT EBELN AS VBELV EBELP AS POSNV BELNR AS VBELN BUZEI AS POSNR
FROM EKBE
INTO TABLE LT_VBFA
WHERE EBELN EQ LS_DATA-VBELN
AND BEWTP EQ 'L'. ENDIF. ***********CHANGED BY JAHLEEL 20160328 END*************************** * 控制交货单最大的项目数
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
NUM_DELIVERIES = LV_DELIVERYS "TUS-2015-12-04
TABLES
STOCK_TRANS_ITEMS = LT_STO_ITEMS
DELIVERIES = LT_DELIVERIES "TUS-2015-12-04
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. IF LT_DELIVERIES[] IS NOT INITIAL.
DO TIMES.
SELECT *
FROM LIPS
INTO TABLE LT_LIPS
FOR ALL ENTRIES IN LT_DELIVERIES
WHERE VBELN = LT_DELIVERIES-DELIV_NUMB. IF SY-SUBRC EQ .
EXIT.
ENDIF.
ENDDO.
ELSE.
DO TIMES.
SELECT *
FROM LIPS
INTO TABLE LT_LIPS
WHERE VBELN = LV_DELIVERY. IF SY-SUBRC EQ .
EXIT.
ENDIF.
ENDDO.
ENDIF. * --->请求交货数量 与交货数量不一致 20152417
IF LT_STO_ITEMS IS NOT INITIAL AND LINES( LT_STO_ITEMS ) NE LINES( LT_LIPS ).
* WAIT UP TO 1 SECONDS.
"更换成内表 TUS-2015-12-04
LOOP AT LT_DELIVERIES.
PERFORM FRM_DELETE_DELIVERY TABLES IT_RETURN USING LT_DELIVERIES-DELIV_NUMB.
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 = LT_DELIVERIES-DELIV_NUMB.
IT_RETURN-MESSAGE_V4 = ''.
APPEND IT_RETURN. CLEAR: E_STATUS,E_DN.
ENDLOOP.
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
IF LT_DELIVERIES[] IS NOT INITIAL.
LOOP AT LT_DELIVERIES.
IT_DN-VBELN = LT_DELIVERIES-DELIV_NUMB.
APPEND IT_DN.
ENDLOOP.
ELSE.
IT_DN-VBELN = LV_DELIVERY.
APPEND IT_DN.
ENDIF. * 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.
根据采购/销售订单创建STO/SO的更多相关文章
- 为什么S/4HANA的销售订单创建会触发生产订单的创建
调用S/4HANA销售订单创建函数SD_SALES_DOCU_MAINTAIN创建一个销售订单时,会触发生产订单的创建. 销售订单的每个行项目对应一个独立的生产订单,SD_SALES_DOCU_MAI ...
- SAP S/4HANA销售订单创建时,会自动触发生产订单的创建
这个自动触发的过程是怎么实现的? 使用下面的代码创建一个销售订单: DATA: ls_header TYPE bapisdhd1, ls_headerx TYPE bapisdhd1x, lt_bap ...
- 如何用代码的方式取出SAP C4C销售订单创建后所有业务伙伴的数据
比如我创建了一个Sales Order(销售订单)后,如何用代码的方式取出这些通过SAP Partner determination自动填充的Involved Parties信息呢? 一种方法可以使用 ...
- 1.5 外部销售自动创建为内部PR
1.5 外部销售自动创建为内部PR 1.5.1 业务方案描述 外部销售订单登记后,在销售订单录入界面点击一个创建内部申请按钮,自动将外部销售订单创建为内部申请,创建后将不得再次创 ...
- SAP Cloud for Customer销售订单External Note的建模细节
SAP Cloud for Customer的销售订单创建页面里,我们可以给一个订单维护External Note,当这个订单同步到S/4HANA生成对应的生产订单后,这个note可以作为备注提示生产 ...
- 销售订单、外向交货单、交货 bapi
转自[http://www.cnblogs.com/elegantok/archive/2009/10/18/1585398.html]***********SALES ORDER INPUT CRE ...
- 销售订单(SO)-API-创建销售订单
创建销售订单API主要注意几点: 初始化环境变量:fnd_global.apps_initialize(); mo_global.init('ONT'); mo_global.set_policy_c ...
- sap 如何获取公司间采购订单或销售订单的交货状态
在上SAP项目过程,上了SD模块的企业一般都要做一些跟公司间采购订单或销售订单的交货状态的报表,通过这些报表可以经客户的业务上提供很大的灵活性,至于如何的灵活,还是那句老话“谁用谁知道".1 ...
- SAP IDOC 通过采购订单输出消息生成销售订单
题记: 在网络上看到一篇类似的公众号文章,叫<通过IDoc逐步指导PO&SO集成>,个人觉得整个配置过程中还是少了一些重点配置,也少了说明整个功能的核心逻辑,那么,趁着这个机会,就 ...
随机推荐
- [HDOJ5935]Car(精度,数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5935 题意:有个老司机在开车, 开车过程中车的速度是不减的. 交警记录了这个老司机在nn个时间点的位置 ...
- CUBRID学习笔记 41 sql语法之groupby 等
cubrid的中sql查询语法groupby GROUP BY ... HAVING Clause 按dept_no分组 SELECT dept_no, avg(sales_amount) FROM ...
- linux的计划任务crontab
crontab(全称cron table计划任务列表)是一个用于周期性被执行的任的工具. 相关指令: usage: crontab [-u user] file crontab [ -u user ...
- hdu 2199 (二分)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/1000 ...
- LTE Module User Documentation(翻译1)——背景、使用概述、基本的仿真程序和配置LTE模型参数
LTE用户文档 (如有不当的地方,欢迎指正!) 1.背景 假定读者已经熟悉 ns-3 simulator ,能运行一般的仿真程序.如果不是的话,强烈推荐读者参考 [ns3tutorial]. 2. ...
- iOS - Swift 数据持久化
1.Sandbox 沙箱 iOS 为每个应用提供了独立的文件空间,一个应用只能直接访问为本应用分配的文件目录,不可以访问其他目录,每个应用自己独立的访问空间被称为该应用的沙盒.也就是说,一个应用与文件 ...
- C#操作Excel数据增删改查(转)
C#操作Excel数据增删改查. 首先创建ExcelDB.xlsx文件,并添加两张工作表. 工作表1: UserInfo表,字段:UserId.UserName.Age.Address.CreateT ...
- caffe的data_reader.cpp分析一下干了点什么
首先说明:下面的内容不一定对 类body: 变量:LayerParameter param_ :它里面放的是:body传进来的layerparameter的参数: BlockingQueue<s ...
- Delphi 程序结构
注:该内容整理自以下链接. http://www.cnblogs.com/hackpig/archive/2010/02/15/1668513.html 概要介绍:Object Pascal语言的结构 ...
- PHP SPL标准库之SplFixedArray使用实例
SplFixedArray主要是处理数组相关的主要功能,与普通php array不同的是,它是固定长度的,且以数字为键名的数组,优势就是比普通的数组处理更快. 看看我本机的Benchmark测试: i ...