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

How to compare inputs of same length but with unequal values


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
BALAMURUGAN J

New User


Joined: 17 Apr 2012
Posts: 1
Location: INDIA

PostPosted: Tue May 15, 2012 4:43 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue May 15, 2012 4:55 pm
Reply with quote

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

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue May 15, 2012 5:17 pm
Reply with quote

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... icon_eek.gif
Back to top
View user's profile Send private message
Peter cobolskolan

Active User


Joined: 06 Feb 2012
Posts: 104
Location: Sweden

PostPosted: Tue May 15, 2012 6:12 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue May 15, 2012 7:04 pm
Reply with quote

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

Moderator Emeritus


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

PostPosted: Tue May 15, 2012 7:13 pm
Reply with quote

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
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top