Compare two files and get RC=4.

IBM's Sort Product, ICETOOL, ICEMAN and ICEGENER.
Post Reply
SarkarMain
New Member
Posts: 1
Joined: Sun Dec 07, 2014 3:33 pm

Compare two files and get RC=4.

Post 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.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Compare two files and get RC=4.

Post 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?
User avatar
Magesh_j
Registered Member
Posts: 33
Joined: Sun Sep 04, 2016 8:50 pm

Re: Compare two files and get RC=4.

Post 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
mahigill
New Member
Posts: 4
Joined: Sat Sep 19, 2015 1:20 pm

Re: Compare two files and get RC=4.

Post 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) 
/* 
User avatar
Magesh_j
Registered Member
Posts: 33
Joined: Sun Sep 04, 2016 8:50 pm

Re: Compare two files and get RC=4.

Post 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
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Compare two files and get RC=4.

Post 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.
User avatar
Magesh_j
Registered Member
Posts: 33
Joined: Sun Sep 04, 2016 8:50 pm

Re: Compare two files and get RC=4.

Post 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
mahigill
New Member
Posts: 4
Joined: Sat Sep 19, 2015 1:20 pm

Re: Compare two files and get RC=4.

Post 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.
User avatar
Magesh_j
Registered Member
Posts: 33
Joined: Sun Sep 04, 2016 8:50 pm

Re: Compare two files and get RC=4.

Post by Magesh_j »

mahigill,

I think still my solution works when file01<file02.

What made you think in other way.

Regards,
Magesh
mahigill
New Member
Posts: 4
Joined: Sat Sep 19, 2015 1:20 pm

Re: Compare two files and get RC=4.

Post 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.
User avatar
Magesh_j
Registered Member
Posts: 33
Joined: Sun Sep 04, 2016 8:50 pm

Re: Compare two files and get RC=4.

Post 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
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Compare two files and get RC=4.

Post 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.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM DFSort, ICETOOL, ICEMAN, ICEGENER.”