MM--物料重新过账的代码摘抄

*&---------------------------------------------------------------------*
*& Report  ZZWASTOR                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT ZZWASTOR .

*********************************************************************
* If you do not know the material document of the goods issue any   *
* more you can use transaction SE16.                                *
* - Type in table name MKPF                                         *
* - Type in the delivery note number in field XBLNR (always with    *
*   leading zeroes)                                                 *
* - Execute                                                         *
* - The Material document number of the goods issue for the deleted *
*   delivery will be shown.                                         *
*                                                                   *
*                                                                   *
*                                                                   *
* LF_BUDAT  =>  Posting date for the reversal                       *
* LF_MJAHR  =>  Posting year of the material document to reverse    *
* LF_MBLNR  =>  Goods issue document (with leading zeroes)          *
* LF_VBELN  =>  Delivery note number (with leading zeroes)          *
* LF_TEST   =>  When 'X' it is test mode only, otherwise GI will be *
*               cancelled                                           *
*********************************************************************

TABLES: MKPF, IMKPF, EMKPF, LIKP.

DATA:   BEGIN OF IMSEG OCCURS 0.
        INCLUDE STRUCTURE IMSEG.
DATA:   END OF IMSEG.

DATA:   BEGIN OF EMSEG OCCURS 0.
        INCLUDE STRUCTURE EMSEG.
DATA:   END OF EMSEG.


PARAMETERS: LF_BUDAT  LIKE SY-DATLO DEFAULT SY-DATLO OBLIGATORY,
            LF_MJAHR  LIKE MKPF-MJAHR DEFAULT SY-DATLO(4) OBLIGATORY,
            LF_MBLNR  LIKE MKPF-MBLNR OBLIGATORY,
            LF_VBELN  LIKE LIKP-VBELN OBLIGATORY,
            LF_TEST   TYPE C DEFAULT 'X'.

DATA:   MBLPO LIKE MSEG-ZEILE.

SELECT SINGLE * FROM MKPF WHERE MBLNR = LF_MBLNR
                          AND   MJAHR = LF_MJAHR
                          AND   XBLNR = LF_VBELN.

IF SY-SUBRC IS INITIAL.
  CALL FUNCTION 'MB_CANCEL_GOODS_MOVEMENT'
    EXPORTING
      BUDAT     = LF_BUDAT
      MBLNR     = LF_MBLNR
      MBLPO     = MBLPO
      MJAHR     = LF_MJAHR
      TCODE     = 'VL09'
      CALLED_BY = 'VL09'
    IMPORTING
      EMKPF     = EMKPF
    TABLES
      EMSEG     = EMSEG
      IMSEG     = IMSEG
    EXCEPTIONS
      OTHERS    = 1.

*... No error found, then it will be posted
  IF EMKPF-SUBRC EQ 1.
    IF LF_TEST IS INITIAL.
      CALL FUNCTION 'MB_POST_GOODS_MOVEMENT'
        EXPORTING
          XBLNR_SD = LF_VBELN
        IMPORTING
          EMKPF    = EMKPF
        EXCEPTIONS
          OTHERS   = 0.

      COMMIT WORK.
    WRITE: / 'Goods movement was cancelled successfully with document:',
            EMKPF-MBLNR.
    ELSE.
      WRITE: / 'Testmode: Goods movement could be cancelled !'.
    ENDIF.
  ELSE.
*... otherwise write an error-log
    LOOP AT EMSEG.
      WRITE: /
                EMSEG-MSGID,
                EMSEG-MSGNO,
                EMSEG-MSGTY,
                EMSEG-MSGV1,
               EMSEG-MSGV2,
               EMSEG-MSGV3,
               EMSEG-MSGV4.
    ENDLOOP.
    WRITE: / EMKPF-MSGID,
             EMKPF-MSGNO,
             EMKPF-MSGTY,
             EMKPF-MSGV1,
             EMKPF-MSGV2,
             EMKPF-MSGV3,
             EMKPF-MSGV4.

  ENDIF.
ELSE.
  WRITE: / 'Material document to reverse does not exsist'.
ENDIF.
                                              .
 

posted on 2007-09-29 13:32  毛小娃  阅读(129)  评论(0编辑  收藏  举报

导航