*-----------------------------------------------------------------------
REPORT zppr032 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 0,
matnr LIKE mast-matnr,
ustufe(11) TYPE c,
stufe LIKE stpox-stufe, " 层次
posnr LIKE stpox-posnr, "项目号
idnrk LIKE stpox-idnrk, "子件物料编码
ojtxp LIKE stpox-ojtxp, "子件物料描述
mtart LIKE stpox-mtart,"物料类别
dumps LIKE stpox-dumps,"虚拟项目标识
* MNGKO LIKE STPOX-MNGKO,"组件数量
menge LIKE stpox-menge,"组件数量,
mngko LIKE stpox-mngko, "以组件计量单位为准的已计算的组件数量 ,MNGLG
* mngko TYPE p DECIMALS 6,
mmein LIKE stpox-mmein, "单位
potx2 LIKE stpox-potx2,"行2
potx1 LIKE stpox-potx1,"客户物料编码
blatt LIKE stpox-blatt,"SAF
datuv LIKE stpox-datuv,
datub LIKE stpox-datub,
ebort(500) TYPE c,
werks LIKE stpox-werks,
stlnr LIKE stpox-stlnr,
stlkn LIKE stpox-stlkn,
spart LIKE mara-spart.
DATA: END OF wt_itab.
DATA test TYPE c.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
* PARAMETERS: p_matnr LIKE mast-matnr OBLIGATORY. "物料号
SELECT-OPTIONS: p_matnr FOR mast-matnr.
SELECT-OPTIONS: p_werks FOR mast-werks."工厂
PARAMETERS: p_stlal LIKE stko-stlal DEFAULT '01'.
PARAMETERS: p_capid LIKE tc04-capid DEFAULT 'PP01'.
*call selection-screen 100.
SELECTION-SCREEN END OF BLOCK b1.
*selection-screen end of screen 100.
*SELECTION-SCREEN BEGIN OF screen 100.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_datuv LIKE rc29l-datuv DEFAULT sy-datum OBLIGATORY.
PARAMETERS: p_aennr LIKE stpo-aennr. "AENR
PARAMETERS: p_revlv LIKE rc29l-revlv.
PARAMETERS: p_bmeng LIKE stko-bmeng DEFAULT 1."需求数量 "STKO BOM表头
PARAMETERS: p_stlan LIKE mast-stlan DEFAULT '1'NO-DISPLAY."BOM 用途
SELECTION-SCREEN END OF BLOCK b2.
*AT SELECTION-SCREEN OUTPUT.
* LOOP AT SCREEN.
* if not P_aennr is initial.
* message 'no data'type 'I'.
* endif.
*
* ENDLOOP.
INITIALIZATION.
START-OF-SELECTION.
*得到物料的子项目
PERFORM get_data.
*打印该BOM的数据
PERFORM print_alv_data.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_data .
*数据定义
DATA: BEGIN OF wtl_matnr OCCURS 0,
werks LIKE marc-werks,
matnr LIKE mara-matnr.
* BMENG LIKE stko-bmeng."需求数量
DATA: END OF wtl_matnr.
DATA: wtl_stb LIKE stpox OCCURS 50 WITH HEADER LINE.
DATA: wa_tab1 LIKE wt_itab OCCURS 50 WITH HEADER LINE.
DATA: BEGIN OF matcat OCCURS 50.
INCLUDE STRUCTURE cscmat.
DATA: END OF matcat.
DATA: BEGIN OF mats.
INCLUDE STRUCTURE cscmat.
DATA: END OF mats.
*展开BOM的字阶
SELECT mast~werks mast~matnr
APPENDING CORRESPONDING FIELDS OF TABLE wtl_matnr
FROM mast
WHERE matnr IN p_matnr
AND werks IN p_werks
AND stlal EQ p_stlal .
*根据选项产生不同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 = 'PP01' "BOM Application
datuv = p_datuv "SY-DATUM
emeng = p_bmeng "BASE QUANTITY
* emeng = wtl_matnr-BMENG "BASE QUANTITY
* AENNR = P_AENNR
* REVLV = P_REVLV
mtnrv = wtl_matnr-matnr "MATERAIL NUMBER
stlan = p_stlan
stlal = p_stlal "可选BOM
mktls = 'X'
mehrs = 'X'
werks = wtl_matnr-werks "'PDGM'
* STLAL = P_STLAL
* CUOBJ = CUOBJ
TABLES
stb = wtl_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
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.
wt_itab-stufe = wtl_stb-stufe. " 层次
wt_itab-posnr = wtl_stb-posnr. "项目号
wt_itab-idnrk = wtl_stb-idnrk. "子件物料编码
wt_itab-ojtxp = wtl_stb-ojtxp. "子件物料描述
wt_itab-mtart = wtl_stb-mtart."物料类别
wt_itab-dumps = wtl_stb-dumps."虚拟项目标识
wt_itab-menge = wtl_stb-menge."组件数量,以基本计量单位为准的已计算的组件数量
wt_itab-mngko = wtl_stb-mngko. "以组件计量单位为准的已计算的组件数量
* WT_ITAB-MNGKO = WTL_STB-MNGKO / wtl_matnr-BMENG ."MNGLG wtl_matnr
wt_itab-mmein = wtl_stb-mmein. ""基本计量单位
wt_itab-potx2 = wtl_stb-potx2."行2
wt_itab-potx1 = wtl_stb-potx1."客户物料编码
wt_itab-blatt = wtl_stb-blatt."SAF
* LOC(40) TYPE C,
wt_itab-datuv = wtl_stb-datuv.
wt_itab-datub = wtl_stb-datub.
wt_itab-werks = wtl_stb-werks.
wt_itab-stlnr = wtl_stb-stlnr.
wt_itab-stlkn = wtl_stb-stlkn.
*查找物料的库存
IF wt_itab-werks ='3120' OR wt_itab-werks = '3130'.
SELECT SINGLE spart FROM mara
INTO wt_itab-spart
WHERE mara~matnr = wt_itab-idnrk.
ENDIF.
PERFORM get_othdata USING wt_itab-stlnr wt_itab-stlkn
CHANGING wt_itab-ebort wt_itab-mngko.
PERFORM format_stufe USING wt_itab-stufe
CHANGING wt_itab-ustufe .
APPEND wt_itab.
CLEAR wt_itab.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form print_alv_data
*&---------------------------------------------------------------------*
* 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 = 'MODEL'.
wlt_fieldcat-no_zero = 'X'.
wlt_fieldcat-intlen = '18'.
APPEND wlt_fieldcat TO wt_fieldcat.
CLEAR wlt_fieldcat.
wlt_fieldcat-fieldname = 'USTUFE'.
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 = 'POSNR'.
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 = '物料编码'.
wlt_fieldcat-intlen = '18'.
wlt_fieldcat-no_zero = 'X'.
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 = 'MTART'.
wlt_fieldcat-tabname = 'WT_ITAB'.
wlt_fieldcat-no_out = ' '.
wlt_fieldcat-seltext_l = 'MTyp'.
APPEND wlt_fieldcat TO wt_fieldcat.
CLEAR wlt_fieldcat.
wlt_fieldcat-fieldname = 'DUMPS'.
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 = 'MENGE'.
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 = 'MNGKO'.
wlt_fieldcat-tabname = 'WT_ITAB'.
wlt_fieldcat-no_out = ' '.
wlt_fieldcat-seltext_l = '组件数量(CUn)'.
wlt_fieldcat-decimals_out = 3.
APPEND wlt_fieldcat TO wt_fieldcat.
CLEAR wlt_fieldcat.
wlt_fieldcat-fieldname = 'MMEIN'.
wlt_fieldcat-tabname = 'WT_ITAB'.
wlt_fieldcat-ddictxt = 'L'.
wlt_fieldcat-no_out = ' '.
wlt_fieldcat-seltext_l = '单位'.
APPEND wlt_fieldcat TO wt_fieldcat.
CLEAR wlt_fieldcat.
wlt_fieldcat-fieldname = 'POTX2'.
wlt_fieldcat-tabname = 'WT_ITAB'.
wlt_fieldcat-no_out = ' '.
wlt_fieldcat-seltext_l = '行2'.
APPEND wlt_fieldcat TO wt_fieldcat.
CLEAR wlt_fieldcat.
wlt_fieldcat-fieldname = 'POTX1'.
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 = 'BLATT'.
wlt_fieldcat-tabname = 'WT_ITAB'.
wlt_fieldcat-no_out = ' '.
wlt_fieldcat-seltext_l = 'SAF'.
APPEND wlt_fieldcat TO wt_fieldcat.
CLEAR wlt_fieldcat.
wlt_fieldcat-fieldname = 'EBORT'.
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 = 'WERKS'.
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 = 'SPART'.
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 = 'DATUV'.
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 = 'DATUB'.
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
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->CL_DD text
*----------------------------------------------------------------------*
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.
m_buff = '<center><font size="5">****Teamwise Electronic Co. Ltd.**** </font></center>'.
CALL METHOD cl_dd->html_insert
EXPORTING
contents = m_buff
CHANGING
position = m_p.
CONCATENATE '<center> Indentied Bill of Material' '<BR></center>' INTO m_buff .
CALL METHOD cl_dd->html_insert
EXPORTING
contents = m_buff
CHANGING
position = m_p.
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 IN 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.
CONCATENATE 'MODEL:' p_matnr-low '~' p_matnr-high '<BR>' INTO m_buff.
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_othdata USING p_wt_itab_stlnr p_wt_itab_stlkn
CHANGING p_wt_itab-ebort p_wt_itab-mngko.
DATA: ls TYPE i.
CLEAR ls.
DATA: BEGIN OF wtl_itab OCCURS 0,
* MAKTX LIKE MAKT-MAKTX,
ebort(500) TYPE c,
END OF wtl_itab.
DATA: BEGIN OF wtp_itab OCCURS 0,
menge TYPE P decimals 6,
bmeng TYPE P decimals 6,
END OF wtp_itab.
SELECT ebort
INTO CORRESPONDING FIELDS OF TABLE wtl_itab
FROM stpu
WHERE stlnr = p_wt_itab_stlnr and stlkn = p_wt_itab_stlkn and ebort <> '' .
IF sy-subrc = 0.
LOOP AT wtl_itab.
CONCATENATE p_wt_itab-ebort wtl_itab-ebort ',' INTO p_wt_itab-ebort.
ENDLOOP.
ls = strlen( p_wt_itab-ebort ).
if ls > 1.
ls = ls - 1.
p_wt_itab-ebort = p_wt_itab-ebort+0(ls).
else.
p_wt_itab-ebort = ''.
endif.
ENDIF.
* select BMENG menge into corresponding fields of table wtp_itab
* from STKO inner join STPO on STKO~STLNR = STPO~STLNR
* where STPO~STLNR = p_wt_itab_stlnr AND STPO~stlkn = p_wt_itab_stlkn.
* loop at wtp_itab.
* p_wt_itab-mngko = wtp_itab-menge / wtp_itab-bmeng.
* endloop.
ENDFORM. " GET_KCDATA
FORM format_stufe USING p_wt_itab-stufe
CHANGING p_wt_itab-ustufe.
* DATA LS(11) TYPE C.
p_wt_itab-ustufe = p_wt_itab-stufe.
TRANSLATE p_wt_itab-ustufe USING ' .'.
p_wt_itab-ustufe+10(1) = ' '.
IF p_wt_itab-stufe < 9.
p_wt_itab-stufe = 9 - p_wt_itab-stufe.
SHIFT p_wt_itab-ustufe BY p_wt_itab-stufe PLACES.
ENDIF.
ENDFORM. "stufe_aufbereiten