**销售订单BOM展开**
DATA: BEGIN OF it_stb OCCURS 0 .
INCLUDE STRUCTURE stpox.
DATA: END OF it_stb.
DATA: it_matcat LIKE TABLE OF cscmat WITH HEADER LINE.
DATA: BEGIN OF it_vbap1 OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
cuobj LIKE vbap-cuobj ,
matnr LIKE vbap-matnr ,
werks LIKE vbap-werks,
sernr LIKE vbap-sernr, "bom展开号
datuv LIKE sy-datum,
END OF it_vbap1.
*取展销售订单BOM所需信息
SELECT vbeln posnr cuobj matnr werks sernr
"INTO (vbap-cuobj , vbap-matnr , vbap-werks)
INTO CORRESPONDING FIELDS OF TABLE it_vbap1
FROM vbap
FOR ALL ENTRIES IN it_vbap
WHERE vbeln = it_vbap-kdauf
AND posnr = it_vbap-kdpos .
IF it_vbap1[] IS INITIAL.
EXIT.
ENDIF.
SELECT sernr brutr INTO TABLE it_snum
FROM snum
FOR ALL ENTRIES IN it_vbap1
WHERE sernr = it_vbap1-sernr.
*取销售订单bom
REFRESH: it_stb , it_matcat .
CALL FUNCTION 'CS_BOM_EXPL_KND_V1'
EXPORTING
capid = 'PP01' "BOM类别 pp01-Ebom(设计) pp02-Mbom(生产)
datuv = it_snum-brutr "BOM生效日期
cuobj = it_vbap1-cuobj "内部对象号
brems = 'X' 有限展开
stpst = '0' "展开层级 0为展到底 默认为0
mdmps = 'X' "仅展开到实件X
mehrs = 'X' "多层展开 为空则只展开一层
mtnrv = it_vbap1-matnr "物料
werks = it_vbap1-werks "工厂
vbeln = it_vbap-kdauf "销售订单号
vbpos = it_vbap-kdpos "项目
TABLES
stb = it_stb
matcat = it_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.
DELETE it_stb WHERE stufe > 2 AND dumps = 'X' . "stufe-BOM层级 dumps-虚件标识
**物料BOM展开**
DATA: BEGIN OF it_stb1 OCCURS 100 .
INCLUDE STRUCTURE stpox.
DATA: END OF it_stb1.
DATA: it_matcat1 LIKE TABLE OF cscmat WITH HEADER LINE.
REFRESH: it_stb1 , it_matcat1.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
capid = 'PP01' "BOM类别
datuv = sy-datum "BOM有效日期
mdmps = ' ' "仅展开道实零件
mehrs = 'X' "多层展开
mtnrv = it_stb-idnrk "物料号
werks = '2000' "工厂
* IMPORTING
* TOPMAT =
* DSTST =
TABLES
stb = it_stb1
matcat = it_matcat1
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 .