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 102 103 104 105 106 107 108 109 110 111
| CREATE OR REPLACE PROCEDURE OPS$PROJET.p_fic_pmetier (wtype IN varchar2) is
-- EGA le 21/07/2011
-- Procédure pour génération du fichier produits metiers
-- 1 parametres : A pour Achat et V pour Ventes
--
-- Noms des fichiers --
wnom_fichier Varchar2(50);
wextension_fichier varchar2(3);
wfichier varchar2(53);
-- Noms des répertoires il faut au préalable
-- déclaré un DIRECTORY oracle avec le nom utilisé
LC$Dir_out Varchar(50) := 'FICOUT' ;
-- Pointeurs de fichier --
LF$FicOUT UTL_FILE.FILE_TYPE ;
--
LC$Ligne Varchar2(32767) ;
--
wexists boolean;
wtaille_fic integer;
wtaille_bloc integer;
--
-- Curseur pour les datas
--
cursor c1 is
select type
,idlogiciel
,DET_PRDMCODE
,DET_PRDLIB
,DET_CONDIT
,DET_UNIT
,DET_TXTVA
,DET_NIV1
,DET_NIV2
,DET_NIV3
,DET_NIV4
,DET_NIV5
,DET_NATPROD
,APPLICD
,MAJD
from produits_metier
where type = wtype;
--
cc1 c1%ROWTYPE;
Begin
-- Construction du nom du fichier
select f_parama_lib4('TMZ','NFPM'),lpad(seq_ext_tmzprm.nextval,3,0)
into wnom_fichier,wextension_fichier
from dual;
--
wfichier := wnom_fichier||wextension_fichier;
--
-- Ouverture du fichier
LF$FicOUT := UTL_FILE.FOPEN( LC$Dir_out, wfichier, 'W', 32764 ) ;
--
OPEN C1;
--
LOOP
-- RAZ de la variable de travail
-- LC$Ligne := NULL;
--
FETCH c1 INTO cc1;
EXIT WHEN c1%NOTFOUND;
--
--
LC$Ligne := cc1.idlogiciel||cc1.DET_PRDMCODE||cc1.DET_PRDLIB||cc1.DET_CONDIT||cc1.DET_UNIT||cc1.DET_TXTVA
||cc1.DET_NIV1||cc1.DET_NIV2||cc1.DET_NIV3||cc1.DET_NIV4||cc1.DET_NIV5||cc1.DET_NATPROD||cc1.APPLICD||cc1.MAJD;
--
UTL_FILE.PUT_LINE(LF$FicOUT,LC$Ligne,TRUE);
--
-- On teste le type de ligne pour connaitre la table à mettre à jour
--
-- Si type = V alors produits métiers pour ventes. MAJ de la table ARTNEW
--
if cc1.type = 'V' then
--
update artnew set prd_metier = 'N'
where rgpart = cc1.det_prdmcode
and art = rgpart;
-- --
-- Si type = A alors produits métiers pour achats. MAJ de la table MATIERE
--
elsif cc1.type = 'A' then
update matiere set prd_metier = 'N'
where mat = substr(cc1.det_prdmcode,4,length(cc1.det_prdmcode) - 3);
end if;
commit;
--
END LOOP;
--
CLOSE C1;
--
-- Fermeture de l'ensemble de fichiers ouverts
--
UTL_FILE.FCLOSE_ALL;
--
-- Lecture des attributs du fichier créé
--
UTL_FILE.FGETATTR(LC$Dir_out, wfichier,wexists,wtaille_fic,wtaille_bloc);
--
-- Destruction du fichier si il est vide
--
if wtaille_fic = 0 then
UTL_FILE.FREMOVE( LC$Dir_out,wfichier);
end if;
--
END;
/ |