542 migo过账 demo

DATA goodsmvt_code LIKE bapi2017_gm_code VALUE ‘04’.
DATA goodsmvt_header LIKE bapi2017_gm_head_01.
DATA materialdocument LIKE bapi2017_gm_head_ret-mat_doc.
DATA matdocumentyear LIKE bapi2017_gm_head_ret-doc_year.
DATA goodsmvt_item TYPE bapi2017_gm_item_create OCCURS 0 WITH HEADER LINE.
DATA return TYPE bapiret2 OCCURS 0 WITH HEADER LINE.

  CLEAR:goodsmvt_item[],return[],materialdocument,matdocumentyear.
  LOOP AT it_mseg.
    CLEAR:goodsmvt_item.
    READ TABLE it_resb INTO is_resb WITH KEY ebeln = it_mseg-ebeln
                                             ebelp = it_mseg-ebelp
                                             matnr = it_mseg-matnr.
    IF sy-subrc = 0.
      goodsmvt_item-move_type = '542'.
  •      goodsmvt_item-spec_stock = 'O'.
        goodsmvt_item-item_text = '委外副产品入库/' && it_mseg-sgtxt.
        goodsmvt_item-material = it_mseg-matnr.
        goodsmvt_item-entry_qnt = it_mseg-menge.
        goodsmvt_item-plant = it_mseg-werks.
        goodsmvt_item-stge_loc = 'B101'.
        goodsmvt_item-po_number = it_mseg-ebeln.
        goodsmvt_item-po_item = it_mseg-ebelp.
        goodsmvt_item-vendor = it_mseg-lifnr.
        APPEND goodsmvt_item.
      ENDIF.
    ENDLOOP.
    IF goodsmvt_item[] IS NOT INITIAL.
      goodsmvt_header-pstng_date = sy-datum.
      goodsmvt_header-doc_date = sy-datum.
      goodsmvt_header-pr_uname = sy-uname.
      goodsmvt_header-header_txt = '委外副产品入库'.
    
      CLEAR lv_mess.
      CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
        EXPORTING
          goodsmvt_header  = goodsmvt_header
          goodsmvt_code    = goodsmvt_code
        IMPORTING
          materialdocument = materialdocument
          matdocumentyear  = matdocumentyear
        TABLES
          goodsmvt_item    = goodsmvt_item[]
          return           = return[].
    
      IF materialdocument IS INITIAL.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
      ELSE.
    
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = 'X'.
      ENDIF.
    ENDIF.
    

你可能感兴趣的:(SAP-MM,SAP-ABAP,ABAP)