Calculating Page-wise Sub-Totals and Grand Total in Adobe forms

By Nisrin Pindwarawala, YASH Technologies

This Tutorial focuses on how to calculate Page-wise Sub-Totals and Grand Total in Adobe forms using JavaScript. 

In this demo, we will work with table 'SFLIGHT' and calculate Sub-totals and Grand total for the field 'PRICE'. 

Step 1: Go to Transaction SFP and Create an Interface. 

 

Step 2: Add the internal table it_sflight in global data  

 

Step 3: In the Code Initialization part, fetch records from sflight into internal table it_sflight. 

SELECT *
       FROM SFLIGHT INTO TABLE IT_SFLIGHT
       UP TO 50 ROWS.

 

Step 4: Save and activate the interface. 

Step 5: Go to transaction SFP and create a form. 

 

Step 6: In the context part of the form drag and drop the table sflight from global data of interface area to the context area and deactivate the field which we don't require in the layout. 

 

Step 7: Create a table by drag n drop from library on to the layout. Include one header row and footer row in the table. 

 

 

Enter the name of the field you want to display in the header row of the table.

 

Move the table fields from the table by drag n drop from Data View Palette on to the body row of the table, which we have created. In the footer row insert a text field in the last column from the library as shown below. 

 

Step 8: Calculating Sub-Total for field price. 

Firstly enable JavaScript for the text field, which we created in footer row.

We can achieve this by selecting,

  • Select "Events with Scripts" in the Show drop down list
  • Select "JavaScript" in the Language drop down list
  • Run at: "Client" as shown below.

 

Write this code in the area provided under these selection boxes. 

var fields = xfa.layout.pageContent(xfa.layout.page(this)-1, "field", 0);
var total = 0;
for (var i=0; i <= fields.length-1; i++) {
if (fields.item(i).name == "PRICE") {
total = total + fields.item(i).rawValue;
}
}
this.rawValue = total;
Click Enter Script Source Changes + to add the script to your form.

 

The value tab of the text field has to be set as below.

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image