简体   繁体   English

使用TransactionID时SAP JCo RETURN表为空

[英]SAP JCo RETURN Table empty when using TransactionID

I'm using the JCo Library to access SAP standard BAPI. 我正在使用JCo库来访问SAP标准BAPI。 Well everything is also working except that the RETURN Table is always empty when I use the TID (TransactionID). 好吧一切都工作,除了当我使用TID(TransactionID)时RETURN表总是空的。

When I just remove the TID, I get the RETURN table filled with Warnings etc. But unfortunately I need to use the TID for the transactional BAPI, otherwise the changes are not commited. 当我只删除TID时,我得到RETURN表填充警告等。但遗憾的是我需要使用TID进行事务性BAPI,否则不会提交更改。

Why is the RETURN TABLE empty when using TID? 使用TID时为什么RETURN TABLE为空?

Or how must I commit changes to a transactional BAPI? 或者我如何提交对事务BAPI的更改?

Here speudo-code of a BAPI access: 这里是BAPI访问的speudo代码:

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;
    }
}

UPDATE 10.01.2013: I was finally able to get both, RETURN table filled and Inputs commited. 更新10.01.2013:我终于能够同时获得两个,RETURN表填充和输入提交。 Solution is to do just both, a commit without TID, get the RETURN table and then making again a commit with TID. 解决方案是同时执行两者,一个没有TID的提交,获取RETURN表,然后再次使用TID进行提交。

Very very strange, but maybe the correct usage of the JCo Commits. 非常奇怪,但也许正确使用JCo Commits。 Can someone explain this to me? 谁可以给我解释一下这个?

I was able to get both, RETURN table filled and Inputs commited. 我能够同时获得两个,RETURN表填充和输入提交。

Solution is to do just both, a commit without TID , get the RETURN table and then making again a commit with TID . 解决方案是同时执行两者, 一个没有TID的提交 ,获取RETURN表,然后再次使用TID进行提交

You should not call execute method 2 times it will incremenmt sequence number You should use begin and end method in JCoContext class. 你不应该调用execute方法2次它会增加序列号你应该在JCoContext类中使用begin和end方法。

If you call begin method at the beginning of the process, the data will be updated and message will be returned. 如果在进程开始时调用begin方法,则将更新数据并返回消息。 Here is the sample code. 这是示例代码。

  JCoDestination destination = JCoDestinationManager.getDestination("");
  try
  {
      JCoContext.begin(destination);
      function.execute(destination)
      function.execute(destination)
  } 
  catch (AbapException ex)
  {
         ...
  } 
  catch (JCoException ex)
  {
         ...
  }  
  catch (Exception ex)
  {
         ...
  }
  finally
  {
      JCoContext.end(destination);
  }

you can reffer the further information from this URL. 您可以通过此URL获取更多信息。 http://www.finereporthelp.com/download/SAP/sapjco3_linux_32bit/javadoc/com/sap/conn/jco/JCoContext.html http://www.finereporthelp.com/download/SAP/sapjco3_linux_32bit/javadoc/com/sap/conn/jco/JCoContext.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM