SAP R/3 SQL DB2 BOM 爆炸式增长

SAP R/3 SQL DB2 BOM Explosion

已更新

我需要获取包含所有组件的 BOM,目前使用的是 Tc。 CK86 ,但这没有提供足够的信息,所以我想通过 SQL 来完成此操作,我来自 oracle 背景,不知道如何在 DB2 R/3 中完成此操作,我没有访问 query builder 或 quickview ,但我确实有通过 SQL 的读取权限,我目前正在尝试找出一种使用表获取此信息的方法:

你们有解决办法吗?

在 Oracle 中,我做了如下操作:

SELECT DISTINCT LEVEL
    ,sys_connect_by_path(msil.segment1, ' @ ') AS "BOM TREE"
    ,msi.segment1
    ,lpad(' ', LEVEL, '') || msil.segment1 Cod_Component
    ,msil.item_type
    ,msil.description Desc_Component
    ,BIC.component_quantity
    ,msiL.primary_unit_of_measure
FROM mtl_system_items msi
    ,bom_bill_of_materials bom
    ,BOM_INVENTORY_COMPONENTS BIC
    ,MTL_SYSTEM_ITEMS MSIL
WHERE msi.organization_id = 332
    AND BOM.ASSEMBLY_ITEM_ID = MSI.INVENTORY_ITEM_ID
    AND BOM.ORGANIZATION_ID = MSI.ORGANIZATION_id
    AND bom.bill_sequence_id = bic.bill_sequence_id
    AND nvl(bic.disable_date, sysdate) >= SYSDATE
    AND BIC.component_ITEM_ID = MSIL.INVENTORY_ITEM_ID
    AND Bom.ORGANIZATION_ID = MSIL.ORGANIZATION_ID
    AND msil.inventory_item_status_code = 'Active'
    AND msi.inventory_item_status_code = 'Active' 
    connect BY prior bic.component_item_id = bom.assembly_item_id
    START WITH msi.segment1 = trim(:parte)
    ORDER BY 2

我正在尝试以下操作,尽量保持简单,但无论我尝试什么,它都会在第 18 行给我一个错误,显然在 DB2 中我需要“连接方式”在“开始”之后,在我的 oracle 工作示例中,它首先有“连接”,不知道它是否有所作为,但无论我如何编写,它都会给我一个错误:“错误 [42601] [IBM][DB2/AIX64 ] SQL0104N 在“ASQ19130' CONNECT BY”之后发现意外标记“PRIOR”。预期标记可能包括:“PRIOR”。

这是我目前得到的:

SELECT DISTINCT level
    ,sys_connect_by_path(msil.stlnr, ' @ ') AS "BOM TREE"
    ,msi.stlnr as parent
    --,lpad(' ', LEVEL, '') || MSIL.MATNR Cod_Component
  --,lpad(' ', LEVEL, '') || MSIL.MATNR as Cod_Component
  ,CAST(SPACE((LEVEL - 1) * 4) || '/' || MSIL.MATNR AS VARCHAR(40)) as Cod_Component
    ,BIC.menge as qty
  ,bic.stlnr as compnumb
    ,msiL.mein as uom
FROM 
   MAST msi
    ,STKO bom
    ,STPO BIC
    ,MAST MSIL
WHERE 
BOM.STLNR = MSI.STLNR
AND BIC.STLNR = MSIL.STLNR 
START WITH msi.MATNR = 'ASQ19130'
CONNECT BY PRIOR BIC.stlnr = bom.stlnr
order by 2

这就是最终结果,对我有用。

(针对错误修复进行了编辑)

万一有人需要这个:

WITH myquery (
    root,
    matnr,matd,
    bom_tree,
    lvl,
    parent_stlkn,
    stlkn,
    idnrk,
    meins, menge
) AS (
    SELECT
        m.matnr root,
        m.matnr,MAKT.MAKTX Matd,
        p.idnrk bom_tree,
        1 lvl,
        p.stlkn,
        p.stlkn,
        p.idnrk,
        p.meins, p.menge
    FROM
        mast m 
        JOIN stko k ON k.stlnr = m.stlnr AND K.STLAL=M.STLAL
        JOIN stpo p ON p.stlnr = k.stlnr,makt
        where m.stlal='01' /*and k.stlal='01'*/
        and m.matnr=MAKT.matnr
),x (
    root,
    matnr,matd,
    bom_tree,
    lvl,
    parent_stlkn,
    stlkn,
    idnrk,
    meins, menge
) AS (
    SELECT
        root,
        matnr,matd,
        bom_tree,
        lvl,
        parent_stlkn,
        stlkn,
        idnrk,
        meins, menge
    FROM
        myquery
    UNION ALL
    SELECT
        x1.root,
        x2.matnr,x2.matd,
        x1.bom_tree
         || ' @ '
         || x2.idnrk bom_tree,
        x1.lvl + 1 lvl,
        x1.parent_stlkn,
        x2.stlkn,
        x2.idnrk,
        x2.meins,x2.menge
    FROM
        myquery x1,
        myquery x2
    WHERE
        x2.matnr = x1.bom_tree
        
) SELECT 
    x.matnr,matd Description,
    marc.herkl country,
    eina.urzla country2,
    mbew.stprs comp_price,
    bom_tree,
    lvl,
    stlkn,
    idnrk comp,
    x.meins UOM,
    menge qpa
FROM
    x, marc, mbew, eina
WHERE
    root  = :p
    and mbew.matnr=marc.matnr
    and mbew.matnr=eina.matnr
    and marc.werks=1850
    and idnrk=mbew.matnr
    --and x.matnr=mbew.matnr
    and mbew.bwkey=1850
ORDER BY
    root,
    parent_stlkn,
    lvl,
    stlkn