Skip to Content
0
Jan 09, 2020 at 10:13 AM

How to remove a StockTransferLine from a StockTransferRequest using oData and Service Layer

141 Views

We’re writing an application that will allow us to use oData and the HANA Service Layer to perform CRUD operations on Stock Transfer Requests. Thus far we have been able to Add and Amend individual Stock Transfer Requests and Lines. However, Remove doesn't have any affect on StockTransferLines, i.e., if I "Remove" a specific line within the StockTransferLines collection within the StockTransferRequest, this is ignored and the line is retained when the StockTransferRequest is updated.

I've included a code snippet below that comments the bits that work / don't work:

HanaConnectionhanaConnection =newHanaConnection(connString.ConnectionString);

hanaConnection.Open();

SAPServiceLayer.SAPB1.StockTransferstockTransferRequestUpdate =newSAPServiceLayer.SAPB1.StockTransfer();

stockTransferRequestUpdate = currentOdataService.GetStockTransferRequest(1044);

if(null!= stockTransferRequestUpdate)

{

// Add Line - WORKS with no issue

StockTransferLinestl_11 =newStockTransferLine();

stl_11.ItemCode ="10";

stl_11.Quantity = 1;

stl_11.UnitPrice = 2;

stl_11.FromWarehouseCode ="MAIN";

stl_11.WarehouseCode ="002";

stockTransferRequestUpdate.StockTransferLines.Add(stl_11);

StockTransferLine stl = stockTransferRequestUpdate.StockTransferLines.Where(tl => tl.LineNum == 1).Single();

// Amending Existing line works

stl.Quantity = 10;

stl.ItemCode = "100";

// Remove Line - Doesn't work, and doesn't throw any error that I can see

stockTransferRequestUpdate.StockTransferLines.Remove(stl);

// Or

stockTransferRequestUpdate.StockTransferLines.RemoveAt(1);

// Update the StockTransferRequest with either Add / Amend / Remove options above

boolupdateSTR = currentOdataService.UpdateStockTransferRequest(stockTransferRequestUpdate);

}

I’m connecting as B1ADMIN user with full rights to CRUD on the Database.

Given that Adding a line; and amending existing lines works without issue. I'm thinking that either I've missed something blindingly obvious or maybe the Remove method requires additional permissions to be explicitly allowed somewhere else other than on the User or maybe the Remove method is dependent on other operations/amendments.

Can anyone help point me in the right direction, please?

Thanks & regards,

Rob