passing a temp table from a form to a report

Hi all. I’m working on a project where I am populating a temp table via X++ code on a form, and I want to pass that data into a (MorphX) report so I can print it. I’ve got the code working fine, by copying the data into a RecordSortedList, but I’m curious as to whether or not there would be a cleaner way to do this. The way I’m doing it, I have to loop through the temp table to copy it to the RecordSortedList, then later loop through the RecordSortedList and feed it to the report.

Here’s the code that executes on my form, when the user presses ‘print’:

RecordSortedList list;
Args rptArgs;
ReportRun reportRun;

// (myTempTable has already been populated.)
list = new RecordSortedList(tablenum(myTempTable));
list.sortOrder(fieldNum(myTempTable, Field1), fieldNum(myTempTable, Field2));

while select * from myTempTable
order by myTempTable.Field1, myTempTable.Field2
{
list.ins(myTempTable);
}

rptArgs = new Args(reportStr(MyReportObject));
rptArgs.object(list);
reportRun = new ReportRun(rptArgs);
reportRun.init();
reportRun.run();

And here’s the code from my report:

public class ReportRun extends ObjectRun
{
RecordSortedList inputList;
}

public void init()
{
super();
inputList = element.args().object();
}

public boolean fetch()
{
boolean moreData;
MyTempTable myTempTable;

moreData = inputList.first(myTempTable);
while (moreData)
{
element.send(myTempTable);
moreData = inputList.next(myTempTable);
}

//ret = super();
return true;
}

As I said, this works fine. I’m just curious if I’m doing this the hard way.

[8-)]

The question is what you need to do with that. If you don’t need to store the data (e.g. for batch processing), you could pass the temporary buffer directly to your form and iterate it by while select. You can simplify things even more by passing the temporary buffer to report’s query by setRecord().

If you want to use temporary table but not the same buffer, create a new one and copy data with the help of data() method.

If you need to store the data, you should consider using a persistent table (especially if the buffer may contain many records).

Thanks Martin. I played around with this a bit this morning, and simplified it a bit. Here’s what the code on the form looks like now:

Args rptArgs;
ReportRun reportRun;

// (myTempTable has already been populated.)
rptArgs = new Args(reportStr(MyReportObject));
rptArgs.record(myTempTable);
reportRun = new ReportRun(rptArgs);
reportRun.init();
reportRun.run();

And here’s the code from the report:

public class ReportRun extends ObjectRun
{
MyTempTable myTempTable;
}
public void init()
{
super();

if (element.args().record() && element.args().dataset() == tableNum(MyTempTable))
myTempTable = element.args().record();
else
throw error(“useful error message here.”);
}
public boolean fetch()
{
boolean ret;
SysQueryRun sysQueryRun;

sysQueryRun = new SysQueryRun(this);
sysQueryRun.setRecord(myTempTable);
sysQueryRun.interactive(false);

ret = super();
return ret;
}

It was such a useful post that i thought i would thank u

well… Thank you! [Y]