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 Anu_developer » Fri Jul 23, 2021 5:43 pm

Hi,

I have a requirement to compare the the total amount in trailer record of input file and the summation output happening in cobol.

Both the fields(in copybook layout as well as the WS variable in cobol) are having pic clause as below.
PIC S9(16)V99

In trailer record(in input file) the value as below. (HIGHLIGHTED VALUE IS the total amount)
T12500000001100000000000009263N

when I tried reading this via copybook,it provides me as value as '-926.35'

but the job abends and saying the fields are matched.
AMT ON TLR ( 926.35) NOT = CALC AMT ( 926.35)



could anyone please help me to know how to compare two fields having PIC S9(16)V99
Anu_developer
 
Posts: 2
Joined: Fri Jul 23, 2021 5:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Summation of Signed Variables

Postby Anu_developer » Fri Jul 23, 2021 6:47 pm

Please let me know how to intrepret Zoned decimal value in cobol to field with pic clause having S9(16)V99
Anu_developer
 
Posts: 2
Joined: Fri Jul 23, 2021 5:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Summation of Signed Variables

Postby Robert Sample » Fri Jul 23, 2021 9:17 pm

Do not add your post to the end of a 9 1/2 year old topic -- I've split it out for you.

could anyone please help me to know how to compare two fields having PIC S9(16)V99
COBOL has the IF statement which is used for this.

00000000000009263N is the signed zoned decimal value -926.35 as you said. Unsigned zoned decimal values look like "normal" numbers, while signed zoned decimal numbers look the same except for the last byte. The last byte has the zone changed to X'C' (from X'F') for positive values which makes the displayed data A through I and a { for 1 through 9 and 0, respectively. The last byte has the zone changed to X'D' (so the characters become J though R and }) for negative values.

but the job abends and saying the fields are matched.
AMT ON TLR ( 926.35) NOT = CALC AMT ( 926.35)
Did you notice that NEITHER of your displayed values has a negative sign? This is an indicator that something is wrong in your code -- most likely something is being moved to an unsigned zoned decimal variable so the negative values become positive and -926.35 will not compare the same as 926.35 in COBOL.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Summation of Signed Variables

Postby sergeyken » Sat Jul 24, 2021 6:29 am

The languages like COBOL have been designed partially for exactly this purpose: to relieve developers from going deep into these computer architectural details. While working with normal COBOL (without unneeded tricks), and with normally designed software product, - there is absolutely no need to worry about such issues, as looking for unpacked decimal sign location… :geek:
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 408
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 6 times
Been thanked: 40 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post