cancel
Showing results for 
Search instead for 
Did you mean: 

Converting an IrfcStructure to datagrid.

Former Member
0 Kudos

Hi,

Im having a bit of difficulty gettign data retrieved as a IrfcStructure correctly formatted in to a asp datagrid. When bound to the grid, the data binds to vertically to a column with many rows (as opposed to one row with columns for each field). as well as this, it creates on column per row it creates with each column repeating the data again and again.

I have had success with binding Irfctbles, but it seems that structures are my nemisis!.

Any ideas anyone?

Many thanks

Accepted Solutions (1)

Accepted Solutions (1)

former_member197445
Contributor
0 Kudos

Try dumping the structure to a datatable and binding the datatable.  Rough untested example below

            Dim rowTable As New DataTable

            For i As Integer = 0 To sapStructure.ElementCount - 1

                rowTable.Columns.Add(sapStructure.GetElementMetadata(i).Name)

            Next

            Dim row As DataRow = rowTable.NewRow()

            For j As Integer = 0 To sapStructure.ElementCount - 1

                row(j) = sapStructure.GetValue(j)

            Next

Answers (1)

Answers (1)

Former Member
0 Kudos

Thank you for the pointer - just to confirm if anyone else needs to do this:

this is the method I am now successfully using (C#)

public DataTable ConvertStructure(IRfcStructure myrefcTable)  //Convert RFCStructure to datatable

        {

            DataTable rowTable = new DataTable();

            for (int i = 0; i <= myrefcTable.ElementCount - 1; i++)

            {

                rowTable.Columns.Add(myrefcTable.GetElementMetadata(i).Name);

            }

            DataRow row = rowTable.NewRow();

            for (int j = 0; j <= myrefcTable.ElementCount - 1; j++)

            {     

                row[j] = myrefcTable.GetValue(j);

            }

            rowTable.Rows.Add(row);

            return rowTable;

}

Call this method in your code by using:

IRfcStructure customerTable = bapiCheckCustomer.GetStructure("BAPI_NAME");

dataGridView1.DataSource = ConvertStructure(customerTable);