Saturday, May 18, 2019

Updating Costcenter in Purchase order and Sales order


static void OGSUpdateCostCenterinSOandPO(Args _args)
{
    PurchTable purchTable;
    SalesTable salesTable;
    RecId newDimension;
    Int i,soUpdated,poUpdated;
    DataAreaId comp;

    container companieswithCostCenter = ['ASAB','SPDC','ALMA'];

    for (i=1;i<=conLen(companieswithCostCenter);i++)
    {
        comp = conPeek(companieswithCostCenter,i);
        changeCompany(comp)
        {
            while select forupdate purchTable
            {
                newDimension = OGSUtil::getDimensionwithCostCenter(purchTable.DefaultDimension);

                if (purchTable.DefaultDimension != newDimension)
                {
                    purchTable.DefaultDimension = newDimension;
                    purchTable.update();
                    poUpdated++;
                }
            }

            while select forupdate salesTable
            {
                newDimension = OGSUtil::getDimensionwithCostCenter(salesTable.DefaultDimension);

                if (salesTable.DefaultDimension != newDimension)
                {
                    salesTable.DefaultDimension = newDimension;
                    salesTable.update();
                    soUpdated++;
                }
            }
        }
    }
    info(strFmt("Finished: %1 SOs and %2 POs updated",soUpdated,poUpdated));
}



No comments:

Post a Comment