Retrieval of records from VSAM files organized as KSDS can be sequential, skip sequential, or direct, using a full or partial key. You can change the method of retrieval at any point within the Reporting Facility program by modification of the 'defineparameters' associated with the file. This section describes each method of access and the associated required 'defineparameters'.
Sequential Retrieval of KSDS Files:
You do not need to specify 'defineparameters' for sequential access to a KSDS file. The Reporting Facility automatically assumes the parameters to be 'KSDS,KEY,SEQ'. However, you can supply 'defineparameters' with one of the following:
The following is a Reporting Facility program illustrating the techniques necessary for KSDS VSAM sequential file access:
USER 'XYZ COMPANY, INC.'
MASTER: FILE VSAM RECORD=100
DEF DIVISION 1-2 X
DEF DEPARTMENT 3-5 X
DEF EMPLOYEE-NUMBER 6-9 N 'EMPNO'
DEF EMPLOYEE-NAME 10-25 X
REPORT 'KSDS SAMPLE 1'
SELECT ALL
CONTROL EMPLOYEE-NUMBER
PRINT DIVISION DEPARTMENT EMPLOYEE-NUMBER EMPLOYEE-NAME
END
Skip Sequential Retrieval of KSDS Files:
Retrieval of KSDS files using the skip sequential method is far more efficient than direct retrieval. When using this method, the first record made available is one that is equal to or greater than the specified key. The keys specified within the Reporting Facility program definition must be in ascending sequence.
Code the 'defineparameters' necessary for skip sequential processing of a KSDS VSAM file as follows:
►►─ 'KSDS,KEY,SKP ─┬───────────┬─ ' ──────────────────────────────────────────►◄ └─ ,GEN(n) ─┘
Is the length of the generic key. You must specify it when you request a generic key.
The following Reporting Facility program illustrates the techniques necessary for KSDS VSAM skip sequential file access. Access is performed with a full key argument.
USER 'XYZ COMPANY, INC.'
MASTER: FILE VSAM RECORD=100
DEF FILE-KEY 1-9 X
DEF DIVISION 1-2 X
DEF DEPARTMENT 3-5 X
DEF EMPLOYEE-NUMBER 6-9 N 'EMPNO'
DEF EMPLOYEE-NAME 10-25 X
DEF FIRST-TIME-SWITCH(1) EQ 'F'
GOTO DO-SEQUENTIAL-ACCESS WHEN FIRST-TIME-SWITCH NE 'F'
MOVE 'AA0019999' TO FILE-KEY
MOVE 'KSDS,KEY,SKP' TO MASTER.VSAM
GET MASTER
MOVE 'SEQ' TO MASTER.VSAM
MOVE 'N' TO FIRST-TIME-SWITCH
GOTO TEST WHEN MASTER NE END-OF-FILE
MOVE BLANK TO MASTER
GOTO TEST
DO-SEQUENTIAL-ACCESS: CONTINUE
GET MASTER
GOTO EOJ WHEN MASTER EQ END-OF-FILE
REPORT 'KSDS SKIP SEQUENTIAL SAMPLE 1'
SELECT ALL
CONTROL EMPLOYEE-NUMBER
PRINT DIVISION DEPARTMENT EMPLOYEE-NUMBER EMPLOYEE-NAME
END
The following is a Reporting Facility program illustrating the techniques necessary for KSDS VSAM skip sequential file access. Access is performed with a generic key argument.
USER 'XYZ COMPANY, INC.'
MASTER: FILE VSAM RECORD=100
DEF FILE-KEY 1-9 X
DEF DIVISION 1-2 X
DEF DEPARTMENT 3-5 X
DEF EMPLOYEE-NUMBER 6-9 N 'EMPNO'
DEF EMPLOYEE-NAME 10-25 X
DEF FIRST-TIME-SWITCH(1) EQ 'F'
GOTO DO-SEQUENTIAL-ACCESS WHEN FIRST-TIME-SWITCH NE 'F'
MOVE 'AA' TO DIVISION
MOVE 'KSDS,KEY,SKP,GEN(2)' TO MASTER.VSAM
GET MASTER
MOVE 'SEQ' TO MASTER.VSAM
MOVE 'N' TO FIRST-TIME-SWITCH
GOTO TEST WHEN MASTER NE END-OF-FILE
MOVE BLANK TO MASTER
GOTO TEST
DO-SEQUENTIAL-ACCESS: CONTINUE
GET MASTER
GOTO EOJ WHEN MASTER EQ END-OF-FILE
REPORT 'KSDS SKIP SEQUENTIAL SAMPLE 2'
SELECT ALL
CONTROL EMPLOYEE-NUMBER
PRINT DIVISION DEPARTMENT EMPLOYEE-NUMBER EMPLOYEE-NAME
END
Direct Retrieval of KSDS Files:
To perform direct retrieval of KSDS files, use the full key argument or a generic key for the file. If this method does not make available the first record that contains the specified key, a NO-RECORD-FOUND condition occurs.
With direct retrieval using a generic key argument, the record made available is one that is equal to or greater than the specified key. The generic key length can be equal to the full key length.
Code the 'defineparameters' necessary for direct retrieval of a KSDS VSAM file as follows:
►►─ 'KSDS,KEY,DIR ─┬───────────┬─ ' ──────────────────────────────────────────►◄ └─ ,GEN(n) ─┘
Is the length of the generic key. You must specify it when you request a generic key.
The following Reporting Facility program illustrates the techniques necessary for KSDS VSAM direct file access. Access is shown here with a full key argument.
USER 'XYZ COMPANY, INC.'
CARDIN: FILE CARD
DEF CARD-KEY 1-9 X
MASTER: FILE VSAM RECORD=100
DEF FILE-KEY 1-9 X
DEF DIVISION 1-2 X
DEF DEPARTMENT 3-5 X
DEF EMPLOYEE-NUMBER 6-9 N 'EMPNO'
DEF EMPLOYEE-NAME 10-25 X
MOVE CARD-KEY to FILE-KEY
GET MASTER
SET MESSAGE(15) TO ' '
GOTO TEST WHEN MASTER NE 'E'
MOVE SPACE TO MASTER
MOVE 'NO RECORD FOUND' TO MESSAGE
REPORT 'KSDS DIRECT RETRIEVAL SAMPLE 1'
SELECT 'A' WHERE FILE-KEY EQ CARD-KEY
SELECT ALL
CONTROL EMPLOYEE-NUMBER
PRINT CARD-KEY A;DIVISION A;DEPARTMENT A;EMPLOYEE-NUMBER
A;EMPLOYEE-NAME MESSAGE
END
|
Copyright © 2014 CA.
All rights reserved.
|
|