Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos

This blog explains about the logic which can be used to print the sum of previous page totals in next page of SAP Adobe forms as “Carry Forward”.

Knowledge on creating simple SAP Adobe forms with a table is required before proceeding with the below logic.

Scenario:

Page1

              Amount
10.11
10.12
10.13
Carry Forward :30.36

Page2

Carry Forward :30.36
Amount
4.00
4.00
2.00
2.00
2.00
Carry Forward :44.36

Page3

Carry Forward :44.36
Amount
1.00
1.00
1.00
1.00
1.00
Carry Forward :49.36

Solution:

1.      1. Create a table with header, body and add a footer row in Form Layout.

2.      2. Give a name ‘ABC’ to the body row cell for which the totaling should be carried out. This cell can be of type Decimal Field. The values for this field ‘ABC’ in body row would be populated from an internal table from driver program. If the internal table has multiple records, the table contents would be flowed to the next page.

3.      3. In the table footer row, create a minimum of two cells ‘DEF’ and ‘GHI’. The Numeric field cell ‘DEF’ (let’s call this Subtotal cell) can be used to hold page-wise subtotal from ‘ABC’ cell (let’s call this value cell). Ensure that the Subtotal cell has Integer as the data format. The Numeric field cell ‘GHI’ (let’s call this Carry forward cell) can be used to hold sum of all subtotals from previous pages and current page.

4.      4. Within the ‘Calculate’ event of Subtotal cell, choose Language as ‘JavaScript’ and Run At as ‘Client’.

Write the below JavaScript code in Script editor:

----- data.ITEM_PAGE1.S1.Table1.FooterRow.DEF::calculate: - (JavaScript, client) -------------------

var fields = xfa.layout.pageContent(xfa.layout.page(this)-1, "field", 0);

var total= new Number;

for (var i=0; i<=fields.length-1; i++)

{

if (fields.item(i).name == "ABC")

{

total = parseInt(total) + parseInt(fields.item(i).rawValue);

}

}

    this.rawValue = total;

In the above code snippet, “xfa.layout.page(this)-1would mean current page. The first line of code would capture all the field names in current page. The second line declares a variable to hold the subtotal. The ‘For’ loop checks if there is a field in current page that matches the name “ABC”. If there is a match, all the values of value cell (ABC) from current page are added into the variable. The last line assigns the calculated subtotal to the subtotal cell “DEF”.

NOTE:  parseIntconverts a variable’s value into integer. Remember that the cell ‘DEF’ is also of type Integer.

5.      5. Within the ‘Calculate’ event of Carry forward cell, choose Language as ‘JavaScript’ and Run At as ‘Client’.

Write the below JavaScript code in Script editor:

----- data.ITEM_PAGE1.S1.Table1.FooterRow.GHI::calculate: - (JavaScript, client) -------------------

var fields = xfa.layout.pageContent(xfa.layout.page(this)-1, "field", 0);

var total= new Number;

for (var i=0; i<=fields.length-1; i++)

{

if (fields.item(i).name == "DEF")

{

total = parseInt(fields.item(i).rawValue);

}

}

    this.rawValue = total;

var fields2 = xfa.layout.pageContent(xfa.layout.page(this)-2, "field", 0);

var total2= new Number;

for (var i=0; i<=fields2.length-1; i++)

{

if (fields2.item(i).name == "GHI")

{

total2 = parseInt(fields2.item(i).rawValue);

}

}

    this.rawValue = total + total2;

In the above code snippet, “xfa.layout.page(this)-1would mean current page. The first line of code would capture all the field names in current page. The second line declares a variable to hold the subtotal. The ‘For’ loop checks if there is a field in current page that matches the name “DEF”. If there is a match, the value of Subtotal cell (DEF) from current page is assigned to a variable called ‘Total’.

xfa.layout.page(this)-2” would mean previous page. ‘Fields2’ would capture all the field names in previous page. The second line declares another variable called ‘Total2’ to hold the sum of subtotals from previous page. The ‘For’ loop checks if there is a field in previous page that matches the name “GHI”. If there is a match, the value of Subtotal cell (DEF) from current page is added to the sum of subtotals from previous page and assigns this to a variable called ‘Total2’. The last line assigns the calculated Carry Forward to the Carry Forward cell “GHI”.

NOTE:  parseIntconverts a variable’s value into integer. Remember that the cell ‘GHI’ is also of type Integer.

6.     6. The sum of subtotals from previous page as Carry forward thus displayed in current page can also be displayed in next page.

7.     7. In Next page, create a Numeric field similar to ‘GHI’. Within the ‘Calculate’ event of this Carry forward cell, choose Language as ‘JavaScript’ and Run At as ‘Client’.

Write the below JavaScript code in Script editor:

----- data.#pageSet[0].Page2.#subform[4].GHI::calculate: - (JavaScript, client) --------------------

var fields2 = xfa.layout.pageContent(xfa.layout.page(this)-2, "field", 0);

var total2= new Number;

for (var i=0; i<=fields2.length-1; i++)

{

if (fields2.item(i).name == "GHI")

{

total2 = parseInt(fields2.item(i).rawValue);

}

}

    this.rawValue = total2;

8.      8. The Carry Forward thus displayed in Next page can be made invisible in last page by adding the below code:

for (var i=0; i<=fields2.length-1; i++)

{

if (fields2.item(i).name == "JKL")

{

    this.presence = "hidden";

}

}

NOTE: In the above code, “JKL” refers to a field name that is displayed in ‘Last Page – 1’.

Labels in this area