Skip to Content
0
Jan 25, 2011 at 09:14 PM

How do I catch a returned RfcTable using SAP .NET Connector 3.0?

709 Views

I am using the SAP .NET Connector 3.0 (.NET Framework 4.0 64-bit) with Visual Studio 2010 Pro on a Windows 7 64-bit computer. I have successfully run the example application from the SAP .NET Connector 3.0 Overview that returned a single company in an exporting variable as a structure and then displayed a single field from the structure.

What I need to be able to do is get a list (table) of the sales orders and work with the rows and fields within the rows. Modifying the example from the Overview document, I tried the following:

static void Main(string[] args)
        {
            RfcDestinationManager.RegisterDestinationConfiguration(new MyBackendConfig());
            RfcDestination prd = RfcDestinationManager.GetDestination("PRD_000");
            try
            {
                RfcRepository repo = prd.Repository;
                IRfcFunction salesOrderBapi = repo.CreateFunction("BAPI_SALESORDER_GETLIST");
                salesOrderBapi.SetValue("CUSTOMER_NUMBER", "246");
                salesOrderBapi.SetValue("SALES_ORGANIZATION", "XXXX");
                salesOrderBapi.Invoke(prd);
                //IRfcTable table = companyBapi.GetTable("SALES_ORDERS");
                IRfcTable table = salesOrderBapi["SALES_ORDERS"].GetTable();
                Console.WriteLine("The table has {0} rows.", table.RowCount);

                foreach (IRfcStructure row in table)
                {
                    String field = row.GetString("SD_DOC");
                    Console.WriteLine(field);
                }
                Console.Read();
            }
            catch (Exception ex)
            {
                Console.Write("There was an error... {0}", ex.Message);
                throw;
            }
        }

When I execute the function from within the SAP GUI with the given parameters, I get a table with 3 rows in it (which is what I expect from what I know of the data). When I execute it from the .NET program, it says that there are 0 rows and the foreach loop doesn't have anything to loop over so I don't know if that portion will even work.

Can someone point out what I'm doing wrong?? Thanks in advance.