z/OS JCL Keyword AVGREC=
Traditionally, disk space allocation has been done in tracks, or cylinders. While the AVGREC=
keyword has not changed what is done under the hood, it does change how space can be specified in JCL: You can specify space in number of records, that you expect to be written to the data set.
Sometimes, however, it would be easiest to specify some megabytes. While KB, and MB are units you can specify in ISPF panels, it needs a little trick in JCL.
Traditional way of Allocating Disk Space: SPACE=()
In MVS JCL, you use the SPACE=()
keyword parameter on the DD statement to tell the data set allocation service how much space to set aside for the new data set:
//ddname DD ...,SPACE=(unit,(primary,secondary))
The first subparameter unit
specifies how to measure, and the primary, and secondary subparameters specify how many of those unit you need. The measures being tracks (TRK
), cylinders (CYL
), and less often blocks (a number).
Some examples:
//ddname DD ...,SPACE=(CYL,(10,100))
The system will allocate 10 cylinders primary space, and 100 cylinders secondary space.
//ddname DD ...,SPACE=(6100,(20,50))
The request is for 20 blocks of 6100 bytes each primary space, and 50 blocks of 6100 bytes secondary. The system will then calculate and round up to whole tracks, or cylinders.
Modern Way of Allocating Disk Space: AVGREC=
The optional AVGREC=
keyword changes the way the system interprets the keywords on the SPACE=()
parameter. The unit subparameter is now interpreted as average record length of the records that will be written to the data set. The primary, and secondary amounts turn into number of records of the specified average record length.
Besides acting as a switch, the AVGREC=
keyword specifies a multiplier for the primary, and secondary numbers.
AVGREC=U
means unit. The numbers are multipled by 1. AVGREC=K
means thousands. The numbers are multipled by 1024.AVGREC=M
means millions. The numbers are multipled by 1048576.
Some examples:
//ddname DD ...,SPACE=(1135,(4000,8000)),AVGREC=U
The system will allocate primary space for 4000 * 1 records of length 1135 bytes, and secondary space for 8000 * 1 records of length 1135 bytes. Again, the system will then calculate and round up to whole tracks, or cylinders.
//ddname DD ...,SPACE=(256,(20,50)),AVGREC=K
The system will allocate primary space for 20 * 1024 records of length 256 bytes, and secondary space for 50 * 1024 records of length 256 bytes. Again, the system will then calculate and round up to whole tracks, or cylinders.
Allocting Disk Space in Megabytes
The average record length as set in the SPACE=()
parameter is not tied to neither the record format (RECFM
), nor the logical record length (LRECL
) in any way. This is good news, since it allows us to use just the value that serves us best, say one.
//ddname DD ...,SPACE=(1,(20,50)),AVGREC=M
The system will allocate primary space for 20 * 1048576 records of length one byte. This equals to 20 megabytes (20 MiB). It will equally allocate 50 MiB secondary space each time the data set needs more room.
Conclusion: To specify disk space in JCL in megabytes ...
... add AVGREC=M
to the DD statement and ...
... set the average record length to one in SPACE=(1,...
and finally set primary, and secondary values to the number of MiBs needed.