grzegorz
8th July 2002, 17:18
An interesting example:
I have a table with, let's say, two fields, for instance employee number and salary. I can make a type 2 session to maintain salaries and I can put a variable named, for instance total.salary somewhere on the screen to display a sum of all salaries entered in my table - that is not a problem.
But my user sometimes uses Query option to display a smaller set of employees (but more then one screen, in common) . Of course my user expects that total salary value will be also calculated only for employees matching specified query.
So,my question is: how can it be done?
OmeLuuk
8th July 2002, 17:41
calculate the value in the maintable.io section of your session so that only the retrieved records are in the sum.
grzegorz
8th July 2002, 18:11
Ok, but if there are more rows than one full screen, main.table.io section is not invoked for rows not present on screen. So result is wrong.
NPRao
8th July 2002, 20:32
Hi Grzegorz,
You can possibly do this using the function -
do.all.occ()
Syntax
void do.all.occ( function_name [, ... ] )
Description
This executes the specified function for all occurrences on the current form. When included in the before.choice
subsection of a choice.update.db section, the function is executed only for updated occurrences.
Arguments
function_name The name of the function that must be executed. The function must be of type void.
... Use these optional arguments to pass one or more arguments to the specified function. Use commas (,) to separate the arguments.
Context
4Gl library function.
You can use this function only in 4GL scripts, of types 1, 2, and 3. You can use it in the following event subsections:
before.choice, on.choice, after.choice
before.input, on.input, after.input, check.input
when.field.changes
before.zoom, after.zoom
See also
do.occ(), do.occ.without.update(), on.old.occ()
Example
declaration:
long old_inventory
choice.cont.process:
on.choice:
do.all.occ( update_occurrences, 9999 )
main.table.io:
before.rewrite:
on.old.occ( get_old_inventory )
pctst999.change = pctst999.item - old_inventory
functions:
function void update_occurrences( long new_val )
{
pctst999.special = new_val
}
function void get_old_inventory()
{
old_inventory = pctst999.item
}
Related help topics
Form and form field operations: overview
Form and form field operations: synopsis
© 1998 Baan Development B.V. All rights reserved
You have to write a function to find the totals and code it in the following choice sections so that the function is called when a user uses a filter, page up/down, previous/next record etc.
Standard commands
The following table lists the available standard commands and the types of program in which the various choice subsections can be programmed for each command.
No Choice_option Description Before On After
01 start.set Add/start a new group in main table 1234 ---4 1234
02 first.view View first group of main table 1234 ---4 1234
03 next.view View next group of main table 1234 ---4 1234
04 prev.view View previous group of main table 1234 ---4 1234
05 last.view View last group of main table 1234 ---4 1234
06 def.find Find a specific record on key 1234 ---4 1234
07 find.data Start the set from the current data in the program script. Use: after import of data in a zoom process. (refresh) 1234 ---4 1234
08 first.set View first set of main table 1234 ---4 1234
09 next.set First execute an update.db and then view next set of main table 1234 ---4 1234
10 display.set Open read-only details 1234 ---4 1234
11 prev.set First execute an update.db and then view previous set of main table 1234 ---4 1234
© 1998 Baan Development B.V. All rights reserved
mark_h
8th July 2002, 21:41
I did something like this with one of my sessions. What I did was create a main session where the user input the filter fields, then clicked continue. When they clicked continue it launched a sub-session and used the query.extension to set the filters. When they wanted to change the filters then they just hit the exit key. The users liked this better because it seemed to be quicker than running a query.
I have sinced changed the session to build the sql query. I import filters, build the query and parse it. The only thing you have to remember is that now you control the next record, first record and so on. So when they click on next record I have to rebuild the query. It works really good for my situation.
Not sure if they apply here, but thought I would mention it.
Mark
grzegorz
9th July 2002, 11:21
Thanks a lot, Guru.
Unfortunately function do.all.occ works only on records present on form. So, if there are more records matching specified query then one full screen, total value will be wrong (I tested it). .:confused:
Thanks a lot, Mark.
Your idea is good, but I wonder if any general solution is possible.
Ruskin
10th July 2002, 00:20
Grzegorz,
Have you considered writing your own filter screen. Since you only have a couple of fields and probably only want to filter based on employee number range and possibly salary range, then you could write your own filter screen. Based on what the user enters, you can restrict your query to calculate the totals. For an idea on how to do this run the session tssma3501m000 (Display Service Orders) and click on the 'Selection' button.
This is much the same idea as Mark's option, except that you would call the screen from your main session, in case you don't want to put a filter on your records. Plus, it means, just clicking on a button to change your filter if you so desire.