cancel
Showing results for 
Search instead for 
Did you mean: 

how to call commit/rbck when calling a bapi as a web service in web as 6.20

Former Member
0 Kudos

When trying to create/update records, If the create/update bapi is called thru a web service.

What is the best practice to call a commit when using webservices. Can we call commit/rollback after calling a webservice and checking the error table for errors. I would like to call committ/rollback from .net after i call the webservice and check for errors.

Message was edited by: Tarun Gogia

Accepted Solutions (0)

Answers (1)

Answers (1)

reiner_hille-doering
Active Contributor
0 Kudos

You need to do two things:

- You must have BAPI_TRANSACTION_COMMIT in your proxy. When getting the WSDL (see other thread) just add it separated by a comma.

- You need to turn the use of a common session on. This is done with the query string parameter "session_mode". For details please see the samples / docu and my answer on the thread .

Former Member
0 Kudos

Reiner,

<b>1. Could you provide an example for how to use bapi_transaction_commit in any other update/add webservice.I couldn't find it in the thread you gave the link to. DO I have to add BAPI_TRANSACTION_COMMIT as a web reference. I am not sure where to add BAPI_TRANSACTION_COMMIT separated by a comma</b>

<b>2. About the querystring parameter session_mode = 1 in the first call and session_mode =2 in the last call, does it mean we can have multiple adds/updates and in the end we might just commit or rollback depending on if there were no errors. Also, this querystring should it be in url for wsdl which is used to add a web reference.</b>

Thanks..

Tarun

reiner_hille-doering
Active Contributor
0 Kudos

1. To get WSDL you use the url

http://<host_name>:<port_number>/sap/bc/soap/wsdl/?services=<functionmodule_names>&sap-client=<relev...; , where <functionmodule_names> is a comma-separated list of BAPIs, including BAPI_TRANSACTION_COMMIT.

This will create you a C#/VB proxy with all specified methods in one class.

2. Yes, each official BAPI will only store any changes in the Udate process. You need to call BAPI_TRANSACTION_COMMIT to commit the changes. Else they are lost.

The session_mode parameter must be appendend to the standard-URL from WSDL. You specify it only at runtime - not at design time.

Former Member
0 Kudos

How do i change the wsdl url at runtime. The url property on the service which i instantiated is different and ends with sap/bc/soap/rfc. it isn't the wsdl url. How do i get access and change the wsdl's url.

Thanks...

reiner_hille-doering
Active Contributor
0 Kudos

>The url property on the service which i instantiated is

> different and ends with sap/bc/soap/rfc.

Yes, this is correct. This is the correct thing to change:

WebServiceProxy proxy = new WebServiceProxy();
...
string orgUrl = proxy.Url;
proxy.Url = orgUrl  + "&session_mode=1";
proxy.FirstCall();
proxy.Url = orgUrl;
proxy.SecondCall();
proxy.Url = orgUrl  + "&session_mode=2";
proxy.LastCall();

Former Member
0 Kudos

I am not sure , i understood what you meant by webserviceproxy. Please have a look the following code snippet. Is it totally to avoid using web-reference and consuming it dynamically. Is it a kind of add-on (webserviceProxy) or am i just missing a namespace.

<b>S.url at runtme is

http://<server-name>:8000/sap/bc/soap/rfc</b>;

<b> 'bpadd is the web-reference name

Dim s As bpadd.RfcService = New bpadd.RfcService()

s.Credentials = cred

Dim BuisnessPartner As String = "0000000232"

Dim BAPIRET2() As bpadd.BAPIRET2 = _

{New bpadd.BAPIRET2()}

Dim tmpUrl As String

tmpUrl = s.Url + "&session_mode=1"

s.Url = tmpUrl

s.YEXTERNALBPADD(BuisnessPartner, BAPIRET2)

tmpUrl = s.Url + +"&session_mode=2"

s.Url = tmpUrl

Dim ErrTable As bpadd.BAPIRET2

ErrTable = s.BAPI_TRANSACTION_COMMIT("")</b>

reiner_hille-doering
Active Contributor
0 Kudos

Your code is allmost correct except

- You must save the original url in a string and restore it. In your current code you concatenate "&session_mode=1" with "&session_mode=2".

- If your org URL doesn't already contain query string parameters, you nee to use "?" as delemiter:


'bpadd is the web-reference name
Dim s As bpadd.RfcService = New bpadd.RfcService()

s.Credentials = cred
s.CookieContainer = new CookieContainer();

Dim BuisnessPartner As String = "0000000232"
Dim BAPIRET2() As bpadd.BAPIRET2 = _
{New bpadd.BAPIRET2()}

Dim tmpUrl As String
tmpUrl = s.Url

s.Url = tmpUrl + "?session_mode=1"

s.YEXTERNALBPADD(BuisnessPartner, BAPIRET2)
s.Url = tmpUrl
' do any additional calls here

Dim ErrTable As bpadd.BAPIRET2
s.Url = tmpUrl + "?session_mode=2"
ErrTable = s.BAPI_TRANSACTION_COMMIT("")

Former Member
0 Kudos

Thanks,it worked fine...

Though i have a question, how would this scenario work when multiple users over the web are calling the webservices. I mean though we have a session , but not a sessionID, to uniquely identify a user. So though mutiple calls to bapis would go in a session, but it may not be unique to the user. Is that correct...

reiner_hille-doering
Active Contributor
0 Kudos

Each Web-Request with "session_mode=1" creates a new session on ABAP side, regardless if there is alreay one from the same or other user. It remains open until you do a call with "session_mode=2". The "handle" to the session is the cookie in the CookieContainer.