上篇讲到,BOM在实际写程序中,是很让人头疼的事,第一,因为其结构复杂,第二,因为其数据量非常庞大,一二百万的数据基本属于常量。
这就对展BOM的程序提出非常高的performance需求。(当然表设计也很重要,索引,分页什么的就不提了,属DBA范畴)
在上一篇里给出的链接中,已有方法对BOM进行操作,举一反三,应该基本能把所有的问题都拿下了。
我在实际的工作中,还遇到过另一个需求,这里单独拿出来讲讲。
因为,很多时候,各单位的人员并不会关心你的BOM到底是什么结构。
生产管理人员只关心manufacture bom ,这个半成品/成品,需要哪些料,这些料缺不缺。
采购人员只关系需要买的料(一般指原材raw material,当然也有直接买半成品的)
资材的同仁关心的又不同,等等。。。
假如你(客户)去买电脑,需要的内存是1G(假如预算就到这了,再贵买不起,只能放弃或去别的店里咨询),而店里正好没有现货,却有2G的内存现货(如果此2G的也是压仓库,卖不出去),那么店主(生产商)也许就会说,1G的没有了,我给你2G的吧,价格算1G的价。。。一举两得,店主减少了库存压货,并卖出了电脑赚了钱,而你也白捡了便宜。(这在生产上,叫作 高规低代)
简单流程表示为
客户下单(1G电脑) => 资材人员发现1G内存缺料,并同时发现库存有2G的,两者可替代 => 客服人员联络客户商量是否可高规低代? => 客户同意 => 组装2G的(修改manufacture bom) / 如果客户不同意的话,就得让采购去买料了。。。
在这里有一个很重要的步骤是 “资材人员发现1G内存缺料,并同时发现库存有2G的,两者可替代” ,这就引出了,很多时候,管理人员需要一份report ,
可以明确的知道一颗原材 所对应的所有成品 (或者说一个成品料号 所对应的所有 原材。 我把它叫作 part where use .
在这样的一份report里,将跳过众多的半成品,直接得出 最高介 和 最低介 的关系,是一种part direct relation. 这将非常有利于管理人员掌控物料规划,仓库水位等。
怎么从普通的BOM表,得出这样的一个 part direct的结构?
下面以程式作简单说明:
用途: part where use, 原材的用料累计等,都可以用此方法来计算.
Create table bom
(parent varchar(2) not null,
child varchar(2) not null
)
Insert into bom select 'A0','A1'
Insert into bom select 'A0','A2'
Insert into bom select 'A1','A3'
Insert into bom select 'A1','A4'
Insert into bom select 'A3','A5'
Insert into bom select 'B0','B1'
Insert into bom select 'B1','B2'
Insert into bom select 'B1','B3'
Insert into bom select 'B3','B4'
Insert into bom select 'B3','B5'
Insert into bom select 'A4','C1'
Insert into bom select 'B4','C1'
Go
Create Proc usp_test
AS
declare @loop int
set @loop=1
--查找出bom表里所有最高介
select parent as top_part,child
into #top
from bom as A
where not exists(select 1 from bom where child=A.parent)
While @loop>0
BEGIN
select B.top_part, A.parent, A.child
into #tmp_top
from bom A, #top B
where A.parent=B.child
Delete #top
from #top , #tmp_top
where #top.child=#tmp_top.parent
set @loop=@@rowcount
Insert into #top
select top_part, child from #tmp_top
Drop table #tmp_top
END
--查看#top 結果
--如果建有一个专门存放part direct 的table也不错,方便以后查询
select * from #top order by top_part
GO
exec usp_test
/*
top_part child
----------------------
A0 A2
A0 A5
A0 C1
B0 B2
B0 B5
B0 C1
*/
GO
drop table bom
drop proc usp_test
这样一份的report的好处是,可以直观的表示 A0 这个成品(finish good),所需 A2,A5,C1 这3个原材(raw material). 方便客服,或者采购查询。。。