SubTotal in report

This is my report I developed this through code but I’m not getting sub totals for each accountNum records.I want the output through code not by setting properties like SumAll = Yes

I wrote this fetch method,

public boolean fetch()

{

Query q;

QueryBuildDataSource qbd,qbd2;

QueryBuildRange qbr;

QueryRun qr;

;

q = new Query();

qbd = q.addDataSource(tablenum(CustTable));

qbd2 = qbd.addDataSource(tablenum(CustTrans));

qbr = qbd.addRange(fieldnum(CustTable,AccountNum));

qr = new QueryRun(q);

while(qr.next())

{

if(custTable.AccountNum == custTrans.AccountNum)

{

custTable = qr.get(tablenum(CustTable));

accountNum = custTable.AccountNum;

element.execute(1);

custTrans = qr.get(tablenum(CustTrans));

amountMST = CustTrans.AmountMST;

element.execute(2);

subtotal = custTrans.AmountMST;

subTotal1 = subTotal1 + subTotal;

element.execute(3);

}

subTotal1 =0;

}

return true;

}

I’m not getting exact output what I want .please help me to solve this ASAP.

In programble section 3 add display method and return the value subtotal1

Hi Saju,

I tried the same what you said but I didn’t get the exact output.

You need to replace that " subTotal1 = 0; " after the loop ends!

Below is an example job, hope this helps you

static void printTotalSubTotals(Args _args)
{
Query q;
QueryBuildDataSource qbd,qbd2;
QueryBuildRange qbr;
QueryRun qr;
CustTable custTable;
CustTrans custTrans;
real subtotal, total;
CustAccount custTableAccount;
boolean printTotal = false;
;

q = new Query();
qbd = q.addDataSource(tablenum(CustTable));
qbd2 = qbd.addDataSource(tablenum(CustTrans));
qbd2.relations(true);
qbd2.joinMode(JoinMode::InnerJoin);

qbr = qbd.addRange(fieldnum(CustTable,AccountNum));
qr = new QueryRun(q);

while(qr.next())
{
custTable = qr.get(tablenum(CustTable));
custTrans = qr.get(tablenum(CustTrans));
if (custTable.AccountNum != custTableAccount)
{
custTableAccount = custTable.AccountNum;
if (subTotal || printTotal)
{
info(strfmt(‘SubTotal - %1’, subTotal));
subTotal = 0;
printTotal = true;
}
info(strfmt(‘Header - %1’, custTable.AccountNum));

}
info(strfmt(‘Transactions - %1’,custTrans.AmountMST));
subtotal += custTrans.AmountMST;
total += custTrans.AmountMST;
}
if (subTotal)
info(strfmt(‘SubTotal - %1’,subTotal));
if (total)
info(strfmt(‘Total - %1’,total));
}

Hi Kranthi,

Thanks for your quick reply.

Problem Solved.