Dynamic file allocation in COBOL subroutine



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Dynamic file allocation in COBOL subroutine

Postby ctrevino » Tue Feb 23, 2010 1:29 am

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
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic file allocation in COBOL subroutine

 

Re: Dynamic file allocation in COBOL subroutine

Postby Robert Sample » Tue Feb 23, 2010 2:12 am

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: Dynamic file allocation in COBOL subroutine

Postby ctrevino » Tue Feb 23, 2010 7:00 pm

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)
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic file allocation in COBOL subroutine

Postby Robert Sample » Tue Feb 23, 2010 7:06 pm

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: Dynamic file allocation in COBOL subroutine

Postby ctrevino » Tue Feb 23, 2010 7:23 pm

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.
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic file allocation in COBOL subroutine

Postby MrSpock » Tue Feb 23, 2010 7:25 pm

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?
User avatar
MrSpock
Global moderator
 
Posts: 810
Joined: Wed Jun 06, 2007 9:37 pm
Location: Raleigh NC USA
Has thanked: 0 time
Been thanked: 2 times

Re: Dynamic file allocation in COBOL subroutine

Postby ctrevino » Tue Feb 23, 2010 7:38 pm

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.
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic file allocation in COBOL subroutine

Postby ctrevino » Tue Feb 23, 2010 8:35 pm

Worked like a charm. Thank you so much!!!!!!!!!!!!!!!!!!!!!!!!! :D
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic file allocation in COBOL subroutine

Postby ctrevino » Tue Feb 23, 2010 8:40 pm

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
Christy T.


Wherever you go, there you are - Buckaroo Banzai
ctrevino
 
Posts: 62
Joined: Tue Feb 23, 2010 1:23 am
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic file allocation in COBOL subroutine

Postby Galbi » Sun Mar 21, 2010 6:38 pm

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
Galbi
 
Posts: 5
Joined: Sun Mar 21, 2010 4:51 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post