为什么SAP JCo引发错误“字段......不是......的成员”,即使该字段存在?

时间:2016-09-22 12:49:22

标签: java sap

我想从我的Servlet应用程序向SAP RFC表发送数据。

我试图在下面这样做。

JCO.Function function = null;
Connection conn = new Connection();
JCO.Client mConnection = conn.open();
JCO.Repository mRepository;
mConnection.connect();

mRepository = new JCO.Repository("KEYWORD",mConnection);

try{
    function = this.createFunction("MY RFC NAME");
    if(function != null){
         function.getImportParameterList.setValue("ID1","USERID");
         function.getImportParameterList.setValue("Test Name","UNAME");
         function.getImportParameterList.setValue("CLASSA","UCLASS");

         mConnection.execute(function);
    }
}catch(Exception ex){
    // Exception handling goes here.
}
conn.disconnected();

但我收到了以下错误

com.sap.mw.jco.JCO$Exception:<127> JCO_ERROR_FIELD_NOT_FOUND: Field USERID not a member of INPUT

但我查了一下,SAP中存在专栏。

这里缺少什么? 我也应该通过RFC表名吗?那怎么样?

2 个答案:

答案 0 :(得分:1)

我通过以下代码解决了这个问题。

JCO.Function function = null;
Connection conn = new Connection();
JCO.Client mConnection = conn.open();
JCO.Table GET_DATA = null;
JCO.Repository mRepository;
mConnection.connect();

mRepository = new JCO.Repository("KEYWORD",mConnection);

try{
    function = this.createFunction("MY RFC NAME");
    if(function != null){

         GET_DATA = function.getTableParameterList.getTable(TABLE_NAME);
         GET_DATA.appendRow();

         function.getImportParameterList.setValue("ID1","USERID");
         function.getImportParameterList.setValue("Test Name","UNAME");
         function.getImportParameterList.setValue("CLASSA","UCLASS");

         GET_DATA.nextRow();
         mConnection.execute(function);
    }
}catch(Exception ex){
    // Exception handling goes here.
}
conn.disconnected();

答案 1 :(得分:1)

连接的sap系统上是否存在此功能? 如果是这样,我建议改为使用function = conn.getRepository.getFunction('MY_RFC_NAME')。使用该方法,您可以获得连接的SAP系统上存在的函数模块的元数据和签名。这允许您检查函数是否存在if(function == null) throw new Exception("Function Module MY_RFC_NAME does not exist on connected SAP Syste");,并检查每个参数是否存在并且确实具有您期望的名称和类型。

在大多数情况下会发生这种错误,因为参数名称略有不同。例如USER_ID而不是USERID