FUNCTION Z_SD_SALESORDER_CHANGE1. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" REFERENCE(IM_VBELN) TYPE VBELN *" REFERENCE(IM_TYPE) TYPE CHAR4 *" REFERENCE(IM_BUDAT) TYPE BUDAT DEFAULT IM_BUDAT *" TABLES *" IT_ITEM STRUCTURE ZSDS0025 *" IT_RETURN STRUCTURE BAPIRET2 *"---------------------------------------------------------------------- *********************************************************************** * Function <Z_SD_SALESORDER_CHANGE1> ************************************************************************ * * 作者: DZHANGHUI * 完成日期: 2014/12/31 * 描述: 发货返写修改销售订单 ************************************************************************ * 版本号 日期 作者 修改描述 功能更改说明书 ************************************************************************ * 1. YYYY/MM/DD author Read dataset from app. Server @001 ************************************************************************ DATA : LV_VBELN TYPE BAPIVBELN-VBELN, LS_ITEM TYPE ZSDS0025, LV_WERKS TYPE VBAP-WERKS, LV_ETENR TYPE VBEP-ETENR, LV_MATNR TYPE MATNR, LV_MATNR_OLD TYPE MATNR, LV_UPDATEFLAGE, LV_INDEX TYPE I, LV_POSNR TYPE POSNR, LV_BWTTY TYPE MARC-BWTTY. DATA : BEGIN OF IT_VBAP OCCURS 0, VBELN TYPE VBAP-VBELN, POSNR TYPE VBAP-POSNR, MATNR TYPE VBAP-MATNR, CHARG TYPE VBAP-CHARG, WERKS TYPE VBAP-WERKS, BWTAR TYPE VBAP-BWTAR, "评估类型 END OF IT_VBAP. LV_VBELN = IM_VBELN. * 获取原有的行项目 SELECT VBELN POSNR MATNR CHARG WERKS BWTAR FROM VBAP INTO TABLE IT_VBAP WHERE VBELN = LV_VBELN. REFRESH: IT_RETURN, GT_SALESORDER_ITEM, GT_SALESORDER_ITEMX, GT_SALESORDER_SCHLINE, GT_SALESORDER_SCHLINEX, GT_SALESORDER_CONDITIONS, GT_SALESORDER_CONDITIONX. IF IM_TYPE = 'SJ'. * 删除原有的不带批次的行项目 LV_UPDATEFLAGE = 'D'. LOOP AT IT_VBAP WHERE CHARG = ''. CLEAR GS_SALESORDER_ITEM. GS_SALESORDER_ITEM-ITM_NUMBER = IT_VBAP-POSNR. APPEND GS_SALESORDER_ITEM TO GT_SALESORDER_ITEM. CLEAR GS_SALESORDER_ITEMX. GS_SALESORDER_ITEMX-UPDATEFLAG = LV_UPDATEFLAGE. GS_SALESORDER_ITEMX-ITM_NUMBER = IT_VBAP-POSNR. APPEND GS_SALESORDER_ITEMX TO GT_SALESORDER_ITEMX. LV_POSNR = IT_VBAP-POSNR. ENDLOOP. IF SY-SUBRC NE 0. READ TABLE IT_VBAP INDEX 1. ENDIF. * 新增行项目 LV_UPDATEFLAGE = 'I'. LOOP AT IT_ITEM. * 确保不存在相同的物料和批次的行项目 READ TABLE IT_VBAP WITH KEY MATNR = IT_ITEM-ZSPKH CHARG = IT_ITEM-ZSPPC. CHECK SY-SUBRC NE 0. ADD 10 TO LV_POSNR. * Item CLEAR GS_SALESORDER_ITEM. GS_SALESORDER_ITEM-ITM_NUMBER = LV_POSNR. GS_SALESORDER_ITEM-MATERIAL = IT_ITEM-ZSPKH. GS_SALESORDER_ITEM-PLANT = IT_VBAP-WERKS. GS_SALESORDER_ITEM-BATCH = IT_ITEM-ZSPPC. GS_SALESORDER_ITEM-TARGET_QTY = IT_ITEM-ZSPJH. * 检查是否启用评估类别 PERFORM FRM_CHECK_VALUE_TYPE USING IT_VBAP-WERKS IT_ITEM-ZSPKH CHANGING LV_BWTTY. IF LV_BWTTY EQ 'X'. GS_SALESORDER_ITEM-VAL_TYPE = IT_ITEM-ZSPPC. ENDIF. APPEND GS_SALESORDER_ITEM TO GT_SALESORDER_ITEM. CLEAR GS_SALESORDER_ITEMX. GS_SALESORDER_ITEMX-UPDATEFLAG = LV_UPDATEFLAGE. GS_SALESORDER_ITEMX-ITM_NUMBER = LV_POSNR. GS_SALESORDER_ITEMX-MATERIAL = 'X'. GS_SALESORDER_ITEMX-BATCH = 'X'. GS_SALESORDER_ITEMX-PLANT = 'X'. GS_SALESORDER_ITEMX-TARGET_QTY = 'X'. IF LV_BWTTY EQ 'X'. GS_SALESORDER_ITEMX-VAL_TYPE = 'X'. ENDIF. APPEND GS_SALESORDER_ITEMX TO GT_SALESORDER_ITEMX. * Schedule Line CLEAR GS_SALESORDER_SCHLINE. GS_SALESORDER_SCHLINE-ITM_NUMBER = LV_POSNR. GS_SALESORDER_SCHLINE-SCHED_LINE = '0001'. GS_SALESORDER_SCHLINE-REQ_QTY = IT_ITEM-ZSPJH. GS_SALESORDER_SCHLINE-REQ_DATE = IM_BUDAT. APPEND GS_SALESORDER_SCHLINE TO GT_SALESORDER_SCHLINE. CLEAR GS_SALESORDER_SCHLINEX. GS_SALESORDER_SCHLINEX-ITM_NUMBER = LV_POSNR. GS_SALESORDER_SCHLINEX-SCHED_LINE = '0001'. GS_SALESORDER_SCHLINEX-UPDATEFLAG = LV_UPDATEFLAGE. GS_SALESORDER_SCHLINEX-REQ_QTY = 'X'. GS_SALESORDER_SCHLINEX-REQ_DATE = 'X'. APPEND GS_SALESORDER_SCHLINEX TO GT_SALESORDER_SCHLINEX. * Condtions CLEAR GS_SALESORDER_CONDITIONS. GS_SALESORDER_CONDITIONS-ITM_NUMBER = LV_POSNR. GS_SALESORDER_CONDITIONS-COND_TYPE = 'ZPR4'. GS_SALESORDER_CONDITIONS-COND_VALUE = 1. GS_SALESORDER_CONDITIONS-CURRENCY = 'CNY'. APPEND GS_SALESORDER_CONDITIONS TO GT_SALESORDER_CONDITIONS. CLEAR GS_SALESORDER_CONDITIONX. GS_SALESORDER_CONDITIONX-ITM_NUMBER = LV_POSNR. GS_SALESORDER_CONDITIONX-COND_TYPE = 'ZPR4'. GS_SALESORDER_CONDITIONX-UPDATEFLAG = 'I'. GS_SALESORDER_CONDITIONX-COND_VALUE = 'X'. GS_SALESORDER_CONDITIONX-CURRENCY = 'X'. APPEND GS_SALESORDER_CONDITIONX TO GT_SALESORDER_CONDITIONX. CLEAR GS_SALESORDER_CONDITIONS. GS_SALESORDER_CONDITIONS-ITM_NUMBER = LV_POSNR. GS_SALESORDER_CONDITIONS-COND_TYPE = 'ZPR5'. GS_SALESORDER_CONDITIONS-COND_VALUE = 1. GS_SALESORDER_CONDITIONS-CURRENCY = 'CNY'. APPEND GS_SALESORDER_CONDITIONS TO GT_SALESORDER_CONDITIONS. CLEAR GS_SALESORDER_CONDITIONX. GS_SALESORDER_CONDITIONX-ITM_NUMBER = LV_POSNR. GS_SALESORDER_CONDITIONX-COND_TYPE = 'ZPR5'. GS_SALESORDER_CONDITIONX-UPDATEFLAG = 'I'. GS_SALESORDER_CONDITIONX-COND_VALUE = 'X'. GS_SALESORDER_CONDITIONX-CURRENCY = 'X'. APPEND GS_SALESORDER_CONDITIONX TO GT_SALESORDER_CONDITIONX. ENDLOOP. ELSEIF IM_TYPE = 'XQ'. * 获取销售订单的最大行项目数 SORT IT_VBAP BY POSNR DESCENDING. READ TABLE IT_VBAP INDEX 1. IF SY-SUBRC EQ 0. LV_POSNR = IT_VBAP-POSNR. ELSE. CLEAR LV_POSNR. ENDIF. LOOP AT IT_ITEM. * 物料和批次已存在 跳过 READ TABLE IT_VBAP WITH KEY MATNR = IT_ITEM-ZSPKH CHARG = IT_ITEM-ZSPPC. IF SY-SUBRC EQ 0. CONTINUE. ENDIF. READ TABLE IT_VBAP WITH KEY MATNR = IT_ITEM-ZSPKH CHARG = ''. IF SY-SUBRC EQ 0. LV_INDEX = SY-TABIX. * 修改行项目 LV_UPDATEFLAGE = 'U'. * Item CLEAR GS_SALESORDER_ITEM. GS_SALESORDER_ITEM-ITM_NUMBER = IT_VBAP-POSNR. GS_SALESORDER_ITEM-BATCH = IT_ITEM-ZSPPC. GS_SALESORDER_ITEM-TARGET_QTY = IT_ITEM-ZSPJH. * 检查是否启用评估类别 PERFORM FRM_CHECK_VALUE_TYPE USING IT_VBAP-WERKS IT_ITEM-ZSPKH CHANGING LV_BWTTY. IF LV_BWTTY EQ 'X'. GS_SALESORDER_ITEM-VAL_TYPE = IT_ITEM-ZSPPC. ENDIF. APPEND GS_SALESORDER_ITEM TO GT_SALESORDER_ITEM. CLEAR GS_SALESORDER_ITEMX. GS_SALESORDER_ITEMX-UPDATEFLAG = LV_UPDATEFLAGE. GS_SALESORDER_ITEMX-ITM_NUMBER = IT_VBAP-POSNR. GS_SALESORDER_ITEMX-BATCH = 'X'. GS_SALESORDER_ITEMX-TARGET_QTY = 'X'. IF LV_BWTTY EQ 'X'. GS_SALESORDER_ITEMX-VAL_TYPE = 'X'. ENDIF. APPEND GS_SALESORDER_ITEMX TO GT_SALESORDER_ITEMX. * Schedule Line CLEAR GS_SALESORDER_SCHLINE. GS_SALESORDER_SCHLINE-ITM_NUMBER = IT_VBAP-POSNR. GS_SALESORDER_SCHLINE-SCHED_LINE = '0001'. GS_SALESORDER_SCHLINE-REQ_QTY = IT_ITEM-ZSPJH. GS_SALESORDER_SCHLINE-REQ_DATE = IM_BUDAT. APPEND GS_SALESORDER_SCHLINE TO GT_SALESORDER_SCHLINE. CLEAR GS_SALESORDER_SCHLINEX. GS_SALESORDER_SCHLINEX-ITM_NUMBER = IT_VBAP-POSNR. GS_SALESORDER_SCHLINEX-SCHED_LINE = '0001'. GS_SALESORDER_SCHLINEX-UPDATEFLAG = LV_UPDATEFLAGE. GS_SALESORDER_SCHLINEX-REQ_QTY = 'X'. GS_SALESORDER_SCHLINEX-REQ_DATE = 'X'. APPEND GS_SALESORDER_SCHLINEX TO GT_SALESORDER_SCHLINEX. IT_VBAP-CHARG = IT_ITEM-ZSPPC. MODIFY IT_VBAP INDEX LV_INDEX TRANSPORTING CHARG. ELSE. * ---> 镶嵌订单 新增行 20150420 LV_INDEX = SY-TABIX. * 新增行项目 LV_UPDATEFLAGE = 'I'. ADD 10 TO LV_POSNR. * Item CLEAR GS_SALESORDER_ITEM. GS_SALESORDER_ITEM-ITM_NUMBER = LV_POSNR. GS_SALESORDER_ITEM-MATERIAL = IT_ITEM-ZSPKH. GS_SALESORDER_ITEM-PLANT = IT_VBAP-WERKS. GS_SALESORDER_ITEM-BATCH = IT_ITEM-ZSPPC. GS_SALESORDER_ITEM-TARGET_QTY = IT_ITEM-ZSPJH. * 检查是否启用评估类别 PERFORM FRM_CHECK_VALUE_TYPE USING IT_VBAP-WERKS IT_ITEM-ZSPKH CHANGING LV_BWTTY. IF LV_BWTTY EQ 'X'. GS_SALESORDER_ITEM-VAL_TYPE = IT_ITEM-ZSPPC. ENDIF. APPEND GS_SALESORDER_ITEM TO GT_SALESORDER_ITEM. CLEAR GS_SALESORDER_ITEMX. GS_SALESORDER_ITEMX-UPDATEFLAG = LV_UPDATEFLAGE. GS_SALESORDER_ITEMX-ITM_NUMBER = LV_POSNR. GS_SALESORDER_ITEMX-BATCH = 'X'. GS_SALESORDER_ITEMX-MATERIAL = 'X'. GS_SALESORDER_ITEMX-PLANT = 'X'. GS_SALESORDER_ITEMX-TARGET_QTY = 'X'. IF LV_BWTTY EQ 'X'. GS_SALESORDER_ITEMX-VAL_TYPE = 'X'. ENDIF. APPEND GS_SALESORDER_ITEMX TO GT_SALESORDER_ITEMX. * Schedule Line CLEAR GS_SALESORDER_SCHLINE. GS_SALESORDER_SCHLINE-ITM_NUMBER = LV_POSNR. GS_SALESORDER_SCHLINE-SCHED_LINE = '0001'. GS_SALESORDER_SCHLINE-REQ_QTY = IT_ITEM-ZSPJH. GS_SALESORDER_SCHLINE-REQ_DATE = IM_BUDAT. APPEND GS_SALESORDER_SCHLINE TO GT_SALESORDER_SCHLINE. CLEAR GS_SALESORDER_SCHLINEX. GS_SALESORDER_SCHLINEX-ITM_NUMBER = LV_POSNR. GS_SALESORDER_SCHLINEX-SCHED_LINE = '0001'. GS_SALESORDER_SCHLINEX-UPDATEFLAG = LV_UPDATEFLAGE. GS_SALESORDER_SCHLINEX-REQ_QTY = 'X'. GS_SALESORDER_SCHLINEX-REQ_DATE = 'X'. APPEND GS_SALESORDER_SCHLINEX TO GT_SALESORDER_SCHLINEX. * Condtions CLEAR GS_SALESORDER_CONDITIONS. GS_SALESORDER_CONDITIONS-ITM_NUMBER = LV_POSNR. GS_SALESORDER_CONDITIONS-COND_TYPE = 'ZPR4'. GS_SALESORDER_CONDITIONS-COND_VALUE = 1. GS_SALESORDER_CONDITIONS-CURRENCY = 'CNY'. APPEND GS_SALESORDER_CONDITIONS TO GT_SALESORDER_CONDITIONS. CLEAR GS_SALESORDER_CONDITIONX. GS_SALESORDER_CONDITIONX-ITM_NUMBER = LV_POSNR. GS_SALESORDER_CONDITIONX-COND_TYPE = 'ZPR4'. GS_SALESORDER_CONDITIONX-UPDATEFLAG = 'I'. GS_SALESORDER_CONDITIONX-COND_VALUE = 'X'. GS_SALESORDER_CONDITIONX-CURRENCY = 'X'. APPEND GS_SALESORDER_CONDITIONX TO GT_SALESORDER_CONDITIONX. CLEAR GS_SALESORDER_CONDITIONS. GS_SALESORDER_CONDITIONS-ITM_NUMBER = LV_POSNR. GS_SALESORDER_CONDITIONS-COND_TYPE = 'ZPR5'. GS_SALESORDER_CONDITIONS-COND_VALUE = 1. GS_SALESORDER_CONDITIONS-CURRENCY = 'CNY'. APPEND GS_SALESORDER_CONDITIONS TO GT_SALESORDER_CONDITIONS. CLEAR GS_SALESORDER_CONDITIONX. GS_SALESORDER_CONDITIONX-ITM_NUMBER = LV_POSNR. GS_SALESORDER_CONDITIONX-COND_TYPE = 'ZPR5'. GS_SALESORDER_CONDITIONX-UPDATEFLAG = 'I'. GS_SALESORDER_CONDITIONX-COND_VALUE = 'X'. GS_SALESORDER_CONDITIONX-CURRENCY = 'X'. APPEND GS_SALESORDER_CONDITIONX TO GT_SALESORDER_CONDITIONX. * <--- 镶嵌订单 新增行 20150420 ENDIF. ENDLOOP. ENDIF. CHECK GT_SALESORDER_ITEM IS NOT INITIAL. GS_SALESORDER_HEADER1X-UPDATEFLAG = 'U'. GS_LOGIC_SWITCH-PRICING = 'G'. * 修改订单 CALL FUNCTION 'BAPI_SALESORDER_CHANGE' EXPORTING SALESDOCUMENT = LV_VBELN ORDER_HEADER_INX = GS_SALESORDER_HEADER1X LOGIC_SWITCH = GS_LOGIC_SWITCH TABLES RETURN = GT_RETURN ORDER_ITEM_IN = GT_SALESORDER_ITEM ORDER_ITEM_INX = GT_SALESORDER_ITEMX SCHEDULE_LINES = GT_SALESORDER_SCHLINE SCHEDULE_LINESX = GT_SALESORDER_SCHLINEX CONDITIONS_IN = GT_SALESORDER_CONDITIONS CONDITIONS_INX = GT_SALESORDER_CONDITIONX. LOOP AT GT_RETURN INTO GS_RETURN WHERE TYPE = 'E' OR TYPE = 'X' OR TYPE = 'A'. EXIT. ENDLOOP. IF SY-SUBRC EQ 0. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'. ENDIF. IT_RETURN[] = GT_RETURN[]. REFRESH: GT_SALESORDER_ITEM, GT_SALESORDER_ITEMX, GT_SALESORDER_SCHLINE, GT_SALESORDER_SCHLINEX, GT_SALESORDER_CONDITIONS, GT_SALESORDER_CONDITIONX. ENDFUNCTION.
FORM FRM_CHECK_VALUE_TYPE USING P_WERKS P_MATNR CHANGING P_BWTTY. CLEAR P_BWTTY. SELECT SINGLE BWTTY INTO P_BWTTY FROM MARC WHERE WERKS = P_WERKS AND MATNR = P_MATNR. ENDFORM. " FRM_CHECK_VALUE_TYPE
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/18702.html