Page 1 of 1

Summation of Signed Variables

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

Re: Summation of Signed Variables

PostPosted: Fri Jul 23, 2021 6:47 pm
by Anu_developer
Please let me know how to intrepret Zoned decimal value in cobol to field with pic clause having S9(16)V99

Re: Summation of Signed Variables

PostPosted: Fri Jul 23, 2021 9:17 pm
by Robert Sample
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.

Re: Summation of Signed Variables

PostPosted: Sat Jul 24, 2021 6:29 am
by sergeyken
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: