cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI Transaction commit in JCo

Former Member

Hi,

I am posting a GL document via JCo (Java Program ) into SAP using the BAPI_ACC_DOCUMENT_POST and then calling the BAPI_TRANSACTION_COMMIT to commit the transaction so that it gets updated in SAP system.

After i execute my program, i get the posting successful message and document number is returned to me. But when i look for this document in the SAP system, it is not found.

Any help will be appreciated.

Below is the piece of code where i execute the BAPI's in java after mapping the required data.

function.execute(destination);

System.out.println("Function BAPI_ACC_DOCUMENT_POST executed .");

commFunct.getImportParameterList().setValue("WAIT", "10");

commFunct.execute(destination);

System.out.println("Function BAPI_TRANSACTION_COMMIT executed .");

Regards,

Ganesh.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Hi Ganesh,

With JCo3 the connections are no longer stateful by default, so each RFC call is executed within it's own context. In your case though, you want the commit to occur in the same context where you posted the document. You can do this by adding the following static method calls:


JCoContext.begin(destination);
// Execute both RFC functions here
JCoContext.end(destination);

You can also check the Java API help for JCoContext, which explains this in more detail. Once you added the two lines (ideally end the context in a finally block), you should see the document in SAP.

Cheers, harald

Former Member
0 Kudos

Hi Harald,

It worked. Thanks a lot !!

Regards,

Ganesh.

Former Member
0 Kudos

Hi Ganesh,

  Now ,I  have met the same question with you,can you tell me how it how you had mad it work !!

Any help will be appreciated.

Regards,

Jiams

Former Member
0 Kudos

Thanks Harald,

Your answer helps me a lot too!

cruzer45
Member
0 Kudos

Thanks Harald,

This was the key to getting my code working.

former_member725581
Discoverer

Life savior!

I spent half a day finding why my commit wasn't working.

Thanks Harald!

For those who don't know how to use, here an example:

JCoDestination myDestination;
JCoContext.begin(destination);

JCoFunction myFunction1 = myDestination.getRepository().getFunction("BAPI_INCOMINGINVOICE_CREATE1")
// Fullfil input for myFunction1
myFunction1.execute(myDestination)

JCoFunction myFunction2 = myDestination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT")
// Fullfil input for myFunction2
myFunction2.execute(myDestination)

JCoContext.end(destination);





Answers (3)

Answers (3)

JcoContext.begin(destination) and end(destination) may not work for all senarios as we pass destination as param for these methods which has scopetype attribute as null , instead call below container maually in your ERP class which would make connection as statefull for making bapicommit to sap

@Autowired

JCoManagedConnectionContainer sapCoreManagedConnectionContainer;

final JCoConnection jcoConnection = sapCoreManagedConnectionContainer.getManagedConnection("JCoStatefulServiceUser", "destinationname");

now use this jcoConnection object for executing BAPI * CREATE FM and BAPI_TRANSACTION_COMMIT and remove JcoContext.begin and end() methods.

Former Member
0 Kudos

Hi,

Use statement commFunct.getImportParameterList().setValue("WAIT", "10"); after COMMENT statement.

Former Member
0 Kudos

Hi Ganesh_sn,

Don't use WAIT parameter when calling commit BAPI.

Former Member
0 Kudos

Hi Erhan,

Thanks for your quick response. Actually i tried without giving the WAIT parameter initially after which i tried giving the WAIT

In both the cases, the java program runs successfully returning the document number as return message which is not posted in SAP system. What could be the issue ?.

Regards,

Ganesh.