Sort to retrieve records in between!



Support for NetApp SyncSort for z/OS, Visual SyncSort, SYNCINIT, SYNCLIST and SYNCTOOL

Sort to retrieve records in between!

Postby ibmmf4u » Wed Dec 10, 2014 5:56 pm

Hi,

My requirement goes this way. I am trying to extract the records in between that satisfies some condition from a file. The input file is as follows.

Input File:-
  +++ EXTR MSG - PROGRA1 /- KEY - 000000000000259 20141126 20141204 E
      I                  EXTRACTION COMPLETE                       
      I                                                             
      I                              259 EXTRACTION COMPLETE       
+++                                                                 
  +++ EXTR MSG - PROGRA1 /- KEY - 100000000000063 20141126 20141204 E
      E MESGR1           ERROR EXTRACTING THE KEY RECORD     
      E MESGR1           ERROR EXTRACTING THE KEY RECORD     
      E MESGR1           EXTRACTION COMPLETE                       
      E MESGR1           ERROR EXTRACTING THE KEY RECORD 
      I MESGR1  LOAN ERROR EXTRACTING THE KEY RECORD
      I         LOAN                                         
      I                               63 EXTRACTION COMPLETE         
+++                   
  +++ EXTR MSG - PROGRA1 /- KEY - 000000000000298 20141126 20141204 E
      I                  EXTRACTION COMPLETE                       
      I                                                             
      I                              298 EXTRACTION COMPLETE       
+++                                               
  +++ EXTR MSG - PROGRA1 /- KEY - 200000000000989 20141126 20141204 E
      E MESGR1           ERROR EXTRACTING THE KEY RECORD     
      E MESGR1           ERROR EXTRACTING THE KEY RECORD     
      E MESGR1           EXTRACTION COMPLETE                       
      E MESGR1           ERROR EXTRACTING THE KEY RECORD
      I MESGR1  LOAN ERROR EXTRACTING THE KEY RECORD
      I         LOAN                                         
      I                               989 EXTRACTION COMPLETE         
+++ 


I want to retrieve only the records that has error message's (i.e. the lines with character "E" in 7th position ) along with the line that contains "KEY" information. The output should be as follows.

Output File:-

+++ EXTR MSG - PROGRA1 /- KEY - 100000000000063 20141126 20141204 E
      E MESGR1           ERROR EXTRACTING THE KEY RECORD     
      E MESGR1           ERROR EXTRACTING THE KEY RECORD     
      E MESGR1           EXTRACTION COMPLETE                       
      E MESGR1           ERROR EXTRACTING THE KEY RECORD 

  +++ EXTR MSG - PROGRA1 /- KEY - 200000000000989 20141126 20141204 E
      E MESGR1           ERROR EXTRACTING THE KEY RECORD     
      E MESGR1           ERROR EXTRACTING THE KEY RECORD     
      E MESGR1           EXTRACTION COMPLETE                       
      E MESGR1           ERROR EXTRACTING THE KEY RECORD


I tried using the below sort cards first by assigning the sequence number to it in one file.
INREC IFTHEN=(WHEN=INIT,                   
                OVERLAY=(72:SEQNUM,2,ZD,   
                            RESTART=(1,2)))
SORT FIELDS=COPY                           


And later extracting the records by grouping them with the below sort card but it didn't work.
 INREC IFTHEN=(WHEN=GROUP,                                 
    BEGIN=((3,8,CH,EQ,C'+++ EXTR'),AND,(72,2,CH,EQ,C'01')),
    END=((7,1,CH,EQ,C'E'),AND,((72,2,CH,EQ,C'02'),OR,     
                               (72,2,CH,EQ,C'03'),OR,     
                               (72,2,CH,EQ,C'04'),OR,     
                               (72,2,CH,EQ,C'05'))),       
          PUSH=(191:ID=1))                                 
 SORT FIELDS=COPY                                         
 OUTFIL INCLUDE=(191,1,CH,NE,C' '),BUILD=(1,70,200:X)     


Can someone kindly help me out?

Thanks in advance!
ibmmf4u
 
Posts: 65
Joined: Wed Dec 14, 2011 10:26 pm
Has thanked: 0 time
Been thanked: 1 time

Re: Sort to retrieve records in between!

 

Re: Sort to retrieve records in between!

Postby BillyBoyo » Wed Dec 10, 2014 7:55 pm

First rule of extracting from report-type output is "get rid of everything you don't need".

So make yourself and INCLUDE COND=( which only gets the KEY lines and the E lines.

Use INREC IFTHEN=(WHEN=GROUP with BEGIN= for the KEY (same test as your INCLUDE COND=) and PUSH the entire line to an extension of each record in the group, then tell it there are two records in the group by coding RECORDS=2.

Then in OUTFIL specify OMIT= for your KEY records (you don't need them any more). Then use IFTHEN=(WHEN=(logical expression to identify that you have non-blank in your extension, and use BUILD with the slash operator (/) to make two records.

Test data:

X HEADING
 Y DATA01
X HEADING
 Z DATA02
 Z DATA03


Untested code:

 OPTION COPY
 INCLUDE COND=(1,1,CH,EQ,C'X',
               2,1,CH,EQ,C'Z')
 INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'X'),
                 PUSH=(10:1,9),RECORDS=2)
 OUTFIL OMIT=(1,1,CH,EQ,C'X'),
         IFTHEN=(WHEN=(10,9,CH,NE,C' '),
                  BUILD=(10,9,
                         /,
                         1,9)),
         IFTHEN=(WHEN=NONE,
                  BUILD=(1,9))


If you run it and don't understand what is happening, run it without the OUTFIL and look at the data the OUTFIL is operating on.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times


Return to Syncsort/Synctool

 


  • Related topics
    Replies
    Views
    Last post