On 10 Jan 2013 17:45, sjl wrote:
FieldA is defined as 29.4 and FieldB is defined as 9.0. The
following calculation bombs on "Receiver value too small to
hold the result."

Eval FieldB = FieldA;

I know that I can switch back into fixed format and use:
Z-ADD FIeldA FieldB

and the value of FieldB will contain a truncated value if FieldA is
too large to fit in FieldB. However, is there a way to accomplish
this in free-form RPG?

I know that this sounds stupid, and please do NOT ask me why I need
to do this.

I was told that if the value won't fit, truncate it, and I just
don't want to junk up my pretty free-form program with fixed-form
code.

With FieldA declared as a decimal numeric 29.4 data type and FieldB declared as any numeric 9.0 data type, the following shows *one way* to accomplish the described, while also maintaining the sign; using a declaration with an overlay of Packed BCD [although adjustable for Zoned decimal but using overlay start position 17 versus 9; necessary if FieldA has even vs odd precision], and the target data type can be any numeric 9.0 type:

D* The following two declared for convenience, for the example
D FieldB S 9B00
D FieldA S 29P04
D* These declarations map last 5 bytes of a 25P00 as 09P00
D FldAds DS
D FldA25 25P00
D FldA09 9P00 overlay(FldA25:9)

// Packed
// 1234567890123456789012345F
// 1122334455667788123456789F [last 5 bytes are 9P00]
// Zoned [last 9 bytes are 9S00]
// F1F2F3F4F5F6F7F8F9F0F1F2F3F4F5F6F7F8F9F0F1F2F3F4F5
// F1F2F3F4F5F6F7F8F9F0F1F2F3F4F5F6F1F2F3F4F5F6F7F8F9

// simple, subtle assignment per declaration with overlay
FldA25=FieldA; // truncate and set overlaid
FieldB=FldA09; // set value from overlay declare

// Or make the assignments more obvious, but more complex:
if %abs(FieldA)>=1000000000; // overflow
FldA25=FieldA; // truncate and set overlaid
FieldB=FldA09; // set value from overlay declare
else; // overflow is not an issue
FieldB=FieldA; // set value from original
endif;


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.