View previous topic :: View next topic
|
Author |
Message |
Kunal Surpurkar
New User
Joined: 15 Nov 2012 Posts: 47 Location: India
|
|
|
|
Dear Team,
I have a requirement wherein I need to compare 2 fields of 2 different PS files (inputs) of different structures. And, if the 2 fields are same, then the records from the 2nd input file need to be written to the output file.
The field names that need to be compared are IPAIPRO and CONTMES. These are present in both the files.
first file :
IPAIPRO starts at 1st position and its length is 7
CONTMES starts at 194 position and its length is 4.
Second file :
IPAIPRO starts at 1st position and its length is 7
CONTMES starts at 218 position and its length is 4.
Could anyone tell me the syntax to compare the 2 fields of 2 different PS files??
Thanks a lot in advance. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
How are the fields declared? |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Are you really wanting a PL/1 or assembler routine or have you just been careless and posted here rather than in the appropriate sort forum? Sort can easily do what want using JOINKEYS. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
I don't understand why anyone who has done any programming at all in a given language would ask a question like this on a forum. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Phil,
Possibly because they have not yet been tasked with writing a 2-file match/merge.
There is a cobol sample as a "sticky" (that is easily re-coded in some other language).
These days, he sort products have JOINKEYS which should be considered if the whole process does nothing but the match/merge and write some output.
d |
|
Back to top |
|
|
Kunal Surpurkar
New User
Joined: 15 Nov 2012 Posts: 47 Location: India
|
|
|
|
Dear team,
It would be great if it can be written as a piece of code in PLI.
However, I am not really sure how this is accomplished using SORT as well.
@Akatsukami,
IPAIPRO is CHAR(7) and CONTMES is PIC'(4)9'. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Look at the sticky mentioned earlier and re-code in pl/i.
If you use cobol or pl/i the sort(s) would be done before the match/merge cpode was run. There would be no sorting in the code.
If you use JOINKEYS, you can probably get it all done in one step. |
|
Back to top |
|
|
Kunal Surpurkar
New User
Joined: 15 Nov 2012 Posts: 47 Location: India
|
|
|
|
Hi Dick,
Thanks for the reply.
If I have to use JOINKEYS in sort, May I know the syntax of it and how it can be used in my requirement.
Two files are of length 300 VB...And, IPAIPRO in first file starts at position 7 and CONTMES starts at 194 position.
And in second file, IPAIPRO starts at position 7 and CONTMES starts at 218 position.
Kindly let me know incase you need more information.
Thanks a lot. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
In PL/I, a variable in a structure may have its name qualified so as to be unique (the same is generally true of other languages, although the syntax may vary).
Assuming for the sake of discussion that the two structures holding the records are named rec1 and rec2, these tasks can be carried out by:
Code: |
if (rec1.ipaipro=rec2.ipaipro) then... |
and, of course
Code: |
if (rec1.contmes=rec2.contmes) then... |
|
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
This is your basic 2 file match outline. Memorize it.
Code: |
read a record from each file
do while both files have more data
select
when keys match
do
do matching stuff
read a new record from each file
end
when key of file 1 > key of file 2
do
do key 1 > key 2 stuff
read a new record from file 2
end
when key 1 < key 2
do
do key 1 < key 2 stuff
read a new record from file 1
end
end select
end main loop
if more records in file 1
then do file 1 stuff
if more records in file 2
then do file 2 stuff
end program
|
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
If I have to use JOINKEYS in sort, May I know the syntax of it and how it can be used in my requirement. |
I would not think of this as "have to". Not so long ago, sport products did NOT hasve the JOINKEYS funtionality.
If you look here in the forum, there are Many examples. There are examples in the product documentation.
If you get stuck, post what you tried and explain what happened. Post the JCL and any informational and/or diagnostic information generated. |
|
Back to top |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 154 Location: Kuala Lumpur
|
|
|
|
Nic Clouston wrote: |
This is your basic 2 file match outline. Memorize it.
Code: |
read a record from each file
do while both files have more data
select
when keys match
do
do matching stuff
read a new record from each file
end
when key of file 1 > key of file 2
do
do key 1 > key 2 stuff
read a new record from file 2
end
when key 1 < key 2
do
do key 1 < key 2 stuff
read a new record from file 1
end
end select
end main loop
if more records in file 1
then do file 1 stuff
if more records in file 2
then do file 2 stuff
end program
|
|
If you are going to use this logic, then both files should be sorted based on the Key (Ascending) before this. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If any program is to be used, the files need to be presorted . . . |
|
Back to top |
|
|
Kunal Surpurkar
New User
Joined: 15 Nov 2012 Posts: 47 Location: India
|
|
|
|
Dear Team,
Thanks a lot for your suggestions.
I had tried using the logic in PLI program...but, its taking a lot of time for the program to complete as the files have millions of records.
So, I used JOINKEY concept to find the matching records in the 2 files and it worked.
Thanks a lot once again |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Good to hear it is working - thank you for letting us know
d |
|
Back to top |
|
|
|