在从SAP到C#的数据获取方面需要帮助 [英] Need Help at Getting data from SAP to C#

查看:72
本文介绍了在从SAP到C#的数据获取方面需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从SAP服务器中获取一些数据到Visual Studio中的C#程序中.SAP和该程序之间的连接已经在起作用,但是我真的不知道如何将数据从Server导入到程序中.

I want to get some data from an SAP Server to my C# Programm in Visual Studio. The connection between the SAP and the program is already working but I don't really know how to get the data from the Server into the program.

namespace ConsoleApp1
{
    class Program //: IDestinationConfiguration
    {
        static void Main(string[] args)
        {
            fn f = new fn();

            RfcDestination destination = f.GetRfcDestination("vhcalnplci", "brachi", "Abap2017", "001", "EN", "vhcalnplci", "00", "20", "10");
            RfcSessionManager.BeginContext(destination);
            destination.Ping();

            IRfcFunction function = destination.Repository.CreateFunction("/BODS/RFC_READ_TABLE");

            IRfcTable addresses = function["ADDRESSES"].GetTable();
            Console.WriteLine("STREET");
            for (int index = 0;
            index < addresses.RowCount;
            ++index)
            {
                Console.WriteLine(addresses[index]["STREET"].GetString());
            }
        }
    }
}

如您所见,我已经编写了一些代码,但是不幸的是,当我尝试执行该程序时,出现以下错误:

As you can see I have already written some code but unfortunately when I am trying to execute this program i get the following error:

SAP.Middleware.Connector.RfcInvalidParameterException:容器元数据/BODS/RFC_READ_TABLE的元素地址未知"

SAP.Middleware.Connector.RfcInvalidParameterException: "Element ADDRESSES of container metadata /BODS/RFC_READ_TABLE unknown"

在下面的代码行中:

IRfcTable addresses = function["ADDRESSES"].GetTable();

我知道错误是因为RFC_READ_TABLE模块中不存在该元素,但是正如我所说,我并不真正知道如何获取数据以及该部分程序真正需要的代码.我已经看过SAP的编程指南,但也许会帮助某人帮助我:

I know the error is because the element is not existing in the RFC_READ_TABLE module, but as I said I don't really know how to get data and what code I really need for that part of the program. I already looked through the programming guide from SAP but maybe it will help someone help me: .NET Connector Programming Guide

推荐答案

从我的角度来看,您的问题过于广泛,无法在此处简短回答.您似乎缺乏有关SAP系统及其功能和数据模型的基础知识.建议使用SAP系统的方法是使用适合您需求的特定功能模块(BAPI),如果无法立即使用这种功能模块,则可以在ABAP中开发自己的功能模块.>如果选择任何RFC_READ_TABLE功能模块,则表明您希望像访问数据库一样访问SAP System,而并非如此.这是一个 ERP系统(使用数据库).对于所有RFC_READ_TABLE变体,您甚至需要了解SAP的内部数据库表设计及其表依赖性,并且必须在函数调用中指定适当的SQL语句.此方法容易出错,不是从SAP系统访问数据的推荐方法.

仅举一个例子,如果您想读取存储的客户数据(包括他们的地址),请使用远程功能模块BAPI_CUSTOMER_GETLIST.

最后是您的源代码:

From my perspective your question is too broad to be answered in short here. You seem to lack basic knowledge about SAP systems and their function and data model. The recommended way to work with SAP systems is to use specific function modules (BAPIs) which fit to your needs, and if such a function module would not be available out-of-the-box, then develop your own in ABAP.

If choosing any of the RFC_READ_TABLE function modules, you are showing that you would like to access the SAP System like a database, which it is not. It is an ERP system (which uses a database). With all of the RFC_READ_TABLE variants, you even need to know SAP's internal database table design and their table dependencies and you have to specify appropriate SQL statements in the function call. This approach is error-prone and not the recommended way to access data from a SAP system.

Just to give an example, if you would like to read stored customer data (including their addresses), use the remote function module BAPI_CUSTOMER_GETLIST instead.

And finally to your source code:

  1. 您通过调用 RfcSessionManager.BeginContext(destination)创建了连接资源泄漏,但没有再次结束上下文.仅在确实需要进行有状态调用序列时才调用此方法.您在这里不需要它.
  2. 您没有设置或填写用于调用功能模块的任何导入参数.
  3. 您没有在SAP系统中执行/调用功能模块.这需要调用 function.Invoke(destination).
  4. 您试图访问参数"ADDRESSES",该参数在所选功能模块/BODS/RFC_READ_TABLE中不可用.看一下SAP系统,并通过事务SE37检查功能模块接口公开了哪些参数和表.
  1. You created a connection resource leak with calling RfcSessionManager.BeginContext(destination) but not ending the context again. Call this only if you really need it for doing a stateful call sequence. You don't need it here.
  2. You did not set or fill any import parameter for calling the function module.
  3. You did not execute/call the function module in the SAP System. This requires calling function.Invoke(destination).
  4. You tried to access a parameter "ADDRESSES" which is not available in the choosen function module /BODS/RFC_READ_TABLE. Have a look into the SAP System and check with transaction SE37 which parameters and tables your function module interface exposes.

这篇关于在从SAP到C#的数据获取方面需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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