Hi,
Here is the function that I have created in codeunit-
GetItemQuantity(ItemNo : Code[20];LocationCode : Code[20]) : Decimal
ItemLedEntry.SETRANGE("Item No.",ItemNo);
ItemLedEntry.SETRANGE("Location Code",LocationCode);
IF ItemLedEntry.FINDFIRST THEN REPEAT
Qty += ItemLedEntry.Quantity;
UNTIL(ItemLedEntry.NEXT=0);
EXIT(Qty);
Where ItemLedEntry is a Record Variable of Item Ledger Entry.