BAPI–BOM匯入(感謝依風提供)

來源:互聯網
上載者:User

*& Author            :                            *
*& Create date       : 2007/03/31                          *
*& Program type      : Report                              *
*& Report name       : ZPPPR_BOM_INPUT                     *
*& Description       : BOM_匯入                            *
*& FINISH ON         :                                     *
*& TRANSPROT REQUEST :                                     *
*&---------------------------------------------------------*
REPORT  zpppr_bom_input.
*------>TAB1ES
TABLES :stko,
        stpo.
*------>inner-table
DATA : BEGIN OF gt_itab OCCURS 0,
*----->head
        matnr      LIKE  csap_mbom-matnr,
        werks      LIKE  csap_mbom-werks,"PLANT
        base_quan  LIKE  stko_api01-base_quan,"matnr_QUAN

*----->item
        item_no    LIKE  stpo_api03-item_no,"item_no
        item_categ LIKE  stpo_api03-item_categ,"item_CATEG
        component  LIKE  stpo_api03-component,"item_COMPONENT
        comp_qty   LIKE  stpo_api03-comp_qty,"item_QTY
        comp_scrap LIKE  stpo_api03-comp_scrap,"waster
        issue_loc  LIKE  stpo_api03-issue_loc,"product-stors
        bom_usage  LIKE  csap_mbom-stlan,"BOM_USAGE
        date       LIKE  csap_mbom-datuv,"VALID_FROM
        END OF gt_itab.
DATA : gt_ita1 LIKE gt_itab    OCCURS 0 WITH HEADER  LINE.
DATA : gt_stpo LIKE stpo_api03 OCCURS 0 WITH HEADER  LINE.
DATA : gt_stko LIKE stko_api01 OCCURS 0 WITH HEADER  LINE.
DATA : lv_cancel(1) TYPE c. 
*---->upload
CALL FUNCTION 'UPLOAD'
  EXPORTING
    filename                = 'C:/Documents and Settings/Administrator/Desktop/BOM.txt'
    filetype                = 'DAT'
  IMPORTING
    cancel                  = lv_cancel
  TABLES
    data_tab                = gt_itab
  EXCEPTIONS
    conversion_error        = 1
    invalid_table_width     = 2
    invalid_type            = 3
    no_batch                = 4
    unknown_error           = 5
    gui_refuse_filetransfer = 6
    OTHERS                  = 7.
IF lv_cancel EQ 'X'.
  LEAVE PROGRAM.
ENDIF.        .
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSEIF sy-subrc = 0.
  DATA:   matnr      LIKE  csap_mbom-matnr,
          werks      LIKE  csap_mbom-werks,"PLANT
          base_quan  LIKE  stko_api01-base_quan,"matnr_QUAN
          bom_usage  LIKE  csap_mbom-stlan."BOM_USAGE

  SORT gt_itab BY matnr item_no component.
  LOOP AT gt_itab.
    MOVE gt_itab TO gt_ita1.
    gt_ita1-bom_usage = '1'.
    gt_ita1-date = sy-datum.
    APPEND gt_ita1.
*---->item
    gt_stpo-item_no    = gt_itab-item_no.
    gt_stpo-item_categ = gt_itab-item_categ.
    gt_stpo-component  = gt_itab-component.
    gt_stpo-comp_qty   = gt_itab-comp_qty.
    gt_stpo-comp_scrap = gt_itab-comp_scrap.
    gt_stpo-issue_loc  = gt_itab-issue_loc.
    APPEND gt_stpo.

    AT END OF matnr.
*---->head
      gt_stko-bom_status = '01'.
      gt_stko-base_quan  = gt_ita1-base_quan.
*      gt_stko-base_unit  = 'EA'.
      APPEND gt_stko.
*------>creat-bom
      CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
        EXPORTING
          material      = gt_ita1-matnr
          plant         = gt_ita1-werks
          bom_usage     = gt_ita1-bom_usage
          valid_from    = gt_ita1-date
          i_stko        = gt_stko
          fl_bom_create = 'X'
        TABLES
          t_stpo        = gt_stpo
        EXCEPTIONS
          error         = 1
          OTHERS        = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSEIF sy-subrc = 0.
        REFRESH gt_stko.
        REFRESH gt_stpo.
      ENDIF.
    ENDAT.
  ENDLOOP.
ENDIF.

模板:

BOM資料收集模版
物料編碼 工廠 基本數量 BOM項目號 項目類別 BOM 組件 組件數量 組件廢品(%) 生產訂單發貨倉儲地點
1010000100 1200 1 0010 L 些BOM的組件 1   0003
1010000101 1200 1 0020 L 些BOM的組件 1   0003

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.