Counting records

Counting the record set returned by a query is a frequent task in tailoring. Instead of fetching each record in a loop, you can use the ITSMA Service Management rtecall("count") more efficiently.

Recommended implementation using the doCount() method

function countFile(filename, query)
{
var file = new SCFile( filename );
var nCount = file.doCount( query );
var rc = getLastRC();
if (RC_SUCCESS == rc)
{
return nCount;
}
else
{
print( "Could not count records. " + RCtoString( rc ) );
return -1;
}
}
Recommended implementation using system.functions.rtecall("count"):
function countFile(file)
{
var iTotal= new SCDatum();
var returnCode = 1;
 
system.functions.rtecall("count", returnCode, file, "", iTotal);
 
return iTotal.getText();
}