View previous topic :: View next topic
|
Author |
Message |
hsiva2003
New User
Joined: 22 Feb 2005 Posts: 10 Location: Chennai
|
|
|
|
Can I compare a field declared as numeric COMP and a normal numeric 9(2) field??
Cheers,
Siva.. |
|
Back to top |
|
|
Pankaj Shrivastava Currently Banned New User
Joined: 24 Jul 2009 Posts: 51 Location: Pune
|
|
|
|
No .. Make either of them compatible to other. |
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
Pankaj...If we do then what will happen? |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
RTFM |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Succor wrote: |
Pankaj...If we do then what will happen? |
Perhaps something that you might like to try yourself. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
|