Page 1 of 1

Compare two files and get RC=4.

Posted: Wed Aug 31, 2016 11:31 am
by SarkarMain
Hi,

I have two files with LRECL=80 and both are fixed block (FB). There are only one record in both the file of lenght 8. For example it can be like:


First file record:

Code: Select all

12345678 
Second file:

Code: Select all

12345677


Now I need to compare these two files and if the vlaue in first file is greater than the value in file 2 then my job should return a RC=4. Is it possiblie in SORT? Can someone pleease help.

Re: Compare two files and get RC=4.

Posted: Wed Aug 31, 2016 7:36 pm
by Robert Sample
Have you looked at the DFSORT documentation to see under what conditions you can get a 4 return code? Do any of those conditions match your need?

Re: Compare two files and get RC=4.

Posted: Sun Sep 04, 2016 9:09 pm
by Magesh_j
SarkarMain

Here is code for you.

Code: Select all

//S1 EXEC PGM=SORT                          
//SYSOUT DD SYSOUT=*                        
//SORTIN DD DSN=UR FILE1                    
//       DD DSN=UR FILE2                    
//SORTOUT DD SYSOUT=*                       
//SYSIN DD *                                
  INREC IFTHEN=(WHEN=GROUP,                 
                RECORDS=2,                  
                PUSH=(81:1,08,SEQ=1))       
                                            
  OPTION COPY,STOPAFT=2                     
                                            
  OUTFIL INCLUDE(89,1,CH,EQ,C'2',AND,       
                 1,8,CH,GE,81,8,CH),        
         NULLOFL=RC4,BUILD=(1,80)                        
Thanks
Magesh

Re: Compare two files and get RC=4.

Posted: Sun Sep 04, 2016 10:55 pm
by mahigill
You can also do this it like this:

Code: Select all

//S1 EXEC PGM=ICETOOL 
//TOOLMSG DD SYSOUT=* 
//DFSMSG DD SYSOUT=* 
//CON DD DSN=...  input file1 
//    DD DSN=...  input file2 
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(TRK,(1,1)),DISP=(,PASS) 
//TOOLIN DD * 
SORT FROM(CON) USING(CTL1) 
COUNT FROM(T1) NOTEMPTY RC4 
/* 
//CTL1CNTL DD * 
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(9:C'A',10:SEQNUM,1,ZD)), 
        IFTHEN=(WHEN=(10,1,CH,EQ,C'2'), 
          OVERLAY=(1:1,8,ZD,MUL,-1,TO=ZD,LENGTH=8)) 
  SORT FIELDS=(9,1,CH,A) 
  OPTION EQUALS 
  SUM FIELDS=(1,10,ZD) 
  OUTFIL FNAMES=T1,INCLUDE=(1,10,ZD,GT,+0) 
/* 

Re: Compare two files and get RC=4.

Posted: Mon Sep 05, 2016 2:46 am
by Magesh_j
Mahigill,

using sort fields unnecessarily is waste of cpu resource.
Even u can use joinkeys to achive this, sill requires three pass.

In other words there are many ways to achieve.

Your goal should be providing optimal solution if possible, rather than a solution

Re: Compare two files and get RC=4.

Posted: Mon Sep 05, 2016 3:42 am
by Robert Sample
Magesh_J, mahigill: have either of you confirmed that your "solution" generates a return code of 4 if AND ONLY IF the record in the first file is greater than the record in the second file? If not, then at best you have generated a partial solution and at worst you have created an incorrect solution for the entire problem statement.

Re: Compare two files and get RC=4.

Posted: Mon Sep 05, 2016 6:51 am
by Magesh_j
Robert
Robert Sample wrote: Magesh_J, mahigill: have either of you confirmed that your "solution" generates a return code of 4 if AND ONLY IF the record in the first file is greater than the record in the second file? If not, then at best you have generated a partial solution and at worst you have created an incorrect solution for the entire problem statement.
yeah, I can confirm my code will set the return code 04 when file1 is greater than file2, Please advise which part of my code makes you think in the other way.

Regards,
Magesh

Re: Compare two files and get RC=4.

Posted: Mon Sep 05, 2016 9:17 am
by mahigill
Magesh_j wrote: Mahigill,

using sort fields unnecessarily is waste of cpu resource.
Even u can use joinkeys to achive this, sill requires three pass.

In other words there are many ways to achieve.

Your goal should be providing optimal solution if possible, rather than a solution
It might not be optimal but I thought what happens when file01<file02 and used that code. It should generate RC=0 in that case.

Re: Compare two files and get RC=4.

Posted: Mon Sep 05, 2016 9:26 am
by Magesh_j
mahigill,

I think still my solution works when file01<file02.

What made you think in other way.

Regards,
Magesh

Re: Compare two files and get RC=4.

Posted: Mon Sep 05, 2016 9:06 pm
by mahigill
Magesh_j wrote: mahigill,

I think still my solution works when file01<file02.

What made you think in other way.

Regards,
Magesh
It'll work, no question on that but what will be the return code? That's what I was saying. Topic author might be intrested in that.

Re: Compare two files and get RC=4.

Posted: Mon Sep 05, 2016 9:59 pm
by Magesh_j
Yes, return code would be zero when file1< file2
And file1=file2.

It will set return code 4 when file1>file2.

Thanks
Magesh

Re: Compare two files and get RC=4.

Posted: Tue Sep 06, 2016 12:44 am
by Robert Sample
On review, I missed the RC4 in your code. If you post code -- right or wrong -- expect it to be reviewed by people on this forum, for its correctness.