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
Summation of Signed Variables
-
- Posts: 2
- Joined: Fri Jul 23, 2021 5:31 pm
- Skillset: COBOL
DB2
JCL - Referer: google
-
- Posts: 2
- Joined: Fri Jul 23, 2021 5:31 pm
- Skillset: COBOL
DB2
JCL - Referer: google
Re: Summation of Signed Variables
Please let me know how to intrepret Zoned decimal value in cobol to field with pic clause having S9(16)V99
-
- Global moderator
- Posts: 3720
- Joined: Sat Dec 19, 2009 8:32 pm
- Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
- Referer: other forum
- Location: Dubuque, Iowa, USA
Re: Summation of Signed Variables
Do not add your post to the end of a 9 1/2 year old topic -- I've split it out for you.
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.
COBOL has the IF statement which is used for this.could anyone please help me to know how to compare two fields having PIC S9(16)V99
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.
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.but the job abends and saying the fields are matched.
AMT ON TLR ( 926.35) NOT = CALC AMT ( 926.35)
- sergeyken
- Posts: 458
- Joined: Wed Jul 24, 2019 10:12 pm
- Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
- Referer: Internet search
Re: Summation of Signed Variables
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… 

Javas and Pythons come and go, but JCL and SORT stay forever.