Function: CS_BOM_EXPL_MAT_V2
STB內表的componet quality (count), 有mnglg和mngko, 一般取後者,更準確些.
還要注意 CALL
原代码:
*&---------------------------------------------------------------------*
*& Report Z_PP_FIND_MULTBOM_MAT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
*-----------------------------------------------------------------------
* Identification
* Modul-Name : ZPPPR005
* Author : Samuel Liu Atos Origin Modified by:wiele
* Creation date : 11.09.2006 Modified on: 01.2005
* Owner : PP module
* Dev. under SAP : ECC6.0
* Description : MRP物料清单
*-----------------------------------------------------------------------
REPORT Z_PP_FIND_MULTBOM_MAT NO STANDARD PAGE HEADING
MESSAGE-ID ymm
LINE-COUNT 81
LINE-SIZE 650. "207
************************************************************************
*INCLUDE
************************************************************************
INCLUDE <LINE>.
************************************************************************
*DDIC
************************************************************************
TABLES:MARA,MARC,BKPF,MARD,MAST.
************************************************************************
*ALV层级关系定义
************************************************************************
TYPE-POOLS: SLIS.
DATA: WT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WT_LAYOUT TYPE SLIS_LAYOUT_ALV,
WT_EVENTS TYPE SLIS_T_EVENT.
DATA: WS_EVENTS LIKE LINE OF WT_EVENTS.
************************************************************************
*DATA
************************************************************************
DATA: BEGIN OF WT_ITAB OCCURS 10,
MATNR LIKE MARA-MATNR, "父件物料编码
IDNRK LIKE MARA-MATNR, "子件物料编码
OJTXP LIKE MAKT-MAKTX, "子件物料描述
MEINS LIKE MARA-MEINS, "子件计量单位
MNGLG LIKE STPOX-MNGLG,"子件用量
LABST LIKE MARD-LABST, "子件库存量
LABST_01 LIKE MARD-LABST, "附加工厂一库存量
LABST_02 LIKE MARD-LABST. "附加工厂二库存量
DATA: END OF WT_ITAB.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: P_WERKS LIKE MAST-WERKS OBLIGATORY DEFAULT 'FZ01'.
SELECT-OPTIONS: P_MATNR FOR MAST-MATNR. "物料号
PARAMETERS: P_STLAN LIKE MAST-STLAN DEFAULT '1',"BOM 用途
P_BMENG LIKE STKO-BMENG,"需求数量
x_werks LIKE marc-werks OBLIGATORY DEFAULT 'G001',
z_werks LIKE marc-werks OBLIGATORY DEFAULT 'G001'.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: P_SING RADIOBUTTON GROUP RAD1 DEFAULT 'X'.
PARAMETERS: P_MULT RADIOBUTTON GROUP RAD1.
SELECTION-SCREEN END OF BLOCK b2.
INITIALIZATION.
START-OF-SELECTION.
*得到物料的子项目
PERFORM GET_DATA.
*打印该BOM的数据
PERFORM PRINT_ALV_DATA.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
*数据定义
DATA: BEGIN OF WTL_MATNR OCCURS 0,
WERKS LIKE MARC-WERKS,
MATNR LIKE MARA-MATNR.
DATA: END OF WTL_MATNR.
*展开BOM的字阶
DATA: WTL_STB LIKE STPOX OCCURS 10 WITH HEADER LINE.
SELECT WERKS MATNR
APPENDING CORRESPONDING FIELDS OF TABLE WTL_MATNR
FROM MAST
WHERE MATNR IN P_MATNR
AND WERKS EQ P_WERKS.
*根据选项产生不同BOM的结构
*展多层BOM
IF P_MULT EQ 'X'.
LOOP AT WTL_MATNR.
REFRESH WTL_STB.
CLEAR WTL_STB.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP02' "BOM Application
DATUV = SY-DATUM
EMENG = P_BMENG "BASE QUANTITY
MTNRV = WTL_MATNR-MATNR "MATERAIL NUMBER
STLAN = P_STLAN
* STLAL = P_STLAL
* CUOBJ = CUOBJ
MKTLS = 'X'
MEHRS = 'X'
WERKS = WTL_MATNR-WERKS "'PDGM'
TABLES
STB = WTL_STB
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
OTHERS = 8.
IF SY-SUBRC EQ 0.
LOOP AT WTL_STB.
WT_ITAB-MATNR = WTL_MATNR-MATNR.
WT_ITAB-OJTXP = WTL_STB-OJTXP.
WT_ITAB-IDNRK = WTL_STB-IDNRK.
WT_ITAB-MEINS = WTL_STB-MEINS.
WT_ITAB-MNGLG = WTL_STB-MNGLG.
* P_ITAB_ITEM-STLAL = -STLAL.
* P_ITAB_ITEM-STUFE = STB-STUFE.
*查找物料的库存
PERFORM GET_KCDATA USING WT_ITAB-IDNRK
CHANGING WT_ITAB-LABST
WT_ITAB-LABST_01
WT_ITAB-LABST_02.
APPEND WT_ITAB.
CLEAR WT_ITAB.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDIF.
*展单层BOM
IF P_SING EQ 'X'.
LOOP AT WTL_MATNR.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP02' "BOM Application
DATUV = SY-DATUM
EMENG = P_BMENG "BASE QUANTITY
MTNRV = WTL_MATNR-MATNR "MATERAIL NUMBER
STLAN = P_STLAN
* STLAL = P_STLAL
* CUOBJ = CUOBJ
* MKTLS = 'X'
* MEHRS = 'X'
WERKS = WTL_MATNR-WERKS "'PDGM'
TABLES
STB = WTL_STB
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
OTHERS = 8.
IF SY-SUBRC EQ 0.
LOOP AT WTL_STB.
WT_ITAB-MATNR = WTL_MATNR-MATNR.
WT_ITAB-OJTXP = WTL_STB-OJTXP.
WT_ITAB-IDNRK = WTL_STB-IDNRK.
WT_ITAB-MEINS = WTL_STB-MEINS.
WT_ITAB-MNGLG = WTL_STB-MNGLG.
* P_ITAB_ITEM-STLAL = -STLAL.
* P_ITAB_ITEM-STUFE = STB-STUFE.
PERFORM GET_KCDATA USING WT_ITAB-IDNRK
CHANGING WT_ITAB-LABST
WT_ITAB-LABST_01
WT_ITAB-LABST_02.
APPEND WT_ITAB.
CLEAR WT_ITAB.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PRINT_ALV_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRINT_ALV_DATA .
DATA: WLT_FIELDCAT LIKE LINE OF WT_FIELDCAT.
* PERFORM FILL_EVENTCAT_ALV.
CLEAR WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'MATNR'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '父件物料编码'.
APPEND WLT_FIELDCAT TO WT_FIELDCAT.
CLEAR WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'IDNRK'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件物料编码'.
APPEND WLT_FIELDCAT TO WT_FIELDCAT.
CLEAR WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'OJTXP'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件物料描述'.
APPEND WLT_FIELDCAT TO WT_FIELDCAT.
CLEAR WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'MEINS'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '单位'.
APPEND WLT_FIELDCAT TO WT_FIELDCAT.
CLEAR WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'MNGLG'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件用量'.
APPEND WLT_FIELDCAT TO WT_FIELDCAT.
CLEAR WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = ' LABST'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件库存量'.
APPEND WLT_FIELDCAT TO WT_FIELDCAT.
CLEAR WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'LABST_01'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '附加工厂一库存量'.
APPEND WLT_FIELDCAT TO WT_FIELDCAT.
CLEAR WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'LABST_02'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '附加工厂二库存量'.
APPEND WLT_FIELDCAT TO WT_FIELDCAT.
WT_LAYOUT-ZEBRA = 'X'.
WT_LAYOUT-F2CODE = '&ETA'.
WT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
IS_LAYOUT = WT_LAYOUT
I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
* I_callback_pf_status_set = 'STANDARD1'
I_DEFAULT = 'X'
I_SAVE = 'X'
* I_CALLBACK_USER_COMMAND = 'PROCESS_USER_COMMAND'
IT_FIELDCAT = WT_FIELDCAT[]
IT_EVENTS = WT_EVENTS
TABLES
T_OUTTAB = WT_ITAB.
ENDFORM. " PRINT_ALV_DATA
*---------------------------------------------------------------------*
* FORM ALV_TOP_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> R_DYDO *
* --> TO *
* --> CL_DD_DOCUMENT *
*---------------------------------------------------------------------*
FORM ALV_TOP_OF_PAGE USING CL_DD TYPE REF TO CL_DD_DOCUMENT.
* SET PF-STATUS 'STANDARD1'.
DATA: M_P TYPE I.
DATA: M_BUFF TYPE STRING.
*表头其实完全可以是一个html文件,自己使用html语言进行格式控制
M_BUFF = '<html>'.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
* CONCATENATE '<body bgcolor="#008000">' INTO M_BUFF.
*
** M_BUFF = '<body background="BACKGROUND.GIF">'.
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
M_BUFF = '<center><font size="5">库存配套分析表</font></center>'.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
** CONCATENATE '客户名称:' KNA1-NAME1 KNA1-NAME2 '<BR>' INTO M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
*
** CONCATENATE 'SAP报价单号:' WT_VBAP_01-VBELN '<BR>' INTO M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
* CONCATENATE '字段说明:1)交货已完成:X代表已经全部服务确认' '<BR>'
*INTO M_BUFF.
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
**文字移动
* CONCATENATE '<marquee
*behavior=alternate>啦啦啦,我来回走耶!</marquee> ' '<BR>' INTO
*M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
* CONCATENATE '选择参数:为1 删除交货已完成 为2 删除相等无误的 为3
*删除完成以及无误的' '<BR>' INTO M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
* SELECT SINGLE * FROM T001
* WHERE BUKRS = WS_VBELN
* AND SPRAS = '1'.
*
CONCATENATE '报表日期 :' SY-DATUM '<BR>' INTO M_BUFF.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
DATA: WTL_NAME1 LIKE T001W-NAME1.
CLEAR WTL_NAME1.
SELECT SINGLE NAME1
INTO WTL_NAME1
FROM T001W
WHERE WERKS EQ P_WERKS.
CONCATENATE '工 厂:' P_WERKS WTL_NAME1 '<BR>' INTO M_BUFF.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
DATA: WTL_NAME2 LIKE T001W-NAME1.
CLEAR WTL_NAME2.
SELECT SINGLE NAME1
INTO WTL_NAME2
FROM T001W
WHERE WERKS EQ X_WERKS.
CONCATENATE '附加工厂1:' X_WERKS WTL_NAME2 '<BR>' INTO M_BUFF.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
DATA: WTL_NAME3 LIKE T001W-NAME1.
CLEAR WTL_NAME3.
SELECT SINGLE NAME1
INTO WTL_NAME3
FROM T001W
WHERE WERKS EQ Z_WERKS.
CONCATENATE '附加工厂2:' Z_WERKS WTL_NAME3 '<BR>' INTO M_BUFF.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
* M_BUFF = '</body>'.
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
*
M_BUFF = '</html>'.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = M_BUFF
CHANGING
POSITION = M_P.
ENDFORM. "ALV_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form GET_KCDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WT_ITAB_IDNRK text
* <--P_WT_ITAB_LABST text
* <--P_WT_ITAB_LABST_01 text
* <--P_WT_ITAB_LABST_02 text
*----------------------------------------------------------------------*
FORM GET_KCDATA USING P_WT_ITAB_IDNRK
CHANGING P_WT_ITAB_LABST
P_WT_ITAB_LABST_01
P_WT_ITAB_LABST_02.
DATA: WTL_RESULT TYPE C.
CLEAR WTL_RESULT.
DATA: BEGIN OF WTL_ITAB_101 OCCURS 0,
MANDT LIKE MARD-MANDT,
MATNR LIKE MARD-MATNR,
WERKS LIKE MARD-WERKS,
LGORT LIKE MARD-LGORT,
LABST LIKE MARD-LABST,
INSME LIKE MARD-INSME,
DISKZ LIKE MARD-DISKZ,
KLABS LIKE MARD-KLABS.
DATA: END OF WTL_ITAB_101.
SELECT MANDT MATNR WERKS LGORT INSME LABST DISKZ klabs
FROM MARD
INTO CORRESPONDING FIELDS OF TABLE WTL_ITAB_101
WHERE WERKS EQ p_werks
AND MATNR = P_WT_ITAB_IDNRK
AND DISKZ <> '1'
ORDER BY MATNR .
P_WT_ITAB_LABST = 0.
* KSTOR = 0.
IF WTL_ITAB_101[] IS INITIAL.
P_WT_ITAB_LABST = 0.
* KSTOR = 0.
ENDIF.
LOOP AT WTL_ITAB_101 .
P_WT_ITAB_LABST = P_WT_ITAB_LABST + WTL_ITAB_101-LABST +
WTL_ITAB_101-klabs.
* KSTOR = KSTOR + ITAB_101-LABST + ITAB_101-klabs.
ENDLOOP.
*检查物料的工厂是否存在
PERFORM CHECK_MAT USING P_WT_ITAB_IDNRK
X_WERKS
CHANGING WTL_RESULT.
*检查参考工厂1的库存
IF WTL_RESULT NE 'X'.
SELECT MANDT MATNR WERKS LGORT INSME LABST DISKZ klabs
FROM MARD
INTO CORRESPONDING FIELDS OF TABLE WTL_ITAB_101
WHERE WERKS EQ X_werks
AND MATNR = P_WT_ITAB_IDNRK
AND DISKZ <> '1'
ORDER BY MATNR .
IF WTL_ITAB_101[] IS INITIAL.
P_WT_ITAB_LABST_01 = 0.
* KSTOR = 0.
ENDIF.
LOOP AT WTL_ITAB_101.
P_WT_ITAB_LABST_01 = P_WT_ITAB_LABST_01 + WTL_ITAB_101-LABST +
WTL_ITAB_101-klabs.
* KSTOR = KSTOR + ITAB_101-LABST + ITAB_101-klabs.
ENDLOOP.
ENDIF.
*检查参考工厂2
PERFORM CHECK_MAT USING P_WT_ITAB_IDNRK
Z_WERKS
CHANGING WTL_RESULT.
*从参考工厂2中取数据
IF WTL_RESULT NE 'X'.
SELECT MANDT MATNR WERKS LGORT INSME LABST DISKZ klabs
FROM MARD
INTO CORRESPONDING FIELDS OF TABLE WTL_ITAB_101
WHERE WERKS EQ Z_werks
AND MATNR = P_WT_ITAB_IDNRK
AND DISKZ <> '1'
ORDER BY MATNR .
IF WTL_ITAB_101[] IS INITIAL.
P_WT_ITAB_LABST_02 = 0.
* KSTOR = 0.
ENDIF.
LOOP AT WTL_ITAB_101.
P_WT_ITAB_LABST_02 = P_WT_ITAB_LABST_02 + WTL_ITAB_101-LABST +
WTL_ITAB_101-klabs.
* KSTOR = KSTOR + ITAB_101-LABST + ITAB_101-klabs.
ENDLOOP.
ENDIF.
ENDFORM. " GET_KCDATA
*&---------------------------------------------------------------------*
*& Form CHECK_MAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_CH_ITEM text
* -->P_X_WERKS text
* <--P_WTL_RESULT text
*----------------------------------------------------------------------*
FORM CHECK_MAT USING P_CH_ITEM
P_X_WERKS
CHANGING P_WTL_RESULT.
IF P_X_WERKS NE P_WERKS.
SELECT SINGLE *
FROM MARC
WHERE MATNR EQ P_CH_ITEM
AND WERKS EQ P_X_WERKS.
IF SY-SUBRC NE SPACE.
P_WTL_RESULT = 'X'.
ENDIF.
ELSE.
P_WTL_RESULT = 'X'.
ENDIF.
ENDFORM. " CHECK_MAT
----------------------------------------------------------
关键代码如下:
*&
REPORT
SELECTION-SCREEN
PARAMETERS:
SELECT-OPTIONS:
PARAMETERS:
SELECTION-SCREEN
SELECTION-SCREEN
PARAMETERS:
PARAMETERS:
SELECTION-SCREEN
INITIALIZATION.
START-OF-SELECTION.
*得到物料的子项目
*打印该BOM的数据
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&
*----------------------------------------------------------------------*
FORM
*数据定义
*展开BOM的字阶
*根据选项产生不同BOM的结构
*展多层BOM