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

How to compare 2 fields of 2 PS files in a PLI program


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Kunal Surpurkar

New User


Joined: 15 Nov 2012
Posts: 47
Location: India

PostPosted: Mon Jan 13, 2014 4:34 pm
Reply with quote

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
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Mon Jan 13, 2014 5:54 pm
Reply with quote

How are the fields declared?
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


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

PostPosted: Mon Jan 13, 2014 6:57 pm
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Mon Jan 13, 2014 8:26 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jan 13, 2014 11:11 pm
Reply with quote

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
View user's profile Send private message
Kunal Surpurkar

New User


Joined: 15 Nov 2012
Posts: 47
Location: India

PostPosted: Tue Jan 14, 2014 12:27 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jan 14, 2014 12:53 am
Reply with quote

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
View user's profile Send private message
Kunal Surpurkar

New User


Joined: 15 Nov 2012
Posts: 47
Location: India

PostPosted: Tue Jan 14, 2014 5:03 pm
Reply with quote

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
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Tue Jan 14, 2014 5:29 pm
Reply with quote

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
View user's profile Send private message
Nic Clouston

Global Moderator


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

PostPosted: Tue Jan 14, 2014 7:02 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Jan 14, 2014 7:39 pm
Reply with quote

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
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Wed Jan 15, 2014 8:10 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jan 15, 2014 8:21 am
Reply with quote

Hello,

If any program is to be used, the files need to be presorted . . .
Back to top
View user's profile Send private message
Kunal Surpurkar

New User


Joined: 15 Nov 2012
Posts: 47
Location: India

PostPosted: Mon Jan 27, 2014 10:29 pm
Reply with quote

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 icon_smile.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jan 27, 2014 10:35 pm
Reply with quote

Good to hear it is working - thank you for letting us know icon_smile.gif

d
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 -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Using API Gateway from CICS program CICS 0
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Merge two VSAM KSDS files into third ... JCL & VSAM 6
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
Search our Forums:

Back to Top