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

How to sort Multiple records?


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Wed Apr 18, 2012 4:18 am
Reply with quote

Hi All,

I need a small help. I have an input file with multiple records with a header (ORIGINAL) and tralier(ENDMSG) as below,

INPUT: LRECL=80

Code:
ORIGINAL:JES                                       
DOCNAME:002006022603158655                                   
TO:XXXX
MBX:AAA@AAA.COM                                   
.
.
.
ENDMSG:
ORIGINAL:JES                                       
DOCNAME:002006022603158655                                   
TO:XXXX
MBX:AAA@AAA.COM                                   
.
.
.
ENDMSG:
ORIGINAL:JES                                       
DOCNAME:102006022603158655                                   
TO:XXXX
MBX:CCC@AAA.COM                                   
.
.
.
ENDMSG:
ORIGINAL:JES                                       
DOCNAME:302006022603158655                                   
TO:XXXX
MBX:BBB@AAA.COM                                   
.
.
.
ENDMSG:
ORIGINAL:JES                                       
DOCNAME:202006022603158655                                   
TO:XXXX
MBX:SSS@AAA.COM                                   
.
.
.
ENDMSG:


OUTPUT: LRECL=80

I have to sort based on DOCNAME and MBX.


Quote:
ORIGINAL:JES
DOCNAME:002006022603158655
TO:XXXX
MBX:AAA@AAA.COM
.
.
.
ENDMSG:
ORIGINAL:JES
DOCNAME:002006022603158655
TO:XXXX
MBX:AAA@AAA.COM
.
.
.
ENDMSG:
ORIGINAL:JES
DOCNAME:102006022603158655
TO:XXXX
MBX:CCC@AAA.COM
.
.
.
ENDMSG:
ORIGINAL:JES
DOCNAME:202006022603158655
TO:XXXX
MBX:SSS@AAA.COM
.
.
.
ENDMSG:
ORIGINAL:JES
DOCNAME:302006022603158655
TO:XXXX
MBX:BBB@AAA.COM
.
.
.
ENDMSG:



i tried with the below but it messed up,

Code:
//SYSIN    DD *                                                     
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,8,CH,EQ,C'ORIGINAL'),           
          PUSH=(81:1,80),RECORDS=2),                               
  IFTHEN=(WHEN=GROUP,BEGIN=(1,8,CH,EQ,C'ORIGINAL'),PUSH=(161:ID=8)),
  IFTHEN=(WHEN=GROUP,BEGIN=(1,4,CH,EQ,C'MBX:'),PUSH=(170:05,40))   
  SORT FIELDS=(170,40,CH,A),EQUALS                                 
  OUTFIL IFOUTLEN=80,                                               
  IFTHEN=(WHEN=(1,4,CH,EQ,C'MBX:'),BUILD=(81,80,/,1,80))           
//*     



CORRECT me if i'm wrong.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Apr 18, 2012 4:41 am
Reply with quote

INPUT: LRECL=80

Code:
ORIGINAL:JES                                       
DOCNAME:002006022603158655                                   
TO:XXXX
MBX:AAA@AAA.COM                                   
.
.
.
ENDMSG:


I think I can see what you are trying. You will need to extend a bit.

You'll only have your key when you have fhe MBX, which is the fourth record, with the other part from the second. But you'll need the first and third records as well.

I'm not sure why you chose two GROUPs for ORIGINAL

So,
GROUP for ORIGINAL:, PUSH input record/see later.
GROUP for DOCNAME:. PUSH input record/see later.
GROUP for TO: PUSH input record/see later.

MBX arrives. GROUP, as you have to PUSH the composed key for the following records, so END=(1,7,CH,EQ,C'ENDMSG:').

SORT on the composed key (all in the same place, way out at the end of each record.

Use OUTFIL / (slash operator) in BUILD to output ORIGINAL, DOCNAME, TO and MBX and stripping everything down to size.

Now, the "see later" bit. If, as you did with ORIGINAL, you specify RECORDS=2 on the GROUP you won't get so much pushing going on but you will get the data, you just have to PUSH the entire extended record in each case.

You were going in the right direction. You have Syncsort, I don't, so see how it goes. Let us know, please, with the working code, as it would be a useful example for others.
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Wed Apr 18, 2012 9:24 am
Reply with quote

Hi,

this might assist
Code:
//STEP0100 EXEC PGM=ICETOOL                                   
//TOOLMSG  DD SYSOUT=*                                         
//DFSMSG   DD SYSOUT=*                                         
//IN       DD *                                               
ORIGINAL:JES                                                   
DOCNAME:002006022603158655                                     
TO:XXXX                                                       
MBX:AAA@AAA.COM                                               
.                                                             
.                                                             
.                                                             
ENDMSG:                                                       
ORIGINAL:JES                                                   
DOCNAME:002006022603158655                                     
TO:XXXX                                                       
MBX:AAA@AAA.COM                                               
.                                                             
.                                                             
  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .
.                                               
ENDMSG:                                         
ORIGINAL:JES                                     
DOCNAME:102006022603158655                       
TO:XXXX                                         
MBX:CCC@AAA.COM                                 
.                                               
.                                               
.                                               
ENDMSG:                                         
ORIGINAL:JES                                     
DOCNAME:302006022603158655                       
TO:XXXX                                         
MBX:BBB@AAA.COM                                 
.                                               
.                                               
.                                               
ENDMSG:                                         
ORIGINAL:JES                                     
DOCNAME:202006022603158655                                         
TO:XXXX                                                             
MBX:SSS@AAA.COM                                                     
.                                                                   
.                                                                   
.                                                                   
ENDMSG:                                                             
//DOCNAME  DD DSN=&&DOCNAME,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)     
//MBX      DD DSN=&&MBX,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)         
//RESULT   DD SYSOUT=*                                             
//TOOLIN   DD *                                                     
  SORT FROM(IN)      TO(DOCNAME)  USING(CTL1)                       
  SORT FROM(DOCNAME) TO(MBX)      USING(CTL2)                       
  SORT FROM(MBX)     TO(RESULT)   USING(CTL3)                       
//CTL1CNTL DD *                                                     
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),               
        IFTHEN=(WHEN=GROUP,                                         
                BEGIN=(1,5,CH,EQ,C'ORIGI'),                         
                  END=(1,6,CH,EQ,C'ENDMSG'),                       
                 PUSH=(89:ID=8)),                             
        IFTHEN=(WHEN=(1,7,CH,EQ,C'DOCNAME'),                 
                OVERLAY=(97:X'00'))                           
  SORT FIELDS=(89,9,BI,A)                                     
  OUTREC IFTHEN=(WHEN=GROUP,                                 
                BEGIN=(97,1,CH,EQ,X'00'),                     
                PUSH=(98:09,18))                             
//*                                                           
//CTL2CNTL DD *                                               
  INREC IFTHEN=(WHEN=(1,4,CH,EQ,C'MBX:'),                     
               OVERLAY=(116:X'00'))                           
  SORT FIELDS=(89,8,BI,A,116,1,BI,A)                         
  OUTREC IFTHEN=(WHEN=GROUP,                                 
                BEGIN=(116,1,CH,EQ,X'00'),                   
                 PUSH=(117:05,28))                           
//*                                                           
//CTL3CNTL DD *                                               
  SORT FIELDS=(098,18,BI,A,117,22,BI,A,89,8,BI,A,81,8,BI,A)   
  OUTREC BUILD=(1,80)                                         
/*


Gerry
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Apr 18, 2012 4:08 pm
Reply with quote

This is with DFSORT. No guarantees if you try it on something else, but try.

"To be fair" this thread is probably the one Dave was thinking of yesterday.

I've "simplified" from how I described in the sense that this should be easier to follow. Since all records must be extended, there's probably minimal savings if any by re-arranging the GROUPs as previously mentioned and without using SYMNAMES this is clearer, and more readily adaptable for additional purposes.

Each of the four records from the start until the second element of the key get their own "pushed" record extension. The sort is then on the location of the full key in the two different portions. EQUALS is necessary for your data to be sorted correctly, as you have multiple records with the same key and you want them to stay in the original order.

The four entire records are carried (on all records) to be able to recreate them in their correct place afterwards. The three later groups are forced to end within the bounds of the ORIGINAL group.

The "original" of the records which were pushed have to be removed later, as they are incomplete, so the OMIT on the OUTFIL. The MBX: is identified to write out the pushed records, using the "/" slash operator, and finally itself after the others in original order.

The subsequent are cut down to a size of 80 by the IFOUTLEN.

Code:
//SMULTREC EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
   INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,9,CH,EQ,C'ORIGINAL:'),
                              PUSH=(081:1,80)),
         IFTHEN=(WHEN=GROUP,BEGIN=(1,8,CH,EQ,C'DOCNAME:'),
                             END=(1,9,CH,EQ,C'ORIGINAL:'),
                              PUSH=(161:1,80)), \
         IFTHEN=(WHEN=GROUP,BEGIN=(1,3,CH,EQ,C'TO:'),
                             END=(1,9,CH,EQ,C'ORIGINAL:'),
                              PUSH=(241:1,80)),
         IFTHEN=(WHEN=GROUP,BEGIN=(1,4,CH,EQ,C'MBX:'),
                             END=(1,9,CH,EQ,C'ORIGINAL:'),
                              PUSH=(321:1,80))
                                                           
   SORT FIELDS=(169,6,CH,A,325,76,CH,A),EQUALS
                                                           
   OUTFIL OMIT=(1,9,CH,EQ,C'ORIGINAL:',
             OR,1,8,CH,EQ,C'DOCNAME:',
             OR,1,3,CH,EQ,C'TO:'),
          IFOUTLEN=80,
          IFTHEN=(WHEN=(1,4,CH,EQ,C'MBX:'),
            BUILD=(081,80,/,
                   161,80,/,
                   241,80,/,
                   001,80))
//SORTIN DD *


It needs thorough testing, I have only done so "lightly".

I have run with your input, and it produces this:

Code:

ORIGINAL:JES                                                           
DOCNAME:002006022603158655                                             
TO:XXXX                                                                 
MBX:AAA@AAA.COM                                                         
.                                                                       
.                                                                       
.                                                                       
ENDMSG:                                                                 
ORIGINAL:JES                                                           
DOCNAME:002006022603158655                                             
TO:XXXX                                                                 
MBX:AAA@AAA.COM                                                         
.                                                                       
.                                                                       
.                                                                       
ENDMSG:                                                                 
ORIGINAL:JES                                                           
DOCNAME:102006022603158655                                             
TO:XXXX                                                                 
MBX:CCC@AAA.COM                                                         
.                                                                       
.                                                                       
.                                                                       
ENDMSG:                                                                 
ORIGINAL:JES                                                           
DOCNAME:202006022603158655                                             
TO:XXXX                                                                 
MBX:SSS@AAA.COM                                                         
.                                                                       
.                                                                       
.                                                                       
ENDMSG:                                                                 
ORIGINAL:JES                                                           
DOCNAME:302006022603158655                                             
TO:XXXX                                                                 
MBX:BBB@AAA.COM                                                         
.                                                                       
.                                                                       
.                                                                       
ENDMSG:         
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 -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top