BCS MVS KSDS VSAM COBOL

There are those time when a KSDS (key sequenced data set) using the VSAM (virtual sequential access method) fits the users requirements. The following example explains how such a feat is accomplished. First we need to create the KSDS and the JCL listed below defines how we will create our cluster.

//AMBMVS   JOB (SYS), 'BROOKS COMPUTING SYSTEMS, LLC',CLASS=A,
// MSGCLASS=A,MSGLEVEL=(1,1)
//*
//*
//DEFKSDS  EXEC PGM=IDCAMS
//SYSPRINT DD   DSN=AMBMVS.PDS.SPRT(KSDS),DISP=SHR
//SYSIN    DD   *
 DELETE (AMBMVS.VSAMKSDS.EMPSORTD) CLUSTER
 DEFINE CLUSTER ( -
  NAME (AMBMVS.VSAMKSDS.EMPSORTD) -
  CYLINDERS(1,1) -
  KEYS(20,0) -
  VOLUME(USR003) -
  RECORDSIZE(80,80) -
  INDEXED )
 REPRO INFILE(INFILE) OUTDATASET(AMBMVS.VSAMKSDS.EMPSORTD)
/*
//INFILE DD   DSN=AMBMVS.PDS.CNTL(INPKSDS),DISP=SHR
//*

The input data is listed below.

BUD WHYZER          05000  9  0001  0000001  000000
RALPH CRAMDEN       03000  1  0040  0000055  000022
MIKE KEE            06000  1  0200  0000020  000020
L. A. VATOR         07000  5  0020  0000033  000033
PAUL LONGA          04000  0  0002  0000022  000011
PEARLE E. GATES     01000  2  0010  0000020  000300
MIKE MENZA          02000  3  0030  0000050  000020

Next we will review the COBOL sub program that will perform the VSAM IO.

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.    ABS00017.
000300 AUTHOR.        ARCH BROOKS.
000400 INSTALLATION   BROOKS COMPUTING SYSTEMS, LLC.
000500 DATE-WRITTEN.  10/21/2014.
000600 DATE-COMPILED. 10/21/2014.
000700 ENVIRONMENT DIVISION.
000800 CONFIGURATION SECTION.
000900 SOURCE-COMPUTER. IBM-Z-OS.
001000 OBJECT-COMPUTER. IBM-Z-OS.
001100 INPUT-OUTPUT SECTION.
001200 FILE-CONTROL.
001300     SELECT VSAM-KSDS-FILE ASSIGN VSAMKSDS
001400        ORGANIZATION IS INDEXED
001500        ACCESS MODE IS RANDOM
001600        RECORD KEY IS VSAM-KSDS-RECORD-KEY
001700        FILE STATUS  IS VSAM-STATUS-CODE.
001800 DATA DIVISION.
001900 FILE SECTION.
002000 FD  VSAM-KSDS-FILE.
002100 01  VSAM-KSDS-RECORD.
002200     05  VSAM-KSDS-RECORD-KEY    PIC X(20).
002300     05  VSAM-KSDS-EMP-INFO      PIC X(60).
002400 WORKING-STORAGE SECTION.
002500 LINKAGE SECTION.
002600 01  VSAM-STATUS-CODE.
002700     05 VSAM-STATUS-CODE-BYTE1   PIC X.
002800     05 VSAM-STATUS-CODE-BYTE2   PIC X.
002900 01  REC-KEY PIC X(20).
003000 01  REC-BUF PIC X(80).
003100 PROCEDURE DIVISION USING VSAM-STATUS-CODE.
003200     PERFORM 0010-INIT.
003300 0010-INIT.
003400     OPEN INPUT VSAM-KSDS-FILE
003500     IF VSAM-STATUS-CODE IS NOT EQUAL TO '00' THEN
003600         PERFORM 0050-ERROR-EXIT.
003700     PERFORM 0060-LEAVE-PROGRAM.
003800     ENTRY 'ABS0017A' USING VSAM-STATUS-CODE REC-KEY REC-BUF.
003900 0030-RANDOM-READ.
004000     MOVE REC-KEY TO VSAM-KSDS-RECORD-KEY.
004100     READ VSAM-KSDS-FILE.
004200     MOVE VSAM-KSDS-RECORD TO REC-BUF.
004300     PERFORM 0060-LEAVE-PROGRAM.
004400     ENTRY 'ABS0017B' USING VSAM-STATUS-CODE.
004500 0040-TERMINATION.
004600     CLOSE VSAM-KSDS-FILE.
004700     PERFORM 0060-LEAVE-PROGRAM.
004800 0050-ERROR-EXIT.
004900     DISPLAY 'ERROR DETECTED '.
005000     PERFORM 0060-LEAVE-PROGRAM.
005100 0060-LEAVE-PROGRAM.
005200     GOBACK.

Now we will review the calling COBOL program.

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.    ABM00025.
000300 AUTHOR.        ARCH BROOKS.
000400 INSTALLATION   BROOKS COMPUTING SYSTEMS, LLC.
000500 DATE-WRITTEN.  10/23/2014.
000600 DATE-COMPILED. 10/23/2014.
000700 ENVIRONMENT DIVISION.
000800 CONFIGURATION SECTION.
000900 SOURCE-COMPUTER. IBM-Z-OS.
001000 OBJECT-COMPUTER. IBM-Z-OS.
001100 INPUT-OUTPUT SECTION.
001200 FILE-CONTROL.
001300 DATA DIVISION.
001400 FILE SECTION.
001500 WORKING-STORAGE SECTION.
001600 01  REC-KEY PIC X(20).
001700 01  S-CODE PIC XX.
001800 01  REC-BUF PIC X(80).
001900 PROCEDURE DIVISION.
002000     MOVE ' ' TO S-CODE.
002100     CALL 'ABS00017' USING S-CODE.
002200     DISPLAY 'OPEN STATUS IS ' S-CODE.
002300     MOVE 'BUD WHYZER' TO REC-KEY
002400     CALL 'ABS0017A' USING S-CODE REC-KEY REC-BUF.
002500     IF S-CODE =       '00'
002600     THEN DISPLAY 'RECORD READ ' REC-KEY
002700     DISPLAY REC-BUF
002800     ELSE IF S-CODE =       '23'
002900     THEN DISPLAY 'RECORD NOT FOUND ' REC-KEY.
003000     CALL 'ABS0017B' USING S-CODE.
003100     GOBACK.

Now we will review the command procedure that invokes the calling program.

PROC 0
CONTROL NOLIST NOMSG
FREE FI(SYSPRINT SYSOUT FSFIN VSAMKSDS))
ALLOC F(VSAMKSDS) DA(VSAMKSDS.EMPSORTD) SHR
ALLOC FI(SYSPRINT) DA(*)
ALLOC FI(FSFIN) DA(*)
ALLOC FI(SYSOUT) DA(*)
CALL 'AMBMVS.PDS.LOAD(ABM00025)'
FREE FI(SYSPRINT SYSOUT FSFIN VSAMKSDS)

Upon successful execution of the command procedure you will notice the return code and well as the fetched record will be displayed.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

Leave a Reply