PS 服务采购订单 收获 不允许撤销提示:由于汇总不允许马上取消接受

48 篇文章 4 订阅
3 篇文章 0 订阅

出现此问题的原因是系统没有将采购订单的 服务输入表的处理 凭证更新到 ekbe表里。

请参考一下地址对这个问题的讨论。

http://forums.sdn.sap.com/thread.jspa?threadID=1017367

 

也可以查看sap notes:527907

 

处理代码如下:

REPORT  ZMO_EKBEUPDATE MESSAGE-ID SE.


TABLES: EKKO,
        EKPO,
        EKKN,
        ESSR,
        ESKN,
        EKBE,
        ESLH,
        ML_ESLL,
        T001.

DATA: T_EKKO LIKE EKKO OCCURS 10
             WITH HEADER LINE.
DATA: T_EKPO LIKE EKPO OCCURS 10
             WITH HEADER LINE.
DATA: T_EKKN LIKE EKKN OCCURS 10
             WITH HEADER LINE.
DATA: T_ESSR LIKE ESSR OCCURS 50
             WITH HEADER LINE.
DATA: T_ESKN LIKE ESKN OCCURS 50
             WITH HEADER LINE.
DATA: T_EKBE LIKE EKBE OCCURS 50
             WITH HEADER LINE.
DATA: T_ESLL LIKE ESLL OCCURS 100
             WITH HEADER LINE.
DATA: BEGIN OF H_TAB OCCURS 50,
          PACKNO LIKE ESLH-PACKNO,
      END OF H_TAB.
DATA: XEKBE  LIKE EKBE OCCURS 50
             WITH HEADER LINE.

DATA: ERROR_FLAG.
DATA: EKBE_UPDATE_FLAG.
DATA: COUNT LIKE SY-SUBRC.
DATA: CHECK_KZABN, UPD_KZABN,
      CHECK_BEKKN, UPD_BEKKN,
      CHECK_ESLH,  UPD_ESLH,
      CHECK_COMM,  UPD_COMM,
      CHECK_EKBE,  UPD_EKBE,
      CHECK_PACC.

SELECT-OPTIONS: S_EKKO FOR EKPO-EBELN.
PARAMETER: P_UPDATE DEFAULT ' '.

*----------------------------------------------------------------------*
START-OF-SELECTION.
*----------------------------------------------------------------------*

* Initialize
  IF P_UPDATE = 'x' OR
     P_UPDATE = 'X'.
    P_UPDATE = 'X'.
  ELSE.
    CLEAR P_UPDATE.
  ENDIF.
  CLEAR: ERROR_FLAG, EKBE_UPDATE_FLAG.
  CLEAR: CHECK_KZABN, UPD_KZABN,
         CHECK_BEKKN, UPD_BEKKN.
  CHECK_BEKKN = ' '. UPD_BEKKN = ' '.
  CHECK_ESLH  = ' '. UPD_ESLH  = ' '.
  CHECK_COMM  = ' '. UPD_COMM  = ' '.
  CHECK_EKBE = 'X'. UPD_EKBE ='X'.
  CHECK_PACC  = ' '.

* Read purchase orders
  SELECT * FROM EKPO INTO TABLE T_EKPO
         WHERE EBELN IN S_EKKO
         AND   PSTYP = '9'
         AND   LOEKZ = SPACE.
  IF SY-SUBRC NE 0.
    WRITE: 'No service items selected'.
    EXIT.
  ENDIF.
  SORT T_EKPO BY EBELN EBELP.

  SELECT * FROM EKKO INTO TABLE T_EKKO
           FOR ALL ENTRIES IN T_EKPO
           WHERE EBELN = T_EKPO-EBELN.
  IF SY-SUBRC NE 0.
    WRITE: 'Read error'.
    EXIT.
  ENDIF.
  SORT T_EKKO BY EBELN.

  LOOP AT T_EKPO.
    REFRESH: T_ESSR, T_ESKN, T_EKBE, T_EKKN, H_TAB.
    CLEAR:   T_ESSR, T_ESKN, T_EKBE, T_EKKN, H_TAB.

* Read entry sheets
    SELECT * FROM ESSR INTO TABLE T_ESSR
             WHERE EBELN = T_EKPO-EBELN
             AND   EBELP = T_EKPO-EBELP.
    CHECK SY-SUBRC = 0.

* Read account assignments
    LOOP AT T_ESSR.
      H_TAB-PACKNO = T_ESSR-LBLNI.
      APPEND H_TAB.
    ENDLOOP.
    DESCRIBE TABLE H_TAB LINES SY-TFILL.
    IF SY-TFILL > 0.
      SELECT * FROM ESKN INTO TABLE T_ESKN
               FOR ALL ENTRIES IN H_TAB
               WHERE PACKNO EQ H_TAB-PACKNO
               ORDER BY PRIMARY KEY.
    ENDIF.

* Read PO history
    SELECT * FROM EKBE INTO TABLE T_EKBE
             WHERE EBELN = T_EKPO-EBELN
             AND   EBELP = T_EKPO-EBELP.
    SORT T_EKBE.

* Read PO account assignment
    SELECT * FROM EKKN INTO TABLE T_EKKN
             WHERE EBELN = T_EKPO-EBELN
             AND   EBELP = T_EKPO-EBELP.

* Analyze and correct entry sheets
    LOOP AT T_ESSR.
      COUNT = COUNT + 1.

      READ TABLE T_EKKO WITH KEY EBELN = T_ESSR-EBELN
                                 BINARY SEARCH.
      READ TABLE T_EKPO WITH KEY EBELN = T_ESSR-EBELN
                                 EBELP = T_ESSR-EBELP
                                 BINARY SEARCH.

*   Check acceptance posted
      IF NOT CHECK_PACC IS INITIAL.
        PERFORM CHECK_PACC.
      ENDIF.

*   Check kzabn - missing material document
      IF NOT CHECK_KZABN IS INITIAL.
        PERFORM CHECK_KZABN.
      ENDIF.

*   Check eslh - sheet number missing in eslh
      IF NOT CHECK_ESLH IS INITIAL.
        PERFORM CHECK_ESLH.
      ENDIF.

*   Check bekkn - inconsistency in account assignment
      IF NOT CHECK_BEKKN IS INITIAL.
        PERFORM CHECK_BEKKN.
      ENDIF.

*  Check comm - commitment assignment
      IF NOT CHECK_COMM IS INITIAL.
        PERFORM CHECK_COMM.
      ENDIF.

*  Check ekbe - missing purchase order history
      IF NOT CHECK_EKBE IS INITIAL.
        PERFORM CHECK_EKBE.
      ENDIF.

    ENDLOOP.

  ENDLOOP.

* No errors found
  IF ERROR_FLAG IS INITIAL.
    FORMAT COLOR COL_POSITIVE.
    WRITE: / 'Total number of entry sheets: ', COUNT.
    WRITE: / 'No problems detected'.
    EXIT.
  ENDIF.

************************************************************************
* FORMS                                                                *
************************************************************************
FORM CHECK_PACC.
*&---------------------------------------------------------------------*
*&      Form  CHECK_PVAL
*       Check accepted value
*&---------------------------------------------------------------------*
  DATA: GR_VALUE LIKE ESSR-LWERT.
  DATA: N_ACCASS LIKE EKBE-MENGE,
        MENGE    LIKE EKBE-MENGE.

* Accepted ?
  CHECK NOT T_ESSR-KZABN IS INITIAL.

* Number of account assignments
  READ TABLE T_ESKN WITH KEY PACKNO = T_ESSR-LBLNI
                         BINARY SEARCH.
  CHECK SY-SUBRC = 0.
  CLEAR N_ACCASS.
  LOOP AT T_ESKN FROM SY-TABIX.
    IF T_ESKN-PACKNO NE T_ESSR-LBLNI.
      EXIT.
    ENDIF.
    CHECK T_ESKN-LOEKZ IS INITIAL.
    CHECK T_ESKN-NETWR NE 0.
    N_ACCASS = N_ACCASS + 1.
  ENDLOOP.

* Check quantity
  LOOP AT T_EKBE WHERE EBELN = T_ESSR-EBELN
                 AND   EBELP = T_ESSR-EBELP
                 AND   VGABE = '1'
                 AND   LFBNR = T_ESSR-LBLNI.
    IF T_EKBE-SHKZG = 'S'.
      MENGE = MENGE + 1.
    ELSE.
      MENGE = MENGE - 1.
    ENDIF.
  ENDLOOP.

  CHECK MENGE > N_ACCASS.

* Print log
  WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI.
  ERROR_FLAG = 'X'.

ENDFORM.                               " CHECK_PVAL

*---------------------------------------------------------------------*
*       FORM CHECK_KZABN                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM CHECK_KZABN.
*&---------------------------------------------------------------------*
*&      Form  CHECK_KZABN
*&---------------------------------------------------------------------*

  CHECK NOT T_ESSR-KZABN IS INITIAL.

* Check
  READ TABLE T_EKBE WITH KEY EBELN = T_ESSR-EBELN
                             EBELP = T_ESSR-EBELP
                             VGABE = '1'
                             LFBNR = T_ESSR-LBLNI.
  CHECK NOT SY-SUBRC IS INITIAL.

* Print log
  WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
           'Abnahmekennzeichen ohne Buchung'.
  ERROR_FLAG = 'X'.

* Correct
  IF NOT UPD_KZABN IS INITIAL AND
     NOT P_UPDATE IS INITIAL.
    ESSR = T_ESSR.
    UPDATE ESSR.
    IF SY-SUBRC = 0.
      WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
               'Korrigiert, Update erfolgt'.
    ENDIF.
  ENDIF.

ENDFORM.                               " CHECK_KZABN

*---------------------------------------------------------------------*
*       FORM CHECK_ESLH                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM CHECK_ESLH.
*&---------------------------------------------------------------------*
*&      Form  CHECK_ESLH
*&---------------------------------------------------------------------*

  CHECK NOT T_ESSR-PACKNO IS INITIAL.

* Check
  SELECT SINGLE * FROM ESLH
         WHERE PACKNO = T_ESSR-PACKNO.
  IF SY-SUBRC > 0.
    WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
             'ESLH fehlt'.
    ERROR_FLAG = 'X'.
    EXIT.
  ENDIF.

  IF ESLH-EBELN NE T_ESSR-LBLNI OR
     ESLH-BSTYP NE 'Q'.
    ERROR_FLAG = 'X'.
    WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
           'Blattnummer fehlt in ESLH'.

* Correct
    IF NOT UPD_ESLH IS INITIAL AND
       NOT P_UPDATE IS INITIAL.
      ESLH-EBELN = T_ESSR-LBLNI.
      ESLH-BSTYP = 'Q'.
      CLEAR ESLH-EBELP.
      UPDATE ESLH.
      IF SY-SUBRC = 0.
        WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
               'ESLH Korrigiert, Update erfolgt'.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.                               " CHECK_BEKKN

*---------------------------------------------------------------------*
*       FORM CHECK_BEKKN                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM CHECK_BEKKN.
*&---------------------------------------------------------------------*
*&      Form  CHECK_BEKKN
*&---------------------------------------------------------------------*
  DATA: FLAG.
  DATA: N LIKE SY-SUBRC, PO_ZEKKN LIKE EKKN-ZEKKN.
  CLEAR: N, FLAG.

* Account assignment in PO
  CHECK NOT T_EKPO-KZVBR = 'U'.
  DESCRIBE TABLE T_EKKN LINES N.
  IF N = 1.
    READ TABLE T_EKKN INDEX 1.
    PO_ZEKKN = T_EKKN-ZEKKN.
  ENDIF.

* Check
  READ TABLE T_ESKN WITH KEY PACKNO = T_ESSR-LBLNI
                                    BINARY SEARCH.
  CHECK SY-SUBRC = 0.
  LOOP AT T_ESKN FROM SY-TABIX
       WHERE PACKNO = T_ESSR-LBLNI.
    IF T_ESKN-PACKNO NE T_ESSR-LBLNI.
      EXIT.
    ENDIF.
    IF T_ESKN-BEKKN IS INITIAL AND
       NOT T_ESKN-NETWR IS INITIAL.
      FLAG = 'X'.
      EXIT.
    ENDIF.
  ENDLOOP.

  IF FLAG = 'X'.
    ERROR_FLAG = 'X'.
    IF N = 1.
      WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
          'Bekkn missing in acc.assign. - autom. correction possible'.
    ELSE.
      WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
        'Bekkn missing in acc.assign. - autom. correction not possible'.
    ENDIF.

* Correct if possible
    IF NOT UPD_BEKKN IS INITIAL AND
       NOT P_UPDATE IS INITIAL AND
      N EQ 1.
      LOOP AT T_ESKN WHERE PACKNO = T_ESSR-LBLNI.
        CHECK T_ESKN-BEKKN IS INITIAL.
        ESKN = T_ESKN.
        ESKN-BEKKN = PO_ZEKKN.
        UPDATE ESKN.
      ENDLOOP.
      WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
             'Kontierung korrigiert, Update erfolgt'.
    ENDIF.
  ENDIF.

ENDFORM.                               " CHECK_BEKKN

*---------------------------------------------------------------------*
*       FORM CHECK_COMM                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM CHECK_COMM.
*&---------------------------------------------------------------------*
*&      Form  CHECK_COMM
*&---------------------------------------------------------------------*
  DATA: FLAG.
  DATA: H_ZEKKN LIKE EKKN-ZEKKN.
  CLEAR: FLAG.

* Account assignment in PO
  CHECK NOT T_EKPO-KZVBR = 'U'.

* Determine zekkn
  CLEAR H_ZEKKN.
  LOOP AT T_EKKN.
    IF T_EKKN-MENGE = 1.
      H_ZEKKN = T_EKKN-ZEKKN.
      EXIT.
    ENDIF.
  ENDLOOP.

  IF H_ZEKKN IS INITIAL.
    EXIT.
  ENDIF.

* Check
  READ TABLE T_ESKN WITH KEY PACKNO = T_ESSR-LBLNI
                                    BINARY SEARCH.
  CHECK SY-SUBRC = 0.
  LOOP AT T_ESKN FROM SY-TABIX
       WHERE PACKNO = T_ESSR-LBLNI.
    IF T_ESKN-PACKNO NE T_ESSR-LBLNI.
      EXIT.
    ENDIF.
    IF T_ESKN-BEKKN NE H_ZEKKN AND
       NOT T_ESKN-NETWR IS INITIAL.
      FLAG = 'X'.
      EXIT.
    ENDIF.
  ENDLOOP.

  IF FLAG = 'X'.
    ERROR_FLAG = 'X'.
    WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
           'Fehler in Kontierungszuordnung'.

* Correct if possible
    IF NOT UPD_COMM IS INITIAL AND
       NOT P_UPDATE IS INITIAL.
      LOOP AT T_ESKN WHERE PACKNO = T_ESSR-LBLNI.
        CHECK T_ESKN-BEKKN NE H_ZEKKN.
        ESKN = T_ESKN.
        ESKN-BEKKN = H_ZEKKN.
        UPDATE ESKN.
      ENDLOOP.
      WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
             'Kontierung korrigiert, Update erfolgt'.
    ENDIF.
  ENDIF.

ENDFORM.                               " CHECK_COMM

*---------------------------------------------------------------------*
*       FORM CHECK_EKBE                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM CHECK_EKBE.
*&---------------------------------------------------------------------*
*&      Form  CHECK_EKBE
*&---------------------------------------------------------------------*
  CLEAR EKBE_UPDATE_FLAG.

* Read T001
  IF T001-BUKRS NE T_EKKO-BUKRS.
    SELECT SINGLE * FROM T001 WHERE BUKRS = T_EKKO-BUKRS.
  ENDIF.

*CHECK NOT T_ESSR-packno IS INITIAL.  "nicht Packno, wg. Blatt ohne LV
  CHECK NOT T_ESSR-LBLNI IS INITIAL.

* Check
  READ TABLE T_EKBE WITH KEY EBELN = T_ESSR-EBELN
                             EBELP = T_ESSR-EBELP
                             VGABE = '9'
                             BELNR = T_ESSR-LBLNI.

  IF SY-SUBRC > 0.
    WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
             'Entrysheet not in PO history'.
    ERROR_FLAG = 'X'.
  ELSE.
*   rev -updated for deleted service entry sheet
    IF T_EKBE-WRBTR = T_ESSR-NETWR AND T_ESSR-LOEKZ IS INITIAL OR  "rev
        T_EKBE-WRBTR = 0 AND NOT T_ESSR-LOEKZ IS INITIAL.          "rev
*       rev2 - updated for bad currency and bad dmbtr value
        IF T_EKBE-WAERS NE T_EKKO-WAERS OR
           T_EKBE-WAERS EQ T001-WAERS AND T_EKBE-DMBTR NE T_ESSR-NETWR.
          WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
                 'Entrysheet with bad currency in PO history'.
          ERROR_FLAG = 'X'.
          EKBE_UPDATE_FLAG = 'X'.
        ELSE.
          EXIT.
        ENDIF.
    ELSE.
      WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
             'Entrysheet with bad net value in PO history'.
      ERROR_FLAG = 'X'.
      EKBE_UPDATE_FLAG = 'X'.
    ENDIF.
  ENDIF.

* Correct
  IF NOT UPD_EKBE IS INITIAL AND
     NOT P_UPDATE IS INITIAL.
    CLEAR EKBE.
    PERFORM FILL_EKBE.
    IF EKBE_UPDATE_FLAG IS INITIAL.
      INSERT EKBE.
    ELSE.
      UPDATE EKBE.
    ENDIF.
    IF SY-DBCNT GT 1 OR
       SY-SUBRC > 0.
      ROLLBACK WORK.
      EXIT.
    ELSE.
      WRITE: / T_ESSR-EBELN, T_ESSR-EBELP, T_ESSR-LBLNI,
              'PO history corrected -EKBE Korrigiert, Update erfolgt'.
      COMMIT WORK.
    ENDIF.
  ENDIF.

*  ENDIF.

ENDFORM.                               " CHECK_EKBE

*---------------------------------------------------------------------*
*       FORM FILL_XEKBE                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM FILL_EKBE.
*&---------------------------------------------------------------------*
*&      Form  FILL_EKBE
*&---------------------------------------------------------------------*
*       Fuellen fehlender Bestellentwicklungss?tze                     *
*       in der Tabelle EKBE                                            *
*----------------------------------------------------------------------*

  EKBE-MANDT = SY-MANDT.
  EKBE-EBELN = T_EKPO-EBELN.
  EKBE-EBELP = T_EKPO-EBELP.
  EKBE-VGABE = '9'.
  EKBE-BELNR = T_ESSR-LBLNI.
  EKBE-BEWTP = 'D'.
  EKBE-MENGE = 1.
  EKBE-WRBTR = T_ESSR-NETWR.
  EKBE-WAERS = T_ESSR-WAERS.
  EKBE-SHKZG = 'S'.
  IF NOT T_ESSR-BLDAT IS INITIAL.
    EKBE-BLDAT = T_ESSR-BLDAT.
  ELSE.
    EKBE-BLDAT = T_ESSR-ERDAT.
  ENDIF.
  IF NOT T_ESSR-BUDAT IS INITIAL.
    EKBE-BUDAT = T_ESSR-BUDAT.
  ELSE.
    EKBE-BUDAT = T_ESSR-ERDAT.
  ENDIF.

* erst T001 lesen
  IF T_EKKO-WAERS EQ T001-WAERS.
    EKBE-DMBTR = T_ESSR-NETWR.
  ELSE.
* Wert in Hauswaehrung umrechnen
    IF T_EKKO-KUFIX NE SPACE.
      CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
           EXPORTING
                DATE             = T_EKKO-BEDAT
                FOREIGN_AMOUNT   = T_ESSR-NETWR
                FOREIGN_CURRENCY = T_ESSR-WAERS  "oder ekko?
                LOCAL_CURRENCY   = T001-WAERS
                RATE             = T_EKKO-WKURS
           IMPORTING
                LOCAL_AMOUNT     = EKBE-DMBTR.
    ELSE.
      CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
           EXPORTING
                DATE             = T_ESSR-LBLDT
                FOREIGN_AMOUNT   = T_ESSR-NETWR
                FOREIGN_CURRENCY = T_ESSR-WAERS  "EKKO-WAERS
                LOCAL_CURRENCY   = T001-WAERS
           IMPORTING
                LOCAL_AMOUNT     = EKBE-DMBTR.
    ENDIF.
  ENDIF.

  IF NOT T_ESSR-LOEKZ IS INITIAL.      "Blatt geloescht
    EKBE-DMBTR = 0.
    EKBE-WRBTR = 0.                    "auch Belegwert??
  ENDIF.

  EKBE-LFBNR = T_ESSR-LBLNI.

  EKBE-CPUDT = SY-DATUM.
  EKBE-CPUTM = SY-UZEIT.
  EKBE-LFGJA = T_ESSR-ERDAT.

ENDFORM.                               " FILL_EKBE

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值