on 12-16-2009 9:54 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Use statement commFunct.getImportParameterList().setValue("WAIT", "10"); after COMMENT statement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ganesh_sn,
Don't use WAIT parameter when calling commit BAPI.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.