Consultor Eletrônico



Kbase 13287: SAMPLE CODE BROWSE WIDGET on expression calculated value
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   2/10/1999
SAMPLE CODE BROWSE WIDGET on expression calculated value

Description of the problem:

The developer wants to browse WITH BROWSE WIDGET records, and on
the same rows' calculated data based on more complicated
procedures than is possible with expressions.

For example, browse the prices of ITEM CONSTRUCTIONS, which
cannot be with simple FOR EACH joins.

There are thousands of records to browse, and so joining to a
prebuilt TEMP-TABLE doesn't work.

One "solution" is to join rows into a work-table, but keep the
work-table so short that it includes only visible rows of the
browse. Keep this WORK-TABLE in sync with some kind of
trigger-system, which includes all changes of visible rows.

For Progress versions up to 8.1, a more practical solution follows:

Make a FIND Trigger to update a result field and put this field
in the browse.

/****************************************************************/
define button but-done label "Done".

DEF VAR Lu AS DECIMAL.

ON FIND OF Customer DO:
/* You can have very complicated code here */
Lu = Customer.Credit-Limit - Customer.Balance .
END.


open query tran-q for each customer.

define browse tran-b query tran-q exclusive-lock
display customer.name
customer.cust-num

/* Expression, to which you can compare the results */

Customer.Credit-Limit -
Customer.Balance LABEL "Compare list"

/* Field calculated by a trigger */
Lu LABEL "Field by trigger"
with 10 down width 78 .

define frame brs-frm
tran-b skip(1)
but-done.

enable all with frame brs-frm.

wait-for choose of but-done in frame brs-frm
focus tran-b in frame brs-frm.

close query tran-q.

This same solution can be implemented via the UIB as follows:

The FIND trigger must be placed in the Main Block section of code,
since tables are not among the objects to pick from in the Section
Editor in the Triggers section.

The variable to hold the calculated value may be defined in the
Definitions section.

The calculated field is placed in the browse by clicking on
Fields->Calculated Field in the browse's Property Sheet.

For a "regular" browse widget, the expression in this example would be
entered as:
Lu
For a SmartBrowse, the expression would be:
Lu @ Lu
(See kbase 15050,
"How to refer to a calculated field in a SMART BROWSER")

With the introduction of User-Defined Functions in Version 8.2, this
can be done without using triggers.

Simply define a function Lu as follows:

FUNCTION Lu RETURNS DECIMAL
(input creditlimit as decimal, input balance as decimal) :

/* Again, more complicated code can be used here */
RETURN creditlimit - balance.
END FUNCTION.

And in the browse's calculated field, enter:
Lu(customer.credit-limit,customer.balance)

For a Smartbrowse:
Lu(customer.credit-limit,customer.balance) @ Lu

Any of the above approaches can also be used to include a second tab
in a browse without using a joined query, so that INDEXED-REPOSITION
may be used to improve query performance.

Progress Software Technical Support Note # 13287