Comparing Decimal Numbers



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Comparing Decimal Numbers

Postby Subha » Sat Apr 05, 2008 8:37 am

Hi,
I have to compare two decimal numbers.The two numbers are taken from an Input file.
Iam reading these two input variables into a group variable. If the number is 32.33 and 42.47(the second number in the input file is followed by 2 spaces), the following is the declaration.
Eg:
03 input number1
05 num1 Pic S9(7)
05 dec Pic X(1)
05 num2 Pic V99
03 input number2
05 N1 Pic S9(9)
05 D Pic X(1)
05 N2 Pic V999

I would like to know how to compare these two variables and write the greater variable into an Output file through Cobol program.
Subha
 
Posts: 6
Joined: Sat Apr 05, 2008 8:19 am
Has thanked: 0 time
Been thanked: 0 time

Re: Comparing Decimal Numbers

 

Re: Comparing Decimal Numbers

Postby dick scherrer » Sat Apr 05, 2008 9:30 am

Hello,

Please post a few actual records - not an interpretation, but the actual data. Also, make sure that at least one record has a different number of digits in the 2 values. What about negatives?

When posting the data, please use the "Code" tag as this will line up the data and make it much more readable.

To see how your post will look to the forum, click Preview and make changes until your post appears as you want it to. After you have previewed, make sure to click Submit or your post will be lost.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Comparing Decimal Numbers

Postby Subha » Sun Apr 06, 2008 10:49 am

Hi

Thanks . I wanted to know how I would be able to compare any two positive decimal numbers (format of which I have mentioned) using COBOL.
Subha
 
Posts: 6
Joined: Sat Apr 05, 2008 8:19 am
Has thanked: 0 time
Been thanked: 0 time

Re: Comparing Decimal Numbers

Postby CICS Guy » Sun Apr 06, 2008 1:16 pm

Subha wrote:Thanks . I wanted to know how I would be able to compare any two positive decimal numbers (format of which I have mentioned) using COBOL.
The simple answer is yes, but the more detailed answer is that I'm not sure you will be able to do it correctly....
Have you looked at NUMVAL?
CICS Guy
 
Posts: 255
Joined: Wed Jun 20, 2007 4:08 am
Has thanked: 0 time
Been thanked: 0 time

Re: Comparing Decimal Numbers

Postby dick scherrer » Sun Apr 06, 2008 6:16 pm

Hello,

Thanks . I wanted to know how I would be able to compare any two positive decimal numbers (format of which I have mentioned) using COBOL
Before you learn to code you must learn to follow directions. . .

From earlier:
Please post a few actual records - not an interpretation, but the actual data. Also, make sure that at least one record has a different number of digits in the 2 values.
The reason for this is because if a solution is posted that actually works for your very imcomplete example, it will most likely only work for that example (i.e. values with dd.cc).

NUMVAL may help you. Other methods may also.

If you post actual records, we will see.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Comparing Decimal Numbers

Postby Subha » Mon Apr 07, 2008 5:55 pm

Thanks again,

I have a set of values : There are two variables that need to be compared, the variables are N1 and N2. The condition that needs to be satisfied is that If N1 is Greater than N2 then write the greater number into a file.

N1 contains the following values (all positive) : 33.32, 41.47, 100.01, 50.12, 0.02.
N2 contains the following values (all positive) : 44.47, 109.23, 300, 20.01, 50.99.
Subha
 
Posts: 6
Joined: Sat Apr 05, 2008 8:19 am
Has thanked: 0 time
Been thanked: 0 time

Re: Comparing Decimal Numbers

Postby CICS Guy » Mon Apr 07, 2008 7:02 pm

Subha wrote:I have a set of values : There are two variables that need to be compared, the variables are N1 and N2. The condition that needs to be satisfied is that If N1 is Greater than N2 then write the greater number into a file.

N1 contains the following values (all positive) : 33.32, 41.47, 100.01, 50.12, 0.02.
N2 contains the following values (all positive) : 44.47, 109.23, 300, 20.01, 50.99.
Is that 'If N1 is Greater than N2' or more like 'If each N1 is Greater than each N2 as they are paired"?
Unstring each into an array, move each pair to a numeric definitions and compare?
CICS Guy
 
Posts: 255
Joined: Wed Jun 20, 2007 4:08 am
Has thanked: 0 time
Been thanked: 0 time

Re: Comparing Decimal Numbers

Postby dick scherrer » Mon Apr 07, 2008 8:11 pm

Hello,

Once again, you're posted some values. . . not records. . .

Please post the data in record format - using the Code tag for alignment.

Once you have posted some "records" (they don't need to be entire, long records, just example records that show what you are actually working with). It is really not difficult, but might take a couple of minutes. Not such a bad investment if it helps get you something you can use.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Comparing Decimal Numbers

Postby Subha » Mon Apr 07, 2008 8:56 pm

Hello, Thanks again for your reply , but this is all the data I have, I am not very aware and clear of the "Record" you are talking of. I do understand that what I have mentioned before is very clear. It would be of great help if you could give me a generic solution for comparing two Decimal numbers using Cobol .

Could you give me an Example of how to post using the CODE tag. It would help me blog better the next time and make it more self explenatory.

Thanks again for your help.
Subha
 
Posts: 6
Joined: Sat Apr 05, 2008 8:19 am
Has thanked: 0 time
Been thanked: 0 time

Re: Comparing Decimal Numbers

Postby dick scherrer » Mon Apr 07, 2008 9:12 pm

Hello,

I do understand that what I have mentioned before is very clear
What we mention is always very clear - to ourself - it may not be the same very clear to others. . .

The following is using the "Code" tag:
AAAAAbbbbCCCCChhhhIIIIIllll
MMMMMssssPPPPPqqqqOOOOOzzzz

Here is the same without the Code tag:
AAAAAbbbbCCCCCChhhhIIIIIllll
MMMMMssssPPPPPqqqqOOOOOzzzz

Note that with the "Code", the values are presented with a fixed font (rather than a proportional font) which lines things up nicely for better readability.

If you look in the same line as the Code tag there are several others. To see how these work, start a reply, use some of the features and the click Preview. You will be able to see your post as it will appear to the forum, rather than how it lookis in the Reply editor.

but this is all the data I have, I am not very aware and clear of the "Record" you are talking of.
If you are to write code, i expect there to be more info somewhere. It may not have made it to you yet ;) The "record" i speak of is basically taking the series of input fields and showing some sample data for each of the fields (the data i coded above might be records). In your case, the "records" would include the actual length and content for the fields you want to compare.

Generically speaking, you may need to build a "real" field from the pieces you have as input and then compare the built fields. It is not difficult, but can be a bit tedious. Due to what i see to be unequal lengths in the values, you may need to do this coding to handle alignment.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post