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

To get first record in case the file has duplicates


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

New User


Joined: 29 Oct 2010
Posts: 10
Location: Chennai

PostPosted: Fri Jan 20, 2012 11:59 am
Reply with quote

Hi all,

I have a flat file which can have 2 records with same key. My requirement is to fetch first occurrence among the duplicates from the flat file using DFSORT. Can you guys help me.

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

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Fri Jan 20, 2012 12:03 pm
Reply with quote

ibmmainframes.com/post-98317.html
Back to top
View user's profile Send private message
krishna_ragav

New User


Joined: 29 Oct 2010
Posts: 10
Location: Chennai

PostPosted: Fri Jan 20, 2012 1:01 pm
Reply with quote

I just want to expand the situation. The flat file created contains the records from two input flat files. I have merged these two input files by using DFSORT - MERGE=COPY command.

Now the requirement is changed. I want the records from these two input flat files to be sort/merged and loaded into one VSAM file having key from 1-43 location. In case the two flat files have record with same key, the record from first file has to be loaded into VSAM file directly. We dont want any intermediate workfile.

Thanks,
Krishna
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Jan 20, 2012 3:17 pm
Reply with quote

nobody prevents You from using as output dataset the VSAM itself
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Fri Jan 20, 2012 3:29 pm
Reply with quote

Quote:
In case the two flat files have record with same key, the record from first file has to be loaded into VSAM file directly.

If both the files have the same LRECL and DSORG then make a concatenated DD statement in SORTIN and use the technique on ibmmainframes.com/post-98317.html

If this is not the solution you are looking for, then it would be better if you give us more information, like show the input/output records. LRECL,DSORG of the i/p files.
Back to top
View user's profile Send private message
krishna_ragav

New User


Joined: 29 Oct 2010
Posts: 10
Location: Chennai

PostPosted: Fri Jan 20, 2012 4:13 pm
Reply with quote

Hi All,

I have tried using JOINKEYS but i do not know how can we use both F1 and F2 Full LRECL Length in REFORMAT. Because

1) I need complete record from F1 if there any key present in both F1 and F2
2) I need complete record F1 if its un-paired record ( i.e. Its available only in F1)
3) I need complete record F2 if its un-paired record ( i.e. Its available only in F2)

We have done using ICETOOL but people wants either DFSORT - SORT Utility( Not with ICETOOL) / Join Keys.

Code:

//PS010   EXEC PGM=ICEMAN                                               
//SYSOUT    DD SYSOUT=*                                                 
//SYSPRINT  DD SYSOUT=*                                                 
//SYSUDUMP  DD SYSOUT=*                                                 
//SORTJNF1  DD DSN=XXXXX.CASVSMOT,DISP=SHR                             
//SORTJNF2  DD DSN=XXXXX.CASMONTH,DISP=SHR                             
//SORTOUT   DD DSN=XXXXX.CASMONTH.TST1,  CAS MONTHLY VSAM               
//             DISP=(NEW,CATLG,DELETE),                                 
//             UNIT=SYSDA,SPACE=(CYL,(10,10),RLSE),                     
//             DCB=(SYS3.DSCB,                                         
//             RECFM=VB,LRECL=254,DSORG=PS,BLKSIZE=0)                   
//*                                                                     
//SYSIN     DD *                                                       
  JOINKEYS FILE=F1,FIELDS=(1,43,A)                                     
  JOINKEYS FILE=F2,FIELDS=(1,43,A)                                     
  JOIN UNPAIRED,F1     
  REFORMAT FIELDS=(F1:1,250)                                               
  SORT FIELDS=COPY                                                     
//*                   
Back to top
View user's profile Send private message
bodatrinadh

Active User


Joined: 05 Jan 2007
Posts: 101
Location: chennai (India)

PostPosted: Fri Jan 20, 2012 5:15 pm
Reply with quote

Krishna,

Try this..

1) complete record from F1 if there any key present in both F1 and F2
Code:
 
//SYSIN     DD *                                                       
  JOINKEYS FILE=F1,FIELDS=(1,43,A)                                     
  JOINKEYS FILE=F2,FIELDS=(1,43,A)                                           
  REFORMAT FIELDS=(F1:1,250)                                               
  SORT FIELDS=COPY                                                     
//*               

2) complete record F1 if its un-paired record ( i.e. Its available only in F1)
Code:
 
//SYSIN     DD *                                                       
  JOINKEYS FILE=F1,FIELDS=(1,43,A)                                     
  JOINKEYS FILE=F2,FIELDS=(1,43,A)                                     
  JOIN UNPAIRED,F1,ONLY                                                     
  SORT FIELDS=COPY                                                     
//*     

3) complete record F2 if its un-paired record ( i.e. Its available only in F2)
Code:

//SYSIN     DD *                                                       
  JOINKEYS FILE=F1,FIELDS=(1,43,A)                                     
  JOINKEYS FILE=F2,FIELDS=(1,43,A)                                     
  JOIN UNPAIRED,F2,ONLY                                                 
  SORT FIELDS=COPY                                                     
//*   



Thanks
-3nadh
Back to top
View user's profile Send private message
krishna_ragav

New User


Joined: 29 Oct 2010
Posts: 10
Location: Chennai

PostPosted: Fri Jan 20, 2012 5:28 pm
Reply with quote

Thank You. I do not wants to increase no of steps

I am also trying other possibilities

Code:
//JS010 EXEC PGM=SORT                                                   
//SORTIN01 DD DSN=XXXX.CASVSMOT.EDIT,DISP=SHR                 
//SORTIN02 DD DSN=XXXX.COMJW.CASMONTH.EDIT,DISP=SHR           
//SORTOUT DD DSN=XXXX.SEQ.CASMONTH,                           
//             DISP=(NEW,CATLG,DELETE),                                 
//             UNIT=PERMDA,SPACE=(CYL,(100,50),RLSE),                   
//             DCB=(SYS3.DSCB,                                         
//             RECFM=VB,LRECL=254,DSORG=PS,BLKSIZE=0)                   
//SYSOUT DD SYSOUT=*                                                   
//SYSPRINT DD SYSOUT=*                                                 
//SYSIN DD *                                                           
   MERGE FIELDS=(1,43,CH,A)                                             
   SUM FIELDS=NONE                                                     
/*                     


It takes the record from second file and writes into output file If the key present in both the file. But I need to write from 1st file if key is available in both the files. Can you please help me.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Jan 20, 2012 5:33 pm
Reply with quote

the link posted had already given You the reply ...

Code:
//SORTIN    DD <first dataset>
//          DD <second dataset>
//SORTOUT   DD <output dataset> could be the VSAM                       
//SYSIN     DD *                                                       
  OPTION EQUALS                                                       
  SORT   FIELDS=(<position>,<length>,<type>,<order>)                                             
  SUM    FIELDS=NONE                                                   


the option equals makes sure that the sorted records with the same key are in the original order
( file1 records before file2 records )
Back to top
View user's profile Send private message
krishna_ragav

New User


Joined: 29 Oct 2010
Posts: 10
Location: Chennai

PostPosted: Fri Jan 20, 2012 5:57 pm
Reply with quote

Thank You All,

I have tried with option EQUALS and It worked.
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 and retrive records f... DFSORT/ICETOOL 3
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