2

The following query concatenates the columns results for each row. I need to separate columns with either some kind of delimiter or unique row[i] results.

Query: "exec rfc_read_table @query_table='VBAK', @rowcount=50, @FIELDS= '<FIELDS><RFC_DB_FLD xmlns="http://Microsoft.LobServices.Sap/2007/03/Types/Rfc/"><FIELDNAME>MANDT</FIELDNAME></RFC_DB_FLD><RFC_DB_FLD xmlns="http://Microsoft.LobServices.Sap/2007/03/Types/Rfc/"><FIELDNAME>VBELN</FIELDNAME></RFC_DB_FLD></FIELDS>,@fields=@flds output'"

.NET

          using (SAPCommand cmd = conn.CreateCommand())
            {                        
                cmd.CommandText = //See query above

                
                SAPDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    Console.Write(" {0} ", rdr[0]);
                    //Console.Write(" {0} ", rdr[1]);//null...
                    Console.WriteLine();
                }

UPDATE
I am able to separate the columns by following the indexes returned by

DataTable dtFields = (DataTable)cmd.Parameters["@flds"].Value;

(updated query)

The process is so clunky and tosses up exceptions because the indexes become unreliable when the last columns in the query return empty results (also found a length indicator that was wrong). I worked around most of it, but this is so bad. Is there a better supported method to query SAP with .NET?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348

2 Answers2

1

it works for me.

ADD this --> in your script:

   @DELIMITER ='|'

"exec rfc_read_table @query_table='VBAK', @rowcount=50, @DELIMITER ='|', @FIELDS= '<FIELDS><RFC_DB_FLD xmlns="http://Microsoft.LobServices.Sap/2007/03/Types/Rfc/"><FIELDNAME>MANDT</FIELDNAME></RFC_DB_FLD><RFC_DB_FLD xmlns="http://Microsoft.LobServices.Sap/2007/03/Types/Rfc/"><FIELDNAME>VBELN</FIELDNAME></RFC_DB_FLD></FIELDS>,@fields=@flds output'"

Sankumarsingh
  • 9,889
  • 11
  • 50
  • 74
0

Im not sure but in Version 3 of SAP .NET connector such problem should be resolved.

Anton Semenov
  • 6,227
  • 5
  • 41
  • 69