Wednesday, February 9, 2011

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

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.


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(, "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.

Step 9: Calculating Grand Total.

Group the elements of the body row, and then insert subform by right clicking on data.

Move the table under the subform and Insert a new subform with a text field under it.

After following these steps,

  • From the drop down list "Show" select Calculate
  • Enable FormCalc for the text field "Grand Total" as shown below.

Step 10: Code for Grand-Total

Write the code under the area provided for the text field


Click Enter Script Source Changes + to add the script to your form.

Step 11: Save and activate the form. Execute the form.

The output appears like this:



No comments:

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)


Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive