Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic file allocation in cobol 4

Status
Not open for further replies.

apctaz

Programmer
May 16, 2011
3
US
Hello,

I need an example of how to dynamically allocate several files using a cobol program. I am using VS Cobol II. I need to allocate the files and then write records to them.

Can anyone help?
 
Hi apctaz,
I've not ahd need to do this, but beleive it's done by calling a routine called 'setenv'. You can Google that, or have a look here

Hope this helps.

Marc
 

Not sure if this is what you mean but I use this...
Code:
//STEP01  EXEC PGM=DLNOPEN
//SYSOUT   DD  SYSOUT=*
//D1       DD  DSN=PRD1.LVL6.ITEMHIST.#01,
//             SPACE=(CYL,(10,10)),UNIT=DISK6,
//             DCB=(RECFM=FB,LRECL=80,BLKSIZE=27920,DSORG=PS),
//             DISP=(NEW,CATLG,DELETE)

Randy
 
When you run the JCL for your job and use disp=(new,catlg,delete) it allocates the files for you. There is no need to create them ahead of time.
 
I believe that the OP means that the COBOL program figures out the DSN of the file then allocates that file so that it can be opened. I have seen this done, but as I no longer work on mainframes, I have never done it and don't remember how it was done.

I do remember that it works just like the ALLOCATE statement in TSO, but the syntax would be quite different.
 
Like webrabbit, I believe that the original poster wants a bit of Cobol that allocates a file dynamically. If you look at the link I posted, you'll find an example of exactly that. It says:

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.

There's a lot more on this if you Google 'SETENV COBOL'.

Marc
 
Thank you all for responding. But when I try to execute my program it gives me an error saying that it can not file module 'SETENV'.

Does anyone know what library that module is supposed to reside in?

thanks
 
Suggest you talk with your system support people.

The dsn(s) of the library(ies) that contain this module and others is usually site-specific.
 
THINGS ARE NOT WORKING. I FINALLY GOT MY PROGRAM TO COMPILE BUT WHEN I EXECUTE IT. THE FILE IS NOT GETTING CREATED. ANY SUGGESTIONS. THE CODE IS AS FOLLOWS:

ENVIRONMENT DIVISION.


CONFIGURATION SECTION.


SOURCE-COMPUTER. IBM-3090.
OBJECT-COMPUTER. IBM-3090.


INPUT-OUTPUT SECTION.

FILE-CONTROL.

SELECT FILE01-OUT ASSIGN TO FILE01.

EJECT
DATA DIVISION.


FILE SECTION.

FD FILE01-OUT
RECORDING MODE IS F.

01 FILE01-OUT-REC PIC X(1520).
EJECT
*****************************************************

WORKING STORAGE

*****************************************************

WORKING-STORAGE SECTION.

01 FILLER PIC X(16) VALUE
'WORKING STORAGE '.

01 ENV-VARS.
05 ENV-NAME PIC X(08).
05 ENV-VALUE PIC X(100).
05 ENV-OVERWRITE PIC S9(08) COMP.

01 FILE01-STAT PIC 99.

******************************************************************
* MEMBER CERTIFICATE INTERMEDIATE FILE LAYOUT
******************************************************************
++INCLUDE AC051W3

******************************************************************
*
* LINKAGE SECTION
*
******************************************************************

LINKAGE SECTION.

EJECT
******************************************************************
*
* PROCEDURE DIVISION
*
******************************************************************

PROCEDURE DIVISION.
*
000-CONTROL SECTION.
*
MOVE z'FILE01' TO ENV-NAME.
*
display 'create file'.
MOVE z'DSN(ACF.BC00.MBCERT.FOMC),NEW,CYL,SPACE(5,5),UNIT(SYSD
- 'A),CATALOG'
TO ENV-VALUE.
*
MOVE 1 TO ENV-OVERWRITE.
*
CALL "setenv" USING ENV-NAME ENV-VALUE ENV-OVERWRITE.
*
display 'after call'.
OPEN OUTPUT FILE01-OUT.
*
INITIALIZE AC051W3-REC.
*
MOVE 'HAND' TO AC051W3-CMPNY-ID.
*
WRITE FILE01-OUT-REC FROM AC051W3-REC.
*
CLOSE FILE01-OUT.

GOBACK.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top