On 9/26/2014 11:31 AM, Frank Swarbrick wrote:
I've been pondering the TRUNC option since yesterday. Let me ask
thisquestion... Is the only time the TRUNC option come in to effect
when one binary field is moved to another, smaller, binary field?
Because it appears if a packed-decimal or zoned decimal field is
moved in to a smaller binary field the TRUNC(STD) logic is always
performed. Specifically, the sending field is moved to a temp field,
it is then truncated, and then converted to binary. At least in the
examples I've tried.
TRUNC(STD) indicates to the compiler that results of MOVEs or
calculations into BINARY fields should be truncated to the
precision of the PICTURE (this conforms to ANSI standards)
Consider:
05 FLDA PIC S99 COMP.
if you code MOVE +125 TO FLDA the result should be '25'
(x'0019') in FLDA - truncation to the number of 9's in
the picture - with TRUNC(STD).
With TRUNC(BIN) the result is '125' (x'007D') - the whole
result is included as long as it fits into physical size
(halfword in this case) of the target field.
With TRUNC(OPT) the compiler will choose the instruction
path that is fastest; might be a MVC, might be LH / STH,
etc.; it depends. IBM has never documented the rules, claiming
they are 'proprietary' or at least subject to change from
release to release.
Recommend: binary fields should be defined with the
maximimum number of nines (such as PIC S9999 for halfword)
and compile with TRUNC(OPT).
-Steve Comstock
If that's the case I think I'll just stay with TRUNC(STD) since situations where
TRUNC(OPT) would come in to play would be rare enough anyway that there would be no
noticeable gain, and too much to lose. I can't think of many cases where someone would
move a "large" binary field to a smaller one anyway.
Personally, I think "picture defined" COMP/BINARY fields should be eliminated
in favor of the COBOL 2002 BINARY-SHORT (halfword), BINARY-LONG (fullword) and
BINARY-DOUBLE (doubleword) data types, which make much more sense in the real world
anyway. (of course eliminating the legacy data types is never going to happen, because
its too ingrained.)
Thanks,
Frank
________________________________
From: Tom Ross <[email protected]>
To: [email protected]
Sent: Friday, September 26, 2014 10:51 AM
Subject: Re: COBOL 5 compile options
Thanks Tom!
For HGPR, don't you mean the reverse of what you said? PRESERVE would alwa=
ys be save because COBOL preserves and restores the high-halves of the regi=
sters, right? Safer, but not as efficient?
Ooops, at least I was 100% wrong :-) Yes, PRESERVE is safer, although
NOPRESERVE might be safe for most as well.
As for NUMPROC, thanks for the info. Seems to me the documentation could b=
e made clearer, though I don't know exactly all. In the end I can't imagin=
e doing what you suggest, even though "it's the only way to be sure". So w=
e'll probably, unfortunately, just go with NOPFD. But thanks a lot for the=
info!!
Yes, I was aware that my idea was kind of crazy, and eve asked at SHARE if
anyone could ever do such a thing. On the other hand, if you did not find out
if your data has preferred signed and chose PFD, you could get silent death ;-)
Question about one additional option. We use TRUNC(STD) right now. What w=
ould be have to be aware of if we wanted to switch to TRUNC(OPT) (where I a=
ssume OPT =3D "optimize")? Is OPT fully compliant with COBOL standard trun=
cation rules?
TRUNC(OPT) does not result in any code generated to truncate. it is NOT
COBOL Standard conforming and neither is TRUNC(BIN). You could get more
accurate results with TRUNC(OPT) (along with much better performance) but
I know that for many customers 'more accurate' = 'different' = BAD :-)
Cheers,
TomR >> COBOL is the Language of the Future! <<
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN