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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
#!/SOFT/perl5/bin/perl
#*****************************************************************
#* Script de fonctions pour SCK_LOT45_* et SCK_OPCVM *
#*****************************************************************
#* Auteur: ROUSSEL Arnaud *
#* Date de creation: 21/08/2008 *
#* Version: 1.0 *
#*****************************************************************
use 5.008005;
use strict;
use warnings;
use lib "$ENV{STKROOT}/batch/";
use Infra;
#définition des variables
my $1;
my $2;
my $3;
my $input;
my $outpout;
my $control;
my $nbline;
sub Format_PTF
{
$input = $1;
#INPUT=$1
$outpout = $2;
#OUTPUT=$2
$controle = $3;
#CONTROL=$3
$nbline = ;
#NBLINE=`wc -l ${INPUT} | awk '{print $1}'` <-- ligne à remplacer
#Debut controle et formatage fichier arpson
print "Debut controle et formatage du fichier $input";
#cat $INPUT | awk ' <-- ligne à remplacer
open read $input
#initialisation des variables
BEGIN
{
#initialisation du separateur des champs
#FS="\t";
##initialisation de la 1er ligne du tableau bidimensionnel FIELDS avec le nom, longueur champs,
#Type de champ
@fields = (
["PTF_13_F", "COMPANY_2_F", "DESK_3_T", "BOOK_3_T", "SYSTEM_1_T";"DESKARPSON_10_T", "CODE_12_T", "TYPE_1_T", "CODEARPSONISIN_4_T"]
["Portefeuille", "Departement du siege de la CEP", "Affectation DRG", "ACT", "A pour Arpson", "Affectation Arpson", "Code Isin tronque ou num histo", "Typologie produit", ""]);
@CodlengthErr = ("1001", "Longueur chaine de caracteres incorrecte");
@CodFormatDatErr = ( "1002", "Format date incorrect");
@CodFormatIntErr = ("1003", "Format entier numerique incorrecte");
@CodFormatDblErr = ("1004", "Format numerique incorrect");
@CodDataErr = ("1005", "Donnee obligatoire");
@CodDefaultValErr = ("1006", "Valeur par defaut");
#initialisation des champs du fichier log des anomalies
$IdentFile="PTF.ast";
$IdentField="";
$IdentWarn=0;
$IdentlineWarn="";
$CodWarn = "";
$FormatWarn = "";
$DataWarn = "";
#initialisation des variables temporaires
$MESSAGE="";
$NbLineWarn=0;
$PROBLEM="FALSE";
$ValTypCod=""; #Valeur selon ISIN/NumHist
#initialisation des champs du fichier PTF.ast
$B_PTF1=""; #1er champs:Code du portefeuille
$B_PTF2=""; #2eme champs:Code du protefeuille
$B_GRP=""; #3eme champs:Groupe
#Version 1.1: voir description
#initialisation du tableau ReplaceChar contenant les caracteres a rempalcer par espace
@ReplaceChar=(
["-"," "]
["_"," "]
["\\"," "]
["/"," "]);
$LenRepChar=4;
}
sub GetWarning
{
printf("%s\t%s\t%s\t%s\t%s\t%s\t%s",$IdentFile,$IdentField,$IdentWarn,$IdentlineWarn,$CodWarn,$FormaWarn,$DataWarn);
}
sub LTrim (@fields)
{
for(j=0;substr($fields,j,1) == " ";j++);
return substr($fields,j,length($fields)-j+1);
}
#Version 1.1: voir description
sub CharToSpace(Field,ReplaceChar,LenRepChar)
{
$fields = fields;
for (i=1; i<=$LenRepChar; i++)
{
$Char = @ReplaceChar[i,1];
if ( $Char == "\\" )
{
gsub("\\"$Char, @ReplaceChar[i,2], $fields);
}
else
{
gsub($Char, @ReplaceChar[i,2], $fields);
}
}
return $Field;
}
#Corps du programme : Controle de la structure du fichier
/[^$]/
{
#Recuperation du code ISIN/NumHist
if ( substr($9,1,4) == "ISIN" )
{
$ValTypCod=printf("%s%s",substr($7,1,1),substr($7,3,length($7)-3));
}
else
{
$ValTypCod=printf("%s",substr($7,3,length($7)-2));
}
$B_PTF1 = printf("%s%s%s%s%s%s%s",$2,$3,$4,$5,$6,$ValTypCod,$8);
#Controle des champs
for (i=1; i<NF-1; i++)
{
split($fielfs[1,i],SUBTAB,"_");
#Control anomalie 1001
if ( length($i) != SUBTAB[2])
{
$IdentField = $fields[2,i];
$IdentWarn++;
$IdentlineWarn = $B_PTF1;
$CodWarn = $CodLengthErr[0];
$FormaWarn = $CodLengthErr[1];
$DataWarn = $i;
$MESSAGE = printf("%s%s\n",$MESSAGE,$GetWarning());
$PROBLEM="TRUE";
}
#Control anomalie 1005
if(LTrim($i) == "")
{
$IdentField = $fields[2,i];
$IdentWarn++;
$IdentlineWarn = $B_PTF1;
$CodWarn = $CodDataErr[0];
$FormaWarn = $CodDataErr[1];
$DataWarn = $i;
$MESSAGE = printf("%s%s\n",$MESSAGE,$GetWarning());
$PROBLEM="TRUE";
}
}
#Incrementation des nombres de lignes en anomalies
if ( $PROBLEM == "TRUE" )
{
$NbLineWarn++;
}
#Construction d un enregistrement
$B_PTF2 = $B_PTF1;
$B_GRP = sprintf("%s%s%s%s%s",$2,$3,$4,$5,$6);
#Version 1.1: voir description
printf("%s\t%s\t%s\t%s\t\t\n",$1, CharToSpace($B_PTF1,$ReplaceChar,$LenRepChar) \
,CharToSpace($B_PTF2,$ReplaceChar,$LenRepChar) \
,CharToSpace($B_GRP,$ReplaceChar,$LenRepChar));
$TABNR[NR] = MESSAGE;
#Initialisation des variables
$B_PTF1="";
$B_PTF2="";
$B_GRP="";
$MESSAGE = "";
$PROBLEM = "FALSE";
}
#Recuperation des lignes erronnees ainsi que le nombre des lignes erronnees
END
{
for ( i=1 ;i<=NR ;i++)
{
printf("%s",$TABNR[i]);
}
printf("%s\n",$NbLineWarn);
}"'">${OUTPUT}.tmp
CODERR=$?
#RECUPERATION DU FICHIER DE CONTROLE
if [ $CODERR -ne 0 ]
{
print "[Erreur] : le fichier ${output}.tmp n a pu etre cree";
exit 1;
}
else
{
#FIN CONTROLE ET FORMATAGE DU FICHIER ARPSON
print "FIN CONTROLE ET FORMATAGE DU FICHIER $input";
$NBLINE_TOT=`wc -l ${OUTPUT}.tmp | awk '{print $1}'`;
#Recuperation du nombre de lignes reel traite sans la ligne consacre au nombre des lignes en erreur
$REALNBLINE_TOT=`print ${NBLINE_TOT}-1|bc`;
if [ ${REALNBLINE_TOT} -ne ${NBLINE} ]
{
print "PROBLEME SUR LE FICHIER PTF GENERE";
#recuperation du nombre des lignes en anomalies
$NBLINE_ANO=`cat ${OUTPUT}.tmp | tail -1`;
print "RECUPERATION DU FICHIER USER LOG";
#il faut soustraire la ligne portant le nombre des lignes erronnees et les lignes des messages d erreurs
$NBLINE_LOG=`print ${REALNBLINE_TOT}-${NBLINE}|bc`;
$NBLINE_MES=`print ${NBLINE_LOG}+1 |bc`;
print "Nombre de ligne en entree: "$NBLINE | tee -a $CONTROL;
print "Nombre de ligne avec anomalie: "$NBLINE_ANO | tee -a $CONTROL;
print "Nombre de ligne en sortie: "$NBLINE | tee -a $CONTROL;
print "Nombre d'anomalies: "$NBLINE_LOG | tee -a $CONTROL;
print "\nErreur sur les lignes suivantes:" | tee -a $CONTROL;
open read ${OUTPUT}.tmp | tail -$NBLINE_MES | head -${NBLINE_LOG} | tee -a $CONTROL;
open read ${OUTPUT}.tmp | head -${NBLINE} > ${OUTPUT};
}
else
{
open read ${OUTPUT}.tmp | head -${NBLINE} > ${OUTPUT};
touch $CONTROL;
print "PAS DE PROBLEMES SUR LE FICHIER PTF GENERE";
}
unlink ${OUTPUT}.tmp;
}
} |
Partager