Question

I'm using the JCo Library to access SAP standard BAPI. Well everything is also working except that the RETURN Table is always empty when I use the TID (TransactionID).

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.

Why is the RETURN TABLE empty when using TID?

Or how must I commit changes to a transactional BAPI?

Here speudo-code of a BAPI access:

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. Solution is to do just both, a commit without TID, get the RETURN table and then making again a commit with TID.

Very very strange, but maybe the correct usage of the JCo Commits. Can someone explain this to me?

Was it helpful?

Solution

I was able to get both, RETURN table filled and Inputs commited.

Solution is to do just both, a commit without TID, get the RETURN table and then making again a commit with TID.

OTHER TIPS

You should not call execute method 2 times it will incremenmt sequence number You should use begin and end method in JCoContext class.

If you call begin method at the beginning of the process, the data will be updated and message will be returned. 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. http://www.finereporthelp.com/download/SAP/sapjco3_linux_32bit/javadoc/com/sap/conn/jco/JCoContext.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top