View previous topic :: View next topic
|
Author |
Message |
BALAMURUGAN J
New User
Joined: 17 Apr 2012 Posts: 1 Location: INDIA
|
|
|
|
Problem Description:
Compare the content of two files and write the contents in output file if they MATCHES.
I have two input files in sorted order.
First File Contents:
ASFLCMPR
CESD
Second File Contents:
ASFLCMPR
CESD
DESED
Expected Output:
ASFLCMPR
CESD
Actual Output:
ASFLCMPR
CODING:
PROCESS:
PERFORM READLIST TO READLISTX ------>READING FILE1
PERFORM READLISTA TO READLISTB------->READING FILE2
MAINLOOP:
IF NAM1 NE NAM2
PERFORM READLISTA TO READLISTB
GOTO MAINLOOP
ELSE
MOVE NAM2 TO OUT_NAME
WRITE OUTFILE1
GOTO PROCESS
ENDIF
PROBLEM:
It is displaying the first variable correctly. But the second variable s neglected since its having lesser lenght and comparison did not proceed after that.
Kindly help me with this. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Looks to me like you don't read File 1 more than once, from what you have shown.
I don't understand at all what you mean by the subject or your comments about why you don't get a match.
Have you looked at the "Sticky" for a two-file match in the Cobol forum where you have posted? Compare the logic there to the logic you have and you should get to a resolution. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Quote: |
It is displaying the first variable correctly. But the second variable s neglected since its having lesser lenght and comparison did not proceed after that. |
That's a statement constructed with non-IT words.
Did you mean the working-storage variables were of length 8 [PIC X(8)] to accomodate "ASFLCMPR" and when control reach to "CESD", the length of the input-content was less and it did not work, grumble... |
|
Back to top |
|
|
Peter cobolskolan
Active User
Joined: 06 Feb 2012 Posts: 104 Location: Sweden
|
|
|
|
It would be very easy for someone to correct your program if you show the actual code, not just "Is is.... since...".
By the way, who told you to use GO TO in a structured, new, 2012 COBOL program? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Code: |
CODING:
PROCESS:
PERFORM READLIST TO READLISTX ------>READING FILE1
PERFORM READLISTA TO READLISTB------->READING FILE2
MAINLOOP:
IF NAM1 NE NAM2
PERFORM READLISTA TO READLISTB
GOTO MAINLOOP
ELSE
MOVE NAM2 TO OUT_NAME
WRITE OUTFILE1
GOTO PROCESS
ENDIF |
The pseudo-code you have shown, subject to no "end of file" processing, should actually "work" for your data.
Which means you have something wrong in the actual code we can't see.
You don't represent a full solution with your code, unless you know for certain that records on File 1 must always be present on File 2.
You don't mention whether you can have duplicates on either file.
I still can't make sense of your comments about the length. You using reference-modification? Any sort of "STRING"? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello and welcome to the forum,
Your pseudo-code (as posted) will most lilely fail in a "real world" situation. Also, it is not compilable code, so we cannot be specific about your problem resolution.
When "matching" 2 files by a key, there must be tests for more than simply equal or not equal.
As suggested, look at the "2-file match/merge" sample code in the "Sticky" near the top of this COBOL part of the forum.
Post back here if you have any questions. |
|
Back to top |
|
|
|