SAP JCo RETURN Table is empty when using TransactionID

I am using the JCo Library to access the standard SAP BAPI. Well, everything works, except that the RETURN table is always empty when I use TID (TransactionID).

When I just delete the TID, I get a RETURN table populated by Warnings, etc. But unfortunately, I need to use TID for transactional BAPI, otherwise the changes will not be made.

Why is RETURN TABLE empty when using TID?

Or how can I make changes to a transactional BAPI?

Here's the speudo BAPI passcode:

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 01/10/2013: Finally, I was able to get both values: the RETURN table is full and Inputs are entered. The solution is to do both: commit without TID, get the table RETURN, and then commit again with TID.

Very strange, but perhaps the correct use of JCo Commits. Can someone explain this to me?

+4
source share
2 answers

I managed to get both values: the RETURN table is full and Inputs are entered.

The solution is to perform both both commit and no TID , get the table RETURN, and then commit again with TID .

+1
source

You do not have to call the execute method 2 times to increase the sequence number. You must use the begin and end method in the JCoContext class.

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

0
source

All Articles