很开心做了这个程序,递归bom反向展开的
需要取物料的顶层物料
思路是:反向展开失败就得到叶子节点,即顶层物料
*&---------------------------------------------------------------------*
*& Report Z_BOM_REV *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
report z_bom_rev .
types : begin of ty_mat,
matnr type matnr,
andat type andat,
maktx type maktx,
vwalt type stalt,
end of ty_mat.
data it_mat type table of ty_mat with header line.
data: itab type table of stpov with header line ,
equi type table of cscequi,
knd type table of cscknd,
mat type table of cscmat,
std type table of cscstd,
tpl type table of csctpl.
parameters: p_matnr type matnr obligatory,
p_werks type werks obligatory,
p_stlan type stlan obligatory.
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = p_matnr
importing
output = p_matnr.
write:/ ' ', '物料号 ' ,' ','物料描述',' ', ' 创建日期 ',' ', '可选BOM号'.
perform gettops using p_matnr '' '' .
perform disp.
*&---------------------------------------------------------------------*
*& Form gettops
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->MATNR text
* -->ANDAT text
* -->VWALT text
*----------------------------------------------------------------------*
form gettops using matnr andat vwalt.
data intab type table of stpov with header line .
data count type i.
intab[] = itab[].
local itab.
call function 'CS_WHERE_USED_MAT'
exporting
datub = sy-datum
datuv = sy-datum
matnr = matnr
stlan = ''
werks = p_werks
mclmt = '00000000'
mnstl = ''
mxstl = ''
stltp = ''
newsi = ''
tables
wultb = intab
equicat = equi
kndcat = knd
matcat = mat
stdcat = std
tplcat = tpl
exceptions
call_invalid = 1
material_not_found = 2
no_where_used_rec_found = 3
no_where_used_rec_selected = 4
no_where_used_rec_valid = 5
cx_sy_dyn_call_illegal_type = 6
others.
if sy-subrc = 0.
loop at intab where matnr <> matnr and stlan = p_stlan.
count = count + 1.
endloop.
* IF intab-matnr <> matnr.
* PERFORM gettops USING intab-matnr intab-andat intab-vwalt .
*
* ENDIF.
* ENDLOOP.
if count = 0.
it_mat-matnr = matnr.
it_mat-andat = andat.
it_mat-vwalt = vwalt.
append it_mat.
else.
loop at intab where matnr <> matnr and stlan = p_stlan.
perform gettops using intab-matnr intab-andat intab-vwalt .
endloop.
endif.
else.
it_mat-matnr = matnr.
it_mat-andat = andat.
it_mat-vwalt = vwalt.
append it_mat.
endif.
endform. "gettops
*&---------------------------------------------------------------------*
*& Form DISP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form disp.
* WRITE:/ matnr ,andat, vwalt.
sort it_mat by matnr andat vwalt.
delete adjacent duplicates from it_mat.
loop at it_mat.
select single maktx into it_mat-maktx
from makt
where matnr = it_mat-matnr and spras = '1'.
* write: / it_mat-matnr under '物料号',it_mat-maktx under '物料描述',IT_MAT-ANDAT UNDER '创建日期' ,IT_MAT-VWALT UNDER '可选BOM号'.
write: / it_mat-matnr,it_mat-maktx,' ',it_mat-andat ,' ',it_mat-vwalt .
endloop.
endform. "DISP