on 01-30-2012 5:56 AM
I am trying to display data from Sales Orders in a DataGridView. However, Numeric (RAW ?) fields such as NET_PRICE are showing as System.byte[].
Text fields are displayed OK
Any ideas how to convert the data to display correctly ?
Dim destination As RfcDestination = RfcDestinationManager.GetDestination(ABAP_APP_SERVER)
Dim func As IRfcFunction = destination.Repository.CreateFunction("BAPI_SALESORDER_GETLIST")
func.SetValue("Customer_Number", TextBox1.Text.ToString)
func.SetValue("Sales_Organization", SalesOrg.Text.ToString)
func.SetValue("Document_Date", DateFrom.Value)
func.SetValue("Document_Date_To", DateTo.Value)
func.Invoke(destination)
Dim view As IRfcTableView = TryCast(func.GetTable("SALES_ORDERS"), ISupportTableView).DefaultView
DataGridView1.DataSource = View
HI Schmav,
//here i am taking the example for displaying the employee details based upon the empid.
//In show button click copy this code.
//NOte: Ask BAPI names, IMOPRT paramaters and EXPORT parameters from ABAPERS.Here i am taking sample bapi names and //parametrs
RfcDestination prd = RfcDestinationManager.GetDestination("SE37");
RfcRepository repo = prd.Repository;
// BAPI_ADDREMPAU_GETDETAIL is bapi please take bapi name from abaper.
IRfcFunction companyBapi1 = repo.CreateFunction("BAPI_ADDREMPAU_GETDETAIL");
// set the employeenumber based upon the employeenumber we need to display empdetails.
companyBapi1.SetValue("EMPLOYEENUMBER", int.Parse(txtEmploeeNumber.Text));
// Invoke the rfcfunction
companyBapi1.Invoke(prd);
for (int i = 0; i < companyBapi1.ElementCount; i++)
{
RfcDirection direction = companyBapi1<i>.Metadata.Direction;
if (companyBapi1<i>.Metadata.DataType.ToString().Trim() != "STRUCTURE" && direction.ToString().Trim() =="EXPORT")
{
dt.Columns.Add(companyBapi1.Metadata<i>.Name);
}
}
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
int columnnumber = 0;
for (int m = 0; m < companyBapi1.Count; m++)
{
RfcDirection direction = companyBapi1[m].Metadata.Direction;
if (companyBapi1[m].Metadata.DataType.ToString().Trim()!= "STRUCTURE" && direction.ToString().Trim() == "EXPORT" && columnnumber<dt.Columns.Count)
{
dt.Rows[0][columnnumber] = companyBapi1[m].GetString();
}
columnnumber++;
}
}
catch (RfcInvalidParameterException exec)
{
Label1.Text = exec.Message;
}
catch (RfcTypeConversionException exec1)
{
Label1.Text = exec1.Message;
}
catch (RfcCommunicationException exec2)
{
Label1.Text = exec2.Message;
}
catch (RfcBaseException exec3)
{
Label1.Text = exec3.Message;
}
GridView1.DataSource = dt;
GridView1.DataBind();
public class MyBackendConfig : IDestinationConfiguration
{
// RfcDestinationManager.RegisterDestinationConfiguration(new MyBackendConfig());
public RfcConfigParameters GetParameters(String destinationName)
{
if ("SE37".Equals(destinationName))
{
RfcConfigParameters parms = new RfcConfigParameters();
parms.Add(RfcConfigParameters.AppServerHost, "192.168.1.14");
parms.Add(RfcConfigParameters.SystemNumber, "02");
parms.Add(RfcConfigParameters.User, "abaper");
parms.Add(RfcConfigParameters.Password, "erp@1234");
parms.Add(RfcConfigParameters.Client, "800");
parms.Add(RfcConfigParameters.Language, "EN");
parms.Add(RfcConfigParameters.PoolSize, "5");
parms.Add(RfcConfigParameters.MaxPoolSize, "10");
parms.Add(RfcConfigParameters.IdleTimeout, "600");
return parms;
}
else return null;
}
public bool ChangeEventsSupported()
{
return false;
}
public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
// public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
}
Best Regards,
Harish.Y
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would love to provide an answer, but I too am having the same problem. For the benefit of C# users, here's your code translated to C#:
public DataTable GetDataTableFromRFCTable(IRfcTable myrfcTable)
{
DataTable loTable = new DataTable();
int liElement = 0;
for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++)
{
RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);
loTable.Columns.Add(metadata.Name);
}
foreach (IRfcStructure Row in myrfcTable)
{
DataRow ldr = loTable.NewRow();
for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++)
{
RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);
ldr[metadata.Name] = Row.GetString(metadata.Name);
}
loTable.Rows.Add(ldr);
}
return loTable;
}
To bind to a data grid view control:
this.DataGridView1.DataSource = GetDataTableFromRFCTable(SAPTable);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, i found a away to get the right result, but not entirely happy with it.
If I convert the output to a datatable using some code from another post, it works
Public Function GetDataTableFromRFCTable(ByVal myrfcTable As IRfcTable) As DataTable
Dim loTable As New DataTable
Dim liElement As Integer
For liElement = 0 To myrfcTable.Elementcount - 1
Dim metadata As RfcElementMetadata = myrfcTable.GetElementMetadata(liElement)
loTable.Columns.Add(metadata.Name)
Next
For Each Row As IRfcStructure In myrfcTable
Dim ldr As DataRow = loTable.NewRow()
For liElement = 0 To myrfcTable.ElementCount - 1
Dim metadata As RfcElementMetadata = myrfcTable.GetElementMetadata(liElement)
ldr(metadata.Name) = Row.GetString(metadata.Name)
Next
loTable.Rows.Add(ldr)
Next
Return loTable
End Function
Dim destination As RfcDestination = RfcDestinationManager.GetDestination(ABAP_APP_SERVER)
Dim func As IRfcFunction = destination.Repository.CreateFunction("BAPI_SALESORDER_GETLIST")
func.SetValue("Customer_Number", TextBox1.Text.ToString)
func.SetValue("Sales_Organization", SalesOrg.Text.ToString)
func.SetValue("Document_Date", DateFrom.Value)
func.SetValue("Document_Date_To", DateTo.Value)
func.Invoke(destination)
Dim view As DataTable = GetDataTableFromRFCTable(func.GetTable("SALES_ORDERS"))
DataGridView1.DataSource = view
Can anyone tell me a better way to do this ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.