标签:bom批量修改 csap_mat_bom_open csap_bom_item_mainta csap_mat_bom_close abap批量修改bom
在项目中,有时候会批量修改BOM的一些属性,利用的函数有三个,CSAP_MAT_BOM_OPEN ;CSAP_BOM_ITEM_MAINTAIN;CSAP_MAT_BOM_CLOSE,以下代码的需求是批量刷新BOM组件的展开类型,可根据需要,刷新其他的属性,也可以利用这三个函数做一些其他对BOM修改的操作的程序,分享一下,希望对用到的兄弟有帮助。
*&---------------------------------------------------------------------*
*& Report Z_BOM_BATCH_REFRESH
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_BOM_BATCH_REFRESH.
TABLES:MAST.
DATA:ITMAST TYPE STANDARD TABLE OF MAST WITH HEADER LINE,
ITSTKO TYPE STANDARD TABLE OF STKO WITH HEADER LINE,
ITSTPO TYPE STANDARD TABLE OF STPO WITH HEADER LINE.
DATA:LV_DATUV TYPE CSAP_MBOM-DATUV.
DATA:T_STPO TYPE STANDARD TABLE OF STPO_API02 WITH HEADER LINE.
TYPES:BEGIN OF TY_RESULT,
MATNR TYPE MARA-MATNR,
IDNRK TYPE STPO-IDNRK,
MESSAGE(120),
END OF TY_RESULT.
DATA:ITRESULT TYPE TABLE OF TY_RESULT WITH HEADER LINE.
DATA: BEGIN OF G_MATNR OCCURS 0,
MATNR LIKE MARA-MATNR,
END OF G_MATNR.
DATA: FILENAME TYPE STRING.
DATA: SCOUNTER,FCOUNTER,LCOUNTER TYPE I. "成功条数,失败条数,序号
DATA ISFALSE TYPE C VALUE ‘‘. "判断是否有组件异常
*&---------------------------------------------------------------------*
*& 选择屏幕
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLOCK1 WITH FRAME TITLE TEXT-001 . "‘请指定选择条件‘.
"BOM 选择条件
SELECT-OPTIONS: S_WERKS FOR MAST-WERKS, "工厂
S_MATNR FOR MAST-MATNR.
SELECTION-SCREEN END OF BLOCK BLOCK1.
*&---------------------------------------------------------------------*
*& 主程序
*&---------------------------------------------------------------------*
START-OF-SELECTION.
REFRESH ITMAST.
CLEAR ITMAST.
SELECT *
INTO TABLE ITMAST
FROM MAST
WHERE WERKS IN S_WERKS
AND ( MATNR LIKE ‘A%‘ OR MATNR LIKE ‘P%‘ OR MATNR LIKE ‘S%‘ OR MATNR LIKE ‘U%‘ OR MATNR LIKE ‘G%‘ OR MATNR LIKE ‘J%‘ OR MATNR LIKE ‘F%‘)
AND STLAN = ‘1‘
AND MATNR IN S_MATNR.
IF ITMAST[] IS NOT INITIAL.
REFRESH ITSTKO.
CLEAR ITSTKO.
SELECT *
INTO TABLE ITSTKO
FROM STKO
FOR ALL ENTRIES IN ITMAST
WHERE STLTY = ‘M‘
AND STLNR = ITMAST-STLNR
AND STLAL = ITMAST-STLAL
AND STLST = ‘1‘.
REFRESH ITSTPO.
CLEAR ITSTPO.
IF ITSTKO[] IS NOT INITIAL.
SELECT *
INTO TABLE ITSTPO
FROM STPO
FOR ALL ENTRIES IN ITSTKO
WHERE STLTY = ITSTKO-STLTY
AND STLNR = ITSTKO-STLNR.
ENDIF.
ENDIF.
IF ITSTKO[] IS NOT INITIAL.
REFRESH ITRESULT.
CLEAR ITRESULT.
LOOP AT ITMAST.
CLEAR ITSTKO.
READ TABLE ITSTKO WITH KEY STLTY = ‘M‘ STLNR = ITMAST-STLNR STLAL = ITMAST-STLAL.
IF SY-SUBRC EQ 0.
CLEAR T_STPO.
REFRESH T_STPO.
CLEAR LV_DATUV.
LV_DATUV = ITSTKO-DATUV.
* OPEN BOM
CALL FUNCTION ‘CSAP_MAT_BOM_OPEN‘
EXPORTING
MATERIAL = ITMAST-MATNR
PLANT = ITMAST-WERKS
BOM_USAGE = ‘1‘
ALTERNATIVE = ITMAST-STLAL "P_ALT
VALID_FROM = LV_DATUV"ITSTKO-DATUV "P_DATUV
* CHANGE_NO =
* REVISION_LEVEL =
* FL_NO_CHANGE_DOC = ‘ ‘
* IMPORTING
* O_STKO =
* FL_WARNING =
TABLES
T_STPO = T_STPO[]
* T_DEP_DATA =
* T_DEP_DESCR =
* T_DEP_ORDER =
* T_DEP_SOURCE =
* T_DEP_DOC =
EXCEPTIONS
ERROR = 1
OTHERS = 2
.
LOOP AT T_STPO.
IF T_STPO-COMPONENT+0(2) <> ‘YZ‘.
DELETE T_STPO.
CONTINUE.
ENDIF.
ENDLOOP.
LOOP AT T_STPO.
T_STPO-EXPL_TYPE = ‘D2‘.
MODIFY T_STPO.
CLEAR T_STPO.
ENDLOOP.
* 维护BOM
LOOP AT T_STPO.
CALL FUNCTION ‘CSAP_BOM_ITEM_MAINTAIN‘
EXPORTING
I_STPO = T_STPO "HEADLINE
* FL_DEP_ALE_CONFORM = ‘ ‘
* IMPORTING
* O_STPO =
* FL_WARNING =
* TABLES
* T_DEP_DATA =
* T_DEP_DESCR =
* T_DEP_ORDER =
* T_DEP_SOURCE =
* T_DEP_DOC =
EXCEPTIONS
ERROR = 1
OTHERS = 2
.
IF SY-SUBRC = 1.
ITRESULT-MATNR = ITMAST-MATNR.
ITRESULT-IDNRK = T_STPO-COMPONENT.
CONCATENATE ‘BOM‘ ITMAST-MATNR ‘更改失败,‘ ‘组件‘ T_STPO-COMPONENT ‘异常‘ INTO ITRESULT-MESSAGE.
APPEND ITRESULT.
CLEAR ITRESULT.
ELSEIF SY-SUBRC = 2.
ITRESULT-MATNR = ITMAST-MATNR.
ITRESULT-IDNRK = T_STPO-COMPONENT.
CONCATENATE ‘BOM‘ ITMAST-MATNR ‘更改失败,‘ ‘组件‘ T_STPO-COMPONENT ‘异常‘ INTO ITRESULT-MESSAGE.
APPEND ITRESULT.
CLEAR ITRESULT.
ELSEIF SY-SUBRC = 0.
ITRESULT-MATNR = ITMAST-MATNR.
ITRESULT-IDNRK = T_STPO-COMPONENT.
CONCATENATE ‘BOM‘ ITMAST-MATNR ‘更改成功,‘ ‘组件‘ T_STPO-COMPONENT ‘更改成功‘ INTO ITRESULT-MESSAGE.
APPEND ITRESULT.
CLEAR ITRESULT.
ENDIF.
ENDLOOP.
* 关闭BOM
CALL FUNCTION ‘CSAP_MAT_BOM_CLOSE‘
* EXPORTING
* FL_COMMIT_AND_WAIT = ‘X‘
* IMPORTING
* FL_WARNING =
EXCEPTIONS
ERROR = 1
OTHERS = 2
.
IF SY-SUBRC = 0.
ENDIF.
ENDIF.
ENDLOOP.
MESSAGE ‘BOM更改完成,更改结果保存在C盘下!‘ TYPE ‘S‘.
PERFORM FRM_DOWNLOAD.
ELSE.
MESSAGE ‘没找到相对应的BOM‘ TYPE ‘S‘.
ENDIF.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form FRM_DOWNLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_DOWNLOAD .
DATA:LV_FILENAME TYPE STRING.
CLEAR LV_FILENAME.
CONCATENATE ‘C:/ZPP110-BOM刷新展开类型结果表‘ SY-DATUM SY-UZEIT ‘.TXT‘ INTO LV_FILENAME.
CALL FUNCTION ‘GUI_DOWNLOAD‘
EXPORTING
FILENAME = LV_FILENAME
FILETYPE = ‘ASC‘
APPEND = ‘ ‘
TABLES
DATA_TAB = ITRESULT.
IF SY-SUBRC <> 0.
ENDIF.
ENDFORM.
标签:bom批量修改 csap_mat_bom_open csap_bom_item_mainta csap_mat_bom_close abap批量修改bom
原文地址:http://blog.csdn.net/champaignwolf/article/details/45894519