Calculating Onhand of an Item

How can i calculate the onhand of an item in all warehouses excluding few of the configurations(ConfigIds) through X++ ?

We can check the on hand of an item using following code(Suppose the item ID is ‘AXITEM’ and the invent dim ID is ‘AXDIM’) -

static void onHandCheck(Args _args)
{
InventOnhand onhand;
;
onhand = InventOnhand::newItemId(“AXITEM”);
onhand.parmInventDimId(“AXDIM”);
// Physical inventory
print onhand.physicalInvent();
// Physical reserved
print onhand.reservPhysical();
// Total available ordered
print onhand.availOrdered();
// Ordered reserved
print onhand.reservOrdered();
// Available physical
print onhand.availPhysical();

pause;
}

I am not looking for a specific InventDimId, I want onhand for all the inventdimid s leaving the InventDimids having the configIds
with some value (say “configx”)

For that purpose you can loop through all the records of InventDim table except the ones which have the configId field filled with the specific values.