*&---------------------------------------------------------------------*
*& Report ZPPBOM99
*& BOM多级展开
*&---------------------------------------------------------------------*
*& 使用 函数 CS_BOM_EXPL_MAT_V2
*&
*&
*&
*&---------------------------------------------------------------------*
REPORT ZPPBOM99.
TABLES: STKO, "BOM头表
STPO, "BOM项目表
MAKT, "物料表
STAS, "BOMs - 项选择
STZU, "永久 BOM 数据
T416T,
MARA ,
MARC,
MAST, "BOM 链接物料
STPOX.
DATA:BEGIN OF SELPOOL.
INCLUDE STRUCTURE CSTMAT.
DATA:END OF SELPOOL.
DATA:DSTST_FLG LIKE CSDATA-XFELD.
DATA:BEGIN OF STB OCCURS 3000.
INCLUDE STRUCTURE STPOX.
DATA:END OF STB.
DATA:BEGIN OF STB1 OCCURS 3000.
INCLUDE STRUCTURE STPOX.
DATA:END OF STB1.
DATA:BEGIN OF MATCAT OCCURS 50.
INCLUDE STRUCTURE CSCMAT.
DATA:END OF MATCAT.
DATA TMP_STLNR LIKE STKO-STLNR .
DATA:BEGIN OF ITAB_OK OCCURS 1,
* STLAL LIKE STKO-STLAL,
* STLTY LIKE STKO-STLTY,
* STLKN LIKE STAS-STLKN,
EXSTL LIKE STZU-EXSTL, "BOM分组
MATNR LIKE MAST-MATNR, "物料号
MAKTX LIKE MAKT-MAKTX,
* DATUV LIKE STKO-DATUV, "有效起始日期
BMENG LIKE STKO-BMENG, "基本数量
BMEIN LIKE STKO-BMEIN, "BOM 基本单位
BMEIN_TXT(50) , "BOM 基本单位描述
ZTEXT LIKE STZU-ZTEXT, "bom文本
STKTX LIKE STKO-STKTX, "可选文本
* POSNR LIKE STPO-POSNR, "项目号
* IDNRK LIKE STPO-IDNRK, "物料编码
MAKTX2 LIKE MAKT-MAKTX, "物料
* MEINS LIKE STPO-MEINS, "单位
MEINS_TXT(50), "组件单位名称
* MENGE LIKE STPO-MENGE, "数量
* AVOAU LIKE STPO-AVOAU, "工序废品率
* POTX1 LIKE STPO-POTX1, "文本1
* POTX2 LIKE STPO-POTX2, "文本2
* NLFZV LIKE STPO-NLFZV, "工序提前期偏置
* NLFMV LIKE STPO-NLFMV, "工序提前期偏置的单位
NLFMV_TXT(50),"工序提前期偏置的文本
* STLNR LIKE MAST-STLNR,
MANDT LIKE MAST-MANDT,
DATUV1 LIKE STAS-DATUV, "行有效起始
DATUV2 LIKE STAS-DATUV, "行有效至
* AENNR LIKE STPO-AENNR,
* LOEKZ LIKE STKO-LOEKZ , "BOM删除标志
* SORTF TYPE SORTP,
BISMT LIKE MARA-BISMT,
TYPECODE LIKE ZMM222T-TYPECODE,
TYPENAME LIKE ZMM222T-TYPENAME,
WERKS_H LIKE MARC-WERKS.
INCLUDE STRUCTURE STPOX.
DATA: END OF ITAB_OK.
DATA: TMP_MATNR LIKE MAST-MATNR,
TMP_STLAN LIKE MAST-STLAN,
TMP_STLAL LIKE MAST-STLAL,
TMP_WERKS LIKE MAST-WERKS,
P_DATUV_LOW LIKE STKO-DATUV,
P_DATUV_HIGH LIKE STKO-DATUV.
DATA:BEGIN OF ITAB_STKO OCCURS 0,
STLNR LIKE STKO-STLNR,
STKTX LIKE STKO-STKTX,
BMENG LIKE STKO-BMENG,
BMEIN LIKE STKO-BMEIN,
DATUV LIKE STKO-DATUV,
END OF ITAB_STKO.
DATA TMP_CP LIKE MARC-MATNR.
TYPE-POOLS SLIS.
DATA PROGNAME LIKE SY-REPID.
SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-BL1 .
SELECT-OPTIONS:
P_WERKS FOR MAST-WERKS DEFAULT '8100',
P_MATNR FOR MAST-MATNR ,
P_STLAN FOR MAST-STLAN DEFAULT '1',
P_STLAL FOR MAST-STLAL DEFAULT '01',
P_AENAM FOR MAST-AENAM ,
P_ANNAM FOR MAST-ANNAM ,
P_MTART FOR MARA-MTART .
* P_BMENG FOR STKO-BMENG ,
* P_EXSTL FOR STZU-EXSTL ,
* P_LKENZ FOR STAS-LKENZ .
PARAMETERS:
P_LOW LIKE STKO-DATUV DEFAULT SY-DATUM,
P_HIGH LIKE STKO-DATUV DEFAULT SY-DATUM.
SELECTION-SCREEN END OF BLOCK BL1 .
DATA: BEGIN OF ITH OCCURS 0 ,
MATNR TYPE MATNR,
STLAN TYPE STLAN,
STLAL TYPE STLAL,
WERKS TYPE WERKS_D,
STLNR LIKE MAST-STLNR,
END OF ITH.
*INITIALIZATION.
* P_LOW = SY-DATUM.
* P_HIGH = SY-DATUM.
AT SELECTION-SCREEN.
IF SY-UCOMM = SPACE.
EXIT.
ENDIF.
START-OF-SELECTION.
P_DATUV_LOW = P_LOW.
P_DATUV_HIGH = P_HIGH.
SELECT
A~MATNR
A~STLAN
A~STLAL
A~WERKS
A~STLNR
INTO CORRESPONDING FIELDS OF TABLE ITH
FROM MAST AS A
WHERE A~WERKS IN P_WERKS
AND A~MATNR IN P_MATNR
AND A~STLAN IN P_STLAN
AND A~STLAL IN P_STLAL
AND A~ANNAM IN P_ANNAM
AND A~AENAM IN P_AENAM
AND EXISTS ( SELECT MATNR FROM MARA WHERE MATNR = A~MATNR AND MTART IN P_MTART )
ORDER BY A~MATNR.
* SELECT
* A~MATNR
* A~STLAN
* A~STLAL
* A~WERKS
* A~STLNR
* INTO (TMP_MATNR,
* TMP_STLAN,
* TMP_STLAL,
* TMP_WERKS,
* MAST-STLNR)
* FROM MAST AS A
* INNER JOIN MARA AS B ON A~MATNR = B~MATNR
* WHERE A~WERKS IN P_WERKS
* AND A~MATNR IN P_MATNR
* AND A~STLAN IN P_STLAN
* AND A~STLAL IN P_STLAL
* AND A~ANNAM IN P_ANNAM
* AND A~AENAM IN P_AENAM
* AND B~MTART IN P_MTART
* ORDER BY A~MATNR
LOOP AT ITH.
MOVE ITH-MATNR TO TMP_MATNR.
MOVE ITH-STLAN TO TMP_STLAN.
MOVE ITH-STLAL TO TMP_STLAL.
MOVE ITH-WERKS TO TMP_WERKS.
MOVE ITH-STLNR TO MAST-STLNR.
.
SELECT SINGLE STLNR
INTO (STKO-STLNR)
FROM STKO AS C
WHERE ( C~LKENZ = 'X' OR
C~LOEKZ = 'X' ) AND
C~STLNR = MAST-STLNR AND
C~STLAL IN P_STLAL .
* SELECT SINGLE STLNR
* INTO TMP_STLNR
* FROM STKO AS D
* WHERE D~STLST IN ('2','3') .
* changed by abap10 on 20180125
SELECT SINGLE MAKTX
INTO MAKT-MAKTX
FROM MAKT
WHERE MATNR = TMP_MATNR AND SPRAS = '1'." for Chinese description.
IF STKO-STLNR IS INITIAL AND TMP_STLNR IS INITIAL .
PERFORM FRM_EXPLOSION_BOM .
PERFORM APPEND_RESULT.
IF P_DATUV_HIGH > P_DATUV_LOW .
PERFORM FRM_EXPLOSION_BOM1.
PERFORM APPEND_RESULT_ADD.
ENDIF.
ENDIF.
CLEAR:TMP_MATNR,TMP_STLAN,TMP_STLNR ,
STKO-STLNR,MAST-STLAN,
TMP_STLAL,TMP_WERKS.
CLEAR MAKT-MAKTX.
* ENDSELECT .
ENDLOOP.
LOOP AT ITAB_OK.
SELECT SINGLE BISMT INTO ITAB_OK-BISMT FROM MARA WHERE MATNR = ITAB_OK-IDNRK.
SELECT SINGLE TYPECODE INTO ITAB_OK-TYPECODE FROM ZMM222 WHERE MATNR = ITAB_OK-IDNRK AND WERKS = ITAB_OK-WERKS.
SELECT SINGLE TYPENAME INTO ITAB_OK-TYPENAME FROM ZMM222T WHERE TYPECODE = ITAB_OK-TYPECODE.
MOVE ITAB_OK-BMEIN TO ITAB_OK-BMEIN_TXT.
PERFORM F_GET_UNIT USING ITAB_OK-BMEIN_TXT.
MOVE ITAB_OK-MEINS TO ITAB_OK-MEINS_TXT.
PERFORM F_GET_UNIT USING ITAB_OK-MEINS_TXT.
MOVE ITAB_OK-NLFMV TO ITAB_OK-NLFMV_TXT.
PERFORM F_GET_UNIT USING ITAB_OK-NLFMV_TXT.
PERFORM F_CUT_ZERO USING ITAB_OK-MATNR.
PERFORM F_CUT_ZERO USING ITAB_OK-IDNRK.
MODIFY ITAB_OK.
ENDLOOP.
*PERFORM FRM_WRITEDATA .
PERFORM FRM_WRITEDATA2 .
*&---------------------------------------------------------------------*
*& Form FRM_WRITEDATA2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FRM_WRITEDATA2 .
DATA: STR TYPE STRING.
STR = ''.
CONCATENATE STR 'WERKS_H,工厂|' INTO STR.
CONCATENATE STR 'STLAL,可选的BOM|' INTO STR.
CONCATENATE STR 'STLAN,BOM用途|' INTO STR.
CONCATENATE STR 'STLTY,BOM 类别|' INTO STR.
CONCATENATE STR 'STLKN,项目节点|' INTO STR.
CONCATENATE STR 'EXSTL,BOM 分组|' INTO STR.
CONCATENATE STR 'MATNR,物料号|' INTO STR.
CONCATENATE STR 'MAKTX,物料描述|' INTO STR.
CONCATENATE STR 'DATUV,有效起始日|' INTO STR.
CONCATENATE STR 'BMENG,基本数量|' INTO STR.
CONCATENATE STR 'BMEIN_TXT,基本计量单位|' INTO STR.
CONCATENATE STR 'ZTEXT,BOM 文本|' INTO STR.
CONCATENATE STR 'STKTX,可选文本|' INTO STR.
CONCATENATE STR 'POSNR,项目编号|' INTO STR.
CONCATENATE STR 'IDNRK,组件|' INTO STR.
CONCATENATE STR 'MAKTX2,物料描述|' INTO STR.
CONCATENATE STR 'MEINS_TXT,组件单位|' INTO STR.
CONCATENATE STR 'MENGE,组件数量|' INTO STR.
CONCATENATE STR 'AUSCH,部件废品(%)|' INTO STR.
CONCATENATE STR 'BEIKZ,物料供应标识符 |' INTO STR.
CONCATENATE STR 'LGPRO,发货库存地点|' INTO STR.
CONCATENATE STR 'LGORT,生产仓储地点|' INTO STR.
CONCATENATE STR 'ALPGR,替代项目:组|' INTO STR.
CONCATENATE STR 'ALPRF,替代项目:评比定单 |' INTO STR.
CONCATENATE STR 'ALPST,替代项目:策略 |' INTO STR.
CONCATENATE STR 'EWAHR,使用可能性按 % (可选项目)|' INTO STR.
CONCATENATE STR 'SANKA,与成本核算相关标志 |' INTO STR.
CONCATENATE STR 'AVOAU,工序废品按 %|' INTO STR.
CONCATENATE STR 'POTX1,项目文本|' INTO STR.
CONCATENATE STR 'POTX2,项目文本 2|' INTO STR.
CONCATENATE STR 'NLFZV,工序提前期偏置|' INTO STR.
CONCATENATE STR 'NLFMV_TXT,工序提前期偏移量单位|' INTO STR.
CONCATENATE STR 'STLNR,物料单|' INTO STR.
*CONCATENATE STR 'MANDT,客户端|' INTO STR.
CONCATENATE STR 'DATUV1,有效起始日|' INTO STR.
CONCATENATE STR 'DATUV2,有效起始日|' INTO STR.
CONCATENATE STR 'AENNR,更改编号|' INTO STR.
CONCATENATE STR 'LOEKZ,删除标志|' INTO STR.
CONCATENATE STR 'SORTF,排序字段|' INTO STR.
CONCATENATE STR 'BISMT,旧物料号|' INTO STR.
CONCATENATE STR 'TYPENAME,组件优选类别|' INTO STR.
* CALL FUNCTION 'ZLXS_ALV'
* EXPORTING
* I_TITLE = ''
* FIELD_LIST = STR
* TABLES
* I_ITAB = ITAB_OK.
PERFORM SHOW_ALV TABLES ITAB_OK USING '' STR .
ENDFORM. "FRM_WRITEDATA2
*&---------------------------------------------------------------------*
*& Form APPEND_RESULT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM APPEND_RESULT.
LOOP AT STB.
MOVE-CORRESPONDING STB TO ITAB_OK.
* ITAB_OK-STLAL = STB-STLAL.
* ITAB_OK-STLTY = STB-STLTY.
* ITAB_OK-STLKN = STB-STLKN.
* ITAB_OK-EXSTL = STB-EXSTL, "BOM分组
ITAB_OK-MATNR = TMP_MATNR. "物料号
ITAB_OK-MAKTX = MAKT-MAKTX.
ITAB_OK-DATUV = STB-DATUV. "有效起始日期
ITAB_OK-WERKS_H = TMP_WERKS.
* ITAB_OK-BMENG = STB-XMENG. "MENGE. "基本数量
* ITAB_OK-BMEIN = STB-XMEIN. "BOM 基本单位
SELECT SINGLE EXSTL ZTEXT
INTO (ITAB_OK-EXSTL,ITAB_OK-ZTEXT)
FROM STZU
WHERE STLNR = STB-STLNR.
DATA:TMP_DATUV LIKE STKO-DATUV.
CLEAR:TMP_DATUV.
SELECT MAX( DATUV ) AS DATUV INTO TMP_DATUV
FROM STKO
WHERE STLNR = STB-STLNR.
SELECT SINGLE STKTX BMENG BMEIN
INTO (ITAB_OK-STKTX,ITAB_OK-BMENG,ITAB_OK-BMEIN)
FROM STKO
WHERE STLNR = STB-STLNR AND DATUV = TMP_DATUV .
* ITAB_OK-POSNR = STB-POSNR. "项目号
* ITAB_OK-IDNRK = STB-IDNRK. "物料编码
ITAB_OK-MAKTX2 = STB-OJTXP. "物料
* ITAB_OK-MEINS = STB-MEINS. "组件单位
* ITAB_OK-MENGE = STB-MENGE. "组件数量
*
* ITAB_OK-AVOAU = STB-AVOAU. "工序废品率
* ITAB_OK-POTX1 = STB-POTX1. "文本1
* ITAB_OK-POTX2 = STB-POTX2. "文本2
* ITAB_OK-NLFZV = STB-NLFZV. "工序提前期偏置
* ITAB_OK-NLFMV = STB-NLFMV. "工序提前期偏置的单位
*
* ITAB_OK-STLNR = STB-STLNR.
ITAB_OK-MANDT = SY-MANDT.
ITAB_OK-DATUV1 = STB-DATUV. "行有效起始
ITAB_OK-DATUV2 = STB-DATUB. "行有效至
* ITAB_OK-AENNR = STB-AENNR .
* ITAB_OK-LOEKZ = STB-LOEKZ .
APPEND ITAB_OK.
CLEAR:ITAB_OK,STB.
ENDLOOP.
* IF ITAB_OK[] IS NOT INITIAL.
* SELECT STLNR STKTX BMENG BMEIN DATUV
* INTO CORRESPONDING FIELDS OF TABLE ITAB_STKO
* FROM STKO
* FOR ALL ENTRIES IN ITAB_OK
* WHERE STLNR = ITAB_OK-STLNR.
*
* ENDIF.
*
* SORT ITAB_STKO BY STLNR
* ASCENDING
*DATUV
*DESCENDING.
* DELETE ADJACENT DUPLICATES FROM ITAB_STKO
* COMPARING STLNR .
*
* LOOP AT ITAB_OK.
* READ TABLE ITAB_STKO WITH KEY STLNR = ITAB_OK-STLNR.
* IF SY-SUBRC EQ 0.
* ITAB_OK-STKTX = ITAB_STKO-STKTX.
* ITAB_OK-BMENG = ITAB_STKO-BMENG.
* ITAB_OK-BMEIN = ITAB_STKO-BMEIN .
* MODIFY ITAB_OK.
*
* ENDIF.
* ENDLOOP.
* clear:ITAB_STKO.
ENDFORM. " APPEND_RESULT
*&---------------------------------------------------------------------*
*& Form APPEND_RESULT_ADD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM APPEND_RESULT_ADD.
LOOP AT STB.
LOOP AT STB1 WHERE IDNRK = STB-IDNRK.
DELETE STB1 INDEX SY-TABIX .
ENDLOOP.
ENDLOOP.
LOOP AT STB1.
MOVE-CORRESPONDING STB1 TO ITAB_OK.
* ITAB_OK-STLAL = STB1-STLAL.
* ITAB_OK-STLTY = STB1-STLTY.
* ITAB_OK-STLKN = STB1-STLKN.
* ITAB_OK-EXSTL = STB-EXSTL, "BOM分组
ITAB_OK-MATNR = TMP_MATNR. "物料号
ITAB_OK-MAKTX = MAKT-MAKTX.
ITAB_OK-DATUV = STB-DATUV. "有效起始日期
ITAB_OK-WERKS_H = TMP_WERKS.
* ITAB_OK-BMENG = STB-XMENG. "MENGE. "基本数量
* ITAB_OK-BMEIN = STB-XMEIN. "BOM 基本单位
SELECT SINGLE EXSTL ZTEXT
INTO (ITAB_OK-EXSTL,ITAB_OK-ZTEXT)
FROM STZU
WHERE STLNR = STB1-STLNR.
DATA:TMP_DATUV LIKE STKO-DATUV.
CLEAR:TMP_DATUV.
SELECT MAX( DATUV ) AS DATUV INTO TMP_DATUV
FROM STKO
WHERE STLNR = STB-STLNR.
SELECT SINGLE STKTX BMENG BMEIN
INTO (ITAB_OK-STKTX,ITAB_OK-BMENG,ITAB_OK-BMEIN)
FROM STKO
WHERE STLNR = STB1-STLNR AND DATUV = TMP_DATUV.
* ITAB_OK-POSNR = STB1-POSNR. "项目号
* ITAB_OK-IDNRK = STB1-IDNRK. "物料编码
ITAB_OK-MAKTX2 = STB1-OJTXP. "物料
* ITAB_OK-MEINS = STB1-MEINS. "组件单位
* ITAB_OK-MENGE = STB1-MENGE. "组件数量
*
* ITAB_OK-AVOAU = STB1-AVOAU. "工序废品率
* ITAB_OK-POTX1 = STB1-POTX1. "文本1
* ITAB_OK-POTX2 = STB1-POTX2. "文本2
* ITAB_OK-STLNR = STB1-STLNR.
ITAB_OK-MANDT = SY-MANDT.
ITAB_OK-DATUV1 = STB1-DATUV. "行有效起始
ITAB_OK-DATUV2 = STB1-DATUB. "行有效至
* ITAB_OK-AENNR = STB1-AENNR .
* ITAB_OK-LOEKZ = STB1-LOEKZ.
APPEND ITAB_OK.
CLEAR:ITAB_OK,STB1.
ENDLOOP.
ENDFORM. " APPEND_RESULT
*得到成品的bom
FORM FRM_EXPLOSION_BOM.
UNPACK TMP_MATNR TO TMP_CP.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP01'
DATUV = P_DATUV_LOW "SY-DATUM
* DATUB = P_DATUV_HIGH
EHNDL = '1'
MEHRS = '' "展开一层bom
MMORY = '1'
MTNRV = TMP_CP
STLAL = TMP_STLAL
STLAN = TMP_STLAN
WERKS = TMP_WERKS
DELNL = ' '
IMPORTING
TOPMAT = SELPOOL
DSTST = DSTST_FLG
TABLES
STB = STB
MATCAT = MATCAT
EXCEPTIONS
ALT_NOT_FOUND = 1
* CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
* MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
* CONVERSION_ERROR = 8
OTHERS = 9.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "FRM_Explosion_Bom
*得到成品的bom
FORM FRM_EXPLOSION_BOM1.
UNPACK TMP_MATNR TO TMP_CP.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP01'
DATUV = P_DATUV_HIGH "SY-DATUM
* DATUB = P_DATUV_HIGH
EHNDL = '1'
MEHRS = '' "展开一层bom
MMORY = '1'
MTNRV = TMP_CP
STLAL = TMP_STLAL
STLAN = TMP_STLAN
WERKS = TMP_WERKS
DELNL = ' '
IMPORTING
TOPMAT = SELPOOL
DSTST = DSTST_FLG
TABLES
STB = STB1
MATCAT = MATCAT
EXCEPTIONS
ALT_NOT_FOUND = 1
* CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
* MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
* CONVERSION_ERROR = 8
OTHERS = 9.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "FRM_Explosion_Bom1
*FORM f_cut_zero USING vi_output .
* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
* EXPORTING
* input = vi_output
* IMPORTING
* output = vi_output.
*ENDFORM.
INCLUDE ZRPT_FUN.