Le fichier source est ${UPS_HOME}/upsedi/demo/${UPS_LANGUAGE}/formatbinaire.upl.
upscmp Source=formatbinaire.upl
formatbinaire
upssng Source=formatbinaire.upl
Source Composant "Exemple d'emploi de l'import/export" Version 4.0.0;
ImporterModule
/************/
UpsEdi(<UpsEdi.upi>, ImporterDefinitions);
Type Employe Defaut
/*****************/
Nom : Caractere;
Numero : Entier;
Salaire : Reel;
Constructeur();
Fin Type
Variable
/******/
LE : Nul Ou ListeDe Employe;
Procedure CreerListeDEmployes()
/*****************************/
Variable
/******/
E : Nul Ou Employe;
I : Entier;
Debut
Pour I=0 JusquA 10 Faire
E=Employe();
E.Nom="scott"+Caractere(I);
E.Numero=7724+I;
E.Salaire=1000.00+I;
E.DateDEmbauche=Date("12-01-1980");
LE+=E;
E=Employe();
E.Nom="allen"+Caractere(I);
E.Numero=7832+I;
E.Salaire=1200.00+I;
E.DateDEmbauche=Date("13-02-1981");
LE+=E;
E=Employe();
E.Nom="smith"+Caractere(I);
E.Numero=7948+I;
E.Salaire=1400.00+I;
E.DateDEmbauche=Date("14-03-1982");
LE+=E;
E=Employe();
E.Nom="king"+Caractere(I);
E.Numero=7964+I;
E.Salaire=2000.00+I;
E.DateDEmbauche=Date("15-04-1983");
LE+=E;
Fin Pour
Fin Procedure
Procedure ListerEmployes()
/************************/
Variable
/******/
E : Nul Ou Employe;
Debut
Pour E=LE.ParcoursAuDebut() JusquA LE.DernierElement() Faire
Ecran.Ecrire(E.Nom+" "+Caractere(E.Numero)+" "+Caractere(E.Salaire)+" "+Caractere(E.DateDEmbauche));
Fin Pour
Fin Procedure
Fonction CritereEmploye(O : Nul Ou Objet) Retourner Booleen
/*********************************************************/
Variable
/******/
E : Nul Ou Employe;
Debut
Si O==Nul Alors
Retourner Faux;
Fin Si
E=Employe(O);
Retourner E.Nom Comme "scott*";
Fin Fonction
Principal
/*******/
Variable
/******/
F : Nul Ou Fichier;
E : Nul Ou EchangeBinaire;
E2 : Nul Ou Employe;
PasFini:Booleen;
Debut
Ecran.Ecrire("Base de données");
Ecran.Ecrire("===============");
CreerListeDEmployes();
ListerEmployes();
Ecran.Ecrire("\n");
F=Fichier("/tmp/essai.dmp", EcritureBinaire);
E=EchangeBinaire(IFlux(F));
Pour E2=LE.ParcoursAuDebut() JusquA LE.DernierElement() Pas LE.Suivant() Faire
ExporterObjet(E2);
Fin Pour
E=Nul;
F.Fermer();
Ecran.Ecrire("Importation complète");
Ecran.Ecrire("====================");
F=Fichier("/tmp/essai.dmp", LectureBinaire);
E=EchangeBinaire(IFlux(F));
LE=Nul;
PasFini=Vrai;
TantQue PasFini Faire
AttraperException
E2=Employe(ImporterObjet());
LE+=E2;
TraiterException
Cas Pour ImportationImpossible Faire
Si E.FinDImportation Alors
PasFini=Faux;
Sinon
Exception.Renvoyer();
Fin Si
Fin Cas
Fin AttraperException
Fin TantQue
E=Nul;
F.Fermer();
ListerEmployes();
Ecran.Ecrire("\n");
Ecran.Ecrire("A partir du 20èm rang");
Ecran.Ecrire("=====================");
F=Fichier("/tmp/essai.dmp", LectureBinaire);
E=EchangeBinaire(IFlux(F));
E.FiltrerAPartirDe(20);
LE=Nul;
PasFini=Vrai;
TantQue PasFini Faire
AttraperException
E2=Employe(ImporterObjet());
LE+=E2;
TraiterException
Cas Pour ImportationImpossible Faire
Si E.FinDImportation Alors
PasFini=Faux;
Sinon
Exception.Renvoyer();
Fin Si
Fin Cas
Fin AttraperException
Fin TantQue
E=Nul;
F.Fermer();
ListerEmployes();
Ecran.Ecrire("\n");
Ecran.Ecrire("20 premiers rangs");
Ecran.Ecrire("=================");
F=Fichier("/tmp/essai.dmp", LectureBinaire);
E=EchangeBinaire(IFlux(F));
E.FiltrerJusquA(20);
LE=Nul;
PasFini=Vrai;
TantQue PasFini Faire
AttraperException
E2=Employe(ImporterObjet());
LE+=E2;
TraiterException
Cas Pour ImportationImpossible Faire
Si E.FinDImportation Alors
PasFini=Faux;
Sinon
Exception.Renvoyer();
Fin Si
Fin Cas
Fin AttraperException
Fin TantQue
E=Nul;
F.Fermer();
ListerEmployes();
Ecran.Ecrire("\n");
Ecran.Ecrire("Entre 10 et 30èm rang");
Ecran.Ecrire("=====================");
F=Fichier("/tmp/essai.dmp", LectureBinaire);
E=EchangeBinaire(IFlux(F));
E.FiltrerEntre(10,30);
LE=Nul;
PasFini=Vrai;
TantQue PasFini Faire
AttraperException
E2=Employe(ImporterObjet());
LE+=E2;
TraiterException
Cas Pour ImportationImpossible Faire
Si E.FinDImportation Alors
PasFini=Faux;
Sinon
Exception.Renvoyer();
Fin Si
Fin Cas
Fin AttraperException
Fin TantQue
E=Nul;
F.Fermer();
ListerEmployes();
Ecran.Ecrire("\n");
Ecran.Ecrire("scott uniquement");
Ecran.Ecrire("================");
F=Fichier("/tmp/essai.dmp", LectureBinaire);
E=EchangeBinaire(IFlux(F));
E.FiltrerSelon(CritereEmploye);
LE=Nul;
PasFini=Vrai;
TantQue PasFini Faire
AttraperException
E2=Employe(ImporterObjet());
LE+=E2;
TraiterException
Cas Pour ImportationImpossible Faire
Si E.FinDImportation Alors
PasFini=Faux;
Sinon
Exception.Renvoyer();
Fin Si
Fin Cas
Fin AttraperException
Fin TantQue
E=Nul;
F.Fermer();
ListerEmployes();
Ecran.Ecrire("\n");
Fin Principal
Résultat de l'exécution
Base de données
===============
scott0 7,724 1,000.0000 12/01/1980 00:00:00
allen0 7,832 2,000.0000 13/02/1981 00:00:00
smith0 7,948 1,400.0000 14/03/1982 00:00:00
king0 7,964 2,000.0000 15/04/1983 00:00:00
scott1 7,725 1,001.0000 12/01/1980 00:00:00
allen1 7,833 2,001.0000 13/02/1981 00:00:00
smith1 7,949 1,401.0000 14/03/1982 00:00:00
king1 7,965 2,001.0000 15/04/1983 00:00:00
scott2 7,726 1,002.0000 12/01/1980 00:00:00
allen2 7,834 2,002.0000 13/02/1981 00:00:00
smith2 7,950 1,402.0000 14/03/1982 00:00:00
king2 7,966 2,002.0000 15/04/1983 00:00:00
scott3 7,727 1,003.0000 12/01/1980 00:00:00
allen3 7,835 2,003.0000 13/02/1981 00:00:00
smith3 7,951 1,403.0000 14/03/1982 00:00:00
king3 7,967 2,003.0000 15/04/1983 00:00:00
scott4 7,728 1,004.0000 12/01/1980 00:00:00
allen4 7,836 2,004.0000 13/02/1981 00:00:00
smith4 7,952 1,404.0000 14/03/1982 00:00:00
king4 7,968 2,004.0000 15/04/1983 00:00:00
scott5 7,729 1,005.0000 12/01/1980 00:00:00
allen5 7,837 2,005.0000 13/02/1981 00:00:00
smith5 7,953 1,405.0000 14/03/1982 00:00:00
king5 7,969 2,005.0000 15/04/1983 00:00:00
scott6 7,730 1,006.0000 12/01/1980 00:00:00
allen6 7,838 2,006.0000 13/02/1981 00:00:00
smith6 7,954 1,406.0000 14/03/1982 00:00:00
king6 7,970 2,006.0000 15/04/1983 00:00:00
scott7 7,731 1,007.0000 12/01/1980 00:00:00
allen7 7,839 2,007.0000 13/02/1981 00:00:00
smith7 7,955 1,407.0000 14/03/1982 00:00:00
king7 7,971 2,007.0000 15/04/1983 00:00:00
scott8 7,732 1,008.0000 12/01/1980 00:00:00
allen8 7,840 2,008.0000 13/02/1981 00:00:00
smith8 7,956 1,408.0000 14/03/1982 00:00:00
king8 7,972 2,008.0000 15/04/1983 00:00:00
scott9 7,733 1,009.0000 12/01/1980 00:00:00
allen9 7,841 2,009.0000 13/02/1981 00:00:00
smith9 7,957 1,409.0000 14/03/1982 00:00:00
king9 7,973 2,009.0000 15/04/1983 00:00:00
scott10 7,734 1,010.0000 12/01/1980 00:00:00
allen10 7,842 2,010.0000 13/02/1981 00:00:00
smith10 7,958 1,410.0000 14/03/1982 00:00:00
king10 7,974 2,010.0000 15/04/1983 00:00:00
Importation complète
====================
scott0 7,724 1,000.0000 12/01/1980 00:00:00
allen0 7,832 2,000.0000 13/02/1981 00:00:00
smith0 7,948 1,400.0000 14/03/1982 00:00:00
king0 7,964 2,000.0000 15/04/1983 00:00:00
scott1 7,725 1,001.0000 12/01/1980 00:00:00
allen1 7,833 2,001.0000 13/02/1981 00:00:00
smith1 7,949 1,401.0000 14/03/1982 00:00:00
king1 7,965 2,001.0000 15/04/1983 00:00:00
scott2 7,726 1,002.0000 12/01/1980 00:00:00
allen2 7,834 2,002.0000 13/02/1981 00:00:00
smith2 7,950 1,402.0000 14/03/1982 00:00:00
king2 7,966 2,002.0000 15/04/1983 00:00:00
scott3 7,727 1,003.0000 12/01/1980 00:00:00
allen3 7,835 2,003.0000 13/02/1981 00:00:00
smith3 7,951 1,403.0000 14/03/1982 00:00:00
king3 7,967 2,003.0000 15/04/1983 00:00:00
scott4 7,728 1,004.0000 12/01/1980 00:00:00
allen4 7,836 2,004.0000 13/02/1981 00:00:00
smith4 7,952 1,404.0000 14/03/1982 00:00:00
king4 7,968 2,004.0000 15/04/1983 00:00:00
scott5 7,729 1,005.0000 12/01/1980 00:00:00
allen5 7,837 2,005.0000 13/02/1981 00:00:00
smith5 7,953 1,405.0000 14/03/1982 00:00:00
king5 7,969 2,005.0000 15/04/1983 00:00:00
scott6 7,730 1,006.0000 12/01/1980 00:00:00
allen6 7,838 2,006.0000 13/02/1981 00:00:00
smith6 7,954 1,406.0000 14/03/1982 00:00:00
king6 7,970 2,006.0000 15/04/1983 00:00:00
scott7 7,731 1,007.0000 12/01/1980 00:00:00
allen7 7,839 2,007.0000 13/02/1981 00:00:00
smith7 7,955 1,407.0000 14/03/1982 00:00:00
king7 7,971 2,007.0000 15/04/1983 00:00:00
scott8 7,732 1,008.0000 12/01/1980 00:00:00
allen8 7,840 2,008.0000 13/02/1981 00:00:00
smith8 7,956 1,408.0000 14/03/1982 00:00:00
king8 7,972 2,008.0000 15/04/1983 00:00:00
scott9 7,733 1,009.0000 12/01/1980 00:00:00
allen9 7,841 2,009.0000 13/02/1981 00:00:00
smith9 7,957 1,409.0000 14/03/1982 00:00:00
king9 7,973 2,009.0000 15/04/1983 00:00:00
scott10 7,734 1,010.0000 12/01/1980 00:00:00
allen10 7,842 2,010.0000 13/02/1981 00:00:00
smith10 7,958 1,410.0000 14/03/1982 00:00:00
king10 7,974 2,010.0000 15/04/1983 00:00:00
A partir du 20èm rang
=====================
king4 7,968 2,004.0000 15/04/1983 00:00:00
scott5 7,729 1,005.0000 12/01/1980 00:00:00
allen5 7,837 2,005.0000 13/02/1981 00:00:00
smith5 7,953 1,405.0000 14/03/1982 00:00:00
king5 7,969 2,005.0000 15/04/1983 00:00:00
scott6 7,730 1,006.0000 12/01/1980 00:00:00
allen6 7,838 2,006.0000 13/02/1981 00:00:00
smith6 7,954 1,406.0000 14/03/1982 00:00:00
king6 7,970 2,006.0000 15/04/1983 00:00:00
scott7 7,731 1,007.0000 12/01/1980 00:00:00
allen7 7,839 2,007.0000 13/02/1981 00:00:00
smith7 7,955 1,407.0000 14/03/1982 00:00:00
king7 7,971 2,007.0000 15/04/1983 00:00:00
scott8 7,732 1,008.0000 12/01/1980 00:00:00
allen8 7,840 2,008.0000 13/02/1981 00:00:00
smith8 7,956 1,408.0000 14/03/1982 00:00:00
king8 7,972 2,008.0000 15/04/1983 00:00:00
scott9 7,733 1,009.0000 12/01/1980 00:00:00
allen9 7,841 2,009.0000 13/02/1981 00:00:00
smith9 7,957 1,409.0000 14/03/1982 00:00:00
king9 7,973 2,009.0000 15/04/1983 00:00:00
scott10 7,734 1,010.0000 12/01/1980 00:00:00
allen10 7,842 2,010.0000 13/02/1981 00:00:00
smith10 7,958 1,410.0000 14/03/1982 00:00:00
king10 7,974 2,010.0000 15/04/1983 00:00:00
20 premiers rangs
=================
scott0 7,724 1,000.0000 12/01/1980 00:00:00
allen0 7,832 2,000.0000 13/02/1981 00:00:00
smith0 7,948 1,400.0000 14/03/1982 00:00:00
king0 7,964 2,000.0000 15/04/1983 00:00:00
scott1 7,725 1,001.0000 12/01/1980 00:00:00
allen1 7,833 2,001.0000 13/02/1981 00:00:00
smith1 7,949 1,401.0000 14/03/1982 00:00:00
king1 7,965 2,001.0000 15/04/1983 00:00:00
scott2 7,726 1,002.0000 12/01/1980 00:00:00
allen2 7,834 2,002.0000 13/02/1981 00:00:00
smith2 7,950 1,402.0000 14/03/1982 00:00:00
king2 7,966 2,002.0000 15/04/1983 00:00:00
scott3 7,727 1,003.0000 12/01/1980 00:00:00
allen3 7,835 2,003.0000 13/02/1981 00:00:00
smith3 7,951 1,403.0000 14/03/1982 00:00:00
king3 7,967 2,003.0000 15/04/1983 00:00:00
scott4 7,728 1,004.0000 12/01/1980 00:00:00
allen4 7,836 2,004.0000 13/02/1981 00:00:00
smith4 7,952 1,404.0000 14/03/1982 00:00:00
king4 7,968 2,004.0000 15/04/1983 00:00:00
Entre 10 et 30èm rang
=====================
allen2 7,834 2,002.0000 13/02/1981 00:00:00
smith2 7,950 1,402.0000 14/03/1982 00:00:00
king2 7,966 2,002.0000 15/04/1983 00:00:00
scott3 7,727 1,003.0000 12/01/1980 00:00:00
allen3 7,835 2,003.0000 13/02/1981 00:00:00
smith3 7,951 1,403.0000 14/03/1982 00:00:00
king3 7,967 2,003.0000 15/04/1983 00:00:00
scott4 7,728 1,004.0000 12/01/1980 00:00:00
allen4 7,836 2,004.0000 13/02/1981 00:00:00
smith4 7,952 1,404.0000 14/03/1982 00:00:00
king4 7,968 2,004.0000 15/04/1983 00:00:00
scott5 7,729 1,005.0000 12/01/1980 00:00:00
allen5 7,837 2,005.0000 13/02/1981 00:00:00
smith5 7,953 1,405.0000 14/03/1982 00:00:00
king5 7,969 2,005.0000 15/04/1983 00:00:00
scott6 7,730 1,006.0000 12/01/1980 00:00:00
allen6 7,838 2,006.0000 13/02/1981 00:00:00
smith6 7,954 1,406.0000 14/03/1982 00:00:00
king6 7,970 2,006.0000 15/04/1983 00:00:00
scott7 7,731 1,007.0000 12/01/1980 00:00:00
allen7 7,839 2,007.0000 13/02/1981 00:00:00
scott uniquement
================
scott0 7,724 1,000.0000 12/01/1980 00:00:00
scott1 7,725 1,001.0000 12/01/1980 00:00:00
scott2 7,726 1,002.0000 12/01/1980 00:00:00
scott3 7,727 1,003.0000 12/01/1980 00:00:00
scott4 7,728 1,004.0000 12/01/1980 00:00:00
scott5 7,729 1,005.0000 12/01/1980 00:00:00
scott6 7,730 1,006.0000 12/01/1980 00:00:00
scott7 7,731 1,007.0000 12/01/1980 00:00:00
scott8 7,732 1,008.0000 12/01/1980 00:00:00
scott9 7,733 1,009.0000 12/01/1980 00:00:00
scott10 7,734 1,010.0000 12/01/1980 00:00:00