× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Great,

I'd assumed that if the variable that was to contain the result of the
program call was smaller than the size that the return variable was
declared to be on the prototype then the program would fail. But it
seems from what you're saying that as long as the result field is large
enough to store the physical result of the calculation the declaration
of the precision and scale of the return variable on the prototype is
immaterial (except for putting a constraint on the maximum possible
value that can be returned) ie.

If:

D answer1 S 5 2
D answer2 S 4 2

And procedure CalculateAnswer is prototyped to return a (31, 9) decimal
but on this particular call the physical value returned is 234.45

Then:

Answer1 = CalculateAnswer(); ->Success
Answer2 = CalculateAnswer(); ->Fail

That's exactly what I needed to know. Thanks all for your help. Much
appreciated.

Steve

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of
J.Beckeringh@xxxxxxxxxxxxxxxxxxxxxxxxxx
Sent: Monday, 7 September 2009 2:18 PM
To: RPG programming on the IBM i / System i
Subject: RE: Numeric parameters and return values for utility procedures

Steve,

Why do you need temp? Why not:

Monitor
answer = CalculateRate(19.4:3245.5623);
On-Error RESULT_OVERFLOW;
ReportError(Result to Large)
EndMon;

Another option is passing length and precision as parameters:
answer = CalculateRate(19.4:3245.5623:%len(answer):%decpos(answer));
The function than has to calculate maximum (and minimum) values and
check
whether the result is valid. You can make the parameters optional and
assume default values when they are not passed.

Joep Beckeringh


rpg400-l-bounces@xxxxxxxxxxxx wrote on 07-09-2009 04:33:02:

Am I right in assuming you are suggesting that in the calling
program declare a temp field of size of 31, 9. Use this with the
utility function and finally copy the data returned in the temp
field into the real variable ie. A var of size 14, 4 (or any other
size 10, 3 or 7, 4 etc)

For example:
Calling Program:
D answer S 14, 4
D temp S 31, 9

temp = CalculateRate(19.4:3245.5623);
Monitor
answer = temp;
On-Error RESULT_OVERFLOW;
ReportError(Result to Large)
EndMon;

I think that seems to work how I would like. Cheers.

I would be interested to hear what other methods people would
suggest? I'm starting to think if I wanted it to be completely
modular and completely independent of precision and scale (and avoid
temp fields) I would need to declare a standard decimal precision
across the board ie. All decimal variables are declared to be 31, 9
(much like Java/C# etc does in the background with it's standard
variable type anyway). Due to legacy apps this isn't really an
option so I think Chandana's suggestion is a good compromise.

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.