 |
» |
|
|
|
|  |  |
The order in which records are physically written to a data file is called chronological order. This order is not necessarily the same as a sequence by key value although it may be. In particular, if the records were written by a COBOL procedure to a file opened for sequential access, then the chronological sequence and the primary key sequence are the same. If, however, these orders differ, then the file system provides an intrinsic that allows you to read a KSAM file in chronological order. Figure 5-4 “Reading KSAM File in Chronological Sequence Using FORTRAN” is a program that uses the intrinsic FREADC to read the records in the order they were stored in the file. Other file system intrinsics allow you to position the file to a particular record number in chronological order (FPOINT), to retrieve the current chronological record number (FGETINFO),
and to read a record located by its chronological record number (FREADDIR). The COBOL procedures for KSAM interface do not provide the means to access records by chronological record number. Figure 5-4 Reading KSAM File in Chronological Sequence Using FORTRAN
C*************************************************************
C EXAMPL3 *
C READ KSAM FILE CHRONOLOGICALLY *
C ************************************************************
SYSTEM INTRINSIC F0PEN,FCLOSE,FERRMSG,FCHECK
SYSTEM INTRINSIC FREADC
INTEGER FILNUM
CHARACTER FILENAME*10
CHARACTER OUTPUT*72
CHARACTER MESSAGE(72)
LOGICAL INPUT (36)
LOGICAL MESSAGEW(36)
EQUIVALENCE (MESSAGE,MESSAGEW)
EQUIVALENCE (OUTPUT,INPUT)
DATA FILENAME/"FEXAMFIL "/
C**************************************************************
C OPEN KSAM FILE FOR INPUT *
C**************************************************************
FILENUM=FOPEN(FILNAME,%7L)
IF (FILNUM .EQ. 0) GO TO 200
C**************************************************************
C READ DATA FROM FlLE IN *
C CHRONOLOGICAL ORDER *
C**************************************************************
DISPLAY "PRINT RECORDS IN CHRONOLOGICAL ORDER"
20 ILEN=FREADC(FILNUM,INPUT,-72)
IF (.CC.) 300,30,50
30 DISPLAY OUTPUT
GO TO 20
C**************************************************************
C CLOSE FILE *
C**************************************************************
50 CALL FCLOSE(FILNUM,0,0)
IF (.CC.) 600,55,600
55 STOP "END OF JOB"
C**************************************************************
C ERROR MESSAGES *
C**************************************************************
200 CALL FCHECK(FILNUM,IERRNUM)
CALL FERRMSG(IERRNUM,MESSAGEW,LENGTH)
WRITE(6,250)(MESSAGE(I),I=1,LENGTH)
STOP "CANNOT OPEN KSAM FILE"
300 CALL FCHECK(FILNUM,IERRNUM)
CALL FERRMSG(IERRNUM,MESSAGEW,LENGTH)
WRITE(6,250)(MESSAGE(I),I=1,LENGTH)
STOP "ERROR OCCURRED READING IN CHRONOLOGICAL ORDER"
600 CALL FCHECK(FILNUM,IERRNUM)
CALL FERRMSG(IERRNUM,MESSAGEW,LENGTH)
WRITE(6,250)(MESSAGE(I),I=1,LENGTH)
STOP "CANNOT CLOSE FILE"
250 FORMAT(IX,72A1)
END
Output from Program Execution:
PRINT RECORDS IN CHRONOLOGICAL ORDER
NOLAN JACK 923-4975 967 REED AVE, SUNNYVALE
HOSODA JOE 227-8214 1180 SAINT PETER CT. LOS ALTOS
ECKSTEIN LEO 287-5137 5303 STEVE'S CREEK SANATA CLARA
CARDIN RICK 578-7018 11100 WOLFE ROAD CUPERTINO
PASBY LINDA 295-1187 TOWN & CNTRY VILLAGE SAN JOSE
SEELY HENRY 293-4220 1144 LEBERTY ST. EL CERRITO
ROBERT GERRY 259-5535 12345 TELEGRAPH AVE. BERKELEY
TURNEWR IVAN 984-8498 22905 EMERSON ST. OAKLAND
WHITE GORDON 398-0301 4350 ASHBY AVE. BERKELEY
WEBSTER ELDER 287-4598 1256, KINGFIDHER ST. SUNNYVALE
STOP END OF JOB
|
|