There are many ways to compute the actual page number:
There are methods in JavaScript that expect that the page number start with 1 and methods that need the zero-based numbering. We always recommend that you have a closer look inside the documentation to determine which way to go.
The pageContent function, for example, expects the zero-based numbering.
The coding shown in the examples is very close to C or Java syntax.
Above all the syntax is quite different to ABAP.
The keyword FOR is used for loops.
In the example above, the FOR statement uses the iterator i.
The iterator starts with zero, is increased by 1, and ends up with 19.
Of course, it is also possible to start with another number and increase the iterator by different values.
In most cases loops are used as displayed here.
When scripting with JavaScript, use the xfa.resolveNode method to access a field with SOM expressions (for example, for a SOM expression: DATA[2].SEATSOCC).
xfa.resolveNode starts the search at the topand moves down the form hierarchy.this.
resolveNode starts the search at the current object and moves up the hierarchy.
Example for the usage of resolveNode:
To dynamically access subforms like DATA with index numbers, you can build up a dynamic SOM expression as follows:var nIndex = 0;var dynSom = “TAB.DATA[” + nIndex + “].SEATSOCC”;var oData = xfa.resolveNode(dynSom);oData.rawValue = 350;
xfa.resolveNodes can be used to address an “array” or a kind of collection.
In the above example, all rows of the FLIGHTS table are addressed. The result again is an object with subobjects, methods, and attributes.
To iterate the items of this collection, you can use the ITEM subobject.
In the examples above, the FOR statement loops through all the table nodes using the iterator i.
The iterator starts with zero, is increased by 1, and ends up at the end of the table. The loop ends unless the last row has been processed.
Remember the use of the rawValue property. This property references the actual value of a field or object.
Perhaps the most interesting technique for ABAP form developers is the “pageContent” function.
You can use this function to calculate sums per page (subtotals).
In hundreds of SAP forms, there is the need to show subtotals in footer rows. There are cases where the floating content of body pages is highly dynamic, preventing the developer from coding a summing inside the ABAP print program (for example, additional text modules or variable row dimensions and conditional breaks inside tables). Here, there is no chance to calculate subtotals per page beforehand in the printing program.
pageContent is a powerful function to achieve this.