已更新
我需要获得包含所有组件的BOM,目前使用Tc。 CK86,但是这并没有提供足够的信息,所以我想通过SQL来做这件事,我来自oracle后台,不知道怎么能在DB2 R / 3中完成这个,我没有访问查询构建器或者快速查看,但我确实有通过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中我需要" connect by"在" START"之后,在我的oracle工作示例中,它有" connect"首先,不知道它是否有所作为,但无论我怎么写它,它都会给我一个错误:" ERROR [42601] [IBM] [DB2 / AIX64] SQL0104N意外的令牌&# 34; PRIOR"发现在" ASQ19130' 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
答案 0 :(得分:0)
这就是最终的结果,它对我有用。
万一有人需要这个:
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 DESC,
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