I'm currently learning JCL and I'm playing with the SORT program. As an exercise, I wanted to split some input records into multiple members belonging to the same PDS. Here my JCL code:
//FAILJ JOB
//STEP1 EXEC PGM=SORT
//SORTIN DD *
I
B
D
A
E
F
G
C
H
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//MEMA DD DSN=MY.PDS(MEMA),DISP=OLD
//MEMB DD DSN=MY.PDS(MEMB),DISP=OLD
//SYSIN DD *
SORT FIELDS=(1,1,CH,A)
OUTFIL FNAMES=(MEMA,MEMB),SPLIT
This code produces two members called MY.PDS(MEMA) and MY.PDS(MEMB) containing the same set of records, which is unexpected to me:
B
D
F
H
The expected result for MY.PDS(MEMA) was:
A
C
E
G
I
My question is not "How to fix?", but why this behaviour and how it works internally? I'm using the Hercules mainframe emulator. Is it different on a real mainframe?
PDS members aren't really entirely like separate files. They're just contiguous segments of the data set, which is written sequentially and then the directory updated to point to the records that make up the member just written. You can read them in parallel as separate files, but when you try to write new members in parallel, you wind up writing to the same starting place and one overwrites the other.
For the same reason, you can't append new records to an existing member--you'd wind up overwriting the next member in sequence. You can update records in place, but to add records you can only rewrite the whole thing at the end of the data set, leaving a gap in the middle that you can compress out later. https://www.ibm.com/docs/en/zos/2.5.0?topic=pds-rewriting-member
However! Look into the PDSE (library) data set type. That does allow you to write multiple members at once, and allows unused space to be reused so you don't have to worry about compressing out old members. https://www.ibm.com/docs/en/zos/2.5.0?topic=pdses-pdse-pds-differences
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With