|
View previous topic :: View next topic
|
| Author |
Message |
Anthony Rose
New User
Joined: 27 Oct 2025 Posts: 5 Location: England
|
|
|
|
Hi, I'm quite inexperienced on Z/OS JCL and spent several hours searching not only this forum but all over trying to find a simple non-programming method for a job to detect that a dataset is held before it executes a step that tries to write to that dataset, but it appears that is not possible. Am I correct?
I was thinking of using something like IDCAMS to check but I realised that if you DISP=SHR you’ll be allowed anyway and if you DISP=OLD or MOD then you won’t even get into IDCAMS.
Then I explored using TPM IKJEFT01 (or 1A which normalises RC to 0 or 4) but the only command I could find that might work is LISTCAT and I don't think LISTCAT will abend if a dataset is held.
So whatever solution is employed, it seems you have to program some logic to read the status, which I find surprising.
In the specific case I am looking to solve, we have a job which runs every 5 minutes and accumulates data in a daily dataset. Occasionally we get a query and a programmer can unthinkingly browse the dataset, causing an incident when the next job iteration runs.
I would have loved to write a little IDCAMS step beforehand to touch the dataset and return RC=0 or 4 if it is held, because the job can actually easily leave the dataset write for the next iteration, so could simply skip the write step. |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2263 Location: USA
|
|
|
|
| Anthony Rose wrote: |
I was thinking of using something like IDCAMS to check but I realised that if you DISP=SHR you’ll be allowed anyway and if you DISP=OLD or MOD then you won’t even get into IDCAMS. |
Try to use IDCAMS without allocating your dataset via DD statement. Use IDCAMS commands like
| Code: |
| ALLOCATE DATASET('dsname') ... OLD ... |
I expect you should get a return code instead of ABEND code in this case.
I'm busy (and lazy) to test it right now.
If so, you can even implement some logic within IDCAMS itself, using the IDCAMS statements IF LASTCC = ... THEN ... ELSE ....
Maybe no need to use JCL statements
| Code: |
// IF ... THEN
// . . . . .
// ELSE
// . . . . .
// ENDIF |
|
|
| Back to top |
|
 |
Anthony Rose
New User
Joined: 27 Oct 2025 Posts: 5 Location: England
|
|
|
|
| Oh! I had no idea that could be done! That's brilliant! No need to test, I will do so soon and report back. TYSM!!! |
|
| Back to top |
|
 |
Anthony Rose
New User
Joined: 27 Oct 2025 Posts: 5 Location: England
|
|
|
|
| sergeyken wrote: |
| Anthony Rose wrote: |
I was thinking of using something like IDCAMS to check but I realised that if you DISP=SHR you’ll be allowed anyway and if you DISP=OLD or MOD then you won’t even get into IDCAMS. |
Try to use IDCAMS without allocating your dataset via DD statement. Use IDCAMS commands like
| Code: |
| ALLOCATE DATASET('dsname') ... OLD ... |
I expect you should get a return code instead of ABEND code in this case.
I'm busy (and lazy) to test it right now.
If so, you can even implement some logic within IDCAMS itself, using the IDCAMS statements IF LASTCC = ... THEN ... ELSE ....
Maybe no need to use JCL statements
| Code: |
// IF ... THEN
// . . . . .
// ELSE
// . . . . .
// ENDIF |
|
I am so grateful to you! Especially for your added suggestion to do the work itself inside IDCAMS. It works like a BOMB! I can't imagine why I could not find an example with hours of searching, it is so simple.
Here is my test using two datasets in a random job of mine: it allocates two datasets as OLD and MOD then copies the OLD to the MOD and if there is an error it converts that to RC=1
| Code: |
//BKDAILY EXEC PGM=IDCAMS,COND=(0,NE)
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
ALLOCATE FILE(OLDD) DATASET('ZMT0763.FTSAMNGT.TEMP') OLD
ALLOCATE FILE(MODD) DATASET('ZMT0763.FTSAMNGT.TRANS') MOD
REPRO OUTFILE(MODD) INFILE(OLDD)
IF MAXCC > 1 THEN SET MAXCC = 1
//* |
I've not used IDCAMS before except to set the MAXCC if a dataset is empty which I got from existing jobs. I've learned a lot just now, like some commands are TSO commands like ALLOCATE which explains why I did not see them in a list of IDCAMS commands. I feel EMPOWERED!
tysm! |
|
| Back to top |
|
 |
Anthony Rose
New User
Joined: 27 Oct 2025 Posts: 5 Location: England
|
|
|
|
If anyone finds this example, don't forget to handle the RC=1 as a non-exception
For example, at my site we would code
| Code: |
//CONDCODE EXEC CONDCODE,
// COND.Z1=(1,LT) |
and in CA7 update the job with CONDCODE=0001,RELOPR=LT |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2263 Location: USA
|
|
|
|
| Anthony Rose wrote: |
| Code: |
//BKDAILY EXEC PGM=IDCAMS,COND=(0,NE)
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
ALLOCATE FILE(OLDD) DATASET('ZMT0763.FTSAMNGT.TEMP') OLD
ALLOCATE FILE(MODD) DATASET('ZMT0763.FTSAMNGT.TRANS') MOD
REPRO OUTFILE(MODD) INFILE(OLDD)
IF MAXCC > 1 THEN SET MAXCC = 1
//* |
|
I'd improve it to bypass REPRO when not needed:
| Code: |
//BKDAILY EXEC PGM=IDCAMS,COND=(0,NE)
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
ALLOCATE FILE(OLDD) DATASET('ZMT0763.FTSAMNGT.TEMP') OLD
ALLOCATE FILE(MODD) DATASET('ZMT0763.FTSAMNGT.TRANS') MOD
IF MAXCC = 0 THEN REPRO OUTFILE(MODD) INFILE(OLDD)
IF MAXCC > 1 THEN SET MAXCC = 1
//* |
In some cases extra JCL parameter may be needed, to increase the limit of dynamically created DD allocations.
| Code: |
//BKDAILY EXEC PGM=IDCAMS,COND=(0,NE),DYNAMNMR=10
. . . . .
|
|
|
| Back to top |
|
 |
Anthony Rose
New User
Joined: 27 Oct 2025 Posts: 5 Location: England
|
|
|
|
| sergeyken wrote: |
I'd improve it to bypass REPRO when not needed:
| Code: |
//BKDAILY EXEC PGM=IDCAMS,COND=(0,NE)
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
ALLOCATE FILE(OLDD) DATASET('ZMT0763.FTSAMNGT.TEMP') OLD
ALLOCATE FILE(MODD) DATASET('ZMT0763.FTSAMNGT.TRANS') MOD
IF MAXCC = 0 THEN REPRO OUTFILE(MODD) INFILE(OLDD)
IF MAXCC > 1 THEN SET MAXCC = 1
//* |
In some cases extra JCL parameter may be needed, to increase the limit of dynamically created DD allocations.
| Code: |
//BKDAILY EXEC PGM=IDCAMS,COND=(0,NE),DYNAMNMR=10
. . . . .
|
|
Beautiful, I'll apply that.
(I doubt we'll need the limit increased as it's something I've not seen before at this site so the default limit should be enough, I expect, but it's really handy to know about it so I can check it out and already have the solution to hand.)
You've been very kind, thank you! |
|
| Back to top |
|
 |
|
|