BAPI--BOM导入(感谢依风提供)
*& 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 |