5

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?

FiveO
  • 4,315
  • 3
  • 40
  • 78
  • When you're using transactions you're not able to get any export values or tables. When you don't use transaction, you can hit the 5-10 minute foreground execution time limit. – Balazs Gunics Nov 13 '14 at 08:38

2 Answers2

2

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.

FiveO
  • 4,315
  • 3
  • 40
  • 78
  • HI, I encountered exactly the same problem as you. and I couldn't find way to solve this issue. so I'll follow your solution which commit 2 times... it is bit strange code though.. thank you for your information anyway. – Naga Oct 14 '15 at 01:29
  • I found a probem with this code. if we call execute 2 times, unique number (auto count up number such as slip number) will be updated 2 time. so slip number will be 1, 3, 5, 7 – Naga Oct 14 '15 at 05:47
1

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

Naga
  • 8,886
  • 2
  • 17
  • 32