[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

[sqr-users] How to read a flat file that has a trailer line



I am writing an SQR to read a flat file that has a trailer line at the end with 
different fields than the rest of the file.  The trailer line could be anywhere 
from 5 to 400 lines from the top of the file.  It is marked with a 'T' at the 
beginning

I'm not sure how to tackle this - I know the basics:

open $FileName as 1 for-reading record={IntLength1}:{IntType1} 
status=#filestat......

while 1 = 1 

  READ 1 INTO $INPUT_AREA:{IntLength1}.....

 !Detail line is

        EXTRACT $OUTD-TYPE         FROM $INPUT_AREA          0  1
        EXTRACT $OUTD-CRE-DATE     FROM $INPUT_AREA          1  9
        EXTRACT $OUTD-TRAN-UNIQ    FROM $INPUT_AREA          9 11
        EXTRACT $OUTD-SEQ          FROM $INPUT_AREA         11 14
        EXTRACT $OUTD-BUS-UNIT     FROM $INPUT_AREA         14 19
        EXTRACT $OUTD-MDCY         FROM $INPUT_AREA         19 27
        EXTRACT $OUTD-ACCOUNT      FROM $INPUT_AREA         27 37
        EXTRACT $OUTD-DEPTID       FROM $INPUT_AREA         37 47
        EXTRACT $OUTD-OPER-UNIT    FROM $INPUT_AREA         47 55
        EXTRACT $OUTD-PROD-ID      FROM $INPUT_AREA         55 61
        EXTRACT $OUTD-AMOUNT       FROM $INPUT_AREA         61 72
        EXTRACT $OUTD-DELIM        FROM $INPUT_AREA         72 74
         
 !Trailer line is
 
        EXTRACT $OUTT-TYPE         FROM $INPUT_AREA          0  1
        EXTRACT $OUTT-COUNT        FROM $INPUT_AREA          1  9
        EXTRACT $OUTT-DEBITS       FROM $INPUT_AREA          9 21
        EXTRACT $OUTT-CREDITS      FROM $INPUT_AREA         21 33
        EXTRACT $UNKNOWN           FROM $INPUT_AREA         33 35
        EXTRACT $OUTT-DELIM        FROM $INPUT_AREA         35 37

   do Process-Data
     
end-while

How do I read the last trailer line with different field positions and lengths?

Example of input file:

D2007010201036955  12312006111005                            0000000261543
C2007010201037955  12312006531010    428               00    0000000250865
C2007010201038955  12312006534010    999               00    0000000010678
T000000380000011780745200000117807452                                     

How do I tell the program to read until it gets to 'T' then change what it 
extracts after the 'T'?

TIA,

Joe

_______________________________________________
sqr-users mailing list
sqr-users@sqrug.org
http://www.sqrug.org/mailman/listinfo/sqr-users