0

This is a c# method that invokes SAP BAPI.

 public Message ReleaseBapi(string orderNumber)
    {
        Message msg = new Message();
        DataTable dt = new DataTable();
        _ecc = ERPRfcDestination.InitialiseDestination();
        try
        {
            IRfcFunction api = _ecc.Repository.CreateFunction("BAPI_PRODORD_RELEASE");
            IRfcTable orderNumTable = api.GetTable("ORDERS");
            orderNumTable.Insert();
            IRfcStructure ItemData = orderNumTable.CurrentRow;
            orderNumber = orderNumber.PadLeft(12,'0');
            ItemData.SetValue("ORDER_NUMBER", orderNumber);
            api.SetValue("ORDERS", orderNumTable);
            BeginContext();
            api.Invoke(_ecc);
            //EndContext();

            IRfcTable detReturnTable = api.GetTable("DETAIL_RETURN");//On this line I am getting RfcInvalidStateException
            IRFCToDatatable convertToDT = new IRFCToDatatable();
            dt = convertToDT.ToDataTable(detReturnTable, dt);

            if (dt.Rows.Count > 0)
            {
                msg.Msg = "Order number " + orderNumber + " released";
                msg.MsgType = "S";
                
            }
            else { RollbackAPI(); }
            
        }
        catch (Exception ex)
        {
            msg.MsgType = "D";
            msg.Msg = ex.Message;
            RollbackAPI();
        }
        finally 
        {
            EndContext();
        }
        return msg;
    }

enter image description here

I checked every other instances where similar line of code is written and on debugging I found that it works as expected. Above is the only place where I am getting this error although I was able to invoke the Rfc method.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

0 Answers0