|
本帖最后由 xyesterday 于 2012-3-27 15:58 编辑
下面是一个在firebird数据库里实现的BOM展开procedure,供大家参考..
程序有一个关键字就是LEVEL,,'E'表示是成品或是中间层,'L'表示最底层,也就是进行MRP运算的物料.
其实好的BOM管理系统都会有这么一个关键字. 如果没有的话,最容易想到的原因就是:循环的次数太多了,导致系统运算量过大.
- Create Or Alter Procedure BOM_EXPAND (
- TOP_NUM Varchar(20),
- UNIT Varchar(20),
- QTY Integer)
- Returns (
- OTOP_NUM Varchar(20),
- OUNIT Varchar(20),
- OQTY Integer)
- As
- Declare Variable C Varchar(20);
- Declare Variable Q Integer;
- begin
- OTOP_NUM=TOP_NUM;
- FOR SELECT "ChildNUM","Usage" FROM "BOM"
- WHERE "ParentNUM"=:UNIT AND "Level"='L'
- INTO :C,:Q DO
- BEGIN
- INSERT INTO "BOMVIEW" VALUES(:top_NUM,:C,:Q*:QTY);
- END
- FOR SELECT "ChildNUM","Usage" FROM "BOM"
- WHERE "ParentNUM"=:UNIT AND "Level"!='L'
- INTO :OUNIT,:OQTY DO
- BEGIN
- EXECUTE PROCEDURE "BOM_EXPAND" OTOP_NUM,OUNIT,OQTY*QTY
- RETURNING_VALUES OTOP_NUM,OUNIT,OQTY;
- END
- end
复制代码 |
|