1

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               
    }
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
mbigun
  • 1,304
  • 4
  • 19
  • 46
  • what exactly is your problem/question? Can you give *one* short example ? – Random Dev Nov 01 '14 at 11:58
  • Main problem is that I cannot neither change data for item nor add new items to sales order. In scenario B i'm trying to change target qty in SO, there is no any error messages and `RETRUN` table provides me successfull result. But in reality qty has not been changed. In scenario C I'm trying to add new line to sales order, but invoke method doesn't work here due to error `Screen output without connection to user`. So, I'll be appreciate if somebody will share with me good working sample how to change or add items in sales orders. Probably there is other FM which I can use for this purposes? – mbigun Nov 01 '14 at 12:30

2 Answers2

2

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.

Lanzelot
  • 15,976
  • 4
  • 18
  • 14
  • 1
    A bit late comment, but salesItemsINX.SetValue("ITM_NUMBER", "X"); throws an exception that a string cannot be used as an input to this header, I believe the actual item number needs to be added here as in the original code. – Nouman Qaiser Jan 07 '23 at 09:43
  • 1
    @NoumanQaiser I confirm, the part for Scenario B is wrong. It's the only field of `salesItemsINX` which must be a number, other fields are to be blank or "X". Only the part of Scenario C is valid (note that it may be due to a custom modification, maybe it's not due to SAP standard). – Sandra Rossi Jun 25 '23 at 14:08
1

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.

snow_FFFFFF
  • 3,235
  • 17
  • 29
  • It is done already if you check code for the scenario A: `...repo.CreateFunction("BAPI_TRANSACTION_COMMIT");...` – mbigun Nov 11 '14 at 15:23
  • @mbigun You're right. The concerned line is more `salesDocCommit.Invoke(destination);` (which is called after `BAPI_SALESORDER_CHANGE` in scenario A), but you forgot to mention it in scenarios B and C, so the answer is (partially) valid. – Sandra Rossi Jun 25 '23 at 14:02