On 7/14/2012 10:16 AM, Scott Ford wrote:
John,

So your saying in COBOL are you talking about Comp-3 binary ?

No such thing. A field is either comp-3 (or, nowadays, packed-decimal)
or comp (nowadays, binary) - or floating point which few COBOL
programs use.

I think he's saying keep amounts in pennies as binary fields.
Convert to dollars + decimal point + cents when you display
these fields.



Scott ford
www.identityforge.com

On Jul 14, 2012, at 8:08 AM, John Gilmore <jwgli...@gmail.com> wrote:

Doing integer--as opposed to real fixed-point--arithmetic with
packed-decimal values is the real culprit here.

Integer arithmetic should never be done with anything but binary
integers.  Operations on them are register operations, which are much
faster than storage-to-storage ones; and zero is always positive.
Moreover, it is now possible to make them behave in COBOL exactly as
they do in assembly language.

John Gilmore, Ashland, MA 01721 - USA

On 7/14/12, Gibney, Dave <gib...@wsu.edu> wrote:
Back in 1981, one of the first bugs I had to find/fix was a COBOL (VS?)
routine intended to distribute the rounding difference to a set of records.
Perform until zero left to distribute. It looped at negative zero. I didn't
write it, I don't remember my precise fix.

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU]
On Behalf Of Frank Swarbrick
Sent: Friday, July 13, 2012 3:07 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: COBOL packed decimal

Excellent!  Thank you very much!
Subtle is right!  :-)
Negative zero, huh?  Must be that new math, thing.  :-)

Frank




________________________________
From: "Dan Skomsky @ Home" <poodles...@sbcglobal.net>
To: IBM-MAIN@LISTSERV.UA.EDU
Sent: Friday, July 13, 2012 3:24 PM
Subject: Re: COBOL packed decimal

 From an old discussion on the same subject from back in '05 over at
http://www.tek-tips.com :

Here's an explanation of what is happening.  When we were converting
from VS COBOL to COBOL II/COBOL 370, I found the book "COBOL/370 FOR
VS
COBOL AND COBOL II PROGRAMMERS by Harvey Bookman.  Here's what he says
about your question....

"One change from VS COBOL to COBOL/370 that may seem quite baffling
occurs when a constant or another COMP-3 data field is added or
subtracted to or from a signed COMP-3 data field.  The VS COBOL
compiler produced only an Add Packed (AP) or Subtract Packed (SP)
instruction.  COBOL/370 still produces the same instruction but then
issues a Zero and Add Packed (ZAP) of the resulting field into
itself.  The ZAP is executed for a very subtle reason.
When two negative numbers are added together and an overflow occurs,
the overflow flag in the condition code is turned on while the
resulting sign is set as if overflow did not occur.  This means that
if
two numbers each defined as PIC S9(03) COMP-3 were added together, and
they had values of -1 and -999 before the addition, the resulting
field
would be zero (the digit that overflowed was truncated) with its sign
negative.  The ZAP will preserve the sign of all other computations
but
will change a zero with a negative sign to a zero with a positive
sign."

"Ensuring a positive sign in a zero result was not necessary in the VS
COBOL compiler.  This is because the VS COBOL compiler used a Compare
Packed (CP) instruction to compare numeric fields.  It is interesting
that COBOL/370 now often produces a Compare Logical (CLC) instruction
to compare numeric fields.  While this is a faster instruction than
CP,
it requires the same sign value for an equal condition to occur.  For
example, a CP instruction will find fields with hexadecimal values
'0F'
and '0C' equal, while the CLC will not."

The same instructions are generated in Enterprise COBOL as were for
COBOL/370.

HTH

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU]
On Behalf Of Itschak Mugzach
Sent: Friday, July 13, 2012 4:10 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: COBOL packed decimal

Zero and add pack.

ITschak

On Sat, Jul 14, 2012 at 12:05 AM, Frank Swarbrick
<frank.swarbr...@yahoo.com
wrote:

COBOL code
77  ws-num-packed              pic S9(9) packed-decimal.

      add 2 to ws-num-packed


Generated assembler:


000014
ADD
     00036A                 GN=16    EQU
*
     00036A  FA40 8008 A02C          AP    8(5,8),44(1,10)
WS-NUM-PACKED                     PGMLIT AT +40
     000370  F844 8008 8008          ZAP   8(5,8),8(5,8)  WS-NUM-
PACKED
WS-NUM-PACKED


What is the purpose of the ZAP?

Thanks,
Frank


--------------------------------------------------------------------
-
- For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO
IBM-MAIN




--

Kind regards,

-Steve Comstock
The Trainer's Friend, Inc.

303-355-2752
http://www.trainersfriend.com

* Special promotion: 15% off on all DB2 training classes
    scheduled by September 1, taught by year end 2011

* Check out our entire DB2 curriculum at:
    http://www.trainersfriend.com/DB2_and_VSAM_courses/DB2curric.htm

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to