成品入库过账bapi

入库过账

FUNCTION ZPP_BAPI_PRODUCT_STOCK_IN.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  EXPORTING
*"     VALUE(CZ_MESS) TYPE  CHAR40
*"  TABLES
*"      INPUT STRUCTURE  ZPP_BAPI_PRODUCT_STOCK_INPUT
*"      OUTPUT STRUCTURE  ZPP_BAPI_PRODUCT_STOCK_OUTPUT
*"----------------------------------------------------------------------

  DATA:  GOODSMVT_HEADER  TYPE   BAPI2017_GM_HEAD_01,
         GOODSMVT_CODE    TYPE   BAPI2017_GM_CODE,
         GOODSMVT_HEADRET TYPE   BAPI2017_GM_HEAD_RET,
         MATERIALDOCUMENT TYPE   BAPI2017_GM_HEAD_RET-MAT_DOC,
         MATDOCUMENTYEAR  TYPE   BAPI2017_GM_HEAD_RET-DOC_YEAR,
         GOODSMVT_ITEM    TYPE STANDARD TABLE OF   BAPI2017_GM_ITEM_CREATE,
         GOODSMVT_SERIALNUMBER TYPE STANDARD TABLE OF   BAPI2017_GM_SERIALNUMBER,
         RETURN           TYPE STANDARD TABLE OF   BAPIRET2 ,
         W_CRETURN        TYPE   BAPIRET2,
         W_GOODSMVT_ITEM  TYPE                     BAPI2017_GM_ITEM_CREATE,
         W_GOODSMVT_SERIALNUMBER TYPE              BAPI2017_GM_SERIALNUMBER,
         W_RETURN         TYPE   BAPIRET2.
*  接口调用日志
  DATA: LT_LOG TYPE STANDARD TABLE OF ZZT_INFLOG,
        LW_LOG TYPE ZZT_INFLOG.

  CLEAR:GOODSMVT_HEADER,
        GOODSMVT_CODE,
        GOODSMVT_HEADRET,
        MATERIALDOCUMENT,
        MATDOCUMENTYEAR,
        GOODSMVT_ITEM ,
        RETURN,W_RETURN,
        GOODSMVT_SERIALNUMBER,
        W_GOODSMVT_SERIALNUMBER."LT_TPMSG,LT_RETMSG.

  REFRESH:GOODSMVT_ITEM,RETURN,GOODSMVT_SERIALNUMBER.
  "事物码
  GOODSMVT_CODE-GM_CODE = '02'.               "MB31
*  **********gm_code取值含义*******
*  *******01     MB01
*  *******02     MB31
*  *******03     MB1A
*  *******04     MB1B
*  *******05     MB1C
*  *******06     MB11
*  *******07     MB04
  "
  GOODSMVT_HEADER-HEADER_TXT = INPUT-BKTXT.
  GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
  GOODSMVT_HEADER-DOC_DATE   = SY-DATUM.
  "明细
  DATA:LV_ENTRY_QNT TYPE I.
  CLEAR: LV_ENTRY_QNT,INPUT.
   LV_ENTRY_QNT = LINES( INPUT ).
  READ TABLE INPUT INDEX 1.
  IF SY-SUBRC EQ 0.
    W_GOODSMVT_ITEM-MOVE_TYPE = '101'.
    W_GOODSMVT_ITEM-STCK_TYPE = 'F'.
    W_GOODSMVT_ITEM-MVT_IND = 'F'.
    W_GOODSMVT_ITEM-PLANT = INPUT-WERKS.
    W_GOODSMVT_ITEM-ORDERID = INPUT-AUFNR.
    W_GOODSMVT_ITEM-ENTRY_QNT = LV_ENTRY_QNT.
***  生产订单信息
    SELECT SINGLE PWERK LGORT MATNR MEINS
      INTO (W_GOODSMVT_ITEM-PLANT,W_GOODSMVT_ITEM-STGE_LOC,W_GOODSMVT_ITEM-MATERIAL,W_GOODSMVT_ITEM-ENTRY_UOM)
      FROM AFPO
     WHERE AUFNR = INPUT-AUFNR.

    APPEND W_GOODSMVT_ITEM TO GOODSMVT_ITEM.
  ENDIF.
***  称重数据更新
  IF INPUT-SERNR IS INITIAL AND INPUT-BRGEW IS INITIAL AND INPUT-GEWEI IS INITIAL.
    CZ_MESS = 'E:序列号 或 重量 或 单位为空!'.
  ELSE.
    UPDATE EQUI SET AEDAT = SY-DATUM
                    AENAM = SY-UNAME
                    BRGEW = INPUT-BRGEW
                    GEWEI = INPUT-GEWEI
              WHERE EQUNR = INPUT-SERNR.
    IF SY-SUBRC EQ 0.
      CZ_MESS = 'S:产品重量数据传输成功!'.
      COMMIT WORK.
    ELSE.
      CZ_MESS = 'E:产品重量数据传输失败!'.
    ENDIF.
  ENDIF.

  LOOP AT INPUT.
    W_GOODSMVT_SERIALNUMBER-MATDOC_ITM = '0001'.
    W_GOODSMVT_SERIALNUMBER-SERIALNO = INPUT-SERNR.
    APPEND W_GOODSMVT_SERIALNUMBER TO GOODSMVT_SERIALNUMBER.
  ENDLOOP.

  "执行操作
  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
     EXPORTING
       GOODSMVT_HEADER  = GOODSMVT_HEADER
       GOODSMVT_CODE    = GOODSMVT_CODE
     IMPORTING
       GOODSMVT_HEADRET = GOODSMVT_HEADRET
       MATERIALDOCUMENT = MATERIALDOCUMENT
       MATDOCUMENTYEAR  = MATDOCUMENTYEAR
     TABLES
       GOODSMVT_ITEM    = GOODSMVT_ITEM
       GOODSMVT_SERIALNUMBER = GOODSMVT_SERIALNUMBER
       RETURN           = RETURN
       .

  READ TABLE RETURN WITH KEY TYPE = 'E' INTO W_RETURN.
  IF SY-SUBRC <> 0.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
       EXPORTING
         WAIT = 'X'.
     IF MATERIALDOCUMENT IS NOT INITIAL.
        OUTPUT-FLAG = 'S'.
        OUTPUT-NOTES = '成品入库成功!'.
        OUTPUT-MBLNR = MATERIALDOCUMENT.
        APPEND OUTPUT.
     ENDIF.
***填写日志
    CLEAR LW_LOG.
    LW_LOG-INTTY     = 'SI'.
    LW_LOG-DIRECT    = '2'.
    LW_LOG-INFTX     = '扫码自动入库&更新重量'.
    LW_LOG-OKEY1     = MATERIALDOCUMENT.
    LW_LOG-OKEY2     = CZ_MESS.
    LW_LOG-IKEY1     = INPUT-AUFNR.
    LW_LOG-IKEY2     = INPUT-WERKS.
    LW_LOG-IKEY3     = INPUT-SERNR.
    LW_LOG-IKEY4     = INPUT-BRGEW.
    LW_LOG-LOGST     = 'S'.                   "日志状态
    LW_LOG-LOGTX     = '成品扫码入库成功!'.            "日志文本
    LW_LOG-CAFUN     = 'ZPP_BAPI_PRODUCT_STOCK_IN'.   "调用函数
    APPEND LW_LOG TO LT_LOG.
    CLEAR OUTPUT.
  ELSE.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

    OUTPUT-FLAG = 'E'.
    CONCATENATE '成品入库失败:' W_RETURN-MESSAGE INTO OUTPUT-NOTES.
    APPEND OUTPUT.

    CLEAR LW_LOG.
    LW_LOG-INTTY     = 'SI'.
    LW_LOG-DIRECT    = '2'.
    LW_LOG-INFTX     = '扫码自动入库&更新重量'.
*    LW_LOG-OKEY1     = .
    LW_LOG-OKEY2     = CZ_MESS.
    LW_LOG-IKEY1     = INPUT-AUFNR.
    LW_LOG-IKEY2     = INPUT-WERKS.
    LW_LOG-IKEY3     = INPUT-SERNR.
    LW_LOG-IKEY4     = INPUT-BRGEW.
    LW_LOG-LOGST     = 'E'.                   "日志状态
    LW_LOG-LOGTX     = OUTPUT-NOTES.            "日志文本
    LW_LOG-CAFUN     = 'ZPP_BAPI_PRODUCT_STOCK_IN'.   "调用函数
    APPEND LW_LOG TO LT_LOG.
    CLEAR OUTPUT.
  ENDIF.

  IF INPUT[] IS NOT INITIAL.
    CALL FUNCTION 
    TABLES
      IT_LOG        = LT_LOG
              .
    IF SY-SUBRC EQ 0.
      COMMIT WORK.
    ENDIF.
  ENDIF.
  CLEAR:INPUT[].

ENDFUNCTION.

 

posted @ 2016-07-07 13:29  明大叔  阅读(1306)  评论(0编辑  收藏  举报