Ask the Expert

Dynamic file allocation in COBOL

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.
*

Requires Free Membership to View

Allocate dataset PR.SMSPR.UNIQUE.QUALIFIER.UNIQUEDATE * and OPEN it for OUTPUT OPEN OUTPUT CARD-OUT.

This was first published in March 2005

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: