SORT INREC OUTREC OVERLAY - Adding sequential numbers

In this Mainframe Forum - You can post your queries on JCL, OS/390 JCL, MVS JCL, z/OS JCL, JES2 & JES3

Moderators: Frank Yaeger, DikDude, Moderator Group

Post Reply
venky
Active Member
Posts: 50
Joined: Sat May 12, 2012 10:13 pm

SORT INREC OUTREC OVERLAY - Adding sequential numbers

Post by venky » Wed Aug 08, 2012 1:35 am

Hi,

I have a PS file(500 record length) it contains 200 records, by using sort control card I have coded like this.

//sysin dd *

sort fields=copy
outrec fields=(1:1,500,501:seqnum,3,ZD)
/*

Output I am getting like below.

001
002
003
004
005 and so.....

but I need the output like below


1
2
3
4
5 and so on....for 200 records.

Please provide me a solution. Thanks.

Regards,
Venky.

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Wed Aug 08, 2012 4:46 am

Code: Select all

  INREC OVERLAY=(501:SEQNUM,3,ZD) 
Are you saying you only want a single-digit number? Change the 3 to 1.

You want it instead leading-zero suppressed and left-justified? Look at SQZ in the manaul.

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Wed Aug 08, 2012 6:25 am

Why does someone believe the "number" should be zero suppressed rather than naturallly aligned as you are getting?
Have a good one

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Wed Aug 08, 2012 8:15 am

DikDude wrote:Why does someone believe the "number" should be zero suppressed rather than naturallly aligned as you are getting?
because then there is an opportunity to post a request on how to
sort left-justified/zero-suppressed numeric data.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

venky
Active Member
Posts: 50
Joined: Sat May 12, 2012 10:13 pm

Post by venky » Thu Aug 09, 2012 2:37 am

Thanks Willams,

I have used SQZ function as below.

OUTREC FIELDS=(1,500,501,3,SQZ=(SHIFT=LEFT,PREBLANK=C'0'))

the preblank is replacing zeros with spaces in postion 501 with length 3 as per the outrec positions.

input:

001
002
003
004
005
006
007
008
010

I am getting the output:

1
2
3
4
5
6
7
8
9
1

but I need only leading zeros should become spaces and make left allign

Output I need:

1
2
3
4
5
6
7
8
9
10

Please let me know this can be done.?

thanks once again.

Regards,
Venky

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Thu Aug 09, 2012 3:34 am

OK. Problem is that all he PREBLANK characters get removed.

Try an EDIT on the sequence number to make it zero-suppressed. The SQZ (or JFY, perhaps better here, actually) the spaces. The trailing zeros will now be unaffected.

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Thu Aug 09, 2012 4:25 pm

venky, your latest question and the one at the start of this thread seems different, if you've new question - please remember to start a new thread.

For the latest question, this is one way of doing it:

Code: Select all

//SORTIN   DD *                      
001                                  
002                                  
003                                  
004                                  
005                                  
006                                  
007                                  
008                                  
010                                  
//SYSIN    DD *                      
  OPTION COPY                        
  INREC FIELDS=(1,3,SFF)             
  OUTREC BUILD=(1,3,JFY=(SHIFT=LEFT))
//*
Okay, this might not be the efficient one, because of the passes...
Regards,
Anuj

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Thu Aug 09, 2012 7:17 pm

Anuj,

Don't worry about passes here.

INREC, OUTREC and OUTFIL all take place in one pass of the data, just at different points.

INREC, before any sorting, OUTREC after any sorting, OUTFIL as records written.

With a COPY, the three will take place serially, repeatedly.

There's a nice explanation in the DFSORT manual of how all of such things hang together.

SFF is a nice thought. Might get a chance to "streamline" it later :-)

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Fri Aug 10, 2012 9:45 am

Thanks William. I've not been using SORT for a while now, so played safe... :)

Thanks 'gain for your comments & time,

Regards,

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Sun Aug 19, 2012 11:53 am

A little late, but here it is in one OVERLAY.

Code: Select all

//STEP0100 EXEC PGM=SORT 
//SYSOUT   DD SYSOUT=* 
//SORTOUT  DD SYSOUT=* 
//SYSIN    DD * 
 OPTION COPY 
  INREC OVERLAY=(5:SEQNUM,3,ZD, 
                 5:5,3,UFF, 
                 5:5,3,JFY=(SHIFT=LEFT))
//SORTIN   DD * 
001 
002 
003 
004 
005 
006 
007 
008 
009 
010 
X 
Y 
Z 
OVERLAY allows you to change the same position more than once, so here changed three times: added as SEQNUM; sourced from where the SEQNUM was placed, but defined as UFF (a little more descriptive than Anuj's original idea) so that leading zeros are replaced by space; use JFY to left justify the number, again at the same location.

Output is:

Code: Select all

001 1 
002 2 
003 3 
004 4 
005 5 
006 6 
007 7 
008 8 
009 9 
010 10
X   11
Y   12
Z   13

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Mon Aug 20, 2012 1:30 pm

This is rather neat, Thanks William.
Regards,
Anuj

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Tue Aug 21, 2012 5:09 am

That's OK. The SFF (UFF) was your idea :-)

It is also a good example for SYMNAMES, I think.

Code: Select all

//STEP0100 EXEC PGM=SORT 
//SYMNAMES DD * 
OVERLAY-SEQ,5,3,CH 
OVERLAY-SEQ-LEADING-BLANKS,=,=,UFF 
OVERLAY-SEQ-COL,= 
//SYMNOUT DD SYSOUT=* 
//SYSOUT   DD SYSOUT=* 
//SORTOUT  DD SYSOUT=* 
//SYSIN    DD * 
 OPTION COPY 
  INREC OVERLAY=(OVERLAY-SEQ-COL: 
                          SEQNUM,3,ZD, 
                 OVERLAY-SEQ-COL: 
                          OVERLAY-SEQ-LEADING-BLANKS, 
                 OVERLAY-SEQ-COL: 
                          OVERLAY-SEQ,JFY=(SHIFT=LEFT))
//SORTIN   DD * 
001 
002 
003 
004 
005 
006 
007 
008 
009 
010 
X 
Y 
Z 
Don't have to keep repeating the column number, and an aide memoire as to why UFF is used.

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India

Post by Anuj Dhawan » Tue Aug 21, 2012 7:43 pm

You’re very generous, appreciate that.

Interestingly, this

Code: Select all

********************************* TOP OF DATA **********************************
 ****** SYMNAMES SYMBOL STATEMENTS ******                                       
 OVERLAY-SEQ,5,3                                                                
 OVERLAY-SEQ-LEADING-BLANKS,5,3,UFF                                             
 OVERLAY-SEQ-COL,5                                                              
 ********** SYMBOL DEFINITIONS **********                                       
 OVERLAY-SEQ,5,3                                                                
 OVERLAY-SEQ-LEADING-BLANKS,5,3,UFF                                             
 OVERLAY-SEQ-COL,5                                                              
******************************** BOTTOM OF DATA ********************************
with SYNCSORT FOR Z/OS 1.3.2.2R and with DFsort (ICE201I H RECORD TYPE IS F ) it generated:

Code: Select all

DATA DICTIONARY SYMBOLS SUBSTITUTED :                     
OPTION COPY                                               
INREC OVERLAY=(5:SEQNUM,3,ZD,5:5,3,5:5,3,JFY=(SHIFT=LEFT))
Do you notice "UFF" did not 'show-up' in the generated 'card'. I'm experimenting with it, however, I thought I'll share it with you before I leave for the day.
Regards,
Anuj

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Tue Aug 21, 2012 8:33 pm

Well, that gives me one of those "I wish I'd not purged that output" moments.

It shouldn't work as I coded it. In the OVERLAY, the SYMANES processing is only going to take the start position and length. To get the conversion, you have to be specific with the UFF. Apologies for that. Thanks for the spot.

I can only imagine I "looked" at the output before it was available in the queue, so looked at the previous hand-coded one :-( Can no longer verify :-)

So:

Code: Select all

//STEP0100 EXEC PGM=SORT 
//SYMNAMES DD * 
OVERLAY-SEQ,5,3,CH 
OVERLAY-SEQ-COL,= 
//SYMNOUT DD SYSOUT=* 
//SYSOUT   DD SYSOUT=* 
//SORTOUT  DD SYSOUT=* 
//SYSIN    DD * 
 OPTION COPY 
  INREC OVERLAY=(OVERLAY-SEQ-COL: 
                          SEQNUM,3,ZD, 
                 OVERLAY-SEQ-COL: 
                          OVERLAY-SEQ,UFF,  /* TO REMOVE LEADING ZEROS
                 OVERLAY-SEQ-COL: 
                          OVERLAY-SEQ,JFY=(SHIFT=LEFT))
//SORTIN   DD * 
001 
002 
003 
004 
005 
006 
007 
008 
009 
010 
X 
Y 
Z 
Gives this output:

Code: Select all

001 1 
002 2 
003 3 
004 4 
005 5 
006 6 
007 7 
008 8 
009 9 
010 10
X   11
Y   12
Z   13

Squashman
Member
Posts: 2
Joined: Sat Jul 11, 2009 2:36 am

Post by Squashman » Wed Feb 25, 2015 2:03 am

dbzTHEdinosauer wrote:
DikDude wrote:Why does someone believe the "number" should be zero suppressed rather than naturallly aligned as you are getting?
because then there is an opportunity to post a request on how to
sort left-justified/zero-suppressed numeric data.
Bingo! Something I have been trying to figure out all day. I have no problems doing this in SAS, but SAS is slow with sorting large files. Is there no way to sort left justified zero suppressed numeric data?

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others