We need to create a unique DSN from within a COBOL program. The actual name of the file needs to be unique for every execution of the program. I cannot use a PROC because the JCL to run the job will be submitted from an external source, and we prefer not to give them access to that information. If we could create a DSN from within a COBOL program (e.g., PR.SMSPR.UNIQUE.QUALIFIER.UNIQUEDATE) then the external JCL would only need to supply...
the EXEC card and input filename. I know IBM Utilities has the ability to do this.
You CAN do dynamic allocation from a COBOL program! If you are using Enterprise COBOL you can assign the file to an environment variable rather than a DDNAME, then set the DSNAME in the environment variable and then OPEN the file. For details see the Enterprise COBOL Programming Guide.
Here is a partial example of what your code could look like. The function "setenv" is a C routine in the LE run-time library. You must compile with PGMNAME(LONGMIXED) to allow the lower-case routine name:
FILE-CONTROL. * Assign CARD-OUT to Environment Variable "PRINT" SELECT CARD-OUT ASSIGN S-PRINT STATUS IS PRINT-STAT. 01 ENV-VARS. 05 ENV-NAME PIC X(8). 05 ENV-VALUE PIC X(100). 05 ENV-OVERWRITE PIC S9(8) COMP. 01 PRINT-STAT PIC 99. PROCEDURE DIVISION. SETUP. MOVE z'PRINT' TO ENV-NAME. * Note the continued null-terminated literal MOVE z'DSN(PR.SMSPR.UNIQUE.QUALIFIER.UNIQUEDATE),NEW,CYL,SPAC - 'E(5,5),UNIT(SYSDA),CATALOG' TO ENV-VALUE. MOVE 1 TO ENV-OVERWRITE. CALL "setenv" USING ENV-NAME, ENV-VALUE, ENV-OVERWRITE.
* Allocate dataset PR.SMSPR.UNIQUE.QUALIFIER.UNIQUEDATE * and OPEN it for OUTPUT OPEN OUTPUT CARD-OUT.
Dig Deeper on Mainframe operating systems and management
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.