代码之家  ›  专栏  ›  技术社区  ›  TeoVr81

使用C#SAP connector搜索SAP客户

  •  1
  • TeoVr81  · 技术社区  · 8 年前

    我需要从C#应用程序中搜索SAP系统中的客户。 我正在使用C#。网络连接器。 我尝试调用BAPI“BAPI\u CUSTOMER\u FIND”,以获取名称以“C”开头的所有客户,这是我的代码:

    SAPConnectionConfigurator cfg = new SAPConnectionConfigurator();
    RfcDestinationManager.RegisterDestinationConfiguration(cfg);
    RfcDestination dest = RfcDestinationManager.GetDestination("mySAPdestination");
    RfcRepository repo = dest.Repository;
    IRfcFunction customerList = repo.CreateFunction("BAPI_CUSTOMER_FIND");
    customerList.SetValue("MAX_CNT", "100");
    IRfcTable searchFields = customerList.GetTable("SELOPT_TAB");
    searchFields.Insert();
    searchFields.CurrentRow.SetValue("COMP_CODE", "");
    searchFields.CurrentRow.SetValue("TABNAME", "KNA1");
    searchFields.CurrentRow.SetValue("FIELDNAME", "NAME1");
    searchFields.CurrentRow.SetValue("FIELDVALUE", "C*");
    customerList.Invoke(dest);
    IRfcTable results = customerList.GetTable("RESULT_TAB");
    

    调用正常,但我不知道如何读取结果。我需要客户列表,但RESULT\u TAB表的结构很奇怪:

    https://www.sapdatasheet.org/abap/tabl/bapikna111.html

    如何获取客户列表?我打错电话了吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Dirk Trilsbeek    8 年前

    在这种情况下,您可能没有得到任何结果表 RESULT_TAB 仅包含一行原始搜索参数和警告消息。您需要设置参数 PL_HOLD 'X' 允许使用占位符。

    当有结果时,您将在表中看到几行 结果\u选项卡 ,带字段 FIELDVALUE 包含实际客户名称(因为您在字段中搜索 NAME1 -更改搜索字段,结果也会更改)和 CUSTOMERNUMBER 包含客户编号。

    如果结果多于设置 MAX_CNT, 您将看到消息类型 I 身份证件 FN 数字 063´ 最后一行 您的结果集(使用您的登录语言显示一条消息,告诉您有超过X个结果)。

    如果你的搜索根本没有结果 RETURN 将包含警告消息(消息类型 W 身份证件 FN公司 数字 802 )和表中的单行 结果\u选项卡 应包含其他警告消息类型 W 身份证件 FN公司 数字 065 以及以您的登录语言显示的解释性消息文本,告诉您在搜索中未找到任何帐户。

    如果你想知道如何阅读 IRfcTable 总之,您可以对其内容进行迭代。它本质上是IRfcStructure项的列表。

    foreach(IRfcStructure row in returnTable) 
    {
         var customerNumber = row.GetString("CUSTOMERNUMBER");
    }