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

Filter records from a file


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

New User


Joined: 25 Jan 2007
Posts: 42
Location: france

PostPosted: Wed Mar 02, 2022 9:16 pm
Reply with quote

Hello,

I have as input the sequential file containing the following data:

//IN DD *
BBBBBBBB C 20220301 MADRID
AAAAAAAA A 20220302 PARIS
AAAAAAAA B 20220302 LONDRES
AAAAAAAA D 20220101 DUBLIN
AAAAAAAA E 20220101 ROME
CCCCCCCC F 19000301 STOCKOLM
AAAAAAAA G 20201225 COPENHAGUE
CCCCCCCC F 19010301 ATHENES
/*

In 1(8) An ID
In 9(3) It doesn't matter
In 12(8) A date
In 20(20) City

Whatever what I except : All ID of the most recent date

//OUT DD *
AAAAAAAA A 20220302 PARIS
AAAAAAAA B 20220302 LONDRES
BBBBBBBB C 20220301 MADRID
CCCCCCCC F 19010301 ATHENES
/*

Thank's by advance for your help.
best regards
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Wed Mar 02, 2022 9:29 pm
Reply with quote

0. Use the Code button to highlight your samples.

1. RTFM on SORT facilities.

2. Try to run SORT examples from the manuals

3. Try to apply the knowledge from 1-2 to your issue.

4. If something remains unclear, then present your code at the forum (do not forget about #0), including all input, output, the code itself, and error log.
Back to top
View user's profile Send private message
tuxama

New User


Joined: 25 Jan 2007
Posts: 42
Location: france

PostPosted: Thu Mar 03, 2022 11:53 am
Reply with quote

Hello,

Hello,

I have as input the sequential file containing the following data:

Code:
//IN DD *
BBBBBBBB C 20220301 MADRID
AAAAAAAA A 20220302 PARIS
AAAAAAAA B 20220302 LONDRES
AAAAAAAA D 20220101 DUBLIN
AAAAAAAA E 20220101 ROME
CCCCCCCC F 19000301 STOCKOLM
AAAAAAAA G 20201225 COPENHAGUE
CCCCCCCC F 19010301 ATHENES
/*


In 1(8) An ID
In 9(3) It doesn't matter
In 12(8) A date
In 20(20) City

Whatever what I except : All ID of the most recent date

Code:
//OUT DD *
AAAAAAAA A 20220302 PARIS
AAAAAAAA B 20220302 LONDRES
BBBBBBBB C 20220301 MADRID
CCCCCCCC F 19010301 ATHENES
/*


Here my code

Code:
//TOOLIN   DD *                                                   
  SORT FROM(IN)   TO(TMP1) USING(CTL1)                             
  SORT FROM(TMP1) TO(TMP2) USING(CTL2)                             
  COPY JKFROM USING(CTL3)                                         
/*                                                                 
//CTL1CNTL DD *                                                   
  SORT FIELDS=(1,8,CH,A,12,8,CH,D)                                 
/*                                                                 
//CTL2CNTL DD *                                                   
  SORT FIELDS=(1,8,CH,A),EQUALS                                   
  SUM FIELDS=NONE                                                 
/*                                                                 
//CTL3CNTL DD *                                                   
  JOINKEYS F1=TMP1,FIELDS=(1,8,A,12,8,D)                           
  JOINKEYS F2=TMP2,FIELDS=(1,8,A,12,8,D)                           
  JOIN UNPAIRED,F1,F2                                             
  REFORMAT FIELDS=(F1:1,40,F2:1,40,?)                             
  OPTION COPY                                                     
                                                                   
  OUTFIL FNAMES=TMP3,INCLUDE=(81,1,CH,EQ,C'B'),BUILD=(1,40)  MATCH
  OUTFIL FNAMES=TMP4,INCLUDE=(81,1,CH,EQ,C'1'),BUILD=(1,40)  F1ONLY
  OUTFIL FNAMES=TMP5,INCLUDE=(81,1,CH,EQ,C'2'),BUILD=(40,40) F2ONLY
/*



Sorry for the first post icon_sad.gif
I
I just want to know if anyone has a different solution ; perhaps more elegant, more efficient or simpler ?


Thank's by advance for your help.
best regards
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Thu Mar 03, 2022 7:13 pm
Reply with quote

Can be done in one single pass:

Code:
//SORTING EXEC PGM=SORT
. . . . .
//DEBUG    DD  SYSOUT=*
//SORTOUT  DD  SYSOUT=*
//SORTIN DD *
BBBBBBBB C 20220301 MADRID
BBBBBBBB D 20220301 CHICAGO
AAAAAAAA A 20220302 PARIS
AAAAAAAA B 20220302 LONDRES
AAAAAAAA D 20220101 DUBLIN
AAAAAAAA E 20220101 ROME
CCCCCCCC F 19000301 STOCKOLM
AAAAAAAA G 20201225 COPENHAGUE
CCCCCCCC F 19010301 ATHENES
//*-+----1----+----2----+----3----+----4----+----5
//*
//SYSIN DD *                                                   
 SORT FIELDS=(1,8,CH,A,
             12,8,CH,D,         the latest date to come first
             10,1,CH,A,
             21,20,CH,A)
 OUTREC IFTHEN=(WHEN=GROUP,
                KEYBEGIN=(1,8),
                PUSH=(81:1,8,     keep same ID
                      91:12,8))   keep same date                                                                         
  OUTFIL FNAMES=DEBUG    - just to verify intermediate table
  OUTFIL FNAMES=SORTOUT,
         INCLUDE=(1,8,CH,EQ,81,8,CH,
             AND,12,8,CH,EQ,91,8,CH),
         BUILD=(1,80)       truncate to original record size
//*
Back to top
View user's profile Send private message
tuxama

New User


Joined: 25 Jan 2007
Posts: 42
Location: france

PostPosted: Thu Mar 03, 2022 10:47 pm
Reply with quote

Hello sergeyken,

Thank you very much for your answer. This solution is much simpler and very interesting.
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 2 files(F1 & F2) and writ... JCL & VSAM 5
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top