[RPG]offline - sum of calculation

Please do not use to report errors- use your regional help desk.
Please mark posts as being for RPG or RDMLX (LANSA) developer.
To subscribe by email, display this forum, scroll to the end and select ‘Subscribe Forum’.
Post Reply
MegumiSawada
Posts: 268
Joined: Tue Feb 19, 2013 5:18 pm

[RPG]offline - sum of calculation

Post by MegumiSawada »

Hi,

I have asked how to show the result of calculation of offline table.
http://longrange.lansa.com.au/viewtopic.php?f=11&t=507

I would like to get the sum of these result and show it as a label on the offline formview.
The vaule should be get when button is clicked on the formview.

Is it possible to implement with offline formveiw?
If yes, could you please let me know how to?

Best Regards,
Megumi Sawada
Attachments
IMG_0163.PNG
IMG_0163.PNG (47.02 KiB) Viewed 4492 times
tsupartono
Posts: 289
Joined: Wed Apr 18, 2012 10:21 am

Re: [RPG]offline - sum of calculation

Post by tsupartono »

Megumi,
If I understand your question correctly, the difference between this and your previous scenario is the trigger, when the calculated values will be displayed, this time the values will be calculated when a button is touched?
If that's the case, you can start with no binding for the calculated column, then as the user touched the "calculate" button, you'd use ECL to change the binding of the calculated column to SELECT number2 - number1.
ECL code snippet:

Code: Select all

lrexec
(
  function() 
  {
    // We are assuming that the calculated column is COL%4 (adjust accordingly)
    // Do NOT change '$3' in the property name below, it indicates data binding
    var p = "form.fields.mytable.col%4.content.value.$3.sql";
    this.q_setProperty(p, ""select &(fld:number2) - &(fld:number1)");
  }
}
MegumiSawada
Posts: 268
Joined: Tue Feb 19, 2013 5:18 pm

Re: [RPG]offline - sum of calculation

Post by MegumiSawada »

Hi Tony,
Thank you for your reply.

I would like to sum up these results when button is clicked.

Mytable.Row%1.Col%4 = 100
Mytable.Row%2.Col%4 = 200
Mytable.Row%3.Col%4 = 300
Mytable.Row%4.Col%4 = 400

Then I would liek to show the result of (100 + 200 + 300 + 400 ), i.e. 1000 as a label above the table.
I don't know how to do it with offline form...

Best Regards,
Megumi Sawada
tsupartono
Posts: 289
Joined: Wed Apr 18, 2012 10:21 am

Re: [RPG]offline - sum of calculation

Post by tsupartono »

There is a solution where the total would be calculated automatically without the end-user having to press a button.

Because the calculated column is NUMBER2 - NUMBER1, so the sum of that calculated values would be SUM(NUMBER2) - SUM(NUMBER1)

Let's say that your table on the form is showing values from a table called VALUES, you can get the sum of the calculated field using this SQL statement:

Code: Select all

select sum(NUMBER2) - sum(NUMBER1) from VALUES
You just need to bind the label that would show the total to this SQL like so:

Code: Select all

     A                                  3 10HTML('Type:Label
     A                                      Value.&.SQL:"
     A                                      select sum(NUMBER2)-sum(NUMBER1)
     A                                      from VALUES
     A                                      "
     A                                      ')         
MegumiSawada
Posts: 268
Joined: Tue Feb 19, 2013 5:18 pm

Re: [RPG]offline - sum of calculation

Post by MegumiSawada »

Hi Tony,

Thank you for your reply.
The user's requirement is a bit more complex, but I think I can make it work based on your advice.
Thank you!

Best Regards,
Megumi Sawada
Post Reply