[USflag] The American Programmer [USflag]


Home
Books on Mainframe Programming
Mainframe Manuals and Tutorials
System Abend codes, Sqlcodes, VSAM/QSAM codes
Everything about the IBM AS/400 Midrange Computer - iSeries
Everything about CICS
Cobol programs, manuals, books
  Sample Cobol code: The Simple, Single File COBOL Program
  Sample Cobol code: The Simple, Single File Report COBOL Program with Record Count or Final Totals
  Sample Cobol code: The Simple, Single File Report COBOL Program with Record Count or Final Totals
  Sample Cobol code: The Sequence Check COBOL Program
  Sample Cobol code: The Record Selection COBOL Program
  Sample Cobol code: The Edit or Validate COBOL Program
  Sample Cobol code: The The One Level Subtotal (Control Break) COBOL Program
  Sample Cobol code: The Three Level Subtotal (Control Break) COBOL Program
  Sample Cobol code: The Sequential File, Batch Update COBOL Program
  Sample Cobol code: The COBOL Sort
  Sample Cobol code: The CASE Structure: COBOL EVALUATE
  Sample Cobol code: Direct Subscripting in COBOL
  Sample Cobol code: The Sequential, or Serial Search in COBOL
  Sample Cobol code: The Binary Search in COBOL
  Sample Cobol code: Loading a Table from a Sequential File in a COBOL program
  Sample Cobol code: The VSAM File Read Sequentially in a COBOL program
  Sample Cobol code: The VSAM KSDS, Read Randomly in a COBOL program
  Sample Cobol code: The VSAM File, Read Randomly in a COBOL program
  Sample Cobol code: VSAM Initial Load in a COBOL program
  Sample Cobol code: VSAM File Maintenance (Add, Change, Delete) in a COBOL program
  Sample Cobol code: VSAM Read Sequentially, with START, in a COBOL program
  Sample Cobol code: Creating a Variable Format File in a COBOL program
  Sample Cobol code: Reading a Variable Format File in a COBOL program
  Sample Cobol code: Creating a Variable Format File with Occurs Depending On in a COBOL program
  Sample Cobol code: COBOL Reading a Variable Format File with Occurs Depending On, in a COBOL program
  Sample Cobol code: COBOL The Table Load with Occurs Depending On
  Sample Cobol/DB2 code: Singleton Select
  Manuals on the COBOL programming language.
  Books on Cobol
  Abend Codes from Cobol programs
Everything about DB2 and SQL
Everything about IMS
Everything about Java and JavaScript
Everything about JCL and JES
Everything about REXX
Everything about zOS, VSAM, Tivoli, Assembler
Everything about TSO, ISPF, Spufi
Site Map and Site Search

           Home   > COBOL   > COBOL program VSAM Read Sequentially, with START

VSAM Read Sequentially, with START, in a COBOL program


21. VSAM Read Sequentially, with START

VSAMSTR1.
We are going to read a VSAM file sequentially with a new twist: we will not start at the beginning of the VSAM file, we will start somewhere in the middle.
It uses the START verb to start in the middle. Other than that, it is exactly like the VSAM KSDS read sequentially.

Here is the program VSAMSTR1:

Compliments of Gabe Gargiulo, author of several recent books on programming and modern languages, available at Amazon.com.



000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. VSAMSTR1.
000300* READ VSAM KSDS SEQUENTIALLY
000400*          STARTING IN THE MIDDLE OF THE FILE: USES START
000500* JUST DISPLAY THE VSAM RECORDS
000600* THE LOGIC IS THE SAME AS FOR THE SIMPLE FILE READ SEQUENTIALLY
000700* IMPORTANT CLAUSES ARE ORGANIZATION IS INDEXED
000800* ACCESS MODE IS SEQUENTIAL   OPEN INPUT
000900* 23 ON A START IS CAN'T FIND, CAN'T DO IT. USE READ...AT END
001000 ENVIRONMENT DIVISION.
001100 CONFIGURATION SECTION.
001200 INPUT-OUTPUT SECTION.
001300 FILE-CONTROL.
001400*    INPUT VSAM FILE IS: TSOUSR1.VSAMKSDS.EMPSORTD
001500*    JCL TO CREATE INPUT FILE IS VSAMDEF.JCL
001600*    USES EMPSORTD AS INPUT TO JCL
001700*    OF COURSE THE NAMES MAY BE DIFFERENT AT YOUR COMPANY
001800     SELECT VSAM-KSDS-FILE ASSIGN VSAMKSDS
001900        ORGANIZATION IS INDEXED
002000        ACCESS MODE IS SEQUENTIAL
002100        RECORD KEY IS VSAM-KSDS-RECORD-KEY
002200        FILE STATUS  IS VSAM-STATUS-CODE
002300                        VSAM-EXTENDED-STATUS-CODE.
002400 DATA DIVISION.
002500 FILE SECTION.
002700 FD  VSAM-KSDS-FILE.
002800 01  VSAM-KSDS-RECORD.
002900*    THE 20 MEANS THE KEY FIELD HAS A LENGTH OF 20
003000*    REFER  BACK TO THE JCL WHICH CREATES THE VSAM FILE
003100*    BECAUSE THAT IS WHERE THE 20 COMES FROM
003200*    THE RECORD KEY IS ACTUALLY EMPLOYEE NAME IN THIS DATA FILE
003300     05  VSAM-KSDS-RECORD-KEY    PIC X(20).
003400     05  VSAM-KSDS-EMP-INFO    PIC X(60).
003600 WORKING-STORAGE SECTION.
003700
003800 01  VSAM-STATUS-CODE.
003900     05 VSAM-STATUS-CODE-BYTE1   PIC X.
004000     05 VSAM-STATUS-CODE-BYTE2   PIC X.
004200 01  VSAM-EXTENDED-STATUS-CODE.
004300     05 VSAM-EXTENDED-RETURN-CODE   PIC S9(4) COMP.
004400     05 VSAM-EXTENDED-FUNCTION-CODE PIC S9(4) COMP.
004500     05 VSAM-EXTENDED-FEEDBACK-CODE PIC S9(4) COMP.
004600
004700 01  SWITCHES.
004800      05  FILE-AT-END     PIC X  VALUE 'N'.
005000 PROCEDURE DIVISION.
005100     PERFORM INITIALIZATION
005200     PERFORM PROCESS-ALL
005300         UNTIL FILE-AT-END = 'Y'
005400     PERFORM TERMINATION
005500     GOBACK.
005600
005700 INITIALIZATION.
005800     OPEN INPUT VSAM-KSDS-FILE
005900     IF VSAM-STATUS-CODE IS NOT EQUAL TO '00'
006000     THEN GO TO ERROR-EXIT
006100     END-IF
006200*     THIS IS WHAT IS ADDED, FOR THE START VERB
006300*     PLACE A DATA VALUE IN THE RECORD KEY
006400*     IT NEED NOT BE AN EXACT MATCH, IF YOU USE > (GREATER THAN)
006500      MOVE 'MAL A. MUTE' TO VSAM-KSDS-RECORD-KEY
006600      START VSAM-KSDS-FILE    KEY IS >  VSAM-KSDS-RECORD-KEY
006700     EVALUATE VSAM-STATUS-CODE
006800       WHEN '23'
006900*     YOU COULD TERMINATE THE PROGRAM HERE IF YOU WISH.
007000*       WE WILL KEEP GOING VALIANTLY
007100       DISPLAY 'CANNOT SUCCESSFULLY START'
007200       DISPLAY 'PROGRAM WILL START AT THE BEGINNING'
007300       DISPLAY 'AS IF START NOT DONE'
007400       WHEN '00'
007500                  DISPLAY 'START WAS SUCCESSFUL'
007600       WHEN OTHER GO TO ERROR-EXIT
007700       END-EVALUATE.
007800     PERFORM READ-PAR.
007900
008000 PROCESS-ALL.
008100*    THIS PROGRAM IS SIMPLE.
008200*    IT JUST DISPLAYS THE RECORDS OF THE VSAM FILE
008300*    OTHER PROGRAMS WOULD DO MORE INVOLVED PROCESSING
008400     DISPLAY VSAM-KSDS-RECORD
008500     PERFORM READ-PAR.
008600
008700 TERMINATION.
008800     CLOSE VSAM-KSDS-FILE.
008900
009000 READ-PAR.
009100     READ VSAM-KSDS-FILE
009200     AT END MOVE 'Y' TO FILE-AT-END
009300     NOT AT END
009400      IF VSAM-STATUS-CODE IS NOT EQUAL TO '00'
009500      THEN GO TO ERROR-EXIT
009600      END-IF
009700      END-READ.
009800
009900 ERROR-EXIT.
010000*   SEE THE PROGRAM VSAMSEQ2 FOR VSAM STATUS CODES
010100*   AND EXTENDED STATUS CODES
010200*   AND THE REMAINDER OF THIS PARAGRAPH

Compliments of Gabe Gargiulo, author of several recent books on programming and modern languages, available at Amazon.com.
Here is the input data file userid.VSAMKSDS.EMPSORTD: (the next two lines are a column ruler) 1 2 3 4 5 6 123456789.123456789.123456789.123456789.123456789.123456789.12345678 BUD WEIZER 05000 9 0001 0000001 000000 HERB GARDNER 03000 1 0040 0000055 000022 HUGH MUNGUS 06000 1 0200 0000020 000020 L. A. VATOR 07000 5 0020 0000033 000033 PAT A. GONIA 04000 0 0002 0000022 000011 PEARLE E. GATES 01000 2 0010 0000020 000300 PHIL HARMONIC 02000 3 0030 0000050 000020 Here is sample JCL: //* vsamstr1.jcl //DEFKSDS EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //SYSIN DD * DELETE (userid.VSAMKSDS.EMPSORTD) CLUSTER DEFINE CLUSTER - (NAME(userid.VSAMKSDS.EMPSORTD) - CYLINDERS(1,1) - KEYS(20,0) - RECORDSIZE(80,80)- INDEXED ) REPRO INFILE(INFILE) OUTDATASET(userid.VSAMKSDS.EMPSORTD) /* //INFILE DD DSN=userid.COBBOOK.DATA(EMPSORTD),DISP=SHR //* //STEP1 EXEC PGM=VSAMSTR1 //STEPLIB DD DSN=your.executable.program.library.goes.here,DISP=SHR //*OF COURSE, THE NEXT DATASET NAME MAY BE DIFFERENT AT YOUR COMPANY //VSAMKSDS DD DSN=userid.VSAMKSDS.EMPSORTD,DISP=SHR //SYSOUT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //SYSABOUT DD SYSOUT=* //SYSDBOUT DD SYSOUT=*

Top of Page

Your email and other personal information will not be given to anyone
[Books Computer]

Home Books for Computer Professionals Privacy Terms |
Site Map and Site Search Programming Manuals and Tutorials The REXX Files Top of Page |