UB单修改详解编程语言

FUNCTION Z_SD_UB_CHANGE. 
*"---------------------------------------------------------------------- 
*"*"Local Interface: 
*"  IMPORTING 
*"     REFERENCE(IM_EBELN) TYPE  EBELN 
*"     REFERENCE(IM_TYPE) TYPE  CHAR4 
*"     REFERENCE(IM_BUDAT) TYPE  BUDAT DEFAULT SY-DATUM 
*"  TABLES 
*"      IT_ITEM STRUCTURE  ZSDS0025 
*"      IT_RETURN STRUCTURE  BAPIRET2 OPTIONAL 
*"---------------------------------------------------------------------- 
*********************************************************************** 
*  Function <Z_SD_UB_CHANGE> 
************************************************************************ 
* 
*  作者:            DZHANGHUI 
*  完成日期:        2014/12/31 
*  描述:            UB单返写 发货 
************************************************************************ 
*  版本号 日期   作者   修改描述 功能更改说明书 
************************************************************************ 
*  1.  YYYY/MM/DD author  Read dataset from app. Server @001 
************************************************************************ 
  DATA : LV_EBELN    TYPE BAPIMEPOHEADER-PO_NUMBER, 
         LV_ITEM     LIKE GS_POITEM-PO_ITEM, 
         LV_WERKS    LIKE GS_POITEM-PLANT, 
         LV_SUPPL    LIKE GS_POITEM-SUPPL_STLOC, 
         LV_CAT      LIKE GS_POITEM-ITEM_CAT, 
         LV_VAL_TYPE LIKE GS_POITEM-VAL_TYPE, 
         LV_BWTTY    LIKE MARC-BWTTY.         "评估类别 
 
  DATA : LS_ITEM TYPE ZSDS0025. 
 
  LV_EBELN = IM_EBELN. 
 
  REFRESH : GT_POITEM,GT_POITEMX, 
            GT_POSCHEDULE,GT_POSCHEDULEX. 
 
* 获取PO的Detail 
  CALL FUNCTION 'BAPI_PO_GETDETAIL1' 
    EXPORTING 
      PURCHASEORDER = LV_EBELN 
    TABLES 
      POITEM        = GT_POITEM. 
 
 
*  IF IM_TYPE = 'SJ'."素金 
*   删除原来的行项目 
  LOOP AT GT_POITEM INTO GS_POITEM. 
    IF ( GS_POITEM-BATCH IS INITIAL OR GS_POITEM-BATCH  EQ GS_POITEM-MATERIAL ) AND 
        GS_POITEM-DELETE_IND IS INITIAL. 
      GS_POITEM-DELETE_IND = 'D'. 
      MODIFY GT_POITEM FROM GS_POITEM INDEX SY-TABIX TRANSPORTING DELETE_IND. 
 
      GS_POITEMX-PO_ITEM = GS_POITEM-PO_ITEM. 
      GS_POITEMX-DELETE_IND = 'X'. 
      APPEND GS_POITEMX TO GT_POITEMX. 
    ENDIF. 
 
    LV_ITEM = GS_POITEM-PO_ITEM. 
    LV_WERKS = GS_POITEM-PLANT. 
    LV_SUPPL = GS_POITEM-SUPPL_STLOC. 
    LV_CAT   = GS_POITEM-ITEM_CAT. 
    LV_VAL_TYPE   = GS_POITEM-VAL_TYPE. 
  ENDLOOP. 
 
*   获取工厂 项目类型 
  IF SY-SUBRC NE 0. 
    READ TABLE GT_POITEM INTO GS_POITEM INDEX 1. 
    LV_ITEM = GS_POITEM-PO_ITEM. 
    LV_WERKS = GS_POITEM-PLANT. 
    LV_SUPPL = GS_POITEM-SUPPL_STLOC. 
    LV_CAT   = GS_POITEM-ITEM_CAT. 
    LV_VAL_TYPE   = GS_POITEM-VAL_TYPE. 
  ENDIF. 
 
*   新增需要发货的行项目 
  LOOP AT IT_ITEM INTO LS_ITEM. 
*   检查不存在相同物料和批次的行项目 
    READ TABLE GT_POITEM INTO GS_POITEM WITH KEY MATERIAL = LS_ITEM-ZSPKH BATCH = LS_ITEM-ZSPPC DELETE_IND = ''. 
    CHECK SY-SUBRC NE 0. 
 
    ADD 10 TO LV_ITEM. 
 
    CLEAR GS_POITEM. 
    GS_POITEM-PO_ITEM     = LV_ITEM. 
    GS_POITEM-MATERIAL    = LS_ITEM-ZSPKH. 
    GS_POITEM-PLANT       = LV_WERKS. 
    GS_POITEM-BATCH       = LS_ITEM-ZSPPC. 
    GS_POITEM-SUPPL_STLOC = LV_SUPPL. 
    GS_POITEM-QUANTITY    = LS_ITEM-ZSPJH. 
    GS_POITEM-ITEM_CAT    = LV_CAT. 
*     检查物料是否启用评估类别 
    PERFORM FRM_CHECK_VALUE_TYPE USING    LV_WERKS LS_ITEM-ZSPKH 
                                 CHANGING LV_BWTTY. 
*     评估类型 
    IF LV_BWTTY EQ 'X'. 
      GS_POITEM-VAL_TYPE    = LS_ITEM-ZSPPC. 
    ENDIF. 
 
    APPEND GS_POITEM TO GT_POITEM. 
 
    CLEAR GS_POITEMX. 
    GS_POITEMX-PO_ITEM     = LV_ITEM. 
    GS_POITEMX-MATERIAL    = 'X'. 
    GS_POITEMX-PLANT       = 'X'. 
    GS_POITEMX-BATCH       = 'X'. 
    GS_POITEMX-SUPPL_STLOC = 'X'. 
    GS_POITEMX-QUANTITY    = 'X'. 
    GS_POITEMX-ITEM_CAT    = 'X'. 
    IF LV_BWTTY EQ 'X'. 
      GS_POITEMX-VAL_TYPE    = 'X'. 
    ENDIF. 
    APPEND GS_POITEMX TO GT_POITEMX. 
 
*   更新计划行 
    CLEAR GS_POSCHEDULE. 
    GS_POSCHEDULE-PO_ITEM = LV_ITEM. 
    GS_POSCHEDULE-SCHED_LINE = 1. 
    GS_POSCHEDULE-DELIVERY_DATE = IM_BUDAT. 
    APPEND GS_POSCHEDULE TO GT_POSCHEDULE. 
 
    CLEAR GS_POSCHEDULEX. 
    GS_POSCHEDULEX-PO_ITEM = LV_ITEM. 
    GS_POSCHEDULEX-SCHED_LINE = 1. 
    GS_POSCHEDULEX-DELIVERY_DATE = 'X'. 
    APPEND GS_POSCHEDULEX TO GT_POSCHEDULEX. 
  ENDLOOP. 
*  ELSEIF IM_TYPE = 'XQ'."镶嵌 
*    LOOP AT IT_ITEM INTO LS_ITEM. 
**     检查是否存在相同的物料和批次,若存在则不需返写 
*      READ TABLE GT_POITEM INTO GS_POITEM WITH KEY MATERIAL = LS_ITEM-ZSPKH 
*                                                   BATCH    = LS_ITEM-ZSPPC. 
*      CHECK SY-SUBRC NE 0. 
* 
**     查找无批次的行项目 - 返写批次信息 
*      READ TABLE GT_POITEM INTO GS_POITEM WITH KEY MATERIAL = LS_ITEM-ZSPKH 
*                                                   BATCH    = ''. 
*      IF SY-SUBRC EQ 0. 
*        GS_POITEM-BATCH = LS_ITEM-ZSPPC. 
*        GS_POITEM-QUANTITY = LS_ITEM-ZSPJH. 
*        MODIFY GT_POITEM FROM GS_POITEM INDEX SY-TABIX TRANSPORTING BATCH. 
* 
*        GS_POITEMX-PO_ITEM = GS_POITEM-PO_ITEM. 
*        GS_POITEMX-BATCH = 'X'. 
*        GS_POITEMX-QUANTITY = 'X'. 
*        APPEND GS_POITEMX TO GT_POITEMX. 
*      ENDIF. 
*    ENDLOOP. 
*  ENDIF. 
  CHECK GT_POITEM IS NOT INITIAL. 
 
* 修改订单 
  CALL FUNCTION 'BAPI_PO_CHANGE' 
    EXPORTING 
      PURCHASEORDER = LV_EBELN 
    TABLES 
      RETURN        = GT_RETURN 
      POITEM        = GT_POITEM 
      POITEMX       = GT_POITEMX 
      POSCHEDULE    = GT_POSCHEDULE 
      POSCHEDULEX   = GT_POSCHEDULEX. 
 
  LOOP AT GT_RETURN INTO GS_RETURN WHERE TYPE = 'X' OR 
                                         TYPE = 'A' OR 
                                         TYPE = 'E'. 
    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. 
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

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/18703.html

(0)
上一篇 2021年7月19日 21:22
下一篇 2021年7月19日 21:22

相关推荐

发表回复

登录后才能评论