|
Glenn,
I believe you misunderstood the original poster.
I believe what Ewart want's is a way to store the following formulas in a DB
table:
Description Name Formula
------------------- ------- ----------------
Base value Base Qty * price
Tax1 20% of base Tax1 Base * .02
Tax2 30% of Tax1 Tax2 Tax1 * .03
Total Total Base + Tax1 + Tax2
The for instance, in his customer record, there would be a field perhaps called
TAXCALC, that for a
given customer(s) would store the value "Total".
Now when figuring the tax for the given customer, his RPG program would need to
dynamically figure out
that:
Customer's tax = Total
= (Base + Tax1 + Tax2)
= ((Qty * Price) + (base * .20) + (Tax1 * .30))
= ((10 * 100) + ((10 * 100) * .20) + (((10 * 100) * .20) * .30))
= 1260
(note corrected percentages 20% = .2 not .02)
I assume that the OP's example is considerably simplified and that there are
reasons he couldn't just
store a tax rate of 26%
All that being the case, my answer to Ewart is as follows:
As far as I know, RPG doesn't have the built in dynamic capabilities you are
looking for. Basically,
to take a string such as '(10 * 100)' and evaluate it to the numeric value of
1000.
There's two steps to this problem as I see it:
1) Going from 'Total' to '((10 * 100) + ((10 * 100) * .20) + (((10 * 100) *
.20) * .30))'
2) Evaluating '((10 * 100) + ((10 * 100) * .20) + (((10 * 100) * .20) * .30))'
Step one involves basically parsing a string till you get to all numeric or
mathematical operation
characters. This could be done recursively, in RPG IV or some other language.
For step two, you could technically write an RPG procedure or two that would
calculate it. Look
around on the net for examples of writing programs that process "infix"
expressions. Note that
writing this expression evaluator yourself would be considerably simplified if
you used "postfix"
expressions, '10 10 *' instead of "infix" '10 * 10' (Google for infix and
postfix for more info)
However, it may be easier to just use a language that has the dynamic
evaluation capabilities you
need. Dynamic SQL would be one option. The other option would be a language
like Perl that includes
the dynamic evaluation you are looking for.
You might want to look at doing the whole calculation procedure in Perl or
perhaps Rexx has the
capabilities you need.
HTH,
Charles Wilt
Software Engineer
CINTAS Corporation - IT 92B
513.701.1307
wiltc@xxxxxxxxxx
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On
Behalf Of Glenn
Gundermann
Sent: Wednesday, March 14, 2007 8:51 AM
To: RPG programming on the AS400 / iSeries
Subject: Re: Dynamic formulae calculation in RPG
Ewart,
You should keep it simple and easy to read, hence easy to modify and easy to
debug by coding it
exactly how you have it written down in your
requirements:
/free
Base = Qty * Price;
Tax1 = Base * .02;
Tax2 = Tax1 * .03;
Total = Base + Tax1 + Tax2;
/end-free
You could of course make it impossible for the next programmer to understand
what you are doing:
/free
Total = Qty * Price * 1.0206;
/end-free
Glenn Gundermann
ggundermann@xxxxxx
(647) 272-3295
Hello All, We have a complicated Invoice calculation process where a lot local taxes are to be considered. In order to make these calculations dynamic I plan to do the calculations using dynamic formulas so that any future changes can be considered. Eg: Description Name Formula Value Base value Base Qty * price 1000 Tax1 20% of base Tax1 Base * .02 20 Tax2 30% of Tax1 Tax2 Tax1 * .03 0.6 Total Total Base + Tax1 + Tax2 1020.6 Has anyone built something like that & can share the code - I can save some time. Thanks & best regards Ewart
-- This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l. This e-mail transmission contains information that is intended to be confidential and privileged. If you receive this e-mail and you are not a named addressee you are hereby notified that you are not authorized to read, print, retain, copy or disseminate this communication without the consent of the sender and that doing so is prohibited and may be unlawful. Please reply to the message immediately by informing the sender that the message was misdirected. After replying, please delete and otherwise erase it and any attachments from your computer system. Your assistance in correcting this error is appreciated.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.