abap对采购订单强制置为”交货已完成“状态(BAPI_PO_CHANGE、BAPI_PO_RELEASE、BAPI_PO_RESET_RELEASE)

项目中,需要对一些采购订单做强制“交货已完成”,如果采购订单已批准,是不能用BAPI_PO_CHANGE更改状态的,只有先除去“批准”状态 ,再“交货已完成”,然后再置为批准状态,下面是函数代码,希望对用到的兄弟有帮助。

DATA:PO_NUMBER LIKE EKKO-EBELN.

DATA:T_POITEM LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE.
DATA:T_POITEMX LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE.
DATA:T_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA: LV_FRGKE LIKE EKKO-FRGKE,
LV_FRGSX LIKE EKKO-FRGSX.

DATA:RETURN TYPE TABLE OF BAPIRETURN WITH HEADER LINE.

REFRESH OUTPUT.
CLEAR OUTPUT.

SORT INPUT BY EBELN.
LOOP AT INPUT.
CLEAR T_POITEM.
REFRESH T_POITEM.
CLEAR T_POITEMX.
REFRESH T_POITEMX.

 MOVE-CORRESPONDING INPUT TO OUTPUT.

 CLEAR LV_FRGKE.
 SELECT SINGLE
        FRGKE
        FRGSX
        INTO (LV_FRGKE,LV_FRGSX)
        FROM EKKO
        WHERE EBELN = INPUT-EBELN.
  • 如果采购订单被批准了,则先取消批准,才能修改
    IF LV_FRGKE = 'R'.
    
       CALL FUNCTION 'BAPI_PO_RESET_RELEASE'
            EXPORTING
              PURCHASEORDER = INPUT-EBELN
              PO_REL_CODE   = LV_FRGSX
              USE_EXCEPTIONS = 'X'
            TABLES
              RETURN = RETURN.
       CLEAR RETURN.
       READ TABLE RETURN WITH KEY TYPE = 'E'.
       IF SY-SUBRC EQ 0.
          OUTPUT-FLAG = 'E'.
          OUTPUT-MESSAGE = RETURN-MESSAGE.
       ENDIF.
    ENDIF.
    
    IF OUTPUT-FLAG <> 'E'.
       PO_NUMBER = INPUT-EBELN.
    
       T_POITEM-PO_ITEM = INPUT-EBELP.
       T_POITEM-NO_MORE_GR = 'X'.
       APPEND T_POITEM.
       CLEAR T_POITEM.
    
       T_POITEMX-PO_ITEM = INPUT-EBELP.
       T_POITEMX-PO_ITEMX = 'X'.
       T_POITEMX-NO_MORE_GR = 'X'.
       APPEND T_POITEMX.
       CLEAR T_POITEMX.
    
    
       CALL FUNCTION 'BAPI_PO_CHANGE'
          EXPORTING
            PURCHASEORDER = PO_NUMBER
          TABLES
            RETURN        = T_RETURN
            POITEM        = T_POITEM
            POITEMX       = T_POITEMX.
         READ TABLE T_RETURN WITH KEY TYPE = 'E'.
         IF SY-SUBRC EQ 0.
           OUTPUT-FLAG = 'E'.
           OUTPUT-MESSAGE = T_RETURN-MESSAGE.
           ROLLBACK WORK.
         ELSE.
           OUTPUT-FLAG = 'S'.
           OUTPUT-MESSAGE = '交货已完成更改成功!'.
           CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
             EXPORTING
               WAIT = 'X'.
         ENDIF.
    ENDIF.
    
  • 如果采购订单被批准了,则先取消批准,修改交货已完成后,在重新设置上批准状态
    IF LV_FRGKE = 'R' AND OUTPUT-FLAG <> 'E'.
       CALL FUNCTION 'BAPI_PO_RELEASE'
            EXPORTING
              PURCHASEORDER = INPUT-EBELN
              PO_REL_CODE   = LV_FRGSX
              USE_EXCEPTIONS = 'X'
            TABLES
              RETURN = RETURN.
    ENDIF.
    
    APPEND OUTPUT.
    CLEAR OUTPUT.
    

ENDLOOP.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值