Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Comparison of numeric edited variables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Nileshkul

New User


Joined: 09 May 2016
Posts: 20
Location: India

PostPosted: Sat Mar 16, 2019 1:18 am    Post subject: Comparison of numeric edited variables
Reply with quote

I have 2 variables declared as numeric edited i.e. PIC -9(8).

When I compare both 2 variables even negative value is passed as more than positive value.
For example:
Temp-1 pic -9(8) value -877
Temp-2 pic -9(8) value 888
Now in IF statement temp-1 is passing as more than temp-2

Is it that comparing 2 numeric edited items us not numeric but alphanumeric including just negative sign.
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


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

PostPosted: Sat Mar 16, 2019 3:11 am    Post subject:
Reply with quote

Quote:
Is it that comparing 2 numeric edited items us not numeric but alphanumeric including just negative sign.
Yes - numeric-edited variables are treated as alphanumeric by the compiler. The numeric values are NOT directly compared.
Back to top
View user's profile Send private message
sergeyken

Active Member


Joined: 29 Apr 2008
Posts: 609
Location: Maryland

PostPosted: Sat Mar 16, 2019 10:53 pm    Post subject: Re: Comparison of numeric edited variables
Reply with quote

Nileshkul wrote:
I have 2 variables declared as numeric edited i.e. PIC -9(8).

When I compare both 2 variables even negative value is passed as more than positive value.
For example:
Temp-1 pic -9(8) value -877
Temp-2 pic -9(8) value 888
Now in IF statement temp-1 is passing as more than temp-2

Is it that comparing 2 numeric edited items us not numeric but alphanumeric including just negative sign.

So called "numeric edited(?)" fields are in fact zoned decimal fields, in IBM introduced terminology.

In format PIC -9(8) the values are stored in memory as follows
Code:
-877 = X'F0F0F0F0F0F8F7D7'
 888 = X'F0F0F0F0F0F8F8C8'

Those X-strings in COBOL are not treated according to arithmetic rules when compared, but rather as character strings - as if they were defined as PIC X(8). (When any math is required, those values need to be converted internally, usually to COMP-3; but not for comparison operation).

Hence, the X'F0F0F0F0F0F8F7D7' is greater than X'F0F0F0F0F0F8F8C8', which goes against common sense for any person who is new to mainframe internals.
Back to top
View user's profile Send private message
Nileshkul

New User


Joined: 09 May 2016
Posts: 20
Location: India

PostPosted: Sat Mar 16, 2019 11:09 pm    Post subject: Reply to: Comparison of numeric edited variables
Reply with quote

Thanks both for your reply and guidance.

So I will move these 2 numeric edited items simply to pic s9 as I want to compare them as numbers.

Thanks again....
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Sat Mar 16, 2019 11:33 pm    Post subject:
Reply with quote

Sergeyken, you're not quite right -- the leading minus sign is kept as a separate character with a value of '-' for negative values and space for positive values and X'60' for a minus sign compares larger than X'40' for a space. Code:
Code:
000800  WORKING-STORAGE SECTION.                                       
000810  01  WS-VARS.                                                   
000820      05  WS-TEMP1                PIC -9(08).                     
000830      05  WS-TEMP2                PIC -9(08).                     
001300  PROCEDURE DIVISION.                                             
001301      MOVE -877                   TO  WS-TEMP1.                   
001302      MOVE  888                   TO  WS-TEMP2.                   
001310      IF  WS-TEMP1 > WS-TEMP2                                     
001320          DISPLAY '>' WS-TEMP1 '< IS LARGER THAN >' WS-TEMP2 '<' 
001330      ELSE                                                       
001340          DISPLAY '>' WS-TEMP1 '< IS SMALLER THAN >' WS-TEMP2 '<'
001350      END-IF.                                                     
shows results of
Code:
>-00000877< IS LARGER THAN > 00000888<
PIC S9(08) would be as you show.

In any case, to get numeric results to compare correctly, numeric (not numeric-edited) variables should be used as the TS is going to do.
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 Convert Numeric to Packed decimal and... anand1204 DFSORT/ICETOOL 5 Thu Aug 08, 2019 3:53 am
No new posts Training on numeric fields data formats sergeyken SYNCSORT 12 Thu Aug 01, 2019 8:15 pm
No new posts Convert alpha numeric to signed digits Balu5491 COBOL Programming 4 Mon Feb 25, 2019 10:39 pm
No new posts Code numeric format to display both '... Time2Live COBOL Programming 7 Wed Nov 21, 2018 10:20 pm
No new posts Calling and updating SAS Macro variab... Yogesh Jaiswal All Other Mainframe Topics 7 Thu Oct 11, 2018 12:37 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us