# Simple Operations on Processing Tables

The idea of a processing table is simple. It is a place where you write code that controls your program. The code does not have to be complex. When you are starting off, it can be as simple as 4th grade math and it looks just about like that too.

Getting Totals and Balance Due

Probably the most basic thing you would ever want to do is add up the charges on a multi-line invoice and put the total on the screen somewhere. Next, you might want to take a payment against this charge and show the balance due after the payment. Here is the INPUT processing table that will do this.

We will assume that fields 5 through 14 are the ten charge amount fields on an invoice record. We will let field 15 be the subtotal of those charges, 16 be the tax amount and 17 be the total charges (the addition of the subtotal and the tax). Field 18 will be the total payment received, and field 19 will be the balance due field.

Filename: classinv

Number | -----------Field Heading----------- | Len | --Type--
1 | Acct. Code | 6 | allup
2 | Date | 8 | mdy/
3 | Invoice# | 6 | .0
4 | Status | 1 | allup
5 | charge_1 | 7 | .2
6 | charge_2 | 7 | .2
7 | charge_3 | 7 | .2
8 | charge_4 | 7 | .2
9 | charge_5 | 7 | .2
10 | charge_6 | 7 | .2
11 | charge_7 | 7 | .2
12 | charge_8 | 7 | .2
13 | charge_9 | 7 | .2
14 | charge_10 | 7 | .2
15 | subtotal | 8 | .2
16 | tax | 7 | .2
17 | total_charge | 8 | .2
18 | payments | 8 | .2
19 | balance_due | 8 | .2

Key segment record length: 130

Screen.1

CLASSINV -----------------------------------------------------------------

Acct. Code: *1 |  |  |
Date: *2 |  |  |
Invoice#: *3 |  |  |
Status: *4 |  |  |
charge_1: *5 |  |  |
charge_2: *6 |  |  |
charge_3: *7 |  |  |
charge_4: *8 |  |  |
charge_5: *9 |  |  |
charge_6: *10 |  | subtotal: | *15
charge_7: *11 |  | tax: | *16
charge_8: *12 |  |  | ========
charge_9: *13 |  | total_charge: | !17
charge_10: *14 |  | payments: | *18
|  | balance_due: | !19

The processing to do simple calculations begins with math operators. These are the +, -, * and / operators you learned in grade school. FilePro can add, subtract, multiply and divide just about anything. The difference is, you are usually adding, subtracting and dividing the "contents" of a field, you do not need to know the value in the field, just specify the fields and where you want to place the "answer". In other words if you want to total up 5 fields and put the "answer" into a 6th field just write it out the way you would any math statement. 8=1+3+92 just remember that you are adding up the contents of fields 1, 3 and 92 not adding "1", "3" and "92". Although filePro can certainly do math on real numbers, you just have to put real numbers inside quotes, otherwise it will think you are talking about a real field.

File Name: classinv
Processing_tables Table: input

If:
Then: end

Totals If:
Then:
If:
Then: 15=5+6+7+8+9+10+11+12+13+14
Then: total_charge = subtotal+tax
Then: balance_due = total_charge payments
Then: display
Then: return

@wlf4 If:
Then: gosub totals ; end

@wlf5 If:

Then: gosub totals ; end

@wlf16 If:

Then: gosub totals ; end

@wlf18 If:

Then: gosub totals ; end

Date Math

FilePro can also do math on dates. If you take one date and subtract another from it, filePro will tell you how many days there are between those two dates. Or, if you add a real number of days to a date, filePro will tell you the resulting date. For example:

If:
Then: aa(8,mdy/) = @td + "30"

This will put the resulting date into the dummy variable aa. We know we are going to end up with a date so we give aa a date type edit at the same time that we put it on the left side of the equals sign. If you have code on a "then" line that has an equals sign in it, filePro will ALWAYS take the value it determines is on the right side of the equals sign and assigns it to become the value of whatever field is on the left side of the equals sign. This is ALWAYS true. Even when it may not look right to you. If you are used to algebra, the following would look very wrong, but it works just fine in fielPro.

If:
Then: aa = aa + "3"

How can aa be equal to itself plus "3". That is not what this says in filePro processing terms. To filePro, this means "take whatever value is currently in aa, add "3" to it and stuff this new value into aa. The next time filePro looks at aa, it will be 3 higher than it was before this "then" line was encountered. If you understand this, you understand just about all there is to making filePro do all its tricks.