Expert Answer Center > Expert Knowledgebase > View Answer
EMAIL THIS
Expert Knowledgebase
  EXPERT KNOWLEDGEBASE HOME        RSS FEEDS  
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. QUESTION POSED ON: 21 MAR 2005
QUESTION ANSWERED BY: Tom Ross 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.
Related Topics:

Search Advice from more than 250 TechTarget Experts
Your question may have already been answered! Browse or search more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice
ASSOCIATED RSS FEEDS

Expert Answer Center: Expert Q&As
View all RSS Feeds  |  RSS Info

HomeExperts on DemandIT Expert Webcast SeriesExpert KnowledgebaseSite Index
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts