Thanks Kevin. I'd been trying a number of solutions for quite a while so I
guess I was starting to lose sight of even the basics. Thanks for refreshing
my brain...

Looks like I might stick with the zoned solution as I'd ideally want to have
a variable whose size is defined at runtime.

Thanks again,

2009/12/13 Kevin Wright <Kevin.Wright@xxxxxxxxxxxx>

Hi Erik,

dec(31,31) will not hold a value greater than

You may want to use dec(31,15) say which will hold 16 digits before the
decimal point and 15 digits after the decimal point.

dec(n,p) means a decimal that will hold (n - p) digits before the decimal
point, and p digits after the decimal point.

A search of the C400-L archives should reveal a few instances of this or
similar questions. The fine manual should also give the definition.


Kevin Wright

-----Original Message-----
From: Erik Olsson [mailto:erik.eo.olsson@xxxxxxxxx]
Sent: Monday, 14 December 2009 9:39 AM
To: C programming iSeries / AS400
Subject: [C400-L] Casting dynamically to packed decimal

What I'm trying to accomplish is convert a void ptr (that's actually a
packed decimal) to a character representation of the pointed to packed
decimal value.

The natural way for me would be to cast the void ptr to a packed decimal
then sprintf the decimal variable. But to do that I need to declare a
decimal variable that can hold any valid decimal values and the compiler
demands that the digits and precision are known at compile time.
Declaring one that holds the maximum values (that is, DEC_DIG and
DEC_PRECISION when using the C++ bcd.h file) and casting the void ptr into
that does not give the right result:

Using static_cast to cast say a dec(7,0) into dec(31, 31) results in
(1 seems to become 0.00000000000...1) when I sprintf it.
Using cpynv to do the same thing crashes with MCH1210 (Receiver value too
small to hold result.).

This doesn't really make sense to me as a dec(7,0) should fit nicely into a

Using cpynv to convert directly to a zoned decimal works, but I'd really
like to get the same visual result as sprintf-ing a packed decimal, that is
no leading zeroes, a decimal point... that kind of look.

Any suggestions would be most welcome.

This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives

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-2021 by 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.