根据采购/销售订单创建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 0 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(2). "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 0,
           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 ‘333‘,
         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 1.
  SELECT SINGLE * FROM EKKO WHERE EBELN = LS_DATA-VBELN.
  IF SY-SUBRC EQ 0."PO - STO.
    LV_TYPE = ‘PO‘.
    LV_SHIP_POINT = ‘8001‘.
*    LV_DUE_DATE = ‘99991230‘.
  ELSE.
    LV_TYPE = ‘SO‘.
    LV_SHIP_POINT = ‘8001‘.
*    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 0.
        E_DN = LT_VBFA-VBELN.
        IT_DN-VBELN = E_DN.
        COLLECT IT_DN.
        CONTINUE.
      ENDIF.

      CLEAR E_DN.

      ADD 1 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 ‘99991231‘.
      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 0.
      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 100 TIMES.
        SELECT *
          FROM LIPS
          INTO TABLE LT_LIPS
          FOR ALL ENTRIES IN LT_DELIVERIES
          WHERE VBELN = LT_DELIVERIES-DELIV_NUMB.

        IF SY-SUBRC EQ 0.
          EXIT.
        ENDIF.
      ENDDO.
    ELSE.
      DO 100 TIMES.
        SELECT *
          FROM LIPS
          INTO TABLE LT_LIPS
          WHERE VBELN = LV_DELIVERY.

        IF SY-SUBRC EQ 0.
          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         = ‘00‘.
        IT_RETURN-NUMBER     = ‘000‘.
        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         = ‘00‘.
      IT_RETURN-NUMBER     = ‘000‘.
      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.
时间: 2024-12-25 16:26:07

根据采购/销售订单创建STO/SO的相关文章

为什么S/4HANA的销售订单创建会触发生产订单的创建

调用S/4HANA销售订单创建函数SD_SALES_DOCU_MAINTAIN创建一个销售订单时,会触发生产订单的创建. 销售订单的每个行项目对应一个独立的生产订单,SD_SALES_DOCU_MAINTAIN相当于CRM里的CRM_ORDER_MAINTAIN,在LOOP里处理每一个行项目: 观察这个函数内部的调用栈,发现一个subroutine EIGENFERTIGUNG_BEARBEITEN.: EIGENFERTIGUNG的意思是Own production: BEARBEITEN的意

销售订单、外向交货单、交货 bapi

转自[http://www.cnblogs.com/elegantok/archive/2009/10/18/1585398.html]***********SALES ORDER INPUT CREATION. REPORT soi. PARAMETERS: p_auart TYPE auart OBLIGATORY.PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.PARAM

SAP SD如何将销售订单其它ITEM加入到一个已创建好的交货单里

如下的销售订单,有多个ITEM, 为其中的第一个ITEM创建了DN 80016362, 如果业务发现需要修改该交货单,将销售订单里的其它ITEM也加入到该DN里. 如下方式, VL02N,进入到该交货单的修改界面,如下菜单, 弹出如下界面, 回车, 系统就将销售订单的20/30 行项目带入交货单了. 此时可以根据需要修改交货数量,保存即可. 2019-06-10 写于苏州市. 原文地址:https://www.cnblogs.com/DicksonJYL/p/11023610.html

[SAP ABAP开发技术总结]SD销售订单定价过程

目录导航 声明:原创作品,转载时请注明文章来自SAP师太博客,并以超链接形式标明文章原始出处,否则将追究法律责任!原文出自: 16.3.2.     定价过程... 141 16.3.2.1.           条件技术七要素... 141 16.3.2.2.           条件表V/03.V/04.V/05. 142 16.3.2.3.           存取顺序 V/07. 142 16.3.2.4.           条件类型 V/06. 142 16.3.2.5.      

采购单与调拨单或销售订单关联,增加表FRET记录

采购单与调拨单或销售订单关联,增加表FRET记录,在对采购单做收货时, 系统自动对调拔单或销售订单,创建拣配单(交货单),具体做法: 1.往FRET增加记录: 2.修改采购单抬头和行项目相应关联标识. 代码: (1)在SE11创建结构: ZST_SAVE_FRET BLNRB CHAR 10 0 凭证号,采购 BPOSB NUMC 6 0 凭证项目,采购 BLNRA CHAR 10 0 发货凭证号 BPOSA NUMC 6 0 凭证项目,发货 (2)在SE37创建函数如下: FUNCTION Z

crm操作销售订单实体

using System; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using Microsoft.Crm.Sdk.Messages; /// <summary> /// 销售订单 /// </summary> public class SoleOrderHelper { public static readonly string entityName = "salesorder"; pub

未清销售订单及预测的所有工序物料需求(按BOM展开不考虑已发料)

--按截止日考虑库存分配(所有物料及工序) DECLARE @dueDate DATETIME --截止交期 SELECT @dueDate = T0.T_DueDate FROM OFPR T0 WHERE T0.T_DueDate = [%0] SELECT @dueDate = '[%0]' --------------------------------------------------------------------------------------------- -- ===

OEOIMP-创建销售订单(R12.2.3)

 创建销售订单(R12.2.3) --US Program:Order Import Short Name:OEOIMP Application:Order Management Executable:Order Import --ZHS 程序:订单导入 简称:OEOIMP 应用产品:订单管理 可执行名称:Order Import PLSQL调用 l_request_id := fnd_request.submit_request( 'ONT', 'OEOIMP', 'Order Impor

转载]SAP囚徒 - 通过销售订单领用到成本中心,FI替代

转载]SAP囚徒 - 通过销售订单领用到成本中心,FI替代 原文地址:SAP囚徒 - 通过销售订单领用到成本中心,FI替代实现不同成本中心记账科目不同作者:SAP囚徒 物品领用通常是库存管理的范畴,直接移动类型201计入成本中心即可:但是也有通过销售订单直接领用到成本中心,记费用科目,比如:给客户送少量的样品可以使用销售订单的成本中心来是实现(公司直接送东西给客户有偷税的嫌疑,这里忽略不计): 系统操作步骤如下: 1.VA01创建可以录入成本中心的免费订单 2.VL01N.VL02N对销售订单过