IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Trying to use sort to do two functions in a single step


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Jeff Kirsch

New User


Joined: 23 Jun 2021
Posts: 4
Location: USA

PostPosted: Wed Jun 23, 2021 11:22 pm
Reply with quote

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
View user's profile Send private message
Joerg.Findeisen

Active Member


Joined: 15 Aug 2015
Posts: 561
Location: Bamberg, Germany

PostPosted: Wed Jun 23, 2021 11:46 pm
Reply with quote

*sigh*

Use code tags for code/data, please. Also provide some data for SORTIN for us to test.
Back to top
View user's profile Send private message
Joerg.Findeisen

Active Member


Joined: 15 Aug 2015
Posts: 561
Location: Bamberg, Germany

PostPosted: Wed Jun 23, 2021 11:55 pm
Reply with quote

Look at page 38 https://www-01.ibm.com/servers/resourcelink/svc00100.nsf/pages/zOSV2R4sc236878/$file/icea100_v2r4.pdf
Back to top
View user's profile Send private message
sergeyken
Warnings : 2

Senior Member


Joined: 29 Apr 2008
Posts: 1130

PostPosted: Thu Jun 24, 2021 12:39 am
Reply with quote

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
View user's profile Send private message
sergeyken
Warnings : 2

Senior Member


Joined: 29 Apr 2008
Posts: 1130

PostPosted: Thu Jun 24, 2021 12:48 am
Reply with quote

P.S.
//SYSPRINT DD, and //SORTMSG DD are not used by SORT utilities.
Remove them as the garbage powdering our minds.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2723
Location: NYC,USA

PostPosted: Thu Jun 24, 2021 1:41 am
Reply with quote

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
View user's profile Send private message
sergeyken
Warnings : 2

Senior Member


Joined: 29 Apr 2008
Posts: 1130

PostPosted: Thu Jun 24, 2021 2:29 am
Reply with quote

//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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2723
Location: NYC,USA

PostPosted: Thu Jun 24, 2021 2:41 am
Reply with quote

Yes, They have no effect.
Code:
//SYSUDUMP DD  SYSOUT=*
//SYSPRINT DD  SYSOUT=*
Back to top
View user's profile Send private message
Jeff Kirsch

New User


Joined: 23 Jun 2021
Posts: 4
Location: USA

PostPosted: Thu Jun 24, 2021 6:11 am
Reply with quote

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
View user's profile Send private message
Jeff Kirsch

New User


Joined: 23 Jun 2021
Posts: 4
Location: USA

PostPosted: Thu Jun 24, 2021 7:03 am
Reply with quote

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
View user's profile Send private message
Joerg.Findeisen

Active Member


Joined: 15 Aug 2015
Posts: 561
Location: Bamberg, Germany

PostPosted: Thu Jun 24, 2021 9:32 am
Reply with quote

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. icon_exclaim.gif
Back to top
View user's profile Send private message
sergeyken
Warnings : 2

Senior Member


Joined: 29 Apr 2008
Posts: 1130

PostPosted: Thu Jun 24, 2021 5:37 pm
Reply with quote

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
View user's profile Send private message
Jeff Kirsch

New User


Joined: 23 Jun 2021
Posts: 4
Location: USA

PostPosted: Thu Jun 24, 2021 6:38 pm
Reply with quote

Thank you, Joerg and Sergeyken. I'll change the sequence of the SORT statements.
Back to top
View user's profile Send private message
sergeyken
Warnings : 2

Senior Member


Joined: 29 Apr 2008
Posts: 1130

PostPosted: Thu Jun 24, 2021 7:37 pm
Reply with quote

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
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2723
Location: NYC,USA

PostPosted: Thu Jun 24, 2021 7:48 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Is the Output of Sort/Join dependent ... DFSORT/ICETOOL 2
No new posts Sort to extract lines DFSORT/ICETOOL 8
No new posts Combining Multiple Row Values into Si... DB2 3
No new posts SORT - Multiple Conditions DFSORT/ICETOOL 4
No new posts SYNCSORT/ICETOOL JOINKEYS SORT Statem... DFSORT/ICETOOL 13
Search our Forums:

Back to Top