View previous topic :: View next topic
|
Author |
Message |
tamminenisidhartha Currently Banned New User
Joined: 31 Oct 2012 Posts: 43 Location: INDIA
|
|
|
|
Hi every one.
I am trying to write a PL/I program which compares two files and writes the equal records into a file and writes the records which are different into another file.. The data is numeric and sorted in the files.
Code: |
READ FILE(INFILE1) INTO (INREC1);
READ FILE(INFILE2) INTO (INREC2);
DO WHILE(E_O_INFILE1 ¬= 1 || E_O_INFILE2 ¬= 1);
IF DATA_I = DATA_O THEN DO;
WRITE FILE(OUTFILE1) FROM (INREC1);
READ FILE(INFILE1) INTO (INREC1);
READ FILE(INFILE2) INTO (INREC2);
END;
ELSE
IF DATA_I < DATA_O THEN DO;
WRITE FILE(OUTFILE2) FROM (INREC1);
READ FILE(INFILE1) INTO (INREC1);
END;
ELSE
IF DATA_I > DATA_O THEN DO;
WRITE FILE(OUTFILE2) FROM (INREC2);
READ FILE(INFILE2) INTO (INREC2);
END;
END; |
This is the logic I am workling on.
But I am not getting the output.
It compiling fine.
But in the RUN JCL,
The return code is 00, EXCP is "71".
Correct me where am I actually going wrong here.
Code'd |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Next time use
tags around your code and supply all declarations. We haven't got a clue about what the E_O_INFILEx's have been declared as, or initialized to. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
In addition, what happens to your keys for end-of-file on either file? What happens if one file is empty? |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
Quote: |
Code: |
DO WHILE(E_O_INFILE1 ¬= 1 || E_O_INFILE2 ¬= 1);
|
|
....exactly what is it you hope to achieve by concatenating E_O_INFILE1 with E_O_INFILE2 ???
Garry. |
|
Back to top |
|
|
tamminenisidhartha Currently Banned New User
Joined: 31 Oct 2012 Posts: 43 Location: INDIA
|
|
|
|
@Bill Woodger
I have declared them above in my program.
This will execute only if either of the file is not empty.
The error is that the output file-1 is writing the correct data, which satisfies the condition but the output file-2 which should write the non-similar records, is going into the infinite loop.
The non similar records are being written in a large numbers.
@Garry Carroll
I corrected the concatenation symbol. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Left column is file 1, right column is file 2.
Show how the comparison of your keys operates for this.
Hint: when one file reaches end-of-file you set the comparison key (for me, not in the record area) "high". I don't know, but suspect not, if PL/I has any "magic" doing this for you.
There is a "two file match" sticky in the Cobol forum here. Look at the logic there. |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
tamminenisidhartha wrote: |
@Bill Woodger
I have declared them above in my program.
This will execute only if either of the file is not empty.
The error is that the output file-1 is writing the correct data, which satisfies the condition but the output file-2 which should write the non-similar records, is going into the infinite loop.
The non similar records are being written in a large numbers.
@Garry Carroll
I corrected the concatenation symbol. |
First, what have you declared E_O_INFILE1 and E_O_INFILE2 as ? BIN FIXED or DEC FIXED ?
You seem to have changed from getting cond code zero to going into an infnite loop?
Garry. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Bill Woodger wrote: |
Hint: when one file reaches end-of-file you set the comparison key (for me, not in the record area) "high". I don't know, but suspect not, if PL/I has any "magic" doing this for you. |
In PL/I you would usually do this in the ON ENDFILE unit, and the loop would be controlled not by EOF's, but by key1/2 ^= 'high'. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
prino wrote: |
Bill Woodger wrote: |
Hint: when one file reaches end-of-file you set the comparison key (for me, not in the record area) "high". I don't know, but suspect not, if PL/I has any "magic" doing this for you. |
In PL/I you would usually do this in the ON ENDFILE unit, and the loop would be controlled not by EOF's, but by key1/2 ^= 'high'. |
Which suggests to me the possibility that E_O_INFILEn are actually declared BIT, and that the DO statement ought to be
Code: |
DO WHILE (E_O_INFILE1 ¬= '1'B | E_O_INFILE2 ¬= '1'B); |
|
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
Akatsukami wrote: |
prino wrote: |
Bill Woodger wrote: |
Hint: when one file reaches end-of-file you set the comparison key (for me, not in the record area) "high". I don't know, but suspect not, if PL/I has any "magic" doing this for you. |
In PL/I you would usually do this in the ON ENDFILE unit, and the loop would be controlled not by EOF's, but by key1/2 ^= 'high'. |
Which suggests to me the possibility that E_O_INFILEn are actually declared BIT, and that the DO statement ought to be
Code: |
DO WHILE (E_O_INFILE1 ¬= '1'B | E_O_INFILE2 ¬= '1'B); |
|
... which is what I was hinting at when I asked if the declares were for BIN or DEC.....
Garry. |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
Garry Carroll wrote: |
Akatsukami wrote: |
prino wrote: |
Bill Woodger wrote: |
Hint: when one file reaches end-of-file you set the comparison key (for me, not in the record area) "high". I don't know, but suspect not, if PL/I has any "magic" doing this for you. |
In PL/I you would usually do this in the ON ENDFILE unit, and the loop would be controlled not by EOF's, but by key1/2 ^= 'high'. |
Which suggests to me the possibility that E_O_INFILEn are actually declared BIT , and that the DO statement ought to be
Code: |
DO WHILE (E_O_INFILE1 ¬= '1'B | E_O_INFILE2 ¬= '1'B); |
|
... which is what I was hinting at when I asked if the declares were for BIN or DEC..... |
It's Thanksgiving Day in the U.S.; I only got up about an hour ago, and I'm still working on my first cup of coffee and cigar. I'm entitled to be obtuse, dammit! |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
I would actually go for:
Code: |
Do While (¬E_O_INFILE1 | ¬E_O_INFILE2); |
Actually, my sample program has...
Code: |
DO WHILE (more_master_records | more_update_records); |
|
|
Back to top |
|
|
tamminenisidhartha Currently Banned New User
Joined: 31 Oct 2012 Posts: 43 Location: INDIA
|
|
|
|
Hi all.
The program is running fine now.
I thank you all for your valuable suggestions. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Good to hear it is working - what did you change to make it work correctly?
d |
|
Back to top |
|
|
tamminenisidhartha Currently Banned New User
Joined: 31 Oct 2012 Posts: 43 Location: INDIA
|
|
|
|
@Dick scherrer.
I included the following condition in the "DO WHILE" loop.
Code: |
DO WHILE (E_O_INFILE1='Y' & E_O_INFILE2='N');
PUT SKIP LIST('WRITING REMAIN OF FILE2');
READ FILE(INFILE2) INTO(INREC2);
WRITE FILE(OUTFILE2) FROM (INREC2);
READ FILE(INFILE2) INTO(INREC2);
END;
DO WHILE (E_O_INFILE1='N' & E_O_INFILE2='Y');
PUT SKIP LIST('WRITING REMAIN OF FILE1');
READ FILE(INFILE1) INTO(INREC1);
WRITE FILE(OUTFILE2) FROM (INREC1);
READ FILE(INFILE1) INTO(INREC1);
END; |
Its working fine now.
NOTE:- I changed the end of file variables to "Y" and "N". |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Thank you for posting your solution - it may help another one day
d |
|
Back to top |
|
|
|