获取RFC返回的嵌套结构的值? [英] Fetch the value of nested structure returned by RFC?

查看:230
本文介绍了获取RFC返回的嵌套结构的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手.我有rfc,它以嵌套结构的形式从SAP系统返回数据,但是当我使用以下方法获取数据时:

I am new to C#. I have rfc that returns data from SAP system as nested structure but when I'am fetching that data using:

IrfcTable table = rfc.getTable("exporting_parameter");       // et_customer

它仅返回第一个内部结构. 例如,我为rfc导出的内部表是 et_customer包含如下子结构:

it returns only first inner structure only. For example my exporting internal table for rfc is et_customer that contains sub structure as follow:

gen_data
 bank data
 tax data

仅返回gen_data内部的值. 如何获取全部数据?

it returns value inside gen_data only. How to get entire data?

推荐答案

几个可能有用的扩展.例如从SAP结构转换为其他更知名的结构.

A couple of Extensions that may help. eg Convert from SAP structures to Other better known structures.

public static class SapToDataExtensionClass
{

    public static Dictionary<string,string> ToDictionary(this IRfcStructure stru)
    {
        Dictionary<string,string> dict = new Dictionary<string, string>();

        for (int i = 0; i < stru.Metadata.FieldCount; i++)
        {
            dict.Add(stru.Metadata[i].Name , stru.GetString(i) );  
        }

        return dict;
    }
    public static DataTable GetDataTable(this IRfcTable i_Table)
    {

        DataTable dt = new DataTable();

        dt.GetColumnsFromSapTable(i_Table);

        dt.FillRowsFromSapTable(i_Table);

        return dt;

    }


    public static void FillRowsFromSapTable(this DataTable i_DataTable, IRfcTable i_Table)
    {

        foreach (IRfcStructure tableRow in i_Table)
        {

            DataRow dr = i_DataTable.NewRow();

            dr.ItemArray = tableRow.Select(structField => structField.GetValue()).ToArray();

            i_DataTable.Rows.Add(dr);

        }

    }


    public static void GetColumnsFromSapTable(this DataTable i_DataTable, IRfcTable i_SapTable)
    {

        var DataColumnsArr = i_SapTable.Metadata.LineType.CreateStructure().ToList().Select

        (structField => new DataColumn(structField.Metadata.Name)).ToArray();

        i_DataTable.Columns.AddRange(DataColumnsArr);

    }

}

这篇关于获取RFC返回的嵌套结构的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆