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

Compare comp3 and comp filelds


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

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Mon Aug 16, 2010 11:05 pm
Reply with quote

I have 2 flat files FILEA & FILEB

In FILEA --> records have unique employee number field stored in a comp format ( actually FILEA has been downloaded from a DB2 table and the employee column in the table was an integer)..so the extracted data is binary..

In FILEB --> records have the unique employee number field stored in PD format.

My objective is to read FILEB sequentially and extract the data from FILEA by matching the employee field. But I am not sure how to proceed as the data formats are varying in both the files for the employee number. So how do I compare?

I have planned to write a COBOL code..But can anyone suggest a better way of doing such a task may be using JCL/SORT?
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 Aug 16, 2010 11:18 pm
Reply with quote

Hello,

Whether COBOL or some utility (i.e. sort) is the better choice depends on the complete requirement. . .

If you use COBOL, sort both files on the employee number (BI for comp and PD for comp-3) and match/merge the files (there is tested sample code in a "sticky" near the top of the cobol part of the forum).

To compare the fields simply use an IF:
Code:

IF COMP-FLD = COMP3-FLD
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Tue Aug 17, 2010 12:16 am
Reply with quote

Dick, I found the program. Thanks! If I am not wrong, in the COBOL program the following line does the comparison between the records of the 2 files:

IF COMP-CAPP = COMP-ELIG GO TO 100-CAP-ELIG-MATCH.

But here you both the fields COMP-ELIG & COMP-CAPP have the same datatype PIC 9(9). So the comparson is a straightforward one. In my case the scenario is quite similar except the dataypes of the 2 fields are different (Lets asume COMP-CAPP is COMP & COMP-ELIG is a PD field). How will this be handled in the COBOL program. Will direct comparison work?

Also I was thinking if I could load the second Input file COMP-ELG into a VSAM with key as CER-PROV. becoz I have huge number of records to process..
icon_smile.gif
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Aug 17, 2010 12:28 am
Reply with quote

But here you both the fields COMP-ELIG & COMP-CAPP have the same datatype PIC 9(9). So the comparson is a straightforward one. In my case the scenario is quite similar except the dataypes of the 2 fields are different (Lets asume COMP-CAPP is COMP & COMP-ELIG is a PD field). How will this be handled in the COBOL program. Will direct comparison work?

RTFM
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Tue Aug 17, 2010 12:40 am
Reply with quote

I may look a bit foolish but can you please elaborate! I don't know what you are refereing to by RTFM Craq.
Back to top
View user's profile Send private message
Traveler

New User


Joined: 12 Aug 2010
Posts: 8
Location: Highlands, NJ

PostPosted: Tue Aug 17, 2010 12:46 am
Reply with quote

Think about the problem a little. If you are in COBOL you can created two fields that are both used for the comparison. Define these two fields as smiple fields pic s9(9) , the move will translate the data into display format , you could even go a step furthur and redefine the fields as pic x(9) and use the pic x for the comparison. So that you do a char to char compare.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Aug 17, 2010 12:57 am
Reply with quote

Quote:
Will direct comparison work?

RTFM
There is a link to manuals at the top of this page. Click on it, find the COBOL manuals for your version of COBOL, and start reading. If you read long enough, you will find out much about how COBOL will automatically convert numeric data from one format to another for comparison in an IF statement. Let me repeat Craq's comment for emphasis -- your level of expertise in COBOL is appallingly low for somebody attempting to write code in it:

Read The Freaking Manual
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Aug 17, 2010 12:57 am
Reply with quote

Rijit wrote:
I may look a bit foolish but can you please elaborate! I don't know what you are refereing to by RTFM Craq.


YOU CAN DIRECTLY COMPARE A COMP-3 FIELD AND A COMP FIELD WITH NO PROBLEM! Just read the COBOL manual.
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Tue Aug 17, 2010 1:03 am
Reply with quote

dick scherrer wrote:
Hello,

Whether COBOL or some utility (i.e. sort) is the better choice depends on the complete requirement. . .

If you use COBOL, sort both files on the employee number (BI for comp and PD for comp-3) and match/merge the files (there is tested sample code in a "sticky" near the top of the cobol part of the forum).

To compare the fields simply use an IF:
Code:

IF COMP-FLD = COMP3-FLD


I would like to know if the direct comparison will work in the cobol or we should go for a redefine/move as stated by Traveler.
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Tue Aug 17, 2010 1:05 am
Reply with quote

Craq Giegerich wrote:
Rijit wrote:
I may look a bit foolish but can you please elaborate! I don't know what you are refereing to by RTFM Craq.


YOU CAN DIRECTLY COMPARE A COMP-3 FIELD AND A COMP FIELD WITH NO PROBLEM! Just read the COBOL manual.


Thanks for right advise, may be I need to get into my boots and revisit the COBOL manual.. icon_rolleyes.gif
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


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

PostPosted: Tue Aug 17, 2010 5:00 am
Reply with quote

Oh,
Quote:
Freaking


Whew. I feel better now.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Aug 17, 2010 6:03 am
Reply with quote

From the manual:
Quote:
6.1.6.4 Relation conditions

A relation condition specifies the comparison of two operands. The relational operator that joins the two operands specifies the type of comparison. The relation condition is true if the specified relation exists between the two operands; the relation condition is false if the specified relation does not exist.

Comparisons are defined for the following:

* Two operands of class alphabetic

* Two operands of class alphanumeric

* Two operands of class DBCS

* Two operands of class national

* Two operands of class numeric

* Two operands of different classes where each operand is one of the classes alphabetic, alphanumeric, or national

* Two operands where one is a numeric integer and the other is class alphanumeric or national
Notice that you can compare two numeric variables (or a numeric variable and a numeric literal) -- no matter how the numeric variable is defined.
Back to top
View user's profile Send private message
Rijit

Active User


Joined: 15 Apr 2010
Posts: 168
Location: Pune

PostPosted: Tue Aug 17, 2010 8:34 am
Reply with quote

Thank you Robert for the details..
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 Aug 17, 2010 9:09 am
Reply with quote

Hello,

Hopefully, you realize that the details Robert provided are a direct quote from the manual that people advised you to read. . .
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Tue Aug 17, 2010 4:42 pm
Reply with quote

Phrzby Phil wrote:
Oh,
Quote:
Freaking


Whew. I feel better now.

Substitute other F-words at your own discretion... icon_razz.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 17, 2010 4:56 pm
Reply with quote

Read the Fine Manual.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Tue Aug 17, 2010 5:15 pm
Reply with quote

Read The Fabulous Manual icon_smile.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 17, 2010 5:19 pm
Reply with quote

Kjeld wrote:
Read The Fabulous Manual icon_smile.gif


Kjeld, even I tend not to be that sarcastic.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Tue Aug 17, 2010 5:30 pm
Reply with quote

OK, you're right, only a few manuals would really qualify for that adjective.

On the other hand, some manuals or at least parts of them have become rather famous (another f-word icon_wink.gif ), and indispensable to developers.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 17, 2010 5:36 pm
Reply with quote

Kjeld,
you are being tooooooooo serious.

but, following up on your comment, most REDBOOKs I would put in the Fabulous category.
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 Compare only first records of the fil... SYNCSORT 7
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Compare two files with a key and writ... SYNCSORT 3
No new posts Compare latest 2 rows of a table usin... DB2 1
No new posts How to compare two rows of same table DB2 11
Search our Forums:

Back to Top