View previous topic :: View next topic
|
Author |
Message |
Bhuvaneswari K
New User
Joined: 15 Sep 2008 Posts: 17 Location: Chennai
|
|
|
|
I need to compare two fields from two different files and write into a third file. The first field should match and the second field should not match. The output file should contain records from file 1 which match the above criteria.
For eg:
Code: |
file 1 has, file 2 has,
100 Merlin 100 Babs
200 Black 200 Black
300 White 300 Yellow
|
the output file should be,
Code: |
100 Merlin
300 White
|
Bhuvana |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
The usual questions ..................
What are the file characteristics for both files. i.e. RECFM & LRECL
What are the locations and lengths of the keys to match between the files. |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Bhuvana,
Can you have the situation where the first field does not match and the second field does match and if so, would you want that record in the output file? For example, could you have something like this:
File1
400 Green
File2
500 Green
If so, what would you want in the output file?
Can file1 have duplicates on either field or both fields within it?
Can file2 have duplicates on either field or both fields within it?
For example:
100 Green
100 Green
100 Blue
200 Blue
If so, please show a more complete example of input records and expected output covering all possible variations. |
|
Back to top |
|
|
Bhuvaneswari K
New User
Joined: 15 Sep 2008 Posts: 17 Location: Chennai
|
|
|
|
The file has just two of these fields. The first field is of length 5 and numeric and the second field is of length 4 alphanumeric.
No duplicates occurs within the files.
Also the first field in file 1 must have a matching record in file 2 and the second field must not be matching. Only such records are needed in the output file. hope am clear in my explanation.
thanks
Bhuvana |
|
Back to top |
|
|
Bhuvaneswari K
New User
Joined: 15 Sep 2008 Posts: 17 Location: Chennai
|
|
|
|
One additional info..the record format is FD and the file length is 80
Bhuvana |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Quote: |
The first field is of length 5 and numeric and the second field is of length 4 alphanumeric |
That doesn't match your example. 100 is not 5 characters and Merlin is not 4 characters. But given your description of your data and assuming your fields really are in 1-5 and 6-9, you can use a DFSORT job like the following to do what you asked for:
Code: |
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN01 DD * input file1
100Merl
200Blac
300Whit
400Gree
/*
//SORTIN02 DD * input file2
100Babs
200Blac
300Yell
500Gree
/*
//SORTOUT DD SYSOUT=* output file
//SYSIN DD *
OPTION EQUALS
MERGE FIELDS=(1,5,CH,A)
OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,1,ZD,RESTART=(1,5))),
IFTHEN=(WHEN=GROUP,BEGIN=(81,1,ZD,EQ,1),PUSH=(82:6,4))
OUTFIL INCLUDE=(81,1,ZD,EQ,2,AND,6,4,CH,NE,82,4,CH),
BUILD=(1,5,6:82,4,80:X)
/*
|
|
|
Back to top |
|
|
Bhuvaneswari K
New User
Joined: 15 Sep 2008 Posts: 17 Location: Chennai
|
|
|
|
This seems fine but please tell me if i can proceed in this way:
File1:
12345 AAAA
56789 BBBB
File2:
12345 CCCC
56789 BBBB
Step1: splicing the two files into a temporary file which will be of this format -
12345 AAAA CCCC
56789 BBBB BBBB
Step2: by comparing the two character values (AAAA CCCC) if they are not equl then writing into the output dataset with the first value ie
12345 AAAA
can you suggest how step 2 can be accomplished?
Regards
Bhuvana |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
What you want to do with SPLICE is similar to what I did with WHEN=GROUP, but you will need more than one pass to do it with SPLICE, whereas you only need one pass to do it with WHEN=GROUP.
Why would you want to use a multipass solution when I gave you a one pass solution? |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Code: |
//SORTIN01 DD * input file2 |
Should n't that be a SORTIN02? |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Yes - copy and paste error. Fixed. Thanks. (Guess I'm trying to do too many things at once.) |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
You're welcome. |
|
Back to top |
|
|
|