cancel
Showing results for 
Search instead for 
Did you mean: 

Error in calculation "total" for multiple line items

Former Member
0 Kudos

Hi Friends,

I am currently facing an issue in calculating "total" value  for multiple line items in a single field in form(SFP).

I want to populate the total of (qty, unit cost, labor, material, reins ) automatically according to the number of rows displayed,

The problem is in the total it is displaying only the first row.. the same is replaced with the remaining

Can anyone please let me know to display the total for all line items getting displayed

Refer the attached screenshots

Plz provide your valuable help

Regards

Sona

Accepted Solutions (1)

Accepted Solutions (1)

pavan_prabhu
Active Participant
0 Kudos

Hi Sonakshi,

     The code written by you always fetches for only the first instance of the record  For example you have written it as

var qty = data.Estim_Report.MainsDetails.Table1.Row3.QUANTITY;---> This is for Quantity.

The problem in above code is you are always fetching the first record(DATA.*)and also there is no way you can provide the index at the design level.

Hence the subsequent row totals are not getting replaced but simply assigned the value of first record.

So do not traverse the node starting from DATA. Do it at the record instance level. Because here you are sure that the respective field values are fetched for all the records.

Write the below Java script code on the TOTAL1 field of DATA subform in the Initialize event. This will work.

TOTAL1 field of DATA subform

this.rawvalue = Number ( this.parent.QUANTITY.rawvalue ) +

                         Number ( this.parent.LABOUR.rawvalue ) +

                         Number ( this.parent.MATERIAL.rawvalue ) +

                         Number ( this.parent.REINSTATEMENT.rawvalue ) ;

Note: Here THIS.<FIELDNAME> refers to column value of current row.

Former Member
0 Kudos

Hi Pavan,

Thanks so much for your prompt reply, its working for me now..

But i am now facing other issue .........need your help on this also...........I tried searching some posts but it didnt help..

In the below screenshot can u please look into it and help me out?

gist: How to calculate total for particular field "labour"

Regards

Sona

pavan_prabhu
Active Participant
0 Kudos

Hello Sonakshi,

     It depends on how you are showing the total of Labour. There are 2 cases usually.

Case 1: If you are showing it only once(Grand total) in whole form, then simply declare a variable in Interface. You will know the Labour values since they will be stored in an internal table. So do the calculation in ABAP itself and send it to form. Then bind that variable value to this TOTAL text field in Layout.

Case 2: If you are showing it as a sub total on each page, then declare a global variable in layout and in READY LAYOUT write a Javascript code to add all Labour values on each page and bind that global variable to this TOTAL text field in Layout. At the end of each page, clear this global variable.

Answers (0)