If we consider the following code snippet.
CustSalesQty _temp1,_temp2;
_temp1.IntQty=100;
_temp1.CustAccount =”Cust00001″;
_temp1.insert();
_temp1.IntQty=200;
_temp1.insert();
_temp1.IntQty=300;
_temp1.CustAccount =”Cust00003″;
_temp1.insert();
while select * from _temp1
{
_temp2.data(_temp1);
_temp2.insert();
}
while select * from _temp2
{
info( ” _temp2 with ” + _temp2.CustAccount + ” ” + int2Str(_temp2.IntQty));
}
}
You can check that when we insert the temp1.inQTY=200, We did not set Customer account. At result record new record will insert with customer Cust00001 . You can see output of above code
Point is simple, We need to initialize the table before populate for next values. I found this scenario in custom Inventory reports. When we populate data in different fields based on issue status.
You can set initialized values after ate in side query execution loop. But that piece of code belongs to specific location.
Microsoft provide the out of the box base initValue method. You can add this method by following way.
Best practices says you have to initialize value in this method. And call this method with table reference. This way initialization is table dependent not class dependent.
So we can over write the code as follow
public class CustSalesQty extends common
{
/// <summary>
///
/// </summary>
public void initValue()
{
super();
this.IntQty =0;
this.CustAccount =””;
}
}
Now above code snippet will works as
class Job123
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = “_args”>The specified arguments.</param>
public static void main(Args _args)
{
CustSalesQty _temp1,_temp2;
_temp1.initValue();
_temp1.IntQty=100;
_temp1.CustAccount =”Cust00001″;
_temp1.insert();
_temp1.initValue();
_temp1.IntQty=200;
// _temp1.CustAccount =”Cust00002″;
_temp1.insert();
_temp1.initValue();
_temp1.IntQty=300;
_temp1.CustAccount =”Cust00003″;
_temp1.insert();
while select * from _temp1
{
_temp2.initValue();
_temp2.data(_temp1);
_temp2.insert();
}
while select * from _temp2
{
info( ” _temp2 with ” + _temp2.CustAccount + ” ” + int2Str(_temp2.IntQty));
}
}
}