Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Reg: Comp comparison with numeric field

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Reg: Comp comparison with numeric field
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    Post subject:
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    Post subject: Reply to: Reg: Comp comparison with numeric field
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    Post subject:
Reply with quote

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

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Mon Aug 17, 2009 5:58 pm    Post subject: Re: Reply to: Reg: Comp comparison with numeric field
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    Post subject:
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: 1224
Location: Israel

PostPosted: Mon Aug 17, 2009 6:47 pm    Post subject: Reply to: Reg: Comp comparison with numeric field
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    Post subject: Reply to: Reg: Comp comparison with numeric field
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: 7931
Location: Bellevue, IA

PostPosted: Mon Aug 17, 2009 8:53 pm    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts INVALID FIELD OR CONSTANT IN SORTOF ?? Ron Klop DFSORT/ICETOOL 8 Wed Jan 11, 2017 3:44 pm
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 31 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts CICS NEW SIT PARAMETERS CICS BEHAVIOR... Kyle Carroll CICS 0 Fri Nov 04, 2016 11:55 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us