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

DIFFICULT_COMPARING TWO FILES AND EXTRACTING USING SORT


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

New User


Joined: 14 Oct 2012
Posts: 5
Location: India

PostPosted: Tue Oct 16, 2012 10:43 pm
Reply with quote

Hi
I have two files file 1 & file 2. File 1 has fields fd1,fd2 & fd3...fdn. File 2
has fields fd1,fd2,fd3,d4,d5.

Now, i have to compare whether
fd1(of file1) = fd1(file2) &
fd2(of file1) = fd2(file2) &
fd3(of file1) = fd3(file2)

If the above fields are equal, then i need to write the fields d4 & d5 into another file. Could any one of you please help me how to do this with SORT?
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Tue Oct 16, 2012 11:01 pm
Reply with quote

Have you looked at the many topics using joinkeys? Surely one of them could be adapted to your requirement?
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Tue Oct 16, 2012 11:14 pm
Reply with quote

mal_pra007,

You can use JOINKEYS to match the files and write output. Here is a sample JCL assuming your input files are FB.

Code:

//STEP0100 EXEC PGM=SORT   
//SYSOUT   DD SYSOUT=*     
//INA      DD DISP=SHR,DSN=Your Input file1
//INB      DD DISP=SHR,DSN=Your Input file2
//SORTOUT  DD SYSOUT=*                         
//SYSIN    DD *                                 
  OPTION COPY                                   
  JOINKEYS F1=INA,FIELDS=(File1-Field1,Length1,A,
                          File1-Field2,Length2,A,
                          File1-Field3,Length3,A)

  JOINKEYS F2=INB,FIELDS=(File2-Field1,Length1,A,
                          File2-Field2,Length2,A,
                          File2-Field3,Length3,A)


  REFORMAT FIELDS=(F1:File1-Field4,Length4,
                      File1-Field5,Length5)


//*
Back to top
View user's profile Send private message
mal_pra007

New User


Joined: 14 Oct 2012
Posts: 5
Location: India

PostPosted: Tue Oct 16, 2012 11:30 pm
Reply with quote

Hello Skolusu,
Many Thanks for your reply. Let me try this.

Thanks.
Back to top
View user's profile Send private message
mal_pra007

New User


Joined: 14 Oct 2012
Posts: 5
Location: India

PostPosted: Wed Oct 17, 2012 6:15 pm
Reply with quote

Hello,
As per your suggestion, i have tried like below

Code:
//INFILE1  DD  DSN=TEST1,DISP=SHR         
//INFILE2  DD  DSN=TEST2,DISP=SHR       
//OUT1     DD  DSN=TEST3,                     
//             DISP=(NEW,CATLG,DELETE),                         
//             AVGREC=K,SPACE=(250,(90,30),RLSE),               
//             RECFM=FB,LRECL=250                               
//SYSIN    DD  *                                                 
  OPTION COPY                                                   
  JOINKEYS F1=INFILE1,FIELDS=(43,10,A,                           
                              65,8,A,                           
                              94,5,A)                           
  JOINKEYS F2=INFILE2,FIELDS=(48,10,A,                           
                              103,8,A,                           
                              58,5,A)                           
  REFORMAT FIELDS=(F2:73,10,83,10,93,10)                         
  SORT FIELDS=COPY                                               
  OUTFIL FNAMES=OUT1,INCLUDE=(1,168,CH,NE,C' '),                 
         BUILD=(169,10,179,10,189,10,199:52X)                   


JCL is giving me error 'FIELD BEYOND MAXIMUM RECORD LENGTH'

Requirement:
--------------

TEST1 file contains customer number at 43(of length 10),Date at 65(of length 8), part no at 94(of length 5)
TEST1 file contains customer number at 48(of length 10),Date at 103(of length 8), part no at 58(of length 5)

if each of these fields are equal, then i need to extract
Code:
   parameter 1 at 73(of length 10) from file 2,
   parameter 2 at 83(of length 10) from file 2,
   parameter 3 at 93(of length 10) from file 2,


then append the parameters to the output file from position 169, 179, & 189 respectively.

The contents of file1 from 1st position to 168 position should be copied as it is to the output file

Please help

Code'd
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Oct 17, 2012 6:53 pm
Reply with quote

Your REFORMAT record is 30 bytes long.

What do you think INCLUDE=(1,168,anything after that) is going to do?

What are you trying to do with that?

I don't think you understand the REFORMAT. This is the layout of the record produced by the JOINKEYS. Forget any layout which existed for the JOINKEYS, this is what you extract from the matched/unmatched records.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Wed Oct 17, 2012 7:55 pm
Reply with quote

Including fields from File1 was not in your original request - you only specified fd4 and fd5 to be output. What you now seem to want is to take 1,168 from File1 followed by 3 (not 2) fields from F2.

The syntax for REFORMAT you need is:
Code:
REFORMAT FIELDS=(F1:1,168,F2:73,10,83,10,93,10)


Garry.
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Wed Oct 17, 2012 9:51 pm
Reply with quote

mal_pra007 wrote:

The contents of file1 from 1st position to 168 position should be copied as it is to the output file


mal_pra007,

You need to tell us what you want clearly. Your initial post indicated that you wanted to extract just filed4 and Field5. If you want to copy the contents of file1 also you need to change your REFORMAT statement. Garry Carroll has provided you the syntax. Since your extract fields are continuous, you can club them as single field and code as 73,30

Code:

REFORMAT FIELDS=(F1:1,168,F2:73,30)


You need to get rid off the OUTFIL statement. You really don't need that anymore.
Back to top
View user's profile Send private message
mal_pra007

New User


Joined: 14 Oct 2012
Posts: 5
Location: India

PostPosted: Wed Oct 17, 2012 11:31 pm
Reply with quote

Hello Skolusu & Garry,

Thanks for your advise. Sorry for not giving you clear picture in my initial requirement.

As i mentioned earlier, i need to

compare the fields file1.field1, file1.field2, file1.field3 with file2.field1, file2.field2, file2.field3
If the fields are equal, then i need to write from 1 to 168 characters from file 1 & 30 characters from file 2 starting at 73 into a new file file3


JCL used:

//INFILE1 DD DSN=test1,DISP=SHR
//INFILE2 DD DSN=test2,DISP=SHR
//SYSIN DD *
JOINKEYS F1=INFILE1,FIELDS=(43,10,A,
65,8,A,
94,5,A)
JOINKEYS F2=INFILE2,FIELDS=(48,10,A,
103,8,A,
58,5,A)
REFORMAT FIELDS=(F1:1,168,F2:73,10,83,10,93,10)
OPTION COPY
//SORTOUT DD DSN=test3,
// DISP=(NEW,CATLG,DELETE),
// AVGREC=K,SPACE=(250,(90,30),RLSE),
// RECFM=FB,LRECL=250


Please confirm whether the above is correct
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Wed Oct 17, 2012 11:36 pm
Reply with quote

mal_pra007 wrote:

//SORTOUT DD DSN=test3,
// DISP=(NEW,CATLG,DELETE),
// AVGREC=K,SPACE=(250,(90,30),RLSE),
// RECFM=FB,LRECL=250


Please confirm whether the above is correct


mal_pra007,

How about you run the job and tell us what happened, whether you got the right results or not?


You are only creating 168+30 =198 bytes , why do you have LRECL=250 in your JCL? If you want to create a 250 byte file by padding spaces at the end then add the following to your control cards.
Code:

 INREC OVERLAY=(250:X)


Remove the DCB parameters from JCL . SORT will automatically calculate the DCB.
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 2
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
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