Temporary table
SetTmpData
public void init()
{
dateSearch = systemDateGet();
dateTimeSearch = FcsDateTimeAPI::convertFromDateLocal(dateSearch);
super();
delete_from SPLOperatorReportTmp;
SPLOperatorReportTmp.setTmpData(SPLOperatorReportTmp::FillTable(dateTimeSearch));
}
//we can take a regular table and do it temporary with setTmp()
public void init()
{
super();
SalesLine.setTmp();
salesLine.setTmpData(SPLFillTmpRefTable::populateTmpSalesLineProd(queryRun.query()));
}
//We are using a method of a class, or a method in a table, then the code is executed on the server.
//We need to add on the class the word server : public static server
//In the class or in a table and it return the table.
public static server SalesLine populateTmpSalesLineProd(Query _query)
{
SalesLine salesLine, TmpSalesLine;
boolean canBeProduced;
ProdTableReferences ProdTableReferences;
QueryRun QueryRun;
InventQtyAvailPhysical InventQtyAvailPhysical;
//int i;
;
//On server this does not because pb of rights.
//QueryRun.recordLevelSecurity(true);
TmpSalesLine.setTmp();
QueryRun = new QueryRun(_query);
while(QueryRun.next())
{
salesLine = QueryRun.get(tableNum(SalesLine));
InventQtyAvailPhysical = InventSum::SPLInventQtyAvailPhysical(salesLine.ItemId,salesLine.InventDimId);
if (salesLine.SalesQty > InventQtyAvailPhysical)
{
TmpSalesLine.data(salesLine.data());
TmpSalesLine.doinsert();
}
}
return TmpSalesLine;
}
//Another example with select
//
CustTrans queryDrawnBills()
{
CustTrans custTrans;
CustTransOpen custTransOpen;
CustBillOfExchangeJour custBillOfExchangeJour;
CustTrans tmpCustTrans;
;
// BP Deviation Documented
tmpCustTrans.setTmp();
custTrans.recordLevelSecurity(true);
custBillOfExchangeJour.recordLevelSecurity(true);
custTransOpen.recordLevelSecurity(true);
while select custTrans
exists join custBillOfExchangeJour
where custBillOfExchangeJour.BillOfExchangeId == custTrans.BillOfExchangeID &&
custBillOfExchangeJour.Status == CustVendNegInstStatus::Drawn
exists join custTransOpen
where custTransOpen.RefRecId == custTrans.RecId
...............
{
tmpCustTrans.data(custTrans);
tmpCustTrans.insert(); //doinsert is better without check
}
return tmpCustTrans;
}
//ex in a form :
{
WMSOrder wmsOrderFile;
;
wmsOrderFile.setTmp();
wmsOrderFile.setTmpData(wmsOrder);
while select wmsOrderFile
{
wmsOrderDB = WMSOrder::find(wmsOrderFile.OrderId);
wmsOrderDB.updateShipment(wmsShipment, wmsOrderFile.Qty);
}
}
Find
//In a temporary table we need to pass the temporary table as an argument
static SPLAvailabilityUpdateArrayTmp Find(SPLAvailabilityUpdateArrayTmp _splAvailabilityUpdateArrayTmp,
SPLPsDate _DateTime)
{
select firstonly _splAvailabilityUpdateArrayTmp
index hint DateTimeIdx
where _splAvailabilityUpdateArrayTmp.DateTime == _DateTime;
return _splAvailabilityUpdateArrayTmp;
}
void clicked()
{
SPLAvailabilityUpdateArrayTmp splAvailabilityUpdateArrayTmp;
splAvailabilityUpdateArrayTmp = SPLAvailabilityUpdateArrayTmp::FillTable(_dateTimeDATE,false); //fill the temporary table
//...
splAvailabilityUpdateArrayTmp = splAvailabilityUpdateArrayTmp::find(splAvailabilityUpdateArrayTmp,splTurbCapacity.DateTime); //find with the table
if (splAvailabilityUpdateArrayTmp)
{
}
}
Example how to fill the table
Static server SPLAvailabilityUpdateArrayTmp FillTable(SPLPsDate _dateTimeDATE,boolean TestCreatedDateTime = false)
{
splAvailabilityUpdateArrayTmp splAvailabilityUpdateArrayTmp;
SPLAvailabilityUpdate splAvailabilityUpdate;
SPLPsDate dateTime,dateTimeMoreDay,dateTimeSave,DateTime_i;
utcDateTime CreatedDateTimeDATE,CreatedDateDateMore1;
int i,j;
date dateDay = systemDateget();
int64 numberHalfHours;
dateTime = _dateTimeDATE;
dateTimeMoreDay = FcsDateTimeAPI::addDay(dateTime,1);
CreatedDateTimeDATE = FcsDateTimeAPI::FCSDateTime2UTCDateTime(dateTime);
CreatedDateDateMore1 = FcsDateTimeAPI::FCSDateTime2UTCDateTime(dateTimeMoreDay);
while select splAvailabilityUpdate
index hint DateIdx
where splAvailabilityUpdate.FromDateTimeAll < dateTimeMoreDay
&& (splAvailabilityUpdate.ToDateTimeAll >= dateTime || !splAvailabilityUpdate.ToDateTimeAll)
&& splAvailabilityUpdate.faultCancel == NoYes::No
&& (!TestCreatedDateTime ||
(splAvailabilityUpdate.DeviationType == SPLDeviationType::Fault &&
splAvailabilityUpdate.createdDateTime >= CreatedDateTimeDATE &&
splAvailabilityUpdate.createdDateTime < CreatedDateDateMore1))
{
[DateTime_i,numberHalfHours] = FcsDateTimeAPI::splGetDifferenceOfHHours_OneDay(splAvailabilityUpdate.FromDateTimeAll,
splAvailabilityUpdate.ToDateTimeAll,
dateTime,dateTimeMoreDay);
if (!numberHalfHours)
continue;
j = SPLTurbCapacity::turbinId2ArrayNumber(splAvailabilityUpdate.TurbinID);
if (!j)
continue;
for (i = 1; i <= numberHalfHours; i++)
{
splAvailabilityUpdateArrayTmp = splAvailabilityUpdateArrayTmp::find(splAvailabilityUpdateArrayTmp,DateTime_i);
if (splAvailabilityUpdateArrayTmp)
{
if (splAvailabilityUpdateArrayTmp.DeviationArray[j])
{
info(strFmt("@SPL881",splAvailabilityUpdate.turbinid,
FcsDateTimeAPI::value2display(DateTime_i)));
}
splAvailabilityUpdateArrayTmp.DeviationArray[j] = splAvailabilityUpdate.DeviationType;
splAvailabilityUpdateArrayTmp.TurbCapArray[j] = splAvailabilityUpdate.ProductionCapacity;
splAvailabilityUpdateArrayTmp.update();
}
else
{
splAvailabilityUpdateArrayTmp.clear();
splAvailabilityUpdateArrayTmp.DateTime = DateTime_i;
splAvailabilityUpdateArrayTmp.DeviationArray[j] = splAvailabilityUpdate.DeviationType;
splAvailabilityUpdateArrayTmp.TurbCapArray[j] = splAvailabilityUpdate.ProductionCapacity;
splAvailabilityUpdateArrayTmp.insert();
}
DateTime_i = FcsDateTimeAPI::addMinutes(DateTime_i,30);
}
}
return splAvailabilityUpdateArrayTmp;
}