Using KSAM/XL and KSAM 64 (32650-90886)

Appendix A 219
COBOL Intrinsics
Examples of KSAM File Access
Examples of KSAM File Access
The following three examples illustrate KSAM file access from a COBOL program. The file
accessed in each example is called KSAMFILE. It was created previously with BYTE type
keys: the primary key containing the name of a person and the alternate key containing
his telephone number. The remaining data in each record is his address.
Sequential Write
The first example reads data from an input file into working storage and then writes it to a
KSAM file. Access mode is sequential so that as each record is written, the keys are linked
in sequential order although the records are not physically written in sequence.
Input/output type is output only, the only type allowed for the procedure CKWRITE. The
following procedures are illustrated:
CKOPEN
CKWRITE
CKCLOSE
Figure A-4. Sequential Write Using COBOL
Input to EXAMP1:
NOLAN JACK 923-4975 967 REED AVE. SUNNYVALE CA. 94087
HOSODA JOE 227-8214 1180 SAINT PETER CT. LOS ALTOS CA. 94022
ECKSTEIN LEO 287-5137 5303 STEVENS CREEK SANTA CLARA CA. 95050
CARDIN RICK 578-7018 11100 WOLFE ROAD CUPERTINO CA. 94053
PASBY LINDA 295-1187 TOWN & CNTRY VILLAGE SAN JOSE CA. 94012
SEELY HENRY 293-4220 1144 LIBERTY ST. EL CERRITO CA. 94053
ROBERT GERRY 258-5535 12345 TELEGRAPH AVE. BERKELEY CA. 90871
TURNEWR IVAN 984-8498 22905 EMERSON ST. OAKLAND CA. 98234
WHITE GORDON 398-0301 4350 ASHBY AVE. BERKELEY CA. 91234
WESTER ELDER 287-4598 1256 KINGFISHER ST. SUNNYVALE CA. 43098
**END OF INPUT FOR EXAMP1**
Program EXAMP1
001000 IDENTIFICATION DIVISION.
001100 PROGRAM-ID. EXAMP1.
001200 ENVIRONMENT DIVISION.
001300 INPUT-OUTPUT SECTIONS
001400 FILE-CONTROL.
001500 SELECT SEQ-DATA ASSIGN TO "SEQDATA".
001600 DATA DIVISION.
001700 FILE SECTION.
001800 FD SEQ-DATA
001900 LABEL RECORDS ARE STANDARD.
002000 01 INPUT-REC.
002100 05 REAL-DATA PIC X(72).
002200 WORKING-STORAGE SECTION.
002300 77 RECSIZE PIC S9(4) COMP VALUE 74.
002400 77 RESULT PIC 9(4) VALUE ZERO.