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

Re: Dynamic file allocation in COBOL subroutine

Postby dick scherrer » Sun Mar 21, 2010 9:12 pm

Hello,

The English is not my native language and so I’m sorry for my mistakes
Not to worry - it may take longer, but we'll get it right eventually, though this can be frustrating :)

You need to explain what you did that worked so far and exactly what problem was later encountered.

Now I’d like delete the file before allow it.
I suspect this should be alloc/allocate?

A FREE with OLD will fail if the file has not been allocated. Try MOD DELETE in your code or use a new step before this step to "houseclean".
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Dynamic file allocation in COBOL subroutine

Postby ctrevino » Tue Mar 23, 2010 7:24 pm

Dick,
I was kind of working on something like this also. When I do the allocate step, what would tell it to delete the dataset? I have dynamically allocated datasets that I want deleted but at the very end of the job after my main programs and subprograms are done with it.
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 Mar 23, 2010 7:34 pm

When you call BPXWDYN to do the free, use DELETE as one of the options.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Dynamic file allocation in COBOL subroutine

Postby ctrevino » Tue Mar 23, 2010 10:19 pm

Thanks, Robert. :)
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 Hardik » Wed Apr 28, 2010 7:01 pm

Hi,

I am trying to do similar kind of allocation in my program but got stuck with the following scenario:

My requirement is - I want to allocate a new file (output mode) dynamically in my program and for that I am using a called module (This called module can allocate/deallocate files dynamically using assembler) and that is working file. Now the twist is, if that file already exist then I need to delete it first and than allocate it again. For deleting also I am using the same called module and working fine but the problem is that file gets deleted only after the job is ended, hence I am not able to reallocate it just after performing deletion. If I submit the same job again then it works fine because the file has been already deleted in previous run.

I hope I am clear with my problem stated above. Please let me know if there is any way to deallocate and allocate the same file in the same run.

Thanks..
Hardik
 
Posts: 5
Joined: Wed Apr 28, 2010 6:46 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic file allocation in COBOL subroutine

Postby dick scherrer » Wed Apr 28, 2010 11:29 pm

Hello and welcome to the forum,

You might try simply opening the file as output if it already exists. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Dynamic file allocation in COBOL subroutine

Postby Robert Sample » Wed Apr 28, 2010 11:34 pm

Have you tried doing a FREE after the delete before you allocate again?
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Dynamic file allocation in COBOL subroutine

Postby barrybert » Thu Apr 29, 2010 1:17 pm

Dynamic allocation aside, the module (called or main) that defines the file and opens it and closes it really needs to be the one that reads it.

In order to have 2 different modules operating on the file will require that the DCB (or in COBOL terms the "FD") be passed as a parm between the 2 different modules. ( I am sure you are away that when I say "passed as a parm" what is really happening is that the ADDRESS of the parm is passed and made available to the called module.)

Passing the address of "FD" is the only way the two modules will be able to operate on it.

Different versions of COBOL (especially OLD ones) can pass all sorts of things as parms in a call. (I remember one COBOL module that actually passed COBOL paragraph names to the called module and the called module could return to different locations in the calling module. WOW. But I think that went away when we moved off of COBOL 74.) All you can do is try to pass the required information from module to module.

But I think I would try to find a way to put it all in one module.
barrybert
 
Posts: 3
Joined: Thu Apr 29, 2010 1:14 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic file allocation in COBOL subroutine

Postby Hardik » Thu Apr 29, 2010 2:12 pm

Hi Robert,

Could you please tell me how to use FREE command in COBOl as the assembler code is in a subroutine and I dont want to change that subroutine.

To Mr. Dick,

I first want to delete the exisiting file as I dont need the old records of that file.
So precisely, what is the way to access a file deleted dynamically in a program before end of that program??
And also Thanks for the welcome!! :). However, this being my first post, but I am not new to this forum as I have been continously browsing the contents of this forum from last 2 years and it helped me a lot :-)

With Kind Regards,
Hardik
Hardik
 
Posts: 5
Joined: Wed Apr 28, 2010 6:46 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Dynamic file allocation in COBOL subroutine

Postby Robert Sample » Thu Apr 29, 2010 4:47 pm

Call BPXWDYN to do the free.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

PreviousNext

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post