1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| PROCEDURE "CALCUL_BESOIN1" (PP_IDENT VARCHAR2) IS
BEGIN
DECLARE
IDENT0 MPIECE.IDENT%TYPE;
NENS MPIECE.IDENT%TYPE;
GLOB_QTE NUMBER;
GLOB_IDT MPIECE.IDENT%TYPE;
IDT_QTE NUMBER;
IDT_ENS MPIECE.IDENT%TYPE;
IDT_LEV NUMBER;
IDT_CE NUMBER;
IDT_IDT MPIECE.IDENT%TYPE;
TCAL_IDT_QTE NUMBER;
TCAL_ENS_QTE NUMBER;
TCAL_IDT MPIECE.IDENT%TYPE;
X NUMBER;
-------------- PARCOURIR LA NOMENCLATURE DU HAUT VERS LE BAS POUR EXTRAIRE TOUS LES NUM QUI LA COMPOSE
CURSOR VENTIL_ENS IS
SELECT DISTINCT IDENT FROM COMPLUS.NOMENCLATURE1;
-------------- PARCOURIR LA NOMECNLATURE DU BAS VERS LE HAUT ET CALCULER LES QTES ---------------------
CURSOR VENTIL_IDENT IS
SELECT NENS , QTE, IDENT, LEVEL ,CE FROM COMPLUS.NOMENCLATURE1 WHERE CE = 4
CONNECT BY PRIOR NENS = IDENT AND PRIOR CE = 4 START WITH IDENT = IDENT0;
------------- RECHERCHE IDENT ET NENS DANS LA TABLE ACAL ----------------
CURSOR FIND_IDT IS
SELECT IDT1, QTE1 FROM COMPLUS.TCAL WHERE IDT1 = GLOB_IDT;
BEGIN
---- VIDER LA TABLE DES BESOINS ET LA REINITIALISER AVEC LES ENGINS DE BASE ----------------
DELETE FROM BIDON;
DELETE FROM ABESOIN WHERE NENS = PP_IDENT ;
-------------------------------------------------------------
x:= 0;
GLOB_QTE := 0;
OPEN VENTIL_ENS;
LOOP
FETCH VENTIL_ENS INTO IDENT0;
EXIT WHEN NOT VENTIL_ENS%FOUND ;
OPEN VENTIL_IDENT;
DELETE FROM COMPLUS.TCAL;
LOOP
FETCH VENTIL_IDENT INTO IDT_ENS, IDT_QTE ,IDT_IDT, IDT_LEV, IDT_CE;
EXIT WHEN NOT VENTIL_IDENT%FOUND;
IF GLOB_IDT = PP_IDENT THEN
SELECT QTE1 INTO GLOB_QTE FROM COMPLUS.TCAL WHERE IDT1 = PP_IDENT;
INSERT INTO COMPLUS.ABESOIN VALUES (IDENT0, PP_IDENT, GLOB_QTE);
GLOB_QTE := 0;
DELETE FROM COMPLUS.TCAL WHERE IDT1 NOT IN ( IDT_IDT) ;
END IF;
GLOB_IDT := IDT_IDT;
OPEN FIND_IDT ;
FETCH FIND_IDT INTO TCAL_IDT, TCAL_IDT_QTE;
IF FIND_IDT%NOTFOUND THEN
INSERT INTO COMPLUS.TCAL VALUES(GLOB_IDT, 1);
TCAL_IDT_QTE := 1;
END IF;
CLOSE FIND_IDT;
GLOB_IDT := IDT_ENS;
OPEN FIND_IDT ;
FETCH FIND_IDT INTO TCAL_IDT, TCAL_ENS_QTE;
--- MESSAGE (GLOB_IDT || ' ' || IDENT0 || ' ' || IDT_QTE);
IF FIND_IDT%NOTFOUND THEN
INSERT INTO COMPLUS.TCAL VALUES(GLOB_IDT, IDT_QTE * TCAL_IDT_QTE);
ELSE
UPDATE COMPLUS.TCAL SET QTE1 = QTE1 + (IDT_QTE * TCAL_IDT_QTE) WHERE IDT1 = GLOB_IDT;
END IF;
CLOSE FIND_IDT;
END LOOP;
-- MESSAGE (IDENT0 || ' ' || GLOB_QTE);
-- SELECT QTE1 INTO GLOB_QTE FROM COMPLUS.TCAL WHERE IDT1 = PP_IDENT;
-- INSERT INTO COMPLUS.ABESOIN VALUES (IDENT0, PP_IDENT, GLOB_QTE);
-- GLOB_QTE := 0;
X := X+1;
IF X = 500 THEN
INSERT INTO BIDON VALUES (PP_IDENT , X , X);
X:= 0;
COMMIT;
END IF;
SELECT QTE1 INTO GLOB_QTE FROM COMPLUS.TCAL WHERE IDT1 = PP_IDENT;
INSERT INTO COMPLUS.ABESOIN VALUES (IDENT0, PP_IDENT, GLOB_QTE);
GLOB_QTE := 0;
GLOB_IDT := NULL;
CLOSE VENTIL_IDENT;
END LOOP;
CLOSE VENTIL_ENS;
INSERT INTO ABESOIN VALUES (PP_IDENT, PP_IDENT , 1);
END;
DELETE FROM NOMENCLATURE1 ;
DELETE FROM BIDON;
COMMIT;
END; |
Partager