View previous topic :: :: View next topic

Author 
Message 
harry
New User
Joined: 27 Mar 2006 Posts: 31




Hi,
Hi,
Could any one please let me know how can I compare a comp3 field ? I want to compare the value of
PIC S9(5)V9(5) COMP3. with 999999
IF IT IS > 999999
THEN I want to subtract 1000000 , but its not working for me , because I know I can’t compare a comp3 field with a number .
Could any one please help me to implement this change ?


Back to top 




Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA




harry wrote: 
PIC S9(5)V9(5) COMP3. with 999999
IF IT IS > 999999

Your compare is matching 999999.00000 with a field that is at the most 99999.99999 so it could never be greater. When you are comparing with a numeric literal you need to consider the decimal point. RTFM. 

Back to top 


dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19254 Location: Inside the Matrix




Hello,
Quote: 
but its not working for me , because I know I can’t compare a comp3 field with a number 
Of course you can. . . In fact, about the only compare that makes logical sense is to compare a comp3 field with a number. . .
You need to post the variables and procedure code that is not working and mention what problem(s) you encountered. 

Back to top 


Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8567 Location: Dubuque, Iowa, USA




Quote: 
because I know I can’t compare a comp3 field with a number 
Fortunately  or not  what you know is completely, absolutely, totally wrong. This has been discussed a number of times on this forum  search the forum. 

Back to top 


harry
New User
Joined: 27 Mar 2006 Posts: 31




Hi Mr. dick scherrer,
This is what i am using :
WSORDERNO PIC S9(5)V9(5) COMP3.
*******************************************
IF WSORDERNO > 999999.00000
COMPUTE WSORDERNOOUT = (1000000  WSORDERNO)
ELSE
MOVE WSORDERNO TO WSORDERNOOUT
ENDIF.
But this logic also not working , 

Back to top 


Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA




WSORDERNO PIC S9(5)V9(5) COMP3.
*******************************************
IF WSORDERNO > 999999.00000
S9(5)v9(5) can never be greater then 999999.00000 the max for that field is 99999.99999! 

Back to top 


dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19254 Location: Inside the Matrix




Hello,
Quote: 
IF WSORDERNO > 999999.00000 
Why might an order number have a decimal? Why are there more digits to the left of the decimal in the literal than is possible for the field?
Why is there a computation for the "next" order number?
If this "order number" is to be the key to database tables, vsam files, or even sequential data, this scheme will result in many longterm problems. . . 

Back to top 


dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6970 Location: porcelain throne




the largest value WSORDERNO PIC S9(5)V9(5) COMP3 can contain is:
99999.99999
that's 5  9's decimal point and 5 9's.
or
ninetynine thousand nine hundred ninetynine
point
ninetynine thousand nine hundred ninetynine onehundredthousands. 

Back to top 


harry
New User
Joined: 27 Mar 2006 Posts: 31




dick scherrer, you were talking about long term problems...I know but no body here listen to any thing ...there are so many loop holes but while system design no body came together and all these problem came in where order numbers are defined as comp3...

meanwhile i tried all the option to compare a comp3 field but still no success ...
1> Ordernumber > 99999.99999 also not working .
2>tried to move ordernumber to pic 9 (06) because s9(5)v9(5) is 6 bytes and then tried to compare the new 9(06) field with 999999 but still not working ..
Please advise some way to resolve this issue .
Thanks 

Back to top 


enricosorichetti
Senior Member
Joined: 14 Mar 2007 Posts: 10701 Location: italy




all the copyright credit to dbzTHEdinosauer
the largest value WSORDERNO PIC S9(5)V9(5) COMP3 can contain is:
99999.99999 

Back to top 


dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6970 Location: porcelain throne




Harry,
let's try this another way.
you have a 5 pound bag. it can only hold 5 pounds or less of something.
do not expect that you can fill the 5 pound bag and expect it to weigh more than 5 pounds.
you have to expect the 5 pound bag to weigh less than 5 pounds.
so trying to see if the 5 pound bag weighs 6 pounds, you will always receive 'FALSE'.
the same applies to your comparision.
ordernumber can never be greater than 99999.99999. 

Back to top 


Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8567 Location: Dubuque, Iowa, USA




Your problem is NOT a COBOL issue.
Your problem is a mathematical impossibility: an IF test comparing a value with 5 digits in front of the decimal will not, under any circumstances, be greater than or equal to one million  which is what your comparison is checking.
Since COBOL supports operations on numeric edited fields, you can MOVE your data to a PIC 9(06)V9(05) variable and use that for comparison if you want. However, unless you do calculations on the 6digit variable, since a 5digit variable value will always be less than one hundred thousand, just moving it to a 6digit variable will not change that. Comparing it to one million will always come back less  always. 

Back to top 


ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York




Please look at this and tell me if I have ASSUMED correctly:
It sounds as if you have the task of issuing NEW Order numbers.
AND when the Order number EXCEEDS your limit of 99999.00000,
you are trying to get the ORDERNUMBER to begin at the number
00001.00000.
If I am correct then TRY THIS:
WSORDERNO PIC S9(5)V9(5) COMP3.
*******************************************
IF WSORDERNO = 99999.00000
ADD 1 TO WSORDERNO.
MOVE WSORDERNO TO WSORDERNOOUT.
IF MY ASSUMPTION IS INCORRECT  I hope someone else can give you your solution. 

Back to top 


dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19254 Location: Inside the Matrix




*Sigh*
I suppose you were more focused on posting an answer rather that reading thru the topic and understanding the conversation thus far . . .
If 5 digits is the maximum possible before the decimal why would you suggest using 999999.0000. . . 

Back to top 


ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York




Thats my MISTAKE  I meant to type 5 intergers and 5 decimals. very sorry 99999.00000 

Back to top 


dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19254 Location: Inside the Matrix




Please check and make sure i corrected the post properly.
If all is well, i'll delete our last couple of posts. . .
Also, i believe the code shown will give a new number of 00000.00000 . . .
d 

Back to top 


