Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Sort group records using WHEN=GROUP from SYNCSORT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> SYNCSORT
View previous topic :: :: View next topic  
Author Message
Himanshu Khatri

New User


Joined: 11 Jun 2007
Posts: 15
Location: Pune

PostPosted: Sat Apr 04, 2015 2:01 am    Post subject: Sort group records using WHEN=GROUP from SYNCSORT
Reply with quote

Hi All,

Input file is VB and of LRECL 84 bytes.

Code:
 
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
10010 HDRREC 10002                                                               
10010 DDDDDDDDD  D DDDD       A00 3978 1965-01-01 PRES                           
10010 EEEEEEE    E EEEEEEEE   B01 3476 1973-10-10 MANAGER                       
10010 FFFFF      F FFFF       C01 4738 1975-04-05 MANAGER                       
10010 HDRREC 10003                                                               
10010 GGGGGGGGG  G GGGG       A00 3978 1965-01-01 PRES                           
10010 HHHHHHH    H HHHHHHHH   B01 3476 1973-10-10 MANAGER                       
10010 IIIII      I IIII       C01 4738 1975-04-05 MANAGER                       
10010 HDRREC 10001                                                               
10010 AAAAAAAAA  A AAAA       A00 3978 1965-01-01 PRES                           
10010 BBBBBBB    B BBBB       B01 3476 1973-10-10 MANAGER                       
10010 CCCCC      C CCCC       C01 4738 1975-04-05 MANAGER                       
******************************** Bottom of Data ********************************


All records will start with Department ID. First 5 bytes belong to Department ID. In above file it is 10010
File will have Header record followed by Detail records. Header record will be identified by checking string as 'HDRREC'.
Header record will also have Employee Id of 5 bytes starting from 18 byte. Above file has 3 Employee ID details: 10002, 10003 and 10001.

We need to SORTOUT as below which will also VB file with LRECL 84 bytes:

Code:
 
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
10010 HDRREC 10001                                                               
10010 AAAAAAAAA  A AAAA       A00 3978 1965-01-01 PRES                           
10010 BBBBBBB    B BBBB       B01 3476 1973-10-10 MANAGER                       
10010 CCCCC      C CCCC       C01 4738 1975-04-05 MANAGER                       
10010 HDRREC 10002                                                               
10010 DDDDDDDDD  D DDDD       A00 3978 1965-01-01 PRES                           
10010 EEEEEEE    E EEEEEEEE   B01 3476 1973-10-10 MANAGER                       
10010 FFFFF      F FFFF       C01 4738 1975-04-05 MANAGER                       
10010 HDRREC 10003                                                               
10010 GGGGGGGGG  G GGGG       A00 3978 1965-01-01 PRES                           
10010 HHHHHHH    H HHHHHHHH   B01 3476 1973-10-10 MANAGER                       
10010 IIIII      I IIII       C01 4738 1975-04-05 MANAGER                       
******************************** Bottom of Data ********************************


I wrote below JCL to try out WHEN=GROUP option.
Code:
 
//UND24H   JOB ,'H. KHATRI',CLASS=E,PRTY=02,MSGLEVEL=(1,1),
// NOTIFY=UND24,USER=UND24,MSGCLASS=H                       
//*                                                         
//STEP0010 EXEC PGM=SYNCSORT                               
//*                                                         
//SORTIN   DD DSN=INPUT,                                   
//            DISP=SHR                                     
//SORTOUT  DD DSN=OUTPUT,                                   
//            DISP=(NEW,CATLG,DELETE),                     
//            DCB=(LRECL=84,BLKSIZE=0,RECFM=VB,DSORG=PS),   
//            SPACE=(CYL,(5,5),RLSE),                       
//            UNIT=SYSDA                                   
//*                                                         
//SYSIN    DD *                                             
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(11,06,CH,EQ,C'HDRREC'),   
                PUSH=(85:ID=10,SEQ=2))                     
  SORT FIELDS=(05,05,ZD,A,  -- DEPARTMENT-ID               
               85,10,ZD,A,  -- GROUP-NBR                   
               95,02,ZD,A,  -- GROUP-SEQ-NBR               
               18,05,ZD,D)  -- EMPLOYEE-ID                 
  OUTREC BUILD=(1:1,4,5:5,80)                               
/*                                                 
//*                   
//SYSOUT   DD SYSOUT=*
//*                             


SORTOUT from above JCL:
Code:
 
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
10010 HDRREC 10002                                                               
10010 AAAAAAAAA  A AAAA       A00 3978 1965-01-01 PRES                           
10010 BBBBBBB    B BBBB       B01 3476 1973-10-10 MANAGER                       
10010 HDRREC 10003                                                               
10010 GGGGGGGGG  G GGGG       A00 3978 1965-01-01 PRES                           
10010 HHHHHHH    H HHHHHHHH   B01 3476 1973-10-10 MANAGER                       
10010 IIIII      I IIII       C01 4738 1975-04-05 MANAGER                       
10010 CCCCC      C CCCC       C01 4738 1975-04-05 MANAGER                       
10010 HDRREC 10001                                                               
10010 DDDDDDDDD  D DDDD       A00 3978 1965-01-01 PRES                           
10010 EEEEEEE    E EEEEEEEE   B01 3476 1973-10-10 MANAGER                       
10010 FFFFF      F FFFF       C01 4738 1975-04-05 MANAGER                       
******************************** Bottom of Data ********************************


SYSOUT:
Code:
 
********************************* TOP OF DATA ************************************************************************
 SYNCSORT FOR Z/OS  2.1.0.0R    U.S. PATENTS: 4210961, 5117495   (C) 2014 SYNCSORT INC.   DATE=2015/093   TIME=16.16.1
                                                       z/OS   2.1.0                                                   
 SYNCSORT LICENSED FOR CPU SERIAL NUMBER 54F73, MODEL 2098 Q04             LICENSE/PRODUCT EXPIRATION DATE: 15 MAR 201
 SYSIN :                                                                                                               
   INREC IFTHEN=(WHEN=GROUP,BEGIN=(11,06,CH,EQ,C'HDRREC'),                                                             
                 PUSH=(85:ID=10,SEQ=2))                                                                               
   SORT FIELDS=(05,05,ZD,A,  -- DEPARTMENT-ID                                                                         
                85,10,ZD,A,  -- GROUP-NBR                                                                             
                95,02,ZD,A,  -- GROUP-SEQ-NBR                                                                         
                18,05,ZD,D)  -- EMPLOYEE-ID                                                                           
   OUTREC BUILD=(1:1,4,5:5,80)                                                                                         
 WER813I  INSTALLATION OPTIONS IN MFX LOAD LIBRARY WILL BE USED                                                       
 WER276B  SYSDIAG= 688787, 1282189, 1282189, 1801335                                                                   
 WER164B  18,712K BYTES OF VIRTUAL STORAGE AVAILABLE, MAX REQUESTED,                                                   
 WER164B     0 BYTES RESERVE REQUESTED, 18,420K BYTES USED                                                             
 WER146B  12K BYTES OF EMERGENCY SPACE ALLOCATED                                                                       
 WER108I  SORTIN   : RECFM=VB   ; LRECL=    84; BLKSIZE= 27998                                                         
 WER073I  SORTIN   : DSNAME=INPUT                                                                     
 WER257I  INREC RECORD LENGTH =    96                                                                                 
 WER238I  POTENTIALLY INEFFICIENT USE OF INREC                                                                         
 WER237I  OUTREC RECORD LENGTH =    84                                                                                 
WER110I  SORTOUT  : RECFM=VB   ; LRECL=    84; BLKSIZE= 27998                                     
WER074I  SORTOUT  : DSNAME=OUTPUT                                                 
WER410B  17,684K BYTES OF VIRTUAL STORAGE AVAILABLE ABOVE THE 16-MEGABYTE LINE,                   
WER410B     0 BYTES RESERVE REQUESTED, 17,684K BYTES USED                                         
WER036B  G=3033,SEGLEN=6064                                                                       
WER177I  TURNAROUND SORT PERFORMED                                                               
WER045C  END SORT PHASE                                                                           
WER416B  SORTIN   : EXCP'S=1,UNIT=3390,DEV=2C22,CHP=(4244484E5055,2),VOL=TEST94                   
WER416B  SORTOUT  : EXCP'S=1,UNIT=3390,DEV=2822,CHP=(4244484E5055,2),VOL=TEST99                   
WER416B  TOTAL OF 2 EXCP'S ISSUED FOR SORTING                                                     
WER246I  FILESIZE 1,152 BYTES                                                                     
WER054I  RCD IN         12, OUT         12                                                       
WER072I  EQUALS, BALANCE IN EFFECT                                                               
WER169I  RELEASE 2.1 BATCH 0539 TPF LEVEL 0.0                                                     
WER052I  END SYNCSORT - UND24H,STEP0010,,DIAG=8600,408B,AA14,6477,CEEA,68A3,2640,6C60             
******************************* BOTTOM OF DATA **************************************************


I am going through SYNCSORT manual but not able to figure out how to correct this. Can you please guide me.

Thanks,
Himanshu
Back to top
View user's profile Send private message

RahulG31

Active User


Joined: 20 Dec 2014
Posts: 331
Location: USA

PostPosted: Sat Apr 04, 2015 3:16 am    Post subject: Reply to: Sort group records using WHEN=GROUP from SYNCSORT
Reply with quote

Are the records under HDRREC already in Sorted order OR do you want to make them in sorted order as well?

I am talking about D, E and F records:
Quote:
10010 HDRREC 10002
10010 DDDDDDDDD D DDDD A00 3978 1965-01-01 PRES
10010 EEEEEEE E EEEEEEEE B01 3476 1973-10-10 MANAGER
10010 FFFFF F FFFF C01 4738 1975-04-05 MANAGER
Back to top
View user's profile Send private message
Himanshu Khatri

New User


Joined: 11 Jun 2007
Posts: 15
Location: Pune

PostPosted: Sat Apr 04, 2015 3:52 am    Post subject:
Reply with quote

Yes, records under HDRREC will be in Sorted Order. We don't have to SORT them.

Thanks,
Himanshu
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 331
Location: USA

PostPosted: Sat Apr 04, 2015 3:57 am    Post subject: Reply to: Sort group records using WHEN=GROUP from SYNCSORT
Reply with quote

There seems to be a problem with PUSH. Instead of ID you may want to use the HDRREC number which is already there on the record.

I considered a 60 LRECL FB file and the below SYSIN card worked for that:
Code:
//SYSIN DD *                                               
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(7,06,CH,EQ,C'HDRREC'),   
               PUSH=(61:14,5,SEQ=2))             
 SORT FIELDS=(1,5,CH,A,61,7,CH,A)                         
 OUTFIL BUILD=(1,60)                                       

Can you make changes in this card for VB and let me know if it works for you.
Back to top
View user's profile Send private message
Himanshu Khatri

New User


Joined: 11 Jun 2007
Posts: 15
Location: Pune

PostPosted: Sat Apr 04, 2015 6:31 am    Post subject:
Reply with quote

Thanks Rahul icon_smile.gif. It worked for me.

Code:

//SYSIN    DD *                                           
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(11,06,CH,EQ,C'HDRREC'), 
                PUSH=(85:5,5,90:18,5,SEQ=2))               
  SORT FIELDS=(85,10,ZD,A,95,02,ZD,A)                     
  OUTREC BUILD=(1:1,4,5:5,80)                             
/*                                                         
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7231

PostPosted: Sat Apr 04, 2015 12:55 pm    Post subject: Reply to: Sort group records using WHEN=GROUP from SYNCSORT
Reply with quote

Thanks for posting the solution, it can help others. A couple of things to tidy

You only need columns (n:) when you want to leave "gaps". If you don't need gaps, the columns are just extra which get you nothing.

Code:
//SYSIN    DD *                                           
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(11,06,CH,EQ,C'HDRREC'),
                PUSH=(85:5,5,18,5,SEQ=2))               
  SORT FIELDS=(85,10,ZD,A,95,02,ZD,A)                     
  OUTREC BUILD=(1,4,5,80)


18,5 is the same on each record in a group, so no need to PUSH that. With OPTION EQUALS (or using EQUALS on the SORT statement), which preserves the input order of identical keys in the output data (by assigning a sequence number internally) you don't need the SEQ. Because you have extended your record at the "end", all your records on your output file are now 84 bytes long, no longer variable:

Code:
//SYSIN    DD *                                           
  OPTION EQUALS
  INREC IFTHEN=(WHEN=INIT,
                 BUILD=(1,4,5X,5)),
        IFTHEN=(WHEN=GROUP,
                 BEGIN=(11,06,CH,EQ,C'HDRREC'),
                 PUSH=(5:10,5))               
  SORT FIELDS=(5,5,CH,A,23,05,CH,A)                     
  OUTREC BUILD=(1,4,10)


The BUILD on INIT just leaves some "space" to put the PUSHed Employee ID.

I think the order of your SORT is incorrect, you need your Department Id sorting first. This is a deficiency in your test data, which only had one department. I haven't made the change. Code is untested, so fix any typos. If all employees are in strict sequence across departments, the change would be unnecessary, but that seems unlikely.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> SYNCSORT All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts syncsort: copy lines after the keyword shreya19 SYNCSORT 7 Fri Dec 02, 2016 9:47 am
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Syncsort - Hard coded Value in output PORYES SYNCSORT 1 Thu Nov 03, 2016 9:23 am
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us