Page 1 of 1

[RPG] offline - show the result of the calculation

Posted: Fri Oct 28, 2016 4:06 pm
by MegumiSawada
Hi,

The customer use offline formview and there's a table element on it to show data from local database table.
That table has 3 columns, for example, as follows:
Col%1 --> CONTENT.TEXT.&( FLD: NUMBER1 )
Col%2 --> CONTENT.TEXT.&( FLD: NUMBER2 )
Then in Col%3, they would like to show the result of the calculation of (NUMBER2 - NUMBER1).

I don't know how to do this...Could I have your advice please?

Everytime the user changes the value of Col%1 or Col%2, the Col%3 value should be changed.
I'm not sure if it is possible or not...

I appreciate your kind advice.

Thank you in advance!

Best Regards,
Megumi Sawada

Re: [RPG] offline - show the result of the calculation

Posted: Mon Oct 31, 2016 8:11 am
by tsupartono
Yes it's possible to do that.

Your column 3 should bind to an SQL statement that calculates the diference between the two fields, like so:

Code: Select all

     A                                       Col%3 +
     A                                       ( +
     A                                         Type: Label +
     A                                         Content.Text.&.SQL:
     A                                         "SELECT &(FLD:NUMBER2) - &(FLD:NUMBER1)"
     A                                       )
Then you'd need to tell LR to refresh the form (so that the effective values from the binding are recalculated) when the the value of either textbox A or B has changed, by setting up an OnValueChanged handler for both NUMBER1 and NUMBER2 column. An example of setting it up for NUMBER1 column:

Code: Select all

     A                                         Name: NUMBER1 +
     A                                         Type: TextBox +
     A                                         Content.Value.& ( FLD:NUMBER1 ) +
     A                                         Content.OnValueChange (
     A                                          Operation.Type:RefreshForm)
Note however that data binding works best when you have a moderate amount of data. If you have too many rows in the table (on the form), you'd have a performance issue when binding to SQL statements in conjunction with frequent form refresh. In that case, you might be better off with using imperative style (ECL).

Re: [RPG] offline - show the result of the calculation

Posted: Mon Oct 31, 2016 6:25 pm
by MegumiSawada
Hi Tony,

Thank you!
I have confirmed it works as expected!

Best Regards,
Megumi