The program prints a list of all customers in the SQL database and their current balances.
record CustomerRecord type SQLRecord
{tableNames = [["ADMINISTRATOR.CUSTOMER", "L1"]],
keyItems = [customerNumber]}
customerNumber STRING {column="C_NUMBER", maxLen=6};
customerName STRING {column="C_NAME", isSQLNullable=yes, maxLen=25};
customerAddr1 STRING {column="C_ADDR1", isSQLNullable=yes, maxLen=25};
customerAddr2 STRING {column="C_ADDR2", isSQLNullable=yes, maxLen=25};
customerAddr3 STRING {column="C_ADDR3", isSQLNullable=yes, maxLen=25};
customerBalance MONEY {column="C_BALANCE", isSQLNullable=yes};
end
package com.companyb.customer;
program reportGenerator type BasicProgram
myCustomer CustomerRecord;
myHandler textReportHandler{};
function main()
myHandler.start(); // passes control to handler
// get customer list from database
open myResults scroll for myCustomer;
forEach (from myResults) // loop through results
myHandler.output(myCustomer.customerName, myCustomer.customerBalance);
end // forEach
myHandler.finish(); // close report
end
end
package com.companyb.customer;
record reportRecord type BasicRecord
customerName STRING;
customerBalance MONEY;
end
handler textReportHandler type BasicHandler
myReport TextReport{}; // creates instance
currentReportRecord reportRecord;
runningTotal MONEY = 0;
function start()
myReport.onEveryRowListener = onEveryRow;
myReport.onLastRowListener = onLastRow;
// accept defaults on everything but destination file
myReport.startReport("D:/temp/customerReport.txt",
null,null,null,null,null,null);
end
function output(cName STRING in, cBal MONEY in)
// this information comes from the forEach loop in the main program
currentReportRecord.customerName = cName;
currentReportRecord.customerBalance = cBal;
runningTotal = runningTotal + cBal;
// pass control to the report engine
// onEveryRow is called
myReport.outputToReport();
end
function finish()
// pass control to the report engine again
// onLastRow is called
myReport.finishReport();
end
function onEveryRow(myEvent TextReportEvent in)
myReport.printText(currentReportRecord.customerName);
myReport.column(40);
myReport.printText(currentReportRecord.customerBalance);
myReport.println();
end
function onLastRow(myEvent TextReportEvent in)
myReport.println(); // skip a line
myReport.printText("All customers:");
myReport.column(40);
myReport.printText(runningTotal);
end
end