按BOM清單展開物料及需求(SQL)

2021-09-09 05:12:18 字數 2249 閱讀 9090

適用環境:

人工的去展開bom

create function f_pcode1(@code varchar(20))

returns @re1 table(code varchar(20),father varchar(20),uom varchar(5),quantity float,level1 int)

asbegin

declare @l int

declare @father varchar(20)

declare @uom varchar(5)

declare @quantity float

set @l=0

insert @re1 select @code,@father,@uom,@quantity,@l

while @@rowcount>0

begin

set @l=@l+1

insert @re1(code,father,uom,quantity,level1) select a.code,a.father,a.uom,a.quantity,@l

from itt1 a,@re1 b

where a.father=b.code collate database_default

and b.level1=@l-1

endreturn

end用這個sql我實現了這樣一種功能:按銷售訂單查詢成品的標準bom清單,並計算需求。

輸入成品的料號

輸出父料號、子料號、單位、用量、bom級別

關於b1的兩個功能(二)按銷售訂單展開生產訂單的用料清單

簡單的說:就是輸出乙個銷售訂單銷售物料的生產訂單用料清單

create function f_wo(@code_a varchar(20),@code_b varchar(20))

returns @re1 table(docentry int,code varchar(20),father varchar(20),uom varchar(5), plannedqty float,issuedqty float,level1 int)

asbegin

declare @l int

declare @docentry int

declare @father varchar(20)

declare @code varchar(20)

declare @issuedqty float

declare @plannedqty float

declare @re2 table (docentry int,code varchar(20),father varchar(20), plannedqty float,issuedqty float,originnum int)

insert @re2(docentry,code,father,plannedqty,issuedqty,originnum) select distinct t1.docentry,t1.itemcode, t0.itemcode,t1.plannedqty, t1.issuedqty ,t0.originnum from owor t0 inner join wor1 t1 on t0.docentry = t1.docentry where   t0.originnum = @code_a

set @l=0

insert @re1(code,father,plannedqty,issuedqty,level1) select @code_b,@father,@plannedqty,@issuedqty,@l

while @@rowcount>0

begin

set @l=@l+1

insert @re1(docentry,code,father,issuedqty,plannedqty,level1) select distinct a.docentry,a.code,a.father,a.issuedqty,a.plannedqty,@l

from @re2 a,@re1 b

where a.father=b.code collate database_default

and b.level1=@l-1

endreturn

end--------------

這個就是按單生產的sql。

輸入專案:銷售訂單號、銷售訂單銷售的成品料號。

輸出:生產訂單號

料號父料號

發出數量

計畫數量

bom級別

由以上的兩個功能可以開發出:按銷售訂單生產、計畫的功能。

BOM清單詳解

sap bom按技術型別,又可分為簡單bom 派生bom 多重bom等,那麼這些bom的概念是什麼呢?簡單bom 最開始建立乙個物料bom時,它就是乙個簡單物料bom。在附加替代或派生建立之前,系統不會自動定義技術型別。多重bom 是指用來表示由不同的生產過程而生產出來的一物料的元件的替代組合。即乙...

遞迴展開BOM

procedure wst agile bom extend p item id in number,p level in number iscursor cur p item in number is select id,item number,quantity,component from bo...

BOM展開SQL語句

示例資料 create table tb 父物料 varchar 10 子物料 varchar 10 insert tb select a1 b1 union all select a1 b2 union all select a1 b3 union all select b1 c1 union a...