为什么 SAP JCo 会引发错误 "Field ... not a member of ...",即使该字段存在?

Why does SAP JCo raise an error "Field ... not a member of ..." even though the field exists?

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

我正在尝试以下面的方式执行此操作。

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中存在exist列。

这里缺少什么? 我还应该传递 RFC table 名称吗?那怎么办?

我用下面的代码解决了这个问题。

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();

连接的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