Problem source: http://community.jaspersoft.com/questions/851148/loop-jasper
The calculation of loan payments according to loan amount will involve loop operation and inter-row operation. It is difficult to write code for it using stored procedure or Scriptlets. Yet with the help of esProc, the Jasper calculation will become easier. Here is an example.
The following esProc code is used for preparing the data:
A1: Execute SQL to retrieve records from loan.
A2: Add two computed columns – mRate (monthly rate) and mPayment (monthly payment) to A1. Below is the result:
A3: Calculate payment details for each term based on loan information. Loop function A2.() calculates A2’s members sequentially, uses “()” to perform computation step by step(steps are separated by commas), and returns the computed result of the expression in the last step. new function is used to create a two-dimensional table. A3’s result is cascade data, as shown below:
A4: Combine the cascade data to create a two-dimensional table containing payment details for each term of every loan amount.
A5: Return A4’s result to the report. A reporting tool will identify esProc with JDBC interface as a normal database.
Below is a preview of the finished report: