开云体育

ctrl + shift + ? for shortcuts
© 2025 Groups.io

COBOL help opening datasets to append records.


 

Hi folks.

So I'm trying to append records to an existing dataset with COBOL... wich should be quite straight forward: OPEN EXTEND MY-FILE

But it seems the compiler does not support that opening mode.
I took a look at the 1972 IBM book I use as a reference for the included compiler and, at OPEN clause, section (very brief one... so maybe not a comprehensive guide with not all options covered), I see that it only mentions INPUT and OUTPUT, no EXTEND whatsoever.
So while I believe that it is indeed possible, the thing is that there must be for sure a way to perform such a fundamental operation, even with this compiler.

As anyone a clue? Am I missing something?

Thanks you.
Cheers.
Alex.??


 

开云体育

Alejandro:

Try this. To add new records to the end of a file that already exists, you must:

  1. Open the file OUTPUT,
  2. Then in your JCL, the DD statement for the file needs to have a DISP=MOD

Now, new records will be added to the end of the file.

The old COBOL did not give you a way to express your intent entirely within the program. You have to do a dance between the COBOL and the JCL.

John Holland

Quoting Alejandro olivan Alvarez <alejandro.olivan.alvarez@...>:

Hi folks.

So I'm trying to append records to an existing dataset with COBOL... wich should be quite straight forward: OPEN EXTEND MY-FILE

But it seems the compiler does not support that opening mode.
I took a look at the 1972 IBM book I use as a reference for the included compiler and, at OPEN clause, section (very brief one... so maybe not a comprehensive guide with not all options covered), I see that it only mentions INPUT and OUTPUT, no EXTEND whatsoever.
So while I believe that it is indeed possible, the thing is that there must be for sure a way to perform such a fundamental operation, even with this compiler.

As anyone a clue? Am I missing something?

Thanks you.
Cheers.
Alex.??




 

Alex,

John has already answered your question. I have a Feingold text from that era that clearly states EXTEND is valid for OPEN, but obviously this compiler has not read the Feingold text. I have attached the output of a job showing creating and then extending a simple sequential dataset on disk.


 

开云体育

No - there is no EXTEND mode - too early.

Can I suggest that you use ISAM mode instead for this file if needed create a simple key if there is no field that you can use say starting with 1.

Then OPEN I-O, then all WRITE statements for a new record will work with the added benefit if also using REWRITE if you need to update an existing record.

See the documentation from Jay regarding the use of ISAM type files with Cobol for how to do it.

Vince


On 15/03/2024 13:30, Alejandro olivan Alvarez wrote:

Hi folks.

So I'm trying to append records to an existing dataset with COBOL... wich should be quite straight forward: OPEN EXTEND MY-FILE

But it seems the compiler does not support that opening mode.
I took a look at the 1972 IBM book I use as a reference for the included compiler and, at OPEN clause, section (very brief one... so maybe not a comprehensive guide with not all options covered), I see that it only mentions INPUT and OUTPUT, no EXTEND whatsoever.
So while I believe that it is indeed possible, the thing is that there must be for sure a way to perform such a fundamental operation, even with this compiler.

As anyone a clue? Am I missing something?

Thanks you.
Cheers.
Alex.??
_._,_._,_


 

Thank you all guys for the points.

The thing is that, the code I was playing with, uses SORT together with its input and output procedures (nice feature!).
The goal was to let an input dataset full of records, including a set of header records, be sorted, with duplicated records suppressed, and write them to a member, all in one go if possible.
The strategy was to use the input procedure to bypass the header redcords from sort, and write them directly to output, and in the output procedure, simply check for duplicate records
before writing to file.

So, in my sort in procedure, I opened the output file, and write the header records directly, bypassing them being fed to sort, and, politely, close the file.
Then, on the output procedure from sort, I opened again the file, checked every passing, sorted, record, and write them to output file only if they're different from the last one. And, again, close the file.
Ideally, I would have been able to open in extend mode in the sort output procedure... but there I came with the issue that that's not possible.

Playing with the SHR in the JCL, gave interesting results:
If opening in SHR mode, the second OPENing makes existeing header records to be replaced. No surprise.
But If opening in OLD mode, while the header files are kept, as expected... only a few records are written afterwards, like if the job/step ended prematurely or something weird.

What I'm doing now is to open the output file on the sort input procedure, and let it open (which doesn't look polite in my eyes), then, let the sort output procedure close it.
Since there's only a single opening, it seems I can do all the output file writes in one go in SHR mode.

Cheers.
Alejandro
?


 

Hi Alejandro,

Don't close the file, continue to write in
I found your logic just complicated

搁别苍é


Le jeudi 21 mars 2024 à 11:12:56 UTC+1, Alejandro olivan Alvarez <alejandro.olivan.alvarez@...> a écrit :


Thank you all guys for the points.

The thing is that, the code I was playing with, uses SORT together with its input and output procedures (nice feature!).
The goal was to let an input dataset full of records, including a set of header records, be sorted, with duplicated records suppressed, and write them to a member, all in one go if possible.
The strategy was to use the input procedure to bypass the header redcords from sort, and write them directly to output, and in the output procedure, simply check for duplicate records
before writing to file.

So, in my sort in procedure, I opened the output file, and write the header records directly, bypassing them being fed to sort, and, politely, close the file.
Then, on the output procedure from sort, I opened again the file, checked every passing, sorted, record, and write them to output file only if they're different from the last one. And, again, close the file.
Ideally, I would have been able to open in extend mode in the sort output procedure... but there I came with the issue that that's not possible.

Playing with the SHR in the JCL, gave interesting results:
If opening in SHR mode, the second OPENing makes existeing header records to be replaced. No surprise.
But If opening in OLD mode, while the header files are kept, as expected... only a few records are written afterwards, like if the job/step ended prematurely or something weird.

What I'm doing now is to open the output file on the sort input procedure, and let it open (which doesn't look polite in my eyes), then, let the sort output procedure close it.
Since there's only a single opening, it seems I can do all the output file writes in one go in SHR mode.

Cheers.
Alejandro
?


 

Dear Alejandro,

If I recall correctly, COBOL programs with SORT inside are in fact a SORT main program with COBOL routines inside that do not read or write directly to the input or output files, and maybe when you open an input or output file in the COBOL input side, you are in fact reopen it.

Using COBOL with SORT is a bit tricky and difficult to maintain, specially when configuring JCL steps on advanced job schedulers. This is the reason why it is forbidden in all the big mainframes sites I have worked in Germany, France, Brasil and Spain (mainly big banks).?

In your case, the need to preserve the header records make still more difficult to solve your problem in a single program and jcl step.

Any JCL step and COBOL+SORT program is easier to replace and maintain with three JCL steps of two COBOL programs (input and output treatment), and an external SORT in an step in the middle, but we are using Hercules for fun and learning purposes, as myself currently interested in old FORTRAN IV libraries from the CBT.

Did you tried to add an additional field in the filler trailing bytes with a flag for "header record" as H01, H02,...?
You could SORT with this field as first field in the sort key specification and you wouldn't need to add special header write instructions.

Did you know EASYTRIEVE from Pansophic and later as Computer Associates??
It is very interesting how to write equivalent programs with Easytrieve.

Alejandro Garcia?
Barcelona


On dj., de mar? 21, 2024 at 11:12, Alejandro olivan Alvarez
<alejandro.olivan.alvarez@...> wrote:
Thank you all guys for the points.

The thing is that, the code I was playing with, uses SORT together with its input and output procedures (nice feature!).
The goal was to let an input dataset full of records, including a set of header records, be sorted, with duplicated records suppressed, and write them to a member, all in one go if possible.
The strategy was to use the input procedure to bypass the header redcords from sort, and write them directly to output, and in the output procedure, simply check for duplicate records
before writing to file.

So, in my sort in procedure, I opened the output file, and write the header records directly, bypassing them being fed to sort, and, politely, close the file.
Then, on the output procedure from sort, I opened again the file, checked every passing, sorted, record, and write them to output file only if they're different from the last one. And, again, close the file.
Ideally, I would have been able to open in extend mode in the sort output procedure... but there I came with the issue that that's not possible.

Playing with the SHR in the JCL, gave interesting results:
If opening in SHR mode, the second OPENing makes existeing header records to be replaced. No surprise.
But If opening in OLD mode, while the header files are kept, as expected... only a few records are written afterwards, like if the job/step ended prematurely or something weird.

What I'm doing now is to open the output file on the sort input procedure, and let it open (which doesn't look polite in my eyes), then, let the sort output procedure close it.
Since there's only a single opening, it seems I can do all the output file writes in one go in SHR mode.

Cheers.
Alejandro
?


 

Surprisingly, once I realized that I could simply let the destination file opened (from the execution of sort input procedure) and close it at the end of the sort output procedure, the program did what I wanted with a very nice looking set of code (early 70s style coding :-D)
It is fun to see that, as you say, cobol is simply spawning the SORT program on its own to perform the work, as the SORT program output gets printed as part of the job output.

Initially, I did the exercice with raw JCL / SORT invocation... but I required several steps, separating the headr records from the payload records into different temporary datasets, sort the payload dataset and, finally, merge them into a final one... and all that, without getting rid of duplicates (which was my initial motivation to switch to use SORT under COBOL, since MVT COBOL does not support the SUM stuff)
After reading the COBOL book from 72 about SORT (which was veeery brief, pheww, just a single example!), I learn that the in out procedures were in fact, meant, to do things similar to what I wanted to do.

The idea of tagging the header records is very clever!
The way I solved that is simply counting iterations, since I know how many records my headers consist on... however, it is an interesting ideo to handle 'variable size' headers in a future!

Regarding the software/companies you mention...well... I do not know anything about anything :-P

Cheers.
Alejandro.


 

开云体育

Alejandro,

While not EXACTLY appropriate for your situation –

I am glad to see you solved your issue and got the output you were looking for.

?

Please understand the DISPOSITION parm in JCL – ?

?

NEW – open an create a new file

OLD – open an existing file – (exclusive control)

SHR – open an existing file with SHARE control

MOD – open an existing file and ADD TO THE END OF THE FILE –

?

?

-J-

?

Jeff Bassett

Bassettj@...

(301) 424-3362 (office)

(240) 388-7148 Cell

?

Time spent flying? - is NOT deducted from one’s lifespan

?

From: [email protected] <[email protected]> On Behalf Of Alejandro olivan Alvarez via groups.io
Sent: Thursday, March 21, 2024 9:25 AM
To: [email protected]
Subject: Re: [H390-MVS] COBOL help opening datasets to append records.

?

Surprisingly, once I realized that I could simply let the destination file opened (from the execution of sort input procedure) and close it at the end of the sort output procedure, the program did what I wanted with a very nice looking set of code (early 70s style coding :-D)
It is fun to see that, as you say, cobol is simply spawning the SORT program on its own to perform the work, as the SORT program output gets printed as part of the job output.

Initially, I did the exercice with raw JCL / SORT invocation... but I required several steps, separating the headr records from the payload records into different temporary datasets, sort the payload dataset and, finally, merge them into a final one... and all that, without getting rid of duplicates (which was my initial motivation to switch to use SORT under COBOL, since MVT COBOL does not support the SUM stuff)
After reading the COBOL book from 72 about SORT (which was veeery brief, pheww, just a single example!), I learn that the in out procedures were in fact, meant, to do things similar to what I wanted to do.

The idea of tagging the header records is very clever!
The way I solved that is simply counting iterations, since I know how many records my headers consist on... however, it is an interesting ideo to handle 'variable size' headers in a future!

Regarding the software/companies you mention...well... I do not know anything about anything :-P

Cheers.
Alejandro.