我试图从SAP系统读取一个表,并且我总是收到以下错误:
Exception in thread "main" com.sap.conn.jco.JCoRuntimeException: (127)
JCO_ERROR_FIELD_NOT_FOUND: Field EMPLOYEE is not a member of INPUT
at com.sap.conn.jco.rt.AbstractMetaData.indexOf(AbstractMetaData.java:404)
at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:4074)
at testConf.StepServer.main(StepServer.java:50)这是我的密码:
public static void main(String[] args) {
// This will create a file called mySAPSystem.jcoDestination
System.out.println("executing");
String DESTINATION_NAME1 = "mySAPSystem";
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "xxx.xxx.x.xxx");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "xx");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "xxx");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "username");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "test");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");
createDestinationDataFile(DESTINATION_NAME1, connectProperties);
// This will use that destination file to connect to SAP
try {
JCoDestination destination = JCoDestinationManager.getDestination("mySAPSystem");
System.out.println("Attributes:");
System.out.println(destination.getAttributes());
System.out.println();
destination.ping();
} catch (JCoException e) {
e.printStackTrace();
}
try{
//here starts the problem
JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME1);
JCoFunction function = destination.getRepository().getFunction("RFC_READ_TABLE");
JCoParameterList listParam = function.getImportParameterList();
listParam.setValue("EMPLOYEE", "EMPLOYEE"); // I have found this in an example and I don't understand exactly what should I put there
// I was thinking maybe is the column name but I am not sure
function.execute(destination);
JCoTable table = function.getTableParameterList().getTable("ZEMPLOYEES");//name of my table from SAP
System.out.println(table);
}
catch (JCoException e)
{
System.out.println(e.toString());
return;
}
}当它说JCO_ERROR_FIELD_NOT_FOUND: Field EMPLOYEE不是输入的成员时,错误很明显,但是employee是my表中的一个字段。

这些文档没有太大帮助,它只说:
Sets the object as the value for the named field.
Parameters:
value - the value to set for the field
name - the name of the field to set 女巫,在我看来,我已经做过了。
为了从java读取这个新表,我应该在sap中做任何额外的修改吗?我所做的就是按照本教程(在SAP中创建简单的表)创建一个新表。
也许有更多经验的人可以告诉我应该如何配置这个示例代码才能工作。
发布于 2018-09-06 11:26:35
RFC_READ_TABLE的一般用途
我从未使用过JCo,但据我所知,它的接口非常类似于NCo,即.Net连接器。这基本上是NCo代码,并添加了一些猜测,但它应该可以工作。
// get the table parameter FIELDS that should be in the parameter list
// the parameter table has several fields, only the field FIELDNAME has to be set before calling the function module
JCOTable inputTableParam = function.getTableParameterList().getTable("FIELDS");
// add a row to the FIELDS table parameter
inputTableParam.appendRow();
// set values for the new row
inputTableParam.setValue("FIELDNAME", "EMPLOYEE");
// just for fun, add another field to retrieve
inputTableParam.appendRow();
inputTableParam.setValue("FIELDNAME", "SURNAME");
// now we have to set the non-table parameters
JCoParameterList inputParamList = function.getImportParameterList();
// parameter QUERY_TABLE, defines which table to query
inputParamList.setValue("QUERY_TABLE", "ZEMPLOYEES");
// parameter DELIMITER - we get a single string as the return value, the field values within that string are delimited by this character
inputParamList.setValue("DELIMITER", ";");
// execute the function
function.execute(destination);
// the parameter table DATA contains the rows
JCoTable table = function.getTableParameterList().getTable("DATA");最后,变量table将持有一个表对象,该表对象具有一个名为WA的字段。该字段包含您在输入参数表FIELDS中选择的字段的内容。您可以遍历table并逐行获取值。
使用RFC_READ_TABLE查询
RFC_READ_TABLE实际上不允许查询,它只允许定义WHERE子句。TABLE参数OPTIONS有一个单字段TEXT,72个字符宽,只能接受符合ABAP的WHERE子句。
为了扩展上面的示例,我们将添加一个where子句,以便只从表ZEMPLOYEES中选择SURNAME = "SMITH“和FORNAME = "JOHN”的条目。
JCOTable optionsTableParam = function.getTableParameterList().getTable("OPTIONS");
// add a row to the FIELDS table parameter
optionsTableParam.appendRow();
optionsTableParam.setValue("TEXT", "SURNAME EQ 'SMITH' AND FORNAME EQ 'JOHN');字段TEXT只有72个字符长,因此如果要添加一个long子句,则必须手动将条件分解为几行。RFC_READ_TABLE有点粗糙和有限。
表之间的复杂连接可以通过在system中创建一个视图(transaction SE11),然后使用RFC_READ_TABLE查询该视图来实现。
如果您想从JCo调用函数模块,那么如果您熟悉基本的函数模块属性,这将非常有帮助。您可以查看事务SE37中的函数模块定义。在这里,您可以看到IMPORT、EXPORT、CHANGING和TABLE参数。您必须填充的参数和包含结果的参数取决于您调用的函数模块- RFC_READ_TABLE有不同的函数模块,例如,BAPI_DELIVERY_GETLIST。
下面是JCoFunction的文档以及JCo和NCo之间的一个不同之处,JCo有单独的函数来获取和设置不同的参数类型:https://help.hana.ondemand.com/javadoc/com/sap/conn/jco/JCoFunction.html
发布于 2018-09-06 11:50:18
您正在尝试调用函数RFC_READ_TABLE,并尝试将一个值传递给其参数"EMPLOYEE“。这不是RFC_READ_TABLE的参数,因此出现了错误。
RFC_READ_TABLE有三个重要的输入参数:
RFC_READ_TABLE有一个返回参数:
参见本例:https://vishalmasih.wordpress.com/2014/10/31/sap-jco-searching-for-a-user-in-the-usr04-table/
https://stackoverflow.com/questions/52201563
复制相似问题