【发布时间】:2016-10-13 11:05:44
【问题描述】:
我想使用 RFC 在我的 JCO Table 中添加多个数据到 SAP 服务器。
以下是我的代码。
但问题是只有最后一个 raw 会被设置为 sap。
我错过了什么?
我正在使用一种功能与 SAP 同步数据。
JCO.Function function = null;
JCO.Repository mRepository;
public String updateCustomerToSAP(String bapi){
String message = null;
Connection conn = new Connection();
JCO.client mConnection = conn.open();
JCO.Table GETZPRTL_VISIT = null;
mConnection.connect();
try{
function = this.createFunction(bapi);
if(function == null){
// Not fount
}else{
GETZPRTL_VISIT = function.getTableParameterList().getTable("CUSTOMER_VISIT");
for(int i = 0 ; i < 10 ; i++){
GETZPRTL_VISIT.appendRow();
GETZPRTL_VISIT.setValue("0001 "+i,"ID");
GETZPRTL_VISIT.setValue("john_ro "+i,"USER_NAME");
GETZPRTL_VISIT.setValue("John "+i,"FIRST_NAME");
GETZPRTL_VISIT.setValue("Martin "+i,"LAST_NAME");
GETZPRTL_VISIT.setValue("john.martin@gmail.com "+i,"EMAIL");
}
// Above data is just for and example. I fetch those data from ArrayList and all data are diffrent.
function.getImportParameterList().setValue("Data1","USER_ID");
function.getImportParameterList().setValue("type goes here","TYPE");
function.getImportParameterList().setValue("reason goes here","REASON");
function.getImportParameterList().setValue("final status","STATUS");
function.getImportParameterList().setValue("0001","NUMBER");
mConnection.execute(function);
message = (String) function.getExportParameterList().getValue("MESSAGE");
}
}catch(Exception e){
}
conn.disconnect();
return message;
}
public JCO.Function createFunction(String name) throws Exception{
try{
IFunctionTamplate ft = mRepository.getFunctionTamplate(name.toUpperCase());
if(ft == null)
return null;
return ft.getFunction();
}catch(Exception e){
throw new Exception("Problem retriving JCO.Function object"+ e);
}
}
这里 CUSTOMER_VISIT 是 Table,它在我的 RFC 中。
结构示例
USER_ID
TYPE
REASON
STATUS
NUMBER
CUSTOMER_VISIT <= This is Table inside function module.
CUSTOMER_VISIT 表结构
ID
USER_NAME
FIRST_NAME
LAST_NAME
EMAIL
【问题讨论】:
-
如果您的代码示例完整且未更改,则 GETZPRTL_VISIT 引用的表将包含 10 行,全部相同。是否有可能在功能模块方面进行某种过滤?表CUSTOMER_VISIT是功能模块的表参数,不只是一个结构体?
-
CUSTOMER_VISIT 是侧功能模块中的表。
-
如果只有一条记录,一切正常。但是如果有超过 2 条记录,它只存储最后一条。
-
您是否确认实际上只有一条记录发送到 SAP 系统?我找不到您的代码有任何问题,问题是问题是否出在功能模块中。您可以在 SAP 系统中测试功能模块,而无需从 JCo 连接调用它。
-
我可以看到的另一个问题是 setValue() 似乎首先需要列名,然后是值。您首先使用值调用 setValue(),然后使用列。也许这只是在您的示例代码中。老实说,此时我会进入调试器,看看你的代码可能有什么问题。检查表参数是否真的包含多行或应用程序逻辑中是否存在其他问题。