Reputation: 1302
I'm using SAP .NET Connector 3.0 to build RFC client to let the users in easiest way to communicate with SAP ERP.
Here I would like to provide short samples of what is stopping me to move forward with development.
Currently my purpose is to change existing sales order. BAPI_SALESORDER_CHANGE
is FM I gonna use to change SO header and items data. I have sales order for 12 items (from 000010 to 0000120). Scenarios B and C doesn't work for me.
Scenario A: Customer purchase order changing
Result: PO Number successfully changed. No issues.
public DataTable BAPI_SALESORDER_CHANGE(RfcDestination destination)
{
RfcRepository repo = destination.Repository;
IRfcFunction salesDoc = repo.CreateFunction("BAPI_SALESORDER_CHANGE");
IRfcFunction salesDocCommit = repo.CreateFunction("BAPI_TRANSACTION_COMMIT");
salesDoc.SetValue("SALESDOCUMENT", "3939393837");
IRfcStructure salesHeader = salesDoc.GetStructure("ORDER_HEADER_IN");
salesHeader.SetValue("PURCH_NO_C", "Order_01");
IRfcStructure salesHeaderINX = salesDoc.GetStructure("ORDER_HEADER_INX");
salesHeaderINX.SetValue("UPDATEFLAG", "U");
salesHeaderINX.SetValue("PURCH_NO_C", "X");
RfcSessionManager.BeginContext(destination);
salesDoc.Invoke(destination);
salesDocCommit.Invoke(destination);
RfcSessionManager.EndContext(destination);
IRfcTable returnTable = salesDoc.GetTable("RETURN");
return ConvertToDataTable(returnTable);
}
Scenario B: Item target qty change
Result: I got a message: sales order has been saved. But the quantity wasn't changed. What is wrong here?
public DataTable BAPI_SALESORDER_CHANGE(RfcDestination destination)
{
//...
//Same peace of code as above
IRfcStructure salesHeader = salesDoc.GetStructure("ORDER_HEADER_IN");
IRfcStructure salesHeaderINX = salesDoc.GetStructure("ORDER_HEADER_INX");
salesHeaderINX.SetValue("UPDATEFLAG", "U");
IRfcTable salesItems = salesDoc.GetTable("ORDER_ITEM_IN");
salesItems.Append();
salesItems.SetValue("ITM_NUMBER", 000120);
salesItems.SetValue("TARGET_QTY", Convert.ToDecimal("1"));
IRfcTable salesItemsINX = salesDoc.GetTable("ORDER_ITEM_INX");
salesItemsINX.Append();
salesItemsINX.SetValue("UPDATEFLAG", "U");
salesItemsINX.SetValue("ITM_NUMBER", 000120);
salesItemsINX.SetValue("TARGET_QTY", "X");
//...
//Invoke methods
}
Scenario C: New item adding
Result: Error on salesDoc.Invoke(destination)
method:
Screen output without connection to user
public DataTable BAPI_SALESORDER_CHANGE(RfcDestination destination)
{
//...
//Same peace of code as above
IRfcStructure salesHeader = salesDoc.GetStructure("ORDER_HEADER_IN");
IRfcStructure salesHeaderINX = salesDoc.GetStructure("ORDER_HEADER_INX");
salesHeaderINX.SetValue("UPDATEFLAG", "U");
IRfcTable salesItems = salesDoc.GetTable("ORDER_ITEM_IN");
salesItems.Append();
salesItems.SetValue("ITM_NUMBER", 130);
salesItems.SetValue("MATERIAL", "000000000081828282");
salesItems.SetValue("TARGET_QTY", Convert.ToDecimal("1"));
IRfcTable salesItemsINX = salesDoc.GetTable("ORDER_ITEM_INX");
salesItemsINX.Append();
salesItemsINX.SetValue("UPDATEFLAG", "I");
salesItemsINX.SetValue("ITM_NUMBER", 130);
salesItemsINX.SetValue("MATERIAL", "X");
salesItemsINX.SetValue("TARGET_QTY", "X");
//...
//Invoke methods
}
Upvotes: 1
Views: 2189
Reputation: 16595
Scenario B:
Have you tried to replace
salesItemsINX.SetValue("ITM_NUMBER", 000120);
with
salesItemsINX.SetValue("ITM_NUMBER", "X");
The way I understand these "X-tables" is that you need to mark every field with an X, which you want the BAPI to use/take into account from the origirnal table.
Scenario C:
"Screen output without connection to user" means that BAPI_SALESORDER_CHANGE is doing something, which BAPIs are not allowed to do... namely calling/using ABAP functionality that creates Dynpro ouput!
After so many years I expect that this bug in BAPI_SALESORDER_CHANGE has already been fixed. So you could make sure that your SAP system has the latest hotpackage level, or contact SAP support to have them check whether there is still something that has to be fixed in BAPI_SALESORDER_CHANGE.
Upvotes: 2
Reputation: 3311
Like in an ABAP program, you need to call BAPI_TRANSACTION_COMMIT after your successful call to BAPI_SALESORDER_CHANGE. Otherwise, your transaction is not committed by SAP.
Upvotes: 1