I'm not getting any errors. This is what I did to achieve my task.
//Create new costing version record
costingVersion = null;
costingVersion.initValue();
costingVersion.BlockActivation = NoYesCombo::Yes;
costingVersion.AllowPurch = NoYes::No;
costingVersion.AllowSales = NoYes::No;
costingVersion.BOMCostPriceModel = BOMCostPriceModel::ItemCostPrice;
costingVersion.BOMCalcRun = NoYes::Yes;
costingVersion.LastUpdate = today();
costingVersion.InventSiteId = strUpr(curext());
costingVersion.PurchCalcRun = NoYes::No;
costingVersion.PurchPriceModel = PurchPriceModel::PurchPrice;
costingVersion.Name = strName;
costingVersion.VersionId = strVersionId;
costingVersion.insert();
//Add items to new costing version
psd_AddtoCostVersion = new PSD_AddtoCostVersion();
psd_AddtoCostVersion.parmCostVersion(strVersionId);
psd_AddtoCostVersion.parmEffectivityDate(today());
psd_AddtoCostVersion.run();
//Calculating the costing version
costingVersion = null;
select firstOnly costingVersion where costingVersion.VersionId == strVersionId;
bomCalc = BOMCalcJob::newAll(costingVersion);
bomCalc.parmBOMCalcExplosionMode(BOMCalcExplosionMode::MultiLevel);
bomCalc.parmCostPriceTransfer(NoYes::Yes);
bomCalc.parmCalcDate(today());
bomCalc.run();