VSAM Sample Program on MUSIC/SP

The VSAM (Virtual Storage Access Method) sample program in file  $vsm:vsam.sample  is written in Assembler and copies 80-byte records from a sequential (normal) file on ddname DDNAME1 to a new empty VSAM KSDS (Key-Sequenced Data Set) on ddname DDNAME2.

The required files are in update file  misc8.arc  for the MUSIC/SP Demo system.

To run the sample program, you must first use the interactive AMS (Access Method Services) utility to create the VSAM file. Before starting AMS, run the  libspace  command to check that your MUSIC system has at least 3000K free space in the Save Library. If space is low, perhaps you can delete some earlier archive files (misc1,arc, misc2.arc, etc.) Otherwise the AMS Rexx program does not work correctly, and you may get error messages "File i/o unusual condition 051" on the operator console. Start AMS and enter option 4 (allocate a cluster) in the command area, and press Enter:

AMS main screen

This brings up the screen for allocating a new VSAM file. For a KSDS, there are 2 physical files: the data component (in this case vsamfile1.dat) and the index component (vsamfile1.idx). Enter the file options as shown here:

AMS file allocation screen

Press Enter, which should give output similar to the following:


Access Method Services                   WED NOV 23, 2005 20.10.56 ***

1) DEF CL(NAME( VSAMFILE1.DAT ) KSDS  PRIV RECSZ( 80 80 ) KEYS( 16 0 )) -
2) DATA ( CISIZE( 4096 ) SP( 40 ) SECSP( 0 ) FREESPACE( 0  0) ) -
3) INDEX( CISIZE( 512 ) SPACE( 10 ) SECSPACE( 0 ) )

Command read, processing begins ...
Cluster successfully allocated
Data  Component: $000:VSAMFILE1.DAT
Index Component: $000:VSAMFILE1.IDX

Command successfully completed, return code = 0
Command required   0.31 service units for execution

End of file, command processing ends
Highest return code = 0
Total execution time:   0.64 service units

Next, use the Editor to create the input file of 80-byte records in file  mydata . In our sample, the key is the first 16 characters of each record. Make all the key fields different. The records can be in any order. For example:


record1key      data part of rec 1
record2key      blablabla
record01key     more data
record3key      123 456 789
record1.5key    and so on.

Then execute the sample program by typing  $vsm:vsam.sample  in the *Go command area. The output should be similar to:


000300 BYTES USED
EXECUTION BEGINS
VSAM SAMPLE PROGRAM ENDED NORMALLY

You can check the VSAM file by the following job, which uses the utility  VSAM.COPYFRVS  to copy the records from the VSAM file to the screen (prt):


/file ddname1 n(vsamfile1.dat)
/file 1 prt
/inc vsam.copyfrvs

The output should be like:


record01key     more data
record1.5key    and so on.
record1key      data part of rec 1
record2key      blablabla
record3key      123 456 789
0000005 RECORDS COPIED FROM VSAM FILE

Note that the records have been sorted into key order!

Here is a listing of the sample program source file:


/SYS TIME=MAX
/FILE DDNAME1 NAME(MYDATA) SHR
/FILE DDNAME2 NAME(VSAMFILE1.DAT) OLD NORLSE
/LOAD ASM
*
* THIS SAMPLE PROGRAM READS DATA RECORDS FROM A SEQUENTIAL
* FILE ON DDNAME "DDNAME1" AND WRITES THEM TO A VSAM KSDS
* ON DDNAME "DDNAME2".  IT IS ASSUMED THAT THE VSAM FILE
* HAS ALREADY BEEN CREATED AND INITIALIZED.
* THE INPUT RECORDS ARE ASSUMED TO BE OF LENGTH 80.
*
* AN OPEN ERROR CAUSES AN INVALID OP-CODE WITH R7=X'EE1' AND
* R0=OPEN ERROR CODE.
*
* AN ERROR WRITING TO THE VSAM FILE CAUSES AN INVALID OP-CODE
* WITH R7=X'EE2', R0=ERROR CODE FROM PUT, R15=RETURN CODE FROM PUT.
*
SAMPLE   CSECT
         REGS  ,                  THIS MACRO DEFINES REGISTERS
         STM   R14,R12,12(R13)    SAVE REGISTERS
         LR    R12,R15            SET UP A BASE REGISTER
         USING SAMPLE,R12
         LA    R14,SAVEAREA       SET UP A SAVE AREA
         ST    R13,4(0,R14)
         ST    R14,8(0,R13)
         LR    R13,R14
* OPEN THE TWO FILES
         OPEN  (MYDCB,INPUT)      OPEN SEQUENTIAL FILE
         OPEN  (MYACB)            OPEN VSAM FILE, USING AN ACB
* GET ERROR CODE FIELD FROM ACB
         SHOWCB ACB=MYACB,AREA=OPENERRC,LENGTH=4,FIELDS=(ERROR)
         L     R0,OPENERRC
         LTR   R0,R0              TEST FOR VSAM OPEN ERROR
         BZ    OPENOK             BRANCH IF NO ERROR
* VSAM OPEN ERROR
         LA    R7,X'EE1'          INDICATE INTENTIONAL P.I.
         DC    H'0'               STOP JOB BY INVALID OP-CODE
OPENOK   DS    0H
* READ LOOP: READ NEXT RECORD INTO "MYAREA"
READLOOP GET   MYDCB,MYAREA       READ RECORD USING QSAM
         PUT   RPL=MYRPL          WRITE RECORD TO VSAM FILE
         LTR   R15,R15            TEST FOR WRITE ERROR
         BZ    READLOOP           BRANCH IF NO ERROR
* VSAM ERROR: GET ERROR CODE FROM RPL
         LR    R5,R15             SAVE R15 RETURN CODE
         SHOWCB RPL=MYRPL,AREA=REQERR,LENGTH=4,FIELDS=(FDBK)
         L     R0,REQERR          GET ERROR CODE IN R0
         LR    R15,R5             RESTORE R15 RETURN CODE
         LA    R7,X'EE2'          INDICATE INTENTIONAL P.I.
         DC    H'0'               STOP JOB BY INVALID OP-CODE
* COME HERE WHEN END-OF-FILE ON INPUT: CLOSE THE FILES
EOF      CLOSE (MYDCB)
         CLOSE (MYACB)
* WRITE MESSAGE TO TERMINAL
         WTO   'VSAM SAMPLE PROGRAM ENDED NORMALLY'
* RETURN TO SYSTEM
         L     R13,4(0,R13)       RESTORE SAVE AREA POINTER
         LM    R14,R12,12(R13)    RESTORE REGISTERS
         BR    R14                RETURN
* STORAGE AREAS
SAVEAREA DS    18F                STANDARD SAVE AREA
OPENERRC DS    F                  RECEIVES OPEN ERROR CODE
REQERR   DS    F                  RECEIVES ERROR CODE FROM RPL
MYAREA   DS    CL80               LOGICAL RECORD BUFFER
* DCB FOR SEQUENTIAL INPUT FILE
MYDCB    DCB   DDNAME=DDNAME1,DSORG=PS,MACRF=GM,LRECL=80,EODAD=EOF
* ACB FOR OPENING VSAM FILE
MYACB    ACB   DDNAME=DDNAME2,MACRF=(KEY,SEQ,OUT)
* RPL FOR REQUESTS ON THE VSAM FILE
MYRPL    RPL   ACB=MYACB,AREA=MYAREA,AREALEN=80,RECLEN=80,             X
               OPTCD=(KEY,SEQ,NUP)
         END