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

Eliminate records based on flag priority


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

New User


Joined: 05 Oct 2006
Posts: 2

PostPosted: Tue May 19, 2009 8:29 pm
Reply with quote

Hi,
Good Morning,

I request help in achieving the below requirement:

Input file:
Code:

CASEID   FLAG       NAME
(Char4)  (Char1)   (Char5)

ABCD      'C'      <blank> 
ABCD      'S'      <blank>
ABCD      'S'      <blank>   
ABCD      ' '       NAME1
ABCD      ' '       NAME2
EFGH      'C'      <blank>
EFGH      'C'      <blank>
EFGH      'S'      <blank>
EFGH      'S'      <blank>
EFGH      'S'      <blank>
IJKL      'C'      <blank>
IJKL      ' '       NAME3
IJKL      ' '       NAME4
IJKL      ' '       NAME5
MNOP      'S'      <blank> 
MNOP      'S'      <blank> 
MNOP      ' '       NAME6
QRST      'C'      <blank>
QRST      'C'      <blank>
UVWX      'S'      <blank>
UVWX      'S'      <blank>
UVWX      'S'      <blank>
YZYZ      ' '       NAME7
YZYZ      ' '       NAME8



Now, based on the flag, it should eliminate records belonging to a CaseID
with priority in order of ' ' (space) > 'S' > 'C'
i.e. say if two records with 'S' and ' ' are present for a CASEID, the output
should contain all the record(s) with ' ' flag
or say if 'C' and 'S' flag types of records are present for a CASEID, the output should contain all the record(s) with 'S' flag

The expected output for above example file is given below:

Code:

CASEID   FLAG       NAME
(Char4)  (Char1)   (Char5)
ABCD      ' '       NAME1
ABCD      ' '       NAME2
EFGH      'S'      <blank>
EFGH      'S'      <blank>
EFGH      'S'      <blank>
IJKL      ' '       NAME3
IJKL      ' '       NAME4
IJKL      ' '       NAME5
MNOP      ' '       NAME6
QRST      'C'      <blank>
QRST      'C'      <blank>
UVWX      'S'      <blank>
UVWX      'S'      <blank>
UVWX      'S'      <blank>
YZYZ      ' '       NAME7
YZYZ      ' '       NAME8



Could you please suggest a solution. COBOL solution doesn't look feasible to me, so ICETOOL is the only option I can think of.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue May 19, 2009 9:04 pm
Reply with quote

You can use a DFSORT job like the following to do what you asked for. I assumed your input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes.

Code:

//S1   EXEC  PGM=ICETOOL
//TOOLMSG   DD  SYSOUT=*
//DFSMSG    DD  SYSOUT=*
//IN DD *
ABCDC
ABCDS
ABCDS
ABCD NAME1
ABCD NAME2
EFGHC
EFGHC
EFGHS
EFGHS
EFGHS
IJKLC
IJKL NAME3
IJKL NAME4
IJKL NAME5
MNOPS
MNOPS
MNOP NAME6
QRSTC
QRSTC
UVWXS
UVWXS
UVWXS
YZYZ NAME7
YZYZ NAME8
/*
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(MOD,PASS)
//OUT DD SYSOUT=*
//TOOLIN DD *
SORT FROM(IN) USING(CTL1)
COPY FROM(IN) TO(T1) USING(CTL2)
SPLICE FROM(T1) TO(OUT) ON(1,4,CH) ON(5,1,CH) WITHALL -
  WITH(1,81) USING(CTL3)
/*
//CTL1CNTL DD *
  INREC OVERLAY=(81:5,1,
     CHANGE=(1,C' ',C'1',C'S',C'2'),NOMATCH=(C'3'))
  OPTION EQUALS
  SORT FIELDS=(1,4,CH,A,81,1,CH,A)
  OUTREC OVERLAY=(81:C'BB',83:SEQNUM,8,ZD,RESTART=(1,4))
  OUTFIL FNAMES=T1,INCLUDE=(83,8,ZD,EQ,1),BUILD=(1,82)
/*
//CTL2CNTL DD *
  INREC OVERLAY=(81:C'VV')
/*
//CTL3CNTL DD *
  OUTFIL FNAMES=OUT,INCLUDE=(81,2,CH,EQ,C'VB'),
    BUILD=(1,80)
/*


OUT would have:

Code:

ABCD NAME1       
ABCD NAME2       
EFGHS             
EFGHS             
EFGHS             
IJKL NAME3       
IJKL NAME4       
IJKL NAME5       
MNOP NAME6       
QRSTC             
QRSTC             
UVWXS             
UVWXS             
UVWXS             
YZYZ NAME7       
YZYZ NAME8       
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Tue May 19, 2009 10:17 pm
Reply with quote

yespatel,

The following DFSORT JCL will give you the desired results. I assumed your input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes.

Code:

//STEP0100 EXEC PGM=SOR
//SYSOUT   DD SYSOUT=*
//SORTIN   DD *       
ABCDC                 
ABCDS                 
ABCDS                 
ABCD NAME1             
ABCD NAME2             
EFGHC                 
EFGHC                 
EFGHS                 
EFGHS                 
EFGHS                 
IJKLC                 
IJKL NAME3             
IJKL NAME4             
IJKL NAME5             
MNOPS                 
MNOPS                 
MNOP NAME6             
QRSTC                 
QRSTC                 
UVWXS                 
UVWXS                 
UVWXS                 
YZYZ NAME7             
YZYZ NAME8             
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *                                                       
  INREC IFTHEN=(WHEN=(5,1,CH,EQ,C' '),OVERLAY=(81:C'1')),             
        IFTHEN=(WHEN=(5,1,CH,EQ,C'S'),OVERLAY=(81:C'2')),             
        IFTHEN=(WHEN=(5,1,CH,EQ,C'C'),OVERLAY=(81:C'3'))               
                                                                       
  SORT FIELDS=(1,4,CH,A,81,1,CH,A),EQUALS                             
                                                                       
  OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(82:5,1,SEQNUM,8,ZD,RESTART=(1,4))),
  IFTHEN=(WHEN=GROUP,BEGIN=(83,8,ZD,EQ,1),PUSH=(81:81,1))             
                                                                       
  OUTFIL INCLUDE=(81,2,SS,EQ,C'1 ,2S,3C'),BUILD=(1,80)                 
/*                                                                     
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue May 19, 2009 10:40 pm
Reply with quote

Kolusu,

Clever solution! icon_cool.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue May 19, 2009 11:40 pm
Reply with quote

Hello,

Quote:
COBOL solution doesn't look feasible to me,
FWIW, the cobol solution is rather trivial - basically the same as Skolusu posted. . .

Create a new sort key for the " ", C, and S (i.e. 1, 2, 3) and internally sort the file by case and the new key, then only write the records that contain the highest "priority" for that case to the output file.
Back to top
View user's profile Send private message
yespatel

New User


Joined: 05 Oct 2006
Posts: 2

PostPosted: Wed May 20, 2009 10:31 am
Reply with quote

Hi all,

Genius stuffs,

Thank you very much for your help, Frank, Kolusu, Dick..

All solutions equally brillient, can use any of them

Cheers,

yespatel
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 Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Join multiple records using splice DFSORT/ICETOOL 5
No new posts EZT program to build a flat file with... All Other Mainframe Topics 9
No new posts JCL sortcard to print only the records DFSORT/ICETOOL 11
Search our Forums:

Back to Top