First of all sorry for the long message
my english is not good may be i cant
explain my problem well.
AAA Main Assembly Part in BOM table
ItemNo...ChildItemNo....Qty...ItemType..FirstProduction
AAA..........A1..................1.........Assy........Yes
AAA..........B1..................2.........Item.........No
AAA..........B2..................2.........Item.........No
A1 Child Assembly Part in BOM table
ItemNo...ChildItemNo....Qty...ItemType..FirstProduction
A1.............A2...................1.......Item........No
A1.............A3...................2.......Item........No
Before we manufacture AAA main assy part
we manufacture it's child assy parts (if exists)
a few days ago (for example A1 part according
to above sample) and first we publish a manufacturing
order for A1, after A1's manufacturing is finished
we reduce A2 and A3 parts from ITEMS table's
stock qty field and add A1 qty and then publish a new
manufacturing order for the MAIN ASSY part (AAA).
What i want to do is when we finish MAIN ASSY part's
production (AAA) i want to add ITEMS table's stock field
the MAIN ASSY part (AAA) and reduce the child assy(A1)
and and other parts (which are not child assembly )
but i added childassy and reduced other part ( under A1 )
a few day ago so now i want to reduce just childassy part
qty field. to find out this (the part is being manufacturing before
main assy production ) i added FIRSTPRODUCTION field
into BOM table. The value is Yes or No
so below procedure should check BOM table if a childassy
part's FIRSTPRODUCTION field is Yes then below proc
should show me JUST child assy ItemNo ( not the parts
under it )
Thank you so much for your help.
CREATE PROCEDURE "BOMRECURSIVE"
(
"ITMNO" VARCHAR(20)
)
RETURNS
(
"ITEMNO" VARCHAR(20),
"CHILDITEMNO" VARCHAR(20),
"QTY" NUMERIC(15, 2),
FIRSTPRODUCTION VARCHAR(3),
"ITEMTYPE" VARCHAR(12),
"ITEMNAME" VARCHAR(40),
"UOM" VARCHAR(5),
"STOCK" NUMERIC(18, 2),
"LASTPRICE" NUMERIC(18, 4),
"AVGCOST" NUMERIC(18, 4),
"CURRENCY" VARCHAR(5)
)
AS
BEGIN
FOR SELECT B.ITEMNO,B.CHILDITEMNO,SUM(B.NETQTY)QTY, I.ITEMTYPE,
I.ITEMNAME,I.UOM,I.STOCK,I.LASTPRICE,I.AVGCOST,I.CURRENCY
FROM BOM B
JOIN ITEMS I ON I.ITEMNO=B.CHILDITEMNO
WHERE B.ITEMNO= :"ITMNO"
GROUP BY B.ITEMNO,B.CHILDITEMNO,I.ITEMTYPE,I.ITEMNAME,I.UOM,I.STOCK,I.LASTPRICE,I.AVGCOST,I.CURRENCY
ORDER BY B.CHILDITEMNO
INTO :"ITEMNO",:"CHILDITEMNO", :"QTY",:"ITEMTYPE",:"ITEMNAME",:"UOM",:"STOCK",:"LASTPRICE",:"AVGCOST",:"CURRENCY"
DO
BEGIN
SUSPEND;
FOR SELECT B1.ITEMNO,B1.CHILDITEMNO, SUM(B1.QTY)QTY,B1.ITEMTYPE,
B1.ITEMNAME,B1.UOM,B1.STOCK,B1.LASTPRICE,B1.AVGCOST,B1.CURRENCY
FROM BOMRECURSIVE(:"CHILDITEMNO") B1
JOIN ITEMS I ON I.ITEMNO=B1.CHILDITEMNO
GROUP BY B1.ITEMNO,B1.CHILDITEMNO,B1.ITEMTYPE,B1.ITEMNAME,B1.UOM,B1.STOCK,B1.LASTPRICE,B1.AVGCOST,B1.CURRENCY
INTO :"ITEMNO",:"CHILDITEMNO", :"QTY",:"ITEMTYPE",:"ITEMNAME",:"UOM",:"STOCK",:"LASTPRICE",:"AVGCOST",:"CURRENCY"
DO
BEGIN
SUSPEND;
END
END
END;
|