Master scheduling run for All Items not picking up level 0 items
Master scheduling had been working fine for a number of days following Go-live, but then something happening and a lot of items were not being picked up in the master scheduling run. The symptoms reported by the user was that the process was only running for 10 minutes, where initially it was taking 2 hours to run. Also, no errors were being reported. I suspected a data issue and after a several hours of investigation I finally found the issue. Somehow an InventTable record with a blank ItemId had been created in the database. In the Master Scheduling code that builds the item list for each level there's an If statement that checks the ItemId and if it's blank exits the loop and because this blank item was the first item processed for the level, no items were being selected for this level for the master scheduling run.
take it easy , Following on from the discovery of this issue and the workaround of deleting the blank item from InventTable, the blank item kept reappearing in the database and it was decided to modify the Master Planning code to discard items with a blank ItemId.
select * from InventTable a where a.ItemId = ''
delete from InventTable where ItemId = ''
This was done by making a simple change to the createListsFromQueryRun method of the ReqTransCache_Periodic class which builds the item lists used by master planning.
Remark by Jimmy on May 20th 2011
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/// <summary>
/// Creates the itemSet and inserts record into the ReqProcessItemList and ReqProcessItemListLine tables
/// based on the QueryRun object from the <paramref name="_con"/> parameter.
/// </summary>
/// <param name="_con">
/// Container holding a QueryRun object.
/// </param>
/// <param name="_listSize">
/// Factor for determining the size of the lists.
/// </param>
public void createListsFromQueryRun(container _con, ReqProcessListSize _listSize)
{
QueryRun runQuery = new QueryRun(_con);
ReqProcessItemList reqProcessItemList;
ReqProcessItemListLine reqProcessItemListLine;
InventTable inventTable;
RecordInsertList recordInsertList = new RecordInsertList(tablenum(ReqProcessItemListLine));
Map levelItemMap = new Map(Types::Integer, Types::Class);
Set itemSet;
int itemCount;
MapEnumerator me_level;
SetEnumerator se_item;
int listSize;
int listNum;
boolean createLastList;
void initReqProcessItemList()
{
;
reqProcessItemList.clear();
reqProcessItemList.ProcessId = processId;
reqProcessItemList.Level = me_level.current();
reqProcessItemList.ListNum = listNum;
reqProcessItemList.Status = ReqProcessStatus::Update;
}
;
while (runQuery.next())
{
inventTable = runQuery.get(tablenum(InventTable));
//remark by Jimmy 2011-05-20 --
// Discard any items with a blank ItemId
if (inventTable.ItemId == "")
{
continue;
}
//remark by Jimmy 2011-05-20 --
if (!levelItemMap.exists(inventTable.bomLevel))
{
itemSet = new Set(Types::String);
levelItemMap.insert(inventTable.bomLevel, itemSet);
}
else
itemSet = levelItemMap.lookup(inventTable.bomLevel);
itemSet.add(inventTable.ItemId);
}
ttsbegin;
me_level = levelItemMap.getEnumerator();
while (me_level.moveNext())
{
itemCount = 0;
createLastList = false;
itemSet = me_level.currentValue();
listSize = (maxChildThreads + 1) * _listSize;
if (maxChildThreads > 0 && listSize > (itemSet.elements() / maxChildThreads))
listSize = itemSet.elements() / maxChildThreads;
if (listSize < 1)
listSize = 1;
se_item = itemSet.getEnumerator();
while (se_item.moveNext())
{
reqProcessItemListLine.ProcessId = processId;
reqProcessItemListLine.ListNum = listNum;
reqProcessItemListLine.ItemId = se_item.current();
recordInsertList.add(reqProcessItemListLine);
itemCount++;
createLastList = true;
if (itemCount == listSize)
{
itemCount = 0;
createLastList = false;
initReqProcessItemList();
reqProcessItemList.insert();
listNum++;
}
}
if (createLastList)
{
initReqProcessItemList();
reqProcessItemList.insert();
listNum++;
}
initReqProcessItemList();
reqProcessItemList.Spare = true;
reqProcessItemList.insert();
listNum++;
}
recordInsertList.insertDatabase();
ttscommit;
}