Page 1 of 3

Dynamic file allocation in COBOL subroutine

PostPosted: Tue Feb 23, 2010 1:29 am
by ctrevino
I have successfully written a program to call the assembler routine BPXWDYN and dynamically allocate files for me in COBOL. I need to be able to call this program as a subroutine and then open and use the dynamically allocated file. Is this possible? If so, how?


Thanks in advance,
Christy in FL

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Feb 23, 2010 2:12 am
by Robert Sample
1. You can directly call BPXWDYN from COBOL -- you don't need an Assembler subroutine or any other subroutine.
2. Yes, it is possible to use BPXWDYN. Define the file in COBOL as you usually do in the DATA DIVISION -- SELECT, FILE SECTION, FD. In your PROCEDURE DIVISION, issue the call to BPXWDYN with the right values to allocate the file to the DD name in the SELECT statement. Then do your usual OPEN statement and so forth.

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Feb 23, 2010 7:00 pm
by ctrevino
what I am trying to do is avoid modifying 100 or so programs so I was hoping I could put the dynamic allocation logic in a subroutine, call it from the programs using a subroutine name that we are obsoleting but that is in all of the programs to send the reports to printers dynamically (the users want these reports in a file) but I need to be able to open the file from the calling program while the file is allocated in the subroutine. (I hope this makes sense)

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Feb 23, 2010 7:06 pm
by Robert Sample
Find the COBOL Language Reference manual and look at the EXTERNAL clause of the FILE SECTION. I believe that this is the only way to do what you indicate you want to, which means you have to change every program to include EXTERNAL. Without using EXTERNAL, one COBOL program cannot read or write a file opened in another program. If I misunderstand your requirement, please give more information.

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Feb 23, 2010 7:23 pm
by ctrevino
Thanks. I will try your suggestion and let you know. Changing all the programs to have an EXTERNAL clause would be acceptable because it would be a minor universal change that junior programmers should be able to handle.

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Feb 23, 2010 7:25 pm
by MrSpock
Christy and Robert, I'm not a real expert here, and maybe I'm missing something, but why would this pose a problem? If a sub-routine is called to dynamically allocate a DD by invoking BPXWDYN, then why can't any program use that DD? What would make this process any different than including that DD statement in the JCL, or in a TSO ALLOCATE command?

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Feb 23, 2010 7:38 pm
by ctrevino
Thanks. I will try your suggestion and let you know. Changing all the programs to have an EXTERNAL clause would be acceptable because it would be a minor universal change that junior programmers should be able to handle.

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Feb 23, 2010 8:35 pm
by ctrevino
Worked like a charm. Thank you so much!!!!!!!!!!!!!!!!!!!!!!!!! :D

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Feb 23, 2010 8:40 pm
by ctrevino
To Mr. Spock, I am not sure but when I coded and ran it without the "IS EXTERNAL" in the FD's of both programs, the primary program gave me a file status of 39 when I tried to open it.

I added "IS EXTERNAL" in both the dynamic allocation subroutine and the main program that writes to the dynamically allocated file making sure that the FDs had the same number of bytes in the 01 record. This worked for me no problem.

Three people told my Bureau Chief that we could not create files on the fly like this so he didn't believe me (a blonde chick) when I said that I knew we could. Now, I have a working prototype and can move forward with my proposal.

Thanks to all who post here as it is an invaluable resource for me.

Christy

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Sun Mar 21, 2010 6:38 pm
by Galbi
Hi to all,

The English is not my native language and so I’m sorry for my mistakes.
I didn’t use the BPXWDYN in the subroutine, but directly in the program with good result.

Now I’d like delete the file before allow it.

I used this string “FREE DD(assign name) DA(file name) OLD DELETE” with BPXWDYN but the result is not good.

Who could tell me where is the mistake or what is the correct command?

Thanks in advance

Flavio