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

Reg: Comp comparison with numeric field


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

New User


Joined: 22 Feb 2005
Posts: 10
Location: Chennai

PostPosted: Mon Aug 17, 2009 5:29 pm
Reply with quote

Can I compare a field declared as numeric COMP and a normal numeric 9(2) field??

Cheers,
Siva..
Back to top
View user's profile Send private message
Pankaj Shrivastava
Currently Banned

New User


Joined: 24 Jul 2009
Posts: 51
Location: Pune

PostPosted: Mon Aug 17, 2009 5:34 pm
Reply with quote

No .. Make either of them compatible to other.
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Mon Aug 17, 2009 5:55 pm
Reply with quote

Pankaj...If we do then what will happen?
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


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

PostPosted: Mon Aug 17, 2009 5:57 pm
Reply with quote

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

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Mon Aug 17, 2009 5:58 pm
Reply with quote

Succor wrote:
Pankaj...If we do then what will happen?

Perhaps something that you might like to try yourself.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Aug 17, 2009 6:09 pm
Reply with quote

you should peruse this page from the COBOL II manual (but rules remain the same)
explaining (via a matrix) what datatypes can be used in comparasions: Permissible Comparisons with Numeric Second operands
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Aug 17, 2009 6:47 pm
Reply with quote

hsiva2003 wrote:
Can I compare a field declared as numeric COMP and a normal numeric 9(2) field??

Pankaj Shrivastava wrote:
No

No??!!??
Did I miss something??
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Mon Aug 17, 2009 6:55 pm
Reply with quote

icon_smile.gif didn't want to make you people angry ..I have seen instances where Comp fields have been compared to display numeric fields.I ran a small test for this
Code:

01 WS-T1                     PIC S9(4) COMP VALUE 2.
01 WS-T2                     PIC 9(2) VALUE 1.     
01 WS-T3                     PIC 9(2) VALUE ZEROES.

IF WS-T1  > WS-T2                 
   DISPLAY "NUMERIC VALUE:" WS-T2 
END-IF                             
COMPUTE WS-T3 = WS-T1 + WS-T2     
DISPLAY "NUMERIC VALUE2:" WS-T3   

NUMERIC VALUE:01 
NUMERIC VALUE2:03
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: Mon Aug 17, 2009 8:53 pm
Reply with quote

Quote:
No .. Make either of them compatible to other.
Oh, really? Here's the code:
Code:
           05  WS-COMP-1               PIC S9(18) COMP VALUE +12.
           05  WS-COMP-2               PIC S9(09) COMP VALUE +12.
           05  WS-COMP-3               PIC S9(04) COMP VALUE +12.
           05  WS-DISP-1               PIC  9(02)      VALUE  12.
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           IF  WS-COMP-1 = WS-DISP-1
               DISPLAY 'MATCH 1 EQUAL'
           ELSE
               DISPLAY 'MATCH 1 UNEQUAL'
           END-IF.
           IF  WS-COMP-2 = WS-DISP-1
               DISPLAY 'MATCH 2 EQUAL'
           ELSE
               DISPLAY 'MATCH 2 UNEQUAL'
           END-IF.
           IF  WS-COMP-3 = WS-DISP-1
               DISPLAY 'MATCH 3 EQUAL'
           ELSE
               DISPLAY 'MATCH 3 UNEQUAL'
           END-IF.
which produces output of
Code:
 MATCH 1 EQUAL
 MATCH 2 EQUAL
 MATCH 3 EQUAL


Siva, Pankaj -- there is a link to the manuals at the top of the page. Click on it, click on the COBOL Language Reference, and find out for sure -- not by guessing -- exactly how the IF statement comparisons are done. Yeah, it'll take some reading and digging on your part but the effort will serve you well in the long run.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Aug 17, 2009 9:14 pm
Reply with quote

Permissible Comparisons with Numeric Second operands
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Aug 17, 2009 9:30 pm
Reply with quote

Code:

Table 18. Permissible Comparisons with Numeric Second Operands                                                                     |
|______________________________________________________ ___________________________________________________________________________|
|                                                      |                               Second Operand                              |
|                   First Operand                      |________ _______ ________ _______ ________ _______ ________ _______ _______|
|                                                      |   ZR   |   NL  |   ED   |   BI  |   AE   |   ID  |   IFP  |  EFP  |  FPL  |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
| Nonnumeric Operand                                                                                                               |
|______________________________________________________ ________ _______ ________ _______ ________ _______ ________ _______ _______|
|                                           Group (GR) |   NN   | NN(1) |  NN(1) |       |        |       |        |   NN  |       |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                                      Alphabetic (AL) |   NN   | NN(1) |  NN(1) |       |        |       |        |   NN  |       |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                                    Alphanumeric (AN) |   NN   | NN(1) |  NN(1) |       |        |       |        |   NN  |       |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                            Alphanumeric-Edited (ANE) |   NN   | NN(1) |  NN(1) |       |        |       |        |   NN  |       |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                                  Numeric-Edited (NE) |   NN   | NN(1) |  NN(1) |       |        |       |        |   NN  |       |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                          Figurative Constant (FC(2)) |        |       |  NN(1) |       |        |       |        |   NN  |       |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                             Nonnumeric Literal (NNL) |        |       |  NN(1) |       |        |       |        |   NN  |       |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
| Numeric Operand                                                                                                                  |
|______________________________________________________ ________ _______ ________ _______ ________ _______ ________ _______ _______|
|                        Figurative Constant ZERO (ZR) |        |       |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |       |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                                 Numeric Literal (NL) |        |       |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |       |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                                External Decimal (ED) |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU  |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                                          Binary (BI) |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU  |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                           Arithmetic Expression (AE) |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU  |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                                Internal Decimal (ID) |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU  |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                        Internal Floating-Point (IFP) |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU  |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                        External Floating-Point (EFP) |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |   NU  |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
|                         Floating-Point Literal (FPL) |        |       |   NU   |   NU  |   NU   |   NU  |   NU   |   NU  |       |
|______________________________________________________|________|_______|________|_______|________|_______|________|_______|_______|
| Note:                                                                                                                            |
|                                                                                                                                  |
| (1) Integer item only.                                                                                                           |
| (2) Includes all figurative constants except ZERO.                                                                               |
|__________________________________________________________________________________________________________________________________|

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 Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
Search our Forums:

Back to Top