Design your PMK and add the following item to the sub-totals section
call('var','s',1+call('var','g','','real1'),'real1')
[this adds 1 to an external varible called "real1" (that is set up
by
the VAR function) every time a sub-total is printed - luckily it is
"recursive"]
then add the following to the Totals section
call('var','g','','real1')
[this prints the value of "real1" at the end of the report
It is also advisable to add
call('var','s',0,'real1') in the totals section, below the
other one, so that "real1" is reset to zero at the end of thre printout,
otherwise it might not be zero when you repeat the printout straight
away.
You can use it in any section of the report and it should also work
in
SMKs, if you can think of a use! You can also use other variables:
str1, str2, str3, int1, int2, int3, bool1, bool2, bool3, date1, date2,
date3, real2, real3 (but the "int" variable might not work properly)
You will need to "attach" VAR every time you load OA with the intnention
of using the c-call.
To view the SMK you will need to retrieve the joined records using the
COMPOSE QUERY or STORED QUERY function. Calling the SMK from the BROWSE
window will not work becuase the SMK requires joined databases. In the
SMK it is important that the fields from the dummy database are set to
"Dependent" in the EVALUATED section of the field properties - otherwise
you will be prompted to save the changes when you move between records.
A similar trick (having a dummy one record database) can be used in
print masks. The dummy database could even heave a field containing client
specific information for customising the printout.
W1 A |
1 Sat
]
2 Sun
]
3 Mon
] Named range 'DAYNAMES
4 Tue
]
5 Wed
]
6 Thu
]
7 Fri
]
8 Sat
]
2. To use it to provide daynames against a given date, this spreadsheet
must
be linked to the calling spreadsheet as EXTERNAL Channel
#1
(use <menu> Xternal).
In the body of the spreadsheet, use the formula
+VLIST(WKDAY(CCrr),A1#1)
each time the day name is required, where CCrr is the
absolute address
of the cell containing the date in question. Eg
in the following example,
W1 A | B | C | D | E | F | G | H |
11 Tue 08-10-1996
The date is in C11, and the corresponding dayname in B11
is derived by
the formula +VLIST(WKDAY(C11),A1#1)
The Open Access 4 manual (page 276 of Utilities Reference) describes
a C-call VAR.OAC for passing strings and numbers to database print
forms.
One of the questions raised during the August (1993) meeting was along
the lines "how can I print percentages of the grand total against the record
items in a print mask?". The problem is that the printing procedure works
through the records, printing as it goes. Therefore it doesn't "know" the
grand total until the end of the report. A two-pass procedure is required
in order to calculate the grand total then use this in the percentage calculation
for each record.
One of the suggested solutions was to create a one-record dummy database with a number field (to store the grand total) and a blank text field. A blank text field is also added to the source database. Then the OA Database Query is used to join the two databases (via the blank text fields - which must both be key fields) and the Update function is used to set the grand-total field in the dummy database to its value plus the value of the source record. After the Update is finished the grand total field will be the sum of all the source records (see the OA Database manual for a more thorough explanation of this use for the Update command). The dummy database can then be used in the print mask, using the same blank text field to join the databases.
An alternative solution is to use the VAR C-call under Programmer. First include the following item in the print mask, in order to print a percentage value:
100*amount/(call('var','g','','real1')+0.0001)
This "gets" a value called "real1" from an area in memory set aside
by the C-call. Incidentally, the 0.0001 is a lazy way of trapping divide-by-zero
errors. Now load the Programmer and type in the following program:
Save the program ([F2]S). Now just press [Alt F10] to run the program.
First it retrieves the desired records. Then it calculates the grand total
and passes this value to the C-call. Finally it prints the retrieved records
via the print form which uses the C-call value "real1" to calculate
percentages.
The 'g' and 's' parameters in the C-call refer to "store" and "get".
Note that the OA4 manual contains an error - the SETORGET parameter is
not Boolean - it must be 'g' or 's'.
The 's' option of the C-call also works in a print mask (or database
screen mask!) therefore there is another method for obtaining our grand
total in order to work out percentages. The trick is to have a "store"
C-call at the end of the print form in the totals section and to run the
print form twice. For example, the totals section could have:
"sa":sum(amount)
call('var','s',sa,'real1')
This assigns the grand total to the "real1" variable in the C-call.
First you will need to "attach" the VAR C-call using the Utilities/Language_call
selection from the Main Options Menu. Then "print" the report to the screen.
If the print form is now printed a second time (to paper!) the grand total
will be passed to the formula in the record section.
Notice: Users should not act solely on the basis of the material
contained in this document. Items contained in this document are
presented as possible solutions to problems but do not
constitute advice. In particular, no assurance can be given that
the possible solutions will work in every situation or that loss
of data will not occur. Always back-up data before trying to
rectify a problem.