public void copyNumberSequence()
{
NumberSequenceScope fromNumberSequenceScope, toNumberSequenceScope;
NumberSequenceTable fromNumberSequenceTable, toNumberSequenceTable;
NumberSequenceReference fromNumberSequenceReference, toNumberSequenceReference;
//mk
Map mapKeyValue;
MapEnumerator enumer;
MapIterator mapIter;
int64 iCurrentKey;
int64 sCurrentValue;
while select fromNumberSequenceScope
where (fromNumberSequenceScope.LegalEntity == CompanyInfo::findDataArea(fromCompany).RecId ||
fromNumberSequenceScope.DataArea == fromCompany)
{
try
{
ttsBegin;
toNumberSequenceScope = NumberSequenceScope::findByNaturalKey(
toCompany,
CompanyInfo::findDataArea(toCompany).RecId,
fromNumberSequenceScope.OperatingUnit,
fromNumberSequenceScope.FiscalCalendarPeriod,
fromNumberSequenceScope.OperatingUnitType);
if ((fromNumberSequenceScope.LegalEntity || fromNumberSequenceScope.DataArea) && !toNumberSequenceScope)
{
toNumberSequenceScope.clear();
toNumberSequenceScope.data(fromNumberSequenceScope);
if (toNumberSequenceScope.LegalEntity)
{
toNumberSequenceScope.LegalEntity = CompanyInfo::findDataArea(toCompany).RecId;
}
if (toNumberSequenceScope.DataArea)
{
toNumberSequenceScope.DataArea = toCompany;
}
toNumberSequenceScope.insert();
mapKeyValue = null;
mapKeyValue = new Map(Types::Int64,Types::Int64); //mk
while select fromNumberSequenceTable
where fromNumberSequenceTable.NumberSequenceScope == fromNumberSequenceScope.RecId
{
if (!NumberSequenceTable::findByNaturalKey(fromNumberSequenceTable.NumberSequence, toNumberSequenceScope.RecId))
{
toNumberSequenceTable.clear();
toNumberSequenceTable.data(fromNumberSequenceTable);
toNumberSequenceTable.NumberSequenceScope = toNumberSequenceScope.RecId;
toNumberSequenceTable.NextRec = toNumberSequenceTable.Lowest;
toNumberSequenceTable.insert();
if (!mapKeyValue.exists(fromNumberSequenceTable.RecId))
{
mapKeyValue.insert(fromNumberSequenceTable.RecId,toNumberSequenceTable.RecId); //mk
}
}
}
enumer = null;
while select fromNumberSequenceReference
where fromNumberSequenceReference.NumberSequenceScope == fromNumberSequenceScope.RecId
{
if (!NumberSequenceReference::findNaturalKey(toNumberSequenceScope.RecId, fromNumberSequenceReference.NumberSequenceDatatype))
{
toNumberSequenceReference.clear();
toNumberSequenceReference.data(fromNumberSequenceReference);
toNumberSequenceReference.NumberSequenceScope = toNumberSequenceScope.RecId;
enumer = mapKeyValue.getEnumerator();
iCurrentKey = 0;
sCurrentValue = 0;
while (enumer.moveNext())
{
iCurrentKey = enumer.currentKey();
if (fromNumberSequenceReference.NumberSequenceId == iCurrentKey)
{
sCurrentValue = enumer.currentValue();
//info(strFmt("Key: %1 and Value %2",iCurrentKey,sCurrentValue));
break;
}
}
if (sCurrentValue != 0)
{
toNumberSequenceReference.NumberSequenceId = sCurrentValue; //mk
}
toNumberSequenceReference.insert();
}
}
}
ttsCommit;
}
catch
{
warning("Error copying number sequence");
}
}
}
{
NumberSequenceScope fromNumberSequenceScope, toNumberSequenceScope;
NumberSequenceTable fromNumberSequenceTable, toNumberSequenceTable;
NumberSequenceReference fromNumberSequenceReference, toNumberSequenceReference;
//mk
Map mapKeyValue;
MapEnumerator enumer;
MapIterator mapIter;
int64 iCurrentKey;
int64 sCurrentValue;
while select fromNumberSequenceScope
where (fromNumberSequenceScope.LegalEntity == CompanyInfo::findDataArea(fromCompany).RecId ||
fromNumberSequenceScope.DataArea == fromCompany)
{
try
{
ttsBegin;
toNumberSequenceScope = NumberSequenceScope::findByNaturalKey(
toCompany,
CompanyInfo::findDataArea(toCompany).RecId,
fromNumberSequenceScope.OperatingUnit,
fromNumberSequenceScope.FiscalCalendarPeriod,
fromNumberSequenceScope.OperatingUnitType);
if ((fromNumberSequenceScope.LegalEntity || fromNumberSequenceScope.DataArea) && !toNumberSequenceScope)
{
toNumberSequenceScope.clear();
toNumberSequenceScope.data(fromNumberSequenceScope);
if (toNumberSequenceScope.LegalEntity)
{
toNumberSequenceScope.LegalEntity = CompanyInfo::findDataArea(toCompany).RecId;
}
if (toNumberSequenceScope.DataArea)
{
toNumberSequenceScope.DataArea = toCompany;
}
toNumberSequenceScope.insert();
mapKeyValue = null;
mapKeyValue = new Map(Types::Int64,Types::Int64); //mk
while select fromNumberSequenceTable
where fromNumberSequenceTable.NumberSequenceScope == fromNumberSequenceScope.RecId
{
if (!NumberSequenceTable::findByNaturalKey(fromNumberSequenceTable.NumberSequence, toNumberSequenceScope.RecId))
{
toNumberSequenceTable.clear();
toNumberSequenceTable.data(fromNumberSequenceTable);
toNumberSequenceTable.NumberSequenceScope = toNumberSequenceScope.RecId;
toNumberSequenceTable.NextRec = toNumberSequenceTable.Lowest;
toNumberSequenceTable.insert();
if (!mapKeyValue.exists(fromNumberSequenceTable.RecId))
{
mapKeyValue.insert(fromNumberSequenceTable.RecId,toNumberSequenceTable.RecId); //mk
}
}
}
enumer = null;
while select fromNumberSequenceReference
where fromNumberSequenceReference.NumberSequenceScope == fromNumberSequenceScope.RecId
{
if (!NumberSequenceReference::findNaturalKey(toNumberSequenceScope.RecId, fromNumberSequenceReference.NumberSequenceDatatype))
{
toNumberSequenceReference.clear();
toNumberSequenceReference.data(fromNumberSequenceReference);
toNumberSequenceReference.NumberSequenceScope = toNumberSequenceScope.RecId;
enumer = mapKeyValue.getEnumerator();
iCurrentKey = 0;
sCurrentValue = 0;
while (enumer.moveNext())
{
iCurrentKey = enumer.currentKey();
if (fromNumberSequenceReference.NumberSequenceId == iCurrentKey)
{
sCurrentValue = enumer.currentValue();
//info(strFmt("Key: %1 and Value %2",iCurrentKey,sCurrentValue));
break;
}
}
if (sCurrentValue != 0)
{
toNumberSequenceReference.NumberSequenceId = sCurrentValue; //mk
}
toNumberSequenceReference.insert();
}
}
}
ttsCommit;
}
catch
{
warning("Error copying number sequence");
}
}
}
No comments:
Post a Comment