Page 2 of 3

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Sun Mar 21, 2010 9:12 pm
by dick scherrer
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".

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Mar 23, 2010 7:24 pm
by ctrevino
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.

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Mar 23, 2010 7:34 pm
by Robert Sample
When you call BPXWDYN to do the free, use DELETE as one of the options.

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Tue Mar 23, 2010 10:19 pm
by ctrevino
Thanks, Robert. :)

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Wed Apr 28, 2010 7:01 pm
by Hardik
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..

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Wed Apr 28, 2010 11:29 pm
by dick scherrer
Hello and welcome to the forum,

You might try simply opening the file as output if it already exists. . .

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Wed Apr 28, 2010 11:34 pm
by Robert Sample
Have you tried doing a FREE after the delete before you allocate again?

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Thu Apr 29, 2010 1:17 pm
by barrybert
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.

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Thu Apr 29, 2010 2:12 pm
by Hardik
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

Re: Dynamic file allocation in COBOL subroutine

PostPosted: Thu Apr 29, 2010 4:47 pm
by Robert Sample
Call BPXWDYN to do the free.