1. 创建基本视图
@AbapCatalog.sqlViewName: 'ZVDDL_TEST1'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Get BOM'
define view ZDDL_TEST1
  as select from mast as a
    inner join   stko as b on  a.stlnr = b.stlnr
                           and a.stlal = b.stlal
                           and b.stlty = 'M'
    inner join   stas as c on  c.stlnr = b.stlnr
                           and c.stlty = b.stlty
                           and c.stlal = b.stlal
    inner join   stpo as d on  d.stlty = c.stlty
                           and d.stlnr = c.stlnr
                           and d.stlkn = c.stlkn
{
  a.werks,
  a.stlan,
  a.stlal,
  a.matnr,
  d.idnrk
}
  1. 创建Basic View
@AbapCatalog.sqlViewName: 'ZVDDL_TEST2'
@AbapCatalog.compiler.compareFilter: true
@Hierarchy.parentChild: [{name:'PARENT' , recurseBy:'_PARENT' }]
@VDM.viewType: #BASIC
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'BOM Basic View'
define view ZDDL_TEST2 as select from zvddl_test6
association [0..*] to ZDDL_TEST1 as _PARENT
    on $projection.matnr = _PARENT.idnrk {
    _PARENT,
    werks,
    stlan,
    stlal,
    matnr,
    idnrk
}
  1. 创建层次视图
define hierarchy ZDDl_TEST3
  with parameters
    P_MATNR : abap.char( 40 )
  as parent child hierarchy(
    source ZDDL_TEST2
    child to parent association _PARENT
    start where
          matnr = :P_MATNR
    siblings order by
      matnr
    multiple parents allowed  )
{
$node.hierarchy_level as levels,//Level
  werks,
  stlan,
  stlal,
  matnr,
  idnrk,
  _PARENT

}

查看ZDDL_TEST3,输入物料即可展开BOM.