我正在使用JCo库访问SAP标准BAPI。嗯,除了我使用TID(TransactionID)时RETURN表始终为空之外,其他所有内容也都可以正常工作。
当我仅删除TID时,我得到的RETURN表中填充有Warnings等。但是不幸的是,我需要对事务性BAPI使用TID,否则不会提交更改。
为什么使用TID时RETURN TABLE为空?
还是我必须将更改提交到事务性BAPI?
这是BAPI访问的伪代码:
import com.sap.conn.jco.*;
import org.apache.commons.logging.*;
public class BapiSample {
private static final Log logger = LogFactory.getLog(BapiSample.class);
private static final String CLIENT = "400";
private static final String INSTITUTION = "1000";
protected JCoDestination destination;
public BapiSample() {
this.destination = getDestination("mySAPConfig.properties");
}
public void execute() {
String tid = null;
try {
tid = destination.createTID();
JCoFunction function = destination.getRepository().getFunction("BAPI_PATCASE_CHANGEOUTPATVISIT");
function.getImportParameterList().setValue("CLIENT", CLIENT);
function.getImportParameterList().setValue("INSTITUTION", INSTITUTION);
function.getImportParameterList().setValue("MOVEMNT_SEQNO", "0001");
// Here we will then all parameters of the BAPI....
// ...
// Now the execute
function.execute(destination, tid);
// And getting the RETURN Table. !!! THIS IS ALWAYS EMPTY!
JCoTable returnTable = function.getTableParameterList().getTable("RETURN");
int numRows = returnTable.getNumRows();
for (int i = 0; i < numRows; i++) {
returnTable.setRow(i);
logger.info("RETURN VALUE: " + returnTable.getString("MESSAGE"));
}
JCoFunction commit = destination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT");
commit.execute(destination, tid);
destination.confirmTID(tid);
} catch (Throwable ex) {
try {
if (destination != null) {
JCoFunction rollback = destination.getRepository().getFunction("BAPI_TRANSACTION_ROLLBACK");
rollback.execute(destination, tid);
}
} catch (Throwable t1) {
}
}
}
protected static JCoDestination getDestination(String fileName) {
JCoDestination result = null;
try {
result = JCoDestinationManager.getDestination(fileName);
} catch (Exception ex) {
logger.error("Error during destination resolution", ex);
}
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
更新10.01.2013: 1日我终于能够同时获得RETURN表和提交的输入。解决方案是同时执行这两种操作,即不使用TID进行提交,获取RETURN表,然后再次使用TID进行提交。
非常非常奇怪,但也许是JCo Commits的正确用法。谁可以给我解释一下这个?
归档时间: |
|
查看次数: |
2292 次 |
最近记录: |