View previous topic :: View next topic
|
Author |
Message |
Jeff Kirsch
New User
Joined: 23 Jun 2021 Posts: 6 Location: USA
|
|
|
|
Hi,
I am using SORT to do a couple of functions within a single step. If I separate the two functions, they work fine. However, when entered together, the dataset is cleared out.
I understand why the dataset is cleared out (because the INCLUDE statement cannot locate a value of 0 in the field it's comparing). And when I run the functions separately, I have SORTOUT pointing to DD SYSOUT=*. So here is the JCL I'm trying to get to work
Code: |
//SUBTRC1 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SORTMSG DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=MY.DATASET,DISP=SHR
//SORTOUT DD DSN=MY.DATASET,DISP=SHR
//SYSIN DD *
OPTION COPY,NULLOUT=RC4
INREC OVERLAY=(1:1,1,ZD,SUB,+1,TO=ZD,LENGTH=1)
INCLUDE COND=(1,1,CH,EQ,C'0') |
What I'm trying to accomplish is this
1. Subtract 1 from the field that contains a numeric value (could be 0 - 9)
2. Compare the resulting value in the numeric field (from step 1) to a value of 0. If it's 0 then rc=0 otherwise rc=4
I'm sure this can be done in one step, however I don't understand how to do the compare without using the INCLUDE. Would appreciate any assistance, thanks.
Coded for you |
|
Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1387 Location: Bamberg, Germany
|
|
|
|
*sigh*
Use code tags for code/data, please. Also provide some data for SORTIN for us to test. |
|
Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1387 Location: Bamberg, Germany
|
|
Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2209 Location: USA
|
|
|
|
Jeff Kirsch wrote: |
Hi,
I am using SORT to do a couple of functions within a single step. If I separate the two functions, they work fine. However, when entered together, the dataset is cleared out.
I understand why the dataset is cleared out (because the INCLUDE statement cannot locate a value of 0 in the field it's comparing). And when I run the functions separately, I have SORTOUT pointing to DD SYSOUT=*. So here is the JCL I'm trying to get to work
//SUBTRC1 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SORTMSG DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=MY.DATASET,DISP=SHR
//SORTOUT DD DSN=MY.DATASET,DISP=SHR
//SYSIN DD *
OPTION COPY,NULLOUT=RC4
INREC OVERLAY=(1:1,1,ZD,SUB,+1,TO=ZD,LENGTH=1)
INCLUDE COND=(1,1,CH,EQ,C'0')
What I'm trying to accomplish is this
1. Subtract 1 from the field that contains a numeric value (could be 0 - 9)
2. Compare the resulting value in the numeric field (from step 1) to a value of 0. If it's 0 then rc=0 otherwise rc=4
I'm sure this can be done in one step, however I don't understand how to do the compare without using the INCLUDE. Would appreciate any assistance, thanks. |
RTFM:
The SORT statements are executed not in the order you typed them in your code, but in pre-defined order, as described in any SORT manual.
That is, INCLUDE is always applied before INREC!!!
Hint: instead of the INCLUDE COND= statement use the parameter of a subsequent statement, such as OUTFIL INCLUDE= |
|
Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2209 Location: USA
|
|
|
|
P.S.
//SYSPRINT DD, and //SORTMSG DD are not used by SORT utilities.
Remove them as the garbage powdering our minds. |
|
Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3087 Location: NYC,USA
|
|
|
|
Code: |
//PS001 EXEC PGM=SORT
//SORTIN DD *
2
//SORTOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC OVERLAY=(1:1,1,ZD,SUB,+1,TO=ZD,LENGTH=1)
OUTFIL NULLOFL=RC4,INCLUDE=(1,1,CH,EQ,C'0') |
|
|
Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2209 Location: USA
|
|
|
|
//SYSPRINT DD statement is not used by SORT.
//SYSUDUMP DD may be used after a catastrophic failure within SORT module itself, but there is absolutely no chance that any developer, even the must experienced one, would be able to get any useful information from this terrible huge listing; especially - from the spool, via SYSOUT=* |
|
Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3087 Location: NYC,USA
|
|
|
|
Yes, They have no effect.
Code: |
//SYSUDUMP DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
|
|
|
Back to top |
|
 |
Jeff Kirsch
New User
Joined: 23 Jun 2021 Posts: 6 Location: USA
|
|
|
|
Thank you Joerg, Sergeyken and Rohit.
Sergeyken, yes, I did RTFM, that's how I got as far as I did, although I'll admit I obviously did not comprehend all that I read, and I don't think you fully understand my goal.
Rohit, I appreciate your example. However, after completion of your the two functions listed, I still lose the data in the dataset. So I guess I wasn't clear in what I'm trying to accomplish. Let me try again. The input and output dataset are the same in my example. The only field in the dataset is a 10 byte character field consisting of a single value (could be 0 - 9). So it might look like this
7 space space space ....... and so on
What I am trying to do is have SORT subtract 1 from the value in the dataset and overlay that existing value with a new value. So based on the data above, the end result should be
6 space space space ...... and so on
This logic is working as written. It's actually the second part of the SORT that is causing the issue. The logic is to compare the new value to 0. If it matches, I should get a return code of 0. If it doesn't I should get a return code of 4. That works too, however, because I'm using an INCLUDE, and the value doesn't equate to 0, the record does not get written to the dataset and it's left with just blanks. I'm trying to understand how to do the compare without losing the data that's in the dataset.
Your example (and mine too) is clearing the data from the dataset. Basically leaving 10 spaces.
Hope that makes better sense. Thanks again.
Jeff |
|
Back to top |
|
 |
Jeff Kirsch
New User
Joined: 23 Jun 2021 Posts: 6 Location: USA
|
|
|
|
UPDATE:
Through further testing, I was able to retain the updated record after the compare operation completed.
I modified Rohit's logic from
SORT FIELDS=COPY
INREC OVERLAY=(1:1,1,ZD,SUB,+1,TO=ZD,LENGTH=1)
OUTFIL NULLOFL=RC4,INCLUDE=(1,1,CH,EQ,C'0')
to
SORT FIELDS=COPY
INREC OVERLAY=(1:1,1,ZD,SUB,+1,TO=ZD,LENGTH=1)
OUTFIL FNAMES=DMYOUT,NULLOFL=RC4,INCLUDE=(1,1,CH,EQ,C'0')
Then I added to my JCL
//DMYOUT DD DUMMY
I believe this forced the INCLUDE to write to DMYOUT instead of SORTOUT. Not sure if this is kosher or not, but it works.
Thanks again, Rohit. |
|
Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1387 Location: Bamberg, Germany
|
|
|
|
Jeff Kirsch wrote: |
SORT FIELDS=COPY
INREC OVERLAY=(1:1,1,ZD,SUB,+1,TO=ZD,LENGTH=1)
OUTFIL FNAMES=DMYOUT,NULLOFL=RC4,INCLUDE=(1,1,CH,EQ,C'0' |
Do what has been said before. INREC, SORT, OUTFIL is the sequence.  |
|
Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2209 Location: USA
|
|
|
|
Jeff Kirsch wrote: |
This logic is working as written. It's actually the second part of the SORT that is causing the issue. The logic is to compare the new value to 0. If it matches, I should get a return code of 0. If it doesn't I should get a return code of 4. |
This repeats your initial post, and this was explained to you in all previous responses.
Jeff Kirsch wrote: |
That works too, however, because I'm using an INCLUDE, and the value doesn't equate to 0, the record does not get written to the dataset and it's left with just blanks. |
The record really does not go to the dataset, but nothing is left with just blanks. This your statement is completely wrong.
Jeff Kirsch wrote: |
I'm trying to understand how to do the compare without losing the data that's in the dataset.
Your example (and mine too) is clearing the data from the dataset. Basically leaving 10 spaces. |
1) No compare can loose the data in the dataset, ever.
2) All SORT samples suggested to you do exactly what you asked about. If you in fact need something else, please, describe it clearly. |
|
Back to top |
|
 |
Jeff Kirsch
New User
Joined: 23 Jun 2021 Posts: 6 Location: USA
|
|
|
|
Thank you, Joerg and Sergeyken. I'll change the sequence of the SORT statements. |
|
Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2209 Location: USA
|
|
|
|
Jeff Kirsch wrote: |
Thank you, Joerg and Sergeyken. I'll change the sequence of the SORT statements. |
The physical sequence of SORT statements would not change the utility behavior, not a bit. You just need to keep in mind the order, in which the statements are applied.
It would be a good tone (for clarity!) also to code the statements in the same order they are "executed".
And also: to use proper code alignment, splitting into separate lines, adding comments, etc. etc. etc. This is being said to the world at least since 1960-s, but with no result - the code continues to be a garbage of words, and characters... |
|
Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3087 Location: NYC,USA
|
|
|
|
Jeff Kirsch wrote: |
UPDATE:
Through further testing, I was able to retain the updated record after the compare operation completed.
I modified Rohit's logic from
SORT FIELDS=COPY
INREC OVERLAY=(1:1,1,ZD,SUB,+1,TO=ZD,LENGTH=1)
OUTFIL NULLOFL=RC4,INCLUDE=(1,1,CH,EQ,C'0')
to
SORT FIELDS=COPY
INREC OVERLAY=(1:1,1,ZD,SUB,+1,TO=ZD,LENGTH=1)
OUTFIL FNAMES=DMYOUT,NULLOFL=RC4,INCLUDE=(1,1,CH,EQ,C'0')
Then I added to my JCL
//DMYOUT DD DUMMY
I believe this forced the INCLUDE to write to DMYOUT instead of SORTOUT. Not sure if this is kosher or not, but it works.
Thanks again, Rohit. |
This is correct and you will still get the changed record in SORTOUT. Sequence change won't do any better. |
|
Back to top |
|
 |
|
|