Summation of Signed Variables



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

Summation of Signed Variables

Postby Sushmita V » Tue Jan 24, 2012 12:45 pm

Hi all,
Greetings!

I need to sum two fileds declared with signs.

10 WS-TOT-AMOUNT1 PIC +9(9).99.
10 WS-TOT-AMOUNT2 PIC +9(9).99.

I need to store the summation like below:

WS-TOT-AMOUNT1 = WS-TOT-AMOUNT1 + WS-TOT-AMOUNT2

Can we sum up these by any ways taking +ve or -ve signs in consideration?

Thanks & Regards,
Sushmita V
Sushmita V
 
Posts: 12
Joined: Thu Jan 19, 2012 9:26 pm
Location: Chennai, India
Has thanked: 0 time
Been thanked: 0 time

Re: Summation of Signed Variables

Postby BillyBoyo » Tue Jan 24, 2012 12:59 pm

What you are showing is numbers in "numeric-edited" format, the sort of thing that might be used for a line on a printout.

If that is the format your data is in, you can't directly use the "numbers" for arithmetic operations. If you have been told there are numbers on a file, which are signed and with two decimal places, your actual PIC could be S9(3)V99, where S is an implicit sign and V is an implicit decimal place (the sign will acutally be stored in the data, but not by "displacing" a digit, so the length of the field won't change, the decimal point is purely implicit, with the compiler generating the correct code from the definition, but nothing stored on the file).

In your example, you could define the sign as being SEPERATE but there is nothing you can do about the decimal point. So, +12345 could be defined as 999V99 SIGN SEPERATE and be treated as positive 123.45 and used in arithmetic.

It is well worth spending some time with the manuals and constructing some examples so that you become familiar with all this, you learn much better that way than just by being told. Definining the data correctly will save you problems in the future, and even improve your code in the PROCEDURE DIVISION.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post