[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 Initial Load

VSAM Initial Load in a COBOL program


19. VSAM Initial Load

VSAMLOD1.
In this program you load a VSAM KSDS that has never contained data. This means that you just defined it, but never loaded it.
You could have used the REPRO statement in the IDCAMS JCL to do the same thing.

But if you do it yourself with COBOL coding you can validate the records, check the sequence, modify the records, reformat fields and anything else you need to do.
Here is the program VSAMLOD1:

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



000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. VSAMLOD1.
000300* INITIAL LOAD OF A VSAM FILE (FILE NEVER HAD RECORDS IN IT)
000400*   IMPLIED BY OPEN OUTPUT, ACCESS MODE SEQUENTIAL
000500*   AND WRITE
000600* BASED ON A REGULAR FILE READ SEQUENTIALLY
000700* THE LOGIC IS SAME AS REGULAR FILE READ SEQUENTIALLY
      * IMPORTANT CLAUSES ARE
      * ACCESS MODE IS SEQUENTIAL
      * OPEN FOR OUTPUT
      * STATUS CODE 21 IS OUT OF SEQUENCE
000800 ENVIRONMENT DIVISION.
000900 CONFIGURATION SECTION.
001000 INPUT-OUTPUT SECTION.
001100 FILE-CONTROL.
001200*    THIS IS AN ORDINARY SEQUENTIAL FILE: EMPSORTD
001300*    NEEDS TO BE IN SORTED ORDER, BY THE KEY (FIRST 20 CHARACTERS
001400     SELECT IN-FILE  ASSIGN EMPSORTD.
001500*    INPUT VSAM FILE IS: TSOUSR1.VSAMKSDS.NOTLOADD.EMPSORTD
001600*    OF COURSE THE NAMES MAY BE DIFFERENT AT YOUR COMPANY
001700     SELECT VSAM-KSDS-FILE ASSIGN VSAMKSDS
001800        ORGANIZATION IS INDEXED
001900*    NOTICE THE SEQUENTIAL NEXT
002000        ACCESS MODE IS SEQUENTIAL
002100        RECORD KEY IS VSAM-KSDS-RECORD-KEY
000600        FILE STATUS  IS VSAM-STATUS-CODE
000700                        VSAM-EXTENDED-STATUS-CODE.
002300 DATA DIVISION.
002400 FILE SECTION.
002500 FD  IN-FILE
002600     RECORDING MODE IS F
003000     RECORD CONTAINS 80 CHARACTERS.
003010 01  IN-RECORD.
003020*     THE NEXT WILL BE USED AS THE KEY TO SEARCH IN THE VSAM FILE
003030*     IT HAS TO HAVE THE SAME PICTURE AS THE VSAM RECORD KEY
003040     05  EMPLOYEE-NAME           PIC X(20).
003050     05  EMPLOYEE-INFO           PIC X(60).
003200
003300 FD  VSAM-KSDS-FILE
003400     RECORD CONTAINS 80 CHARACTERS.
003500 01  VSAM-KSDS-RECORD.
003600     05  VSAM-KSDS-RECORD-KEY    PIC X(20).
003700     05  VSAM-KSDS-EMP-INFO      PIC X(60).
003900 WORKING-STORAGE SECTION.
004000 01 SWITCHES.
004100      05  FILE-AT-END     PIC X  VALUE 'N'.
004200
001900 01  VSAM-STATUS-CODE.
002000     05 VSAM-STATUS-CODE-BYTE1   PIC X.
002100     05 VSAM-STATUS-CODE-BYTE2   PIC X.
002200
002300 01  VSAM-EXTENDED-STATUS-CODE.
002400     05 VSAM-EXTENDED-RETURN-CODE   PIC S9(4) COMP.
002500     05 VSAM-EXTENDED-FUNCTION-CODE PIC S9(4) COMP.
002600     05 VSAM-EXTENDED-FEEDBACK-CODE PIC S9(4) COMP.
005000
005700 PROCEDURE DIVISION.
005800     PERFORM INITIALIZATION
005900     PERFORM PROCESS-ALL
006000**       UPPER CASE Y, PLEASE
006100         UNTIL FILE-AT-END = 'Y'
006200     PERFORM TERMINATION
006300     GOBACK.
006400
006500 INITIALIZATION.
006600     OPEN INPUT IN-FILE
006700*     I PREFER A SEPARATE OPEN HERE FOR THE VSAM FILE
006800*     IT KEEPS THE TWO OPENS SEPARATE, AND KEEPS
006900*      ERROR SITUATIONS SEPARATE
007000*      OPEN OUTPUT FOR THE LOAD
007100*      OPEN EXTENDED FOR RESUMING AN INTERRUPTED LOAD
007200     OPEN OUTPUT VSAM-KSDS-FILE
007300     IF VSAM-STATUS-CODE IS NOT EQUAL TO '00'
007400     THEN GO TO ERROR-EXIT
007500     END-IF
007600     PERFORM READ-REGULAR-FILE.
007700
007800 PROCESS-ALL.
007900*     THE FROM ON THE WRITE WILL MOVE THE FIELDS OF THE REGULAR RECORD
008000*     TO THE CORRESPONDING FIELDS OF THE VSAM FILE
008100     WRITE VSAM-KSDS-RECORD    FROM IN-RECORD
008200     EVALUATE VSAM-STATUS-CODE
008300       WHEN '21'
008400                  DISPLAY 'KEY OUT OF SEQUENCE ON LOAD'
008500                  EMPLOYEE-NAME
008600       WHEN '00'
008700                  DISPLAY 'ADDED OK' VSAM-KSDS-RECORD
008800       WHEN OTHER GO TO ERROR-EXIT
008900       END-EVALUATE.
009000     PERFORM READ-REGULAR-FILE.
009100
009200 TERMINATION.
009300     CLOSE IN-FILE VSAM-KSDS-FILE.
009400
009500 READ-REGULAR-FILE.
009600     READ IN-FILE
009700         AT END MOVE 'Y' TO FILE-AT-END
009800     END-READ.
009900
017400 ERROR-EXIT.
017500*   SEE THE PROGRAM VSAMSEQ2 FOR VSAM STATUS CODES
017510*   AND EXTENDED STATUS CODES
017520*   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 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: //* vsamlod1.jcl //DEFKSDS EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //SYSIN DD * DELETE (userid.VSAMKSDS.NOTLOADD.EMPSORTD) CLUSTER DEFINE CLUSTER - (NAME(userid.VSAMKSDS.NOTLOADD.EMPSORTD) - CYLINDERS(1,1) - KEYS(20,0) - RECORDSIZE(80,80)- INDEXED ) //* //STEP1 EXEC PGM=VSAMLOD1 //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.NOTLOADD.EMPSORTD,DISP=SHR //EMPSORTD DD DSN=userid.COBBOOK.DATA(EMPSORTD),DISP=SHR //SYSOUT DD SYSOUT=* //SYSUDUMP 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 |