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?
Fiveo source share