Created On:  08 February 2011

Problem:

How can I allocate and catalog a dataset from within a COBOL batch program? 

Resolution:

The utility MFJSZ099 simulates the IBM mainframe DYNALLOC assembler macro, which uses SVC99 to perform dynamic allocation of datasets from within a batch program.

One of the available functions is to create and catalog a new dataset, using a program-defined dataset name, which can then be written to from within the same run unit.

The attached example consists of two Cobol programs, and one JCL file. The preparation of the necessary control blocks (text units) required by MFJZS099, and the call to MFJZS099 have been packaged within the program NEWDSN2. This is called by NEWDSN1, which accepts a parameter containing the dataset name to be allocated.

In this example, the DDname to which the dataset will be allocated, and the dataset's DCB information are hard-coded within NEWDSN2, but of course these could also be specified externally, and passed as parameters to NEWDSN2, and then fed through to MFJZS099.

N.B. Because the copybooks used to map the parameters to MFJZS099 (which are identical to those used by SVC99) contain in-line comments and comp-x variables, it cannot be compiled with DIALECT"ENTCOBOL", unless the additional directives FLAG"MF" and MF"12" are specified. Additionally, you may wish to override the ENTCOBOL character set (EBCDIC) using the CHARSET"ASCII" directive.
Incident #2490720