功能:由销售订单产生交货单
作者:互联网
REPORT ZSDA11S2.
*&---------------------------------------------------------------------*
*& 使用核心函数 BAPI_DELIVERYPROCESSING_EXEC 版本虽老,但功能齐全,支持采购订单,销售订单及合并创建
*&
*&---------------------------------------------------------------------*
*&自动交货 商用 一次性客户加入商用
*&自动交货 商用 扣板交货加入商用
*&---------------------------------------------------------------------*
*&2015.12.22 增加 18 整单自动交货
*&2017.02.27 分开工厂
*&---------------------------------------------------------------------*
TABLES : ZVBAP,TVKO,T001.
PARAMETERS: P_FORCE TYPE C AS CHECKBOX .
PARAMETERS: P_DATU TYPE INT1 DEFAULT 2.
PARAMETERS: P_WERKS TYPE WERKS_D DEFAULT '6000' .
SELECT-OPTIONS: S_VSTEL FOR ZVBAP-VSTEL,
S_VBELN FOR ZVBAP-VBELN,
S_KUNNR FOR ZVBAP-KUNNR,
S_VTWEG FOR ZVBAP-VTWEG.
*3.产生交货单
*4.查看是否产生成功
*5.不成功就停止
*0 计算是否是计算时间
DATA:
C_PRUEFLOS LIKE QALS-PRUEFLOS.
CONCATENATE 'SY' SY-DATUM INTO C_PRUEFLOS.
DATA: X(10),M(10), L_MESSAGE(300).
CALL FUNCTION 'ENQUEUE_EQQALS1'
EXPORTING
PRUEFLOS = C_PRUEFLOS
EXCEPTIONS
FOREIGN_LOCK = 1.
IF NOT SY-SUBRC IS INITIAL.
L_MESSAGE = '正在进行计算操作,ZSDA11S '.
CONCATENATE L_MESSAGE '退出!' INTO L_MESSAGE.
WRITE L_MESSAGE .
RETURN.
ENDIF.
DATA: S(1).
CLEAR S.
DATA: LINE LIKE ZSDA19.
IF SY-BATCH = 'X' ."后台执行
S = 'A'.
SELECT * INTO LINE
FROM ZSDA19
WHERE DAT1 = SY-DATUM
AND FLAG = 'SO'.
* AND VSTEL = P_VSTEL.
IF SY-UZEIT < LINE-ETIM AND SY-UZEIT >= LINE-STIM.
S = 'X'.
EXIT.
ENDIF.
ENDSELECT.
ENDIF.
IF S = 'A' AND P_FORCE IS INITIAL. "没有工作日历
WRITE '没有工作日历'.
RETURN.
ENDIF.
*1. 取要操作的订单
*DATA: ITVBAP LIKE ZVBAP OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF ITVBAP OCCURS 0.
INCLUDE STRUCTURE ZVBAP .
DATA: SOBKZ TYPE SOBKZ.
DATA: PS_PSP_PNR TYPE PS_PSP_PNR.
DATA: MAABC TYPE MAABC.
DATA: ERDAT TYPE ERDAT.
DATA: END OF ITVBAP.
DATA: CDATE LIKE SY-DATUM.
IF P_DATU IS INITIAL.
P_DATU = 100.
ENDIF.
IF SY-BATCH = 'X'.
P_DATU = 100.
ENDIF.
CDATE = SY-DATUM + P_DATU.
DATA:
BEGIN OF WHERE_ITAB OCCURS 0,
TEXT(320),
END OF WHERE_ITAB .
PERFORM GETWHERE.
DATA: STR TYPE STRING.
CLEAR STR.
* CONCATENATE STR ' * A~VBELN ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' * A~VBELP ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~MATNR ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~LGORT ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' * VTWEG ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' * ETDAT ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' * B~LFSTA AS BESTK ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~ZMENG ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' * LFIMG ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' * FDATE ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~VBELN ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~VBELP ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' MATNR ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~KUNNR ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' LGORT ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' VTWEG ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' ETDAT ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' B~LFSTA AS BESTK ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' * BESTK ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~ZMENG ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' * LFIMG ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' * KZWI1 "这个值要重新计算 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~KZWI2 ' INTO STR SEPARATED BY SPACE .
* CONCATENATE STR ' * KZWI3 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' INT1 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' INT2 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' DAT1 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' DAT2 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' UPDKZ ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' P~ABGRU ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' AUART ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' P~VSTEL ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~NETWR ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' NETWR2 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' XDATE ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' XTIME ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' EUDAT ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' XDATE2 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' XTIME2 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' QDATE ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' KDATE ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' EUDAT ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' SDATE ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' XDATE2 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' XTIME2 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' FDATE ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' FRZE ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' FRDAT ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' FRTIM ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' VKORG ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~WERKS ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' P~SOBKZ ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' P~PS_PSP_PNR ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~BM2 ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' D~MAABC ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' P~ERDAT ' INTO STR SEPARATED BY SPACE .
CONCATENATE STR ' A~MANDT ' INTO STR SEPARATED BY SPACE .
SELECT (STR)
APPENDING CORRESPONDING FIELDS OF TABLE ITVBAP
FROM ZVBAP AS A
JOIN VBAP AS P ON A~VBELN = P~VBELN AND A~VBELP = P~POSNR
JOIN VBUP AS B ON A~VBELN = B~VBELN AND A~VBELP = B~POSNR
JOIN KNA1 AS C ON A~KUNNR = C~KUNNR
JOIN MARC AS D ON A~MATNR = D~MATNR AND D~WERKS = '6000'
WHERE BESTK <> 'C'
*AND B~LFSTA <> 'C'
AND P~ABGRU = ''
AND UPDKZ <> 'D'
AND A~WERKS = P_WERKS
AND ( ( P~VSTEL IN S_VSTEL
AND A~VBELN IN S_VBELN
AND A~KUNNR IN S_KUNNR
AND VTWEG IN S_VTWEG
AND ZZPRCTR = '0000006003'
)
OR ( KTOKD = 'Z007' AND A~KUNNR IN S_KUNNR )
* OR AUART IN ('ZOR9','KN')
)
AND (WHERE_ITAB)
.
*SELECT (STR)
*APPENDING CORRESPONDING FIELDS OF TABLE ITVBAP
*FROM ZVBAP AS A
*JOIN VBAP AS P ON A~VBELN = P~VBELN AND A~VBELP = P~POSNR
*JOIN VBUP AS B ON A~VBELN = B~VBELN AND A~VBELP = B~POSNR
*JOIN ZSDA35 AS Z ON Z~MATNR = A~MATNR AND Z~LGORT = A~LGORT
*WHERE BESTK <> 'C'
*AND P~ABGRU = ''
*AND UPDKZ <> 'D'
*AND A~WERKS = P_WERKS
*AND A~VBELN IN S_VBELN.
DATA: BEGIN OF ITM OCCURS 0,
MATNR TYPE MATNR,
LGORT TYPE LGORT_D,
PSPNR TYPE PS_PSP_PNR,
LABST TYPE LABST,
WERKS TYPE WERKS_D,
END OF ITM.
DATA: BEGIN OF ITXH OCCURS 0,
KUNNR TYPE KUNNR,
KKBER TYPE KKBER,
KNKLI TYPE KNKLI,
KLIMK TYPE KLIMK,
SKFOR TYPE SKFOR,
OFAKW TYPE SKFOR,
OLIKW TYPE SKFOR,
VKORG TYPE VKORG,
END OF ITXH.
DATA: LS_LIKP LIKE LIKP.
DATA: LT_LIPS LIKE LIPS OCCURS 0 WITH HEADER LINE.
DATA: ZLOG LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA: LP LIKE SY-SUBRC.
LOOP AT ITVBAP.
CLEAR LS_LIKP.
LS_LIKP-VKORG = ITVBAP-VKORG.
LS_LIKP-VBELN = ITVBAP-VBELN.
LS_LIKP-ERDAT = SY-DATUM.
LS_LIKP-KUNIV = ITVBAP-VKORG.
LS_LIKP-KUNIV+2(2) = '00'.
PERFORM F_ADD_ZERO USING LS_LIKP-KUNIV.
LT_LIPS-VBELN = ITVBAP-VBELN.
LT_LIPS-MATNR = ITVBAP-MATNR.
LT_LIPS-WERKS = ITVBAP-WERKS.
LT_LIPS-LFIMG = 1.
APPEND LT_LIPS.
CALL FUNCTION 'ZRFC_CHECK_ZPB2'
EXPORTING
* IP_VBELN =
LIKP = LS_LIKP
IMPORTING
EX_SUBRC = LP
TABLES
LIPS = LT_LIPS
ET_LOG = ZLOG.
IF LP > 0.
READ TABLE ZLOG INDEX 1.
WRITE:/ ZLOG-MESSAGE.
DELETE ITVBAP.
CONTINUE.
ENDIF.
ITXH-VKORG = ITVBAP-VKORG.
SELECT SINGLE * FROM TVKO WHERE VKORG = ITVBAP-VKORG.
SELECT SINGLE * FROM T001 WHERE BUKRS = TVKO-BUKRS.
ITXH-KUNNR = ITVBAP-KUNNR.
ITXH-KKBER = T001-KKBER.
COLLECT ITXH.
ENDLOOP.
**以下交货开始
DELETE ITVBAP WHERE BESTK = 'C'. "删除交完货的
DELETE ITVBAP WHERE FRZE <> ''.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN TYPE VBELN,
VSTEL TYPE VSTEL,
END OF ITAB.
**--处理18渠道
SORT ITVBAP.
LOOP AT ITVBAP WHERE VTWEG = '18'.
ITAB-VBELN = ITVBAP-VBELN.
ITAB-VSTEL = ITVBAP-VSTEL.
COLLECT ITAB.
ENDLOOP.
PERFORM GETDN18.
DELETE ITVBAP WHERE VTWEG = '18'.
DATA SSP LIKE ITXH-KLIMK.
SORT ITXH.
LOOP AT ITXH.
SELECT SINGLE KLIMK SKFOR KNKLI
INTO (ITXH-KLIMK,ITXH-SKFOR,ITXH-KNKLI)
FROM KNKK
WHERE KUNNR = ITXH-KUNNR
AND KKBER = ITXH-KKBER.
IF ITXH-KNKLI <> ITXH-KUNNR.
SELECT SINGLE KLIMK SKFOR KNKLI
INTO (ITXH-KLIMK,ITXH-SKFOR,ITXH-KNKLI)
FROM KNKK
WHERE KUNNR = ITXH-KNKLI
AND KKBER = ITXH-KKBER.
ENDIF.
SELECT SINGLE OFAKW OLIKW
INTO (ITXH-OFAKW,ITXH-OLIKW)
FROM S067
WHERE KNKLI = ITXH-KUNNR
AND KKBER = ITXH-KKBER.
IF ITXH-KUNNR = '0010009569'.
ITXH-KLIMK = 10009569.
ENDIF.
MODIFY ITXH.
CLEAR SSP.
SSP = ITXH-KLIMK - ITXH-SKFOR. "超款
IF SSP <= 0.
DELETE ITXH.
DELETE ITVBAP WHERE KUNNR = ITXH-KUNNR AND VKORG = ITXH-VKORG. "删除超款
DATA INFO_3(200).
CONCATENATE
ITXH-KUNNR '~'
'删除超款'
INTO INFO_3.
WRITE:/ INFO_3.
ENDIF.
CLEAR ITXH.
ENDLOOP.
PERFORM GETNOMATNR.
************按交货序列号排序
LOOP AT ITVBAP.
ITM-MATNR = ITVBAP-MATNR.
ITM-LGORT = ITVBAP-LGORT.
ITM-PSPNR = ITVBAP-PS_PSP_PNR.
ITM-WERKS = ITVBAP-WERKS.
COLLECT ITM.
ENDLOOP.
SORT ITM.
LOOP AT ITM. "库存
DATA: L LIKE MARD-LABST,
K LIKE MARD-KLABS.
IF ITM-PSPNR IS INITIAL.
SELECT SUM( LABST ) SUM( KLABS ) INTO (L,K) FROM MARD
WHERE WERKS = ITM-WERKS
AND MATNR = ITM-MATNR
AND LGORT = ITM-LGORT.
ELSE.
SELECT SUM( PRLAB ) SUM( PRSPE ) INTO (L,K) FROM MSPR
WHERE WERKS = ITM-WERKS
AND MATNR = ITM-MATNR
AND LGORT = ITM-LGORT
AND PSPNR = ITM-PSPNR.
ENDIF.
ITM-LABST = L + K.
IF ITM-LABST > 0.
MODIFY ITM.
ELSE. "删除无库存
DELETE ITVBAP WHERE MATNR = ITM-MATNR AND LGORT = ITM-LGORT
AND WERKS = ITM-WERKS
AND PS_PSP_PNR = ITM-PSPNR.
DATA INFO_2(200).
CONCATENATE
ITM-MATNR '~'
ITM-LGORT '~'
ITM-PSPNR '~'
'无库存可用'
INTO INFO_2.
WRITE:/ INFO_2.
ENDIF.
ENDLOOP.
DATA: P_LFIMG LIKE ITVBAP-ZMENG.
DATA: V_ST LIKE VBAP-KWMENG,
TOTAL LIKE VBAP-KWMENG.
DATA INFO_1(200).
SORT ITVBAP BY BM2.
LOOP AT ITVBAP.
CLEAR INFO_1(200).
CONCATENATE
ITVBAP-VBELN '~'
ITVBAP-VBELP '~'
'START......'
INTO INFO_1.
WRITE:/ INFO_1.
CLEAR: V_ST,P_LFIMG.
SELECT RFMNG INTO V_ST
FROM VBFA
WHERE VBELV = ITVBAP-VBELN
AND POSNV = ITVBAP-VBELP
AND VBTYP_N = 'J'.
P_LFIMG = P_LFIMG + V_ST . "创建数量
CLEAR V_ST.
ENDSELECT.
P_LFIMG = ITVBAP-ZMENG - P_LFIMG.
IF P_LFIMG <= 0.
CLEAR INFO_1(200).
CONCATENATE
ITVBAP-VBELN '~'
ITVBAP-VBELP '~'
'无交货数量'
INTO INFO_1.
WRITE:/ INFO_1.
ENDIF.
CHECK P_LFIMG > 0. "有交货数量
* ***增加可用库存判断
READ TABLE ITM WITH KEY MATNR = ITVBAP-MATNR
LGORT = ITVBAP-LGORT
WERKS = ITVBAP-WERKS
PSPNR = ITVBAP-PS_PSP_PNR.
IF SY-SUBRC = 0.
*取占用
CLEAR TOTAL.
SELECT SINGLE SUM( OMENG ) INTO TOTAL
FROM VBBE
WHERE WERKS = P_WERKS
AND VBTYP = 'J'
AND MATNR = ITVBAP-MATNR
AND LGORT = ITVBAP-LGORT
AND WERKS = ITVBAP-WERKS
AND PSPEL = ITM-PSPNR
GROUP BY WERKS MATNR LGORT.
CLEAR V_ST.
V_ST = ITM-LABST - TOTAL.
IF V_ST > 0.
IF V_ST < P_LFIMG.
P_LFIMG = V_ST.
ENDIF.
PERFORM GENDN USING ITVBAP-VBELN ITVBAP-VBELP P_LFIMG.
ELSE.
DELETE ITVBAP WHERE MATNR = ITM-MATNR AND LGORT = ITM-LGORT
AND WERKS = ITM-WERKS
AND PS_PSP_PNR = ITM-PSPNR.
CLEAR INFO_1.
CONCATENATE
ITVBAP-VBELN '~'
ITVBAP-VBELP '~'
ITM-MATNR '~'
ITM-LGORT '~'
ITM-PSPNR '~'
'无可用库存'
INTO INFO_1.
WRITE:/ INFO_1.
ENDIF.
ENDIF.
ENDLOOP.
COMMIT WORK AND WAIT.
*&---------------------------------------------------------------------*
*& Form GENDN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_VBELN text
* -->P_VBELP text
* -->P_LFIMG text
* -->P_DNNO text
*----------------------------------------------------------------------*
FORM GENDN USING P_VBELN P_VBELP P_LFIMG.
**----
*Internal Tables
**----
*Table to Hold Delivery Request
DATA: BEGIN OF TBL_REQUEST OCCURS 0.
INCLUDE STRUCTURE BAPIDELICIOUSREQUEST.
DATA: END OF TBL_REQUEST.
*Table to hold Line Items Created
DATA: BEGIN OF TBL_ITEMS OCCURS 0.
INCLUDE STRUCTURE BAPIDELICIOUSCREATEDITEMS.
DATA: END OF TBL_ITEMS.
*Table to hold BAPI Return Messages
DATA: BEGIN OF TBL_RETURN OCCURS 0.
INCLUDE STRUCTURE BAPIRET2.
DATA: END OF TBL_RETURN.
**----
*Structures
**----
DATA: ST_VBAK LIKE VBAK OCCURS 0 WITH HEADER LINE,
ST_VBAP LIKE VBAP OCCURS 0 WITH HEADER LINE.
SELECT VBELN KUNNR VKORG VTWEG SPART BSTDK
INTO CORRESPONDING FIELDS OF TABLE ST_VBAK
FROM VBAK
WHERE VBELN = P_VBELN.
CHECK SY-SUBRC EQ 0.
SELECT VBELN POSNR WERKS VRKME MEINS MATNR
INTO CORRESPONDING FIELDS OF TABLE ST_VBAP
FROM VBAP
WHERE VBELN = P_VBELN AND POSNR = P_VBELP .
SORT ST_VBAK.
SORT ST_VBAP.
LOOP AT ST_VBAK.
LOOP AT ST_VBAP WHERE VBELN = ST_VBAK-VBELN.
TBL_REQUEST-DOCUMENT_NUMB = ST_VBAP-VBELN.
TBL_REQUEST-DOCUMENT_ITEM = ST_VBAP-POSNR.
TBL_REQUEST-SHIP_TO = ST_VBAK-KUNNR.
TBL_REQUEST-SOLD_TO = ST_VBAK-KUNNR.
TBL_REQUEST-SALES_ORGANISATION = ST_VBAK-VKORG.
TBL_REQUEST-DISTRIBUTION_CHANNEL = ST_VBAK-VTWEG.
TBL_REQUEST-DIVISION = ST_VBAK-SPART.
TBL_REQUEST-PLANT = ST_VBAP-WERKS.
TBL_REQUEST-QUANTITY_SALES_UOM = P_LFIMG.
TBL_REQUEST-SALES_UNIT = ST_VBAP-VRKME.
TBL_REQUEST-BASE_UOM = ST_VBAP-MEINS.
TBL_REQUEST-MATERIAL = ST_VBAP-MATNR.
TBL_REQUEST-DELIVERY_DATE = ST_VBAK-BSTDK.
TBL_REQUEST-DELIVERY_TIME = SY-UZEIT.
TBL_REQUEST-TRANSP_PLAN_DATE = ST_VBAK-BSTDK.
TBL_REQUEST-LOADING_DATE = ST_VBAK-BSTDK.
TBL_REQUEST-GOODS_ISSUE_DATE = ST_VBAK-BSTDK.
TBL_REQUEST-EXTDELV_NO = ST_VBAP-VBELN.
TBL_REQUEST-DOCUMENT_TYPE = 'A'. "Delivery
TBL_REQUEST-DOCUMENT_TYPE_PREDECESSOR = 'A'. "Sales Ord
TBL_REQUEST-DOCUMENT_TYPE_DELIVERY = 'LF'.
APPEND TBL_REQUEST.
ENDLOOP.
ENDLOOP.
CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'
TABLES
REQUEST = TBL_REQUEST
CREATEDITEMS = TBL_ITEMS
RETURN = TBL_RETURN.
DATA: SINFO(200).
SORT TBL_RETURN.
LOOP AT TBL_RETURN.
CONCATENATE
ST_VBAP-VBELN '~'
ST_VBAP-POSNR '~'
TBL_RETURN-TYPE '~'
TBL_RETURN-ID '~'
TBL_RETURN-NUMBER '~'
TBL_RETURN-MESSAGE
INTO SINFO.
WRITE:/ SINFO.
ENDLOOP.
DATA: P_DNNO TYPE VBELN.
CLEAR P_DNNO.
IF TBL_ITEMS[] IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
READ TABLE TBL_ITEMS INDEX 1 .
IF SY-SUBRC = 0.
P_DNNO = TBL_ITEMS-DOCUMENT_NUMB.
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
WRITE:/ P_VBELN,P_VBELP,P_DNNO.
ENDIF.
IF P_DNNO IS NOT INITIAL.
IF ITVBAP-VTWEG = '18'.
ELSE.
UPDATE LIKP SET ANZPK = ITVBAP-VTWEG WHERE VBELN = P_DNNO.
COMMIT WORK.
ENDIF.
DATA SDATE LIKE VBAP-KANNR.
CLEAR SDATE.
SELECT SINGLE KANNR INTO SDATE FROM VBAP WHERE VBELN = ITVBAP-VBELN AND POSNR = ITVBAP-VBELP.
IF SDATE IS INITIAL.
MOVE SY-DATUM TO SDATE.
UPDATE VBAP SET KANNR = SDATE WHERE VBELN = ITVBAP-VBELN AND POSNR = ITVBAP-VBELP.
ENDIF.
IF ITVBAP-FDATE IS INITIAL.
MOVE SY-DATUM TO SDATE.
UPDATE ZVBAP SET FDATE = SDATE WHERE VBELN = ITVBAP-VBELN AND VBELP = ITVBAP-VBELP.
UPDATE ZVBAPH SET FDATE = SDATE WHERE VBELN = ITVBAP-VBELN AND VBELP = ITVBAP-VBELP.
ENDIF.
ENDIF.
* LOOP AT TBL_RETURN.
* WRITE:/ TBL_RETURN-NUMBER,
* TBL_RETURN-MESSAGE,
* TBL_RETURN-MESSAGE_V1,
* TBL_RETURN-MESSAGE_V2,
* TBL_RETURN-MESSAGE_V3 .
* ENDLOOP.
ENDFORM. "GENDN
*&---------------------------------------------------------------------*
*& Form GET_VBELN-LIKP
*&---------------------------------------------------------------------*
* 由SO-> DN
*----------------------------------------------------------------------*
* -->V_ETDAT text
*----------------------------------------------------------------------*
FORM GET_VBELN-LIKP USING V_VBELN V_VBELP.
DATA :
APK TYPE CHAR50,
MATERIALDOCUMENT LIKE LIKP-VBELN,
S_SUBRC TYPE SY-SUBRC,
ET_LOG LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
IF ITVBAP-VTWEG = '18'.
CLEAR APK.
ELSE.
MOVE ITVBAP-VTWEG TO APK.
ENDIF.
CLEAR: MATERIALDOCUMENT.
CALL FUNCTION 'ZRFC_CRM_VL01N'
EXPORTING
IN_VBELN = ITVBAP-VBELN
IN_ANZPK = APK
IN_VSTEL = ITVBAP-VSTEL
IN_POSNR = ITVBAP-VBELP
IN_MAXNR = ITVBAP-VBELP
IMPORTING
EP_SUBRC = S_SUBRC
OU_VBELN = MATERIALDOCUMENT
TABLES
ET_LOG = ET_LOG.
IF MATERIALDOCUMENT <> ''.
WRITE /.
WRITE : ITVBAP-VBELN,ITVBAP-VBELP,MATERIALDOCUMENT.
ENDIF.
IF MATERIALDOCUMENT <> '' AND V_VBELP IS NOT INITIAL .
DATA SDATE LIKE VBAP-KANNR.
CLEAR SDATE.
SELECT SINGLE KANNR INTO SDATE FROM VBAP WHERE VBELN = ITVBAP-VBELN AND POSNR = ITVBAP-VBELP.
IF SDATE IS INITIAL.
MOVE SY-DATUM TO SDATE.
UPDATE VBAP SET KANNR = SDATE WHERE VBELN = ITVBAP-VBELN AND POSNR = ITVBAP-VBELP.
ENDIF.
IF ITVBAP-FDATE IS INITIAL.
MOVE SY-DATUM TO SDATE.
UPDATE ZVBAP SET FDATE = SDATE WHERE VBELN = ITVBAP-VBELN AND VBELP = ITVBAP-VBELP.
UPDATE ZVBAPH SET FDATE = SDATE WHERE VBELN = ITVBAP-VBELN AND VBELP = ITVBAP-VBELP.
ENDIF.
SORT ET_LOG.
LOOP AT ET_LOG.
WRITE /: ITVBAP-VBELN,ET_LOG-MESSAGE.
ENDLOOP.
ENDIF.
ENDFORM. "GET_VBELN-LIKP
*&---------------------------------------------------------------------*
*& Form GETWHERE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GETWHERE.
DATA: KWLST LIKE ZSDA18 OCCURS 0 WITH HEADER LINE. "删除不参与计算的物料
WHERE_ITAB-TEXT = ' A~MANDT = ''800'' '.
APPEND WHERE_ITAB.
* WRITE / WHERE_ITAB.
SELECT * INTO KWLST FROM ZSDA18.
* IF KWLST-KUNNR IS NOT INITIAL.
* DATA: V_K TYPE KUNNR.
* CLEAR V_K.
* SELECT SINGLE KUNNR INTO V_K FROM KNA1 WHERE KUNNR = KWLST-KUNNR AND ZZPRCTR = '0000006003'.
* CHECK V_K IS INITIAL.
* ENDIF.
CLEAR: WHERE_ITAB.
WHERE_ITAB-TEXT = ' AND NOT ( A~MANDT = ''800'' '.
IF KWLST-KUNNR IS NOT INITIAL.
CONCATENATE WHERE_ITAB-TEXT ' and a~KUNNR = ''' KWLST-KUNNR '''' INTO WHERE_ITAB-TEXT.
ENDIF.
IF KWLST-LGORT IS NOT INITIAL .
CONCATENATE WHERE_ITAB-TEXT ' and a~LGORT = ''' KWLST-LGORT '''' INTO WHERE_ITAB-TEXT.
ENDIF.
IF KWLST-MATNR IS NOT INITIAL .
CONCATENATE WHERE_ITAB-TEXT ' and A~MATNR = ''' KWLST-MATNR '''' INTO WHERE_ITAB-TEXT.
ENDIF.
IF KWLST-VTWEG IS NOT INITIAL .
CONCATENATE WHERE_ITAB-TEXT ' and a~VTWEG = ''' KWLST-VTWEG '''' INTO WHERE_ITAB-TEXT.
ENDIF.
CONCATENATE WHERE_ITAB-TEXT ' ) ' INTO WHERE_ITAB-TEXT.
WRITE / WHERE_ITAB.
APPEND WHERE_ITAB.
ENDSELECT.
ENDFORM. "getWhere
*&---------------------------------------------------------------------*
*& Form GetNoMatnr
*&---------------------------------------------------------------------*
* 删除不计算的物料条件 客户 物料 库位
*----------------------------------------------------------------------*
FORM GETNOMATNR.
DELETE ITVBAP WHERE LGORT = '6014'. "删除永不交货的库位
DELETE ITVBAP WHERE VTWEG = '18'. "18渠道永不交货
ENDFORM. "GetNoMatnr
*&---------------------------------------------------------------------*
*& Form GETDN18
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GETDN18 .
DATA :
MATERIALDOCUMENT LIKE LIKP-VBELN,
S_SUBRC TYPE SY-SUBRC.
SORT ITAB.
LOOP AT ITAB.
CLEAR MATERIALDOCUMENT.
DATA:
V_ANZPK TYPE CHAR50,
V_POSNR TYPE CHAR50,
V_MAXNR TYPE CHAR50,
V_BOLNR LIKE LIKP-BOLNR,
MSG(1000),
ET_LOG LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
CLEAR: V_ANZPK,V_POSNR.
* MOVE '18' TO V_ANZPK.
MOVE '1' TO V_POSNR.
MOVE '9999' TO V_MAXNR.
* IF ITAB-VTWEG = '18'.
* CLEAR V_ANZPK.
* V_MAXNR = '9999'.
* ENDIF.
CLEAR: ET_LOG,ET_LOG[].
CALL FUNCTION 'ZRFC_CRM_VL01N'
EXPORTING
IN_VBELN = ITAB-VBELN
IN_ANZPK = V_ANZPK
IN_VSTEL = ITAB-VSTEL
IN_POSNR = V_POSNR
IN_MAXNR = V_MAXNR
IMPORTING
EP_SUBRC = S_SUBRC
OU_VBELN = MATERIALDOCUMENT
TABLES
ET_LOG = ET_LOG.
IF MATERIALDOCUMENT <> ''.
WRITE : ITAB-VBELN,MATERIALDOCUMENT.
ELSE.
SORT ET_LOG.
LOOP AT ET_LOG.
CONCATENATE ITAB-VBELN
ET_LOG-TYPE
ET_LOG-ID
ET_LOG-NUMBER
ET_LOG-MESSAGE
INTO MSG.
WRITE / : MSG.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDFORM. "GetDN
INCLUDE ZRPT_FUN.
标签:CONCATENATE,SEPARATED,功能,INTO,VBELN,订单,STR,交货单,ITVBAP 来源: https://www.cnblogs.com/twttafku/p/14295682.html