Page 1 of 2

Dynamic allocation in COBOl using BPXWDYN

PostPosted: Thu Jun 22, 2023 7:35 pm
by Heisenberg
Hello,

I am trying to dynamically allocate files on Unix on z/os. There will be multiple files generated for each input record and all the output files will have same DDNAME. I am able to allocate these file but all the output records are written in single file.
I am closing the file after each record is written and allocating a different file again, but still the records are in same file. how to write multiple files for multiple input records using BPXWDYN? Please help

TIA
Heisenberg

Re: Dynamic allocation in COBOl using BPXWDYN

PostPosted: Thu Jun 22, 2023 8:17 pm
by sergeyken
Heisenberg wrote:I am able to allocate these file but all the output records are written in single file.

these = Plural
file = Singular

How many files actually allocated?
And how the allocated files are connected to COBOL's (single?) file definition?

Re: Dynamic allocation in COBOl using BPXWDYN

PostPosted: Thu Jun 22, 2023 8:23 pm
by Heisenberg
Hello sergeyken,

Sorry that was a typo. There are seven records in my test input file. All the 7 records are written in a single file. But my expectation is to allocate 7 different output files each having one single record in USS path.

Re: Dynamic allocation in COBOl using BPXWDYN

PostPosted: Thu Jun 22, 2023 8:52 pm
by sergeyken
Heisenberg wrote:Hello sergeyken,

Sorry that was a typo. There are seven records in my test input file. All the 7 records are written in a single file. But my expectation is to allocate 7 different output files each having one single record in USS path.

What exactly is the obstacle which prevents you from doing this?
There are tons of existing documentation, and examples in internet on this issue.
Did you try something? What are the results of your attempts?

Re: Dynamic allocation in COBOl using BPXWDYN

PostPosted: Thu Jun 22, 2023 8:57 pm
by Heisenberg
Hello sergeyken,

Based on the forums and documentation, I used FREE option from the BPXWDYN utility to free the dataset as below.
But the allocation of multiple files is not happening.

01 W-STRING-ALLOC PIC X(200) VALUE 'FREE DD(OTFILE)'.
CALL BPXWDYN USING W-STRING-ALLOC

Re: Dynamic allocation in COBOl using BPXWDYN

PostPosted: Thu Jun 22, 2023 11:11 pm
by sergeyken
Heisenberg wrote:Hello sergeyken,

Based on the forums and documentation, I used FREE option from the BPXWDYN utility to free the dataset as below.
But the allocation of multiple files is not happening.

01 W-STRING-ALLOC PIC X(200) VALUE 'FREE DD(OTFILE)'.
CALL BPXWDYN USING W-STRING-ALLOC

When using FREE option, you make the DD-name OTFILE available for further use.

Since you did not try to allocate any new file in place of the released one, that's why "the allocation of multiple files is not happening"

Re: Dynamic allocation in COBOl using BPXWDYN

PostPosted: Thu Jun 22, 2023 11:23 pm
by sergeyken
For example: How to Use BPXWDYN Utility to Allocate File

01 WS-TEXT     PIC X(55) VALUE   "ALLOC FI(OUT) DS('WORK.TAPE') NEW KEEP UNIT(TAPE) REUSE"  
CALL BPXWDYN USING WS-TEXT.


Did you try this?

Did you try anything at all?

Re: Dynamic allocation in COBOl using BPXWDYN

PostPosted: Fri Jun 23, 2023 1:35 am
by willy jensen
Not being a COBOL person, I will ask a stupid question - do you close the file before the FREE? Otherwise you can't.

Re: Dynamic allocation in COBOl using BPXWDYN

PostPosted: Fri Jun 23, 2023 3:21 pm
by Heisenberg
Hello sergeyken,

The allocation of the file has been done using below code.

'ALLOC DD(N3FIPSO) PATH(/u/USERS/userid/file1.text) PATHOPTS(ORDWR,OCREAT) PATHDISP(KEEP,KEEP) PATHMODE(SIRWXU) FILEDATA(RECORD) '

The file was successfully allocated in the USS directory with 7 records inside it, but I expect seven files with one record each.

The logic as follows.

1. Allocate file using BPXWDYN
2. Open the output file
3. Write Output file
4. Close the Ouput file

This will be performed 7 times with different files name (like file1.txt, file2.txt...) , but only file1.txt created with 7 records in it.
Each time the file is opened and closed, and the allocate function is repeated 7 times with different file names.

@willy jensen, yes ofcourse the file is closed each time.

Re: Dynamic allocation in COBOl using BPXWDYN

PostPosted: Fri Jun 23, 2023 3:40 pm
by willy jensen
Seems that you do not free the file, as sergeyken hinted above.

You must
5. Free the Ouput file

You could use the REUSE parameter for BPXWDYN, but you still must free the file at the very end.