SAP R/3 SQL DB2物料清单展开

9jyewag0  于 2022-11-29  发布在  DB2
关注(0)|答案(1)|浏览(192)
  • 已更新 *

我需要获得所有组件的BOM,目前使用Tc.CK86,但这不能提供足够的信息,所以我想通过SQL来完成此操作,我来自Oracle背景,不知道如何在DB2 R/3中完成此操作,我没有查询构建器或快速视图的访问权限,但我可以通过SQL进行读取访问。我目前正在尝试找出一种使用表格获取此信息的方法:

  • MAST物料至BOM链接
  • STKO物料清单题头
  • STPO物料清单项目

你们谁有办法解决这个问题?
在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中,我需要“connect by”在“START”之后,在我的oracle工作示例中,它首先有“connect”,不知道它是否有区别,但是无论我怎么写,它都给我一个错误:“ERROR [42601] [IBM][DB2/AIX 64] SQL 0104 N在“ASQ 19130 ' CONNECT BY”之后发现了一个意外的标记“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
7jmck4yq

7jmck4yq1#

这就是最后的结果,它对我很有效。
(已编辑以修复错误)
以防有人需要这个:

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

相关问题