Here is the List of Validation. We need to send mail for each validation failure. First Char is Type of Record Say Header/Detail/Trailer
1. The first record in the file must be the header record.
2. The file can have at most one header record.
3. The date on the header should match the date received (Note: If a file in error is retransmitted the next day, this may not be so. The purpose of this edit is to make sure that we are not picking up a duplicate of an earlier file.)
4. The last record in the file must be a trailer record. (This means that the file can have at most one trailer record, and that there should be no header or detail records following the trailer record.)
5. Every record between the header record and the trailer record must be a detail record.
6. The trailer count should match the calculated number of detail records in the file.
Is the file name same i ment for the one validation has to be done?
it will be <filename><receivedate>.txt format.
The date feild in the first line can be validated with system date ?
Yes
The first line i ment header is always with time stamp and footer is always with no. of records?
Yes...Header will be date & time stamp and footer will be with total records
Will ther be a common patern matcher for the record... in teh below case like "DARMAR"
D stands for detail...after that records will be changed.
First Char is Type of Record Say Header/Detail/Trailer
Last records contains number of detail records i.e. 11 it can be 105 or 1230 also but position will be same always.
First record has date which is 20090115011817 in yyyymmddhhmmss format position in header will be same always
Checks if the files header corresponds to the current date.
else the output is "record not of todays date"
Checks if the file has more than one header it wil fail with error "record is corrept"
Checks the date in the header with the system date if ther is a missmatch it wil fail with "record not of todays date"
If there are more than one trailer record it wil give output "record is corrept"
Every record between the header and trailer is considered as a Detail record. I was not able to check the consistancy of that as u did not give me any standard on that.
The trailer count will match the records found if sucessful it wil give message "record is perfect" else fails with the message its corrept.
I have not considered output to be redirected to a file.
Example:
Bips> cat test
HSVSHOSTRECON 20090219011817BP
DARMAR60064966247003504720000000000000000000066626000000000000133000003D003463001332
DARMAR60064966247008334930000000000000000000066626000000000000191000003D006888001911
DARMAR60064966247023430040000000000000000000066626000000000000237000003D010451002371
DARMAR60064966247018096900000000000000000000066626000000000000358000003D000069003581
DARMAR60064966247026650830000000000000000000066626000000000000358000003D011186003581
T00000005
Bips> sh sample test
Record generated today found
Expected enties as per footer:5
record is perfect
----
2nd case :
---
Bips> cat test
HSVSHOSTRECON 20090219011817BP
DARMAR60064966247003504720000000000000000000066626000000000000133000003D003463001332
DARMAR60064966247008334930000000000000000000066626000000000000191000003D006888001911
DARMAR60064966247023430040000000000000000000066626000000000000237000003D010451002371
DARMAR60064966247018096900000000000000000000066626000000000000358000003D000069003581
DARMAR60064966247026650830000000000000000000066626000000000000358000003D011186003581
T00000005
T00000005
Bips> sh sample test
Record generated today found
Expected enties as per footer:5
"Every record between the header and trailer is considered as a Detail record. I was not able to check the consistancy of that as u did not give me any standard on that."
Can you please let me know what you need to know about consistency ?
All the records between header and Trailer must be detail record. If there are more than one header or trailer record than file is corrupt.
#!/bin/ksh
today=`date +%Y%m%d`
TRAILER=false
HEADER=false
DETAIL=0
while read LINE
do
#
# Validating 1st record is Header + header's date
#
FIRST_CAR=`echo $LINE | cut -c1`
if [ $HEADER = "false" -a $FIRST_CAR = "H" ]
then
HEADER=true
echo $LINE | grep $today > /dev/null
if [ $? -eq 1 ]
echo "Header record not from today"
exit 1
fi
else
#
# Validating detail record or trailer recors
#
if [ $HEADER = "true" ]
then
if [ $FIRST_CAR = "D" ]
then
if [ $TRAILER = "false" ]
then
DETAIL=`expr $DETAIL + 1`
else
echo "File is corrupt - Detail record found after a trailer record"
exit 1
fi
else
if [ $FIRST_CAR = "T" -a $TRAILER = "false" ]
then
TRAILER=true
TOT=`echo $LINE | cut -c2-`
if [ $DETAIL -ne $TOT ]
then
echo "File is corrupt - Number of detail record mismatch"
exit 1
fi
else
echo "File is corrupt - Invalid record or more than one header/trailer record"
exit 1
fi
fi
else
echo "File is corrupt - No header record found"
exit 1
fi
fi
done < $1
if [ "$TRAILER" = "false" ]
then
echo "File is corrupt - No trailer record found"
exit 1
else
echo "File seems to be Ok"
fi