cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Web Service Call via javascript

Former Member
0 Kudos

I spent a lot fo time in testing a SAP Web Service via javascript.

Here is an example for calling a SAP Web Service called Z_MATANF_INTRANET_AUFTR via javascript:

function callSAPService() {

try {
var xmlhttp =new ActiveX Object("MSXML2.XMLHTTP.3.0");
var action
action = "http://www.sap.com/Z_MATANF_INTRANET_AUFTR";
var sURL= "http://brvsapp1v1.egv.at:8000/sap/bc/soap/rfc?services=Z_MATANF_INTRANET_AUFTR%3Fsap-client%3D011"
xmlhttp.Open("POST", sURL,false);
xmlhttp.setRequestHeader("SOAPAction", action);
xmlhttp.setRequestHeader("Content-Type", "text/xml");

var SOAPEnvelope = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' "
SOAPEnvelope += "xmlns:urn='urn:sap-com:document:sap:rfc:functions'>"
SOAPEnvelope += "<soapenv:Header/>"
SOAPEnvelope += "<soapenv:Body>"
SOAPEnvelope += "<urn:Z_MATANF_INTRANET_AUFTR>"
<!--You may enter the following 5 items in any order-->
SOAPEnvelope += "<DATAB>2010-07-01</DATAB>"
SOAPEnvelope += "<KOKRS>0001</KOKRS>"
SOAPEnvelope += "<ZAUFTR>"
<!--Zero or more repetitions:-->
SOAPEnvelope += "<item>"
SOAPEnvelope += "</item>"
SOAPEnvelope += "</ZAUFTR>"
SOAPEnvelope += "<ZKOSTL>"
<!--Zero or more repetitions:-->
SOAPEnvelope += "<item>"
SOAPEnvelope += "</item>"
SOAPEnvelope += "</ZKOSTL>"
SOAPEnvelope += "<ZVORG>"
<!--Zero or more repetitions:-->
SOAPEnvelope += "<item>"
SOAPEnvelope += "</item>"
SOAPEnvelope += "</ZVORG>"
SOAPEnvelope += "</urn:Z_MATANF_INTRANET_AUFTR>"
SOAPEnvelope += "</soapenv:Body>"
SOAPEnvelope += "</soapenv:Envelope>"
xmlhttp.Send(SOAPEnvelope);
}
catch (e) {
....
}

var xmlDoc=new ActiveX Object("MSXML2.DOMDocument.3.0");
xmlDoc.async=false;

var tmpXML = xmlhttp.responseXML.xml

.....

}

Edited by: Rainer Barta on Jul 14, 2010 5:38 PM

Accepted Solutions (0)

Answers (4)

Answers (4)

0 Kudos

Add code for Basic Auth

xmlhttp.setRequestHeader("Authorization", "Basic RVhUX0FCQVwewewwenRlbGxvMTA2NA==");

Former Member
0 Kudos

Hi Rainer,

How do you pass SAP user id and password ?

prabhanjan_reddy
Participant
0 Kudos

Hi Subramaniam,

Did you get the answer how we are passing the Userid and password though the URL.

Please can you share me how i can proceed further.

Thanks,

Prabhu

former_member583013
Active Contributor
0 Kudos

This wasn't a question but a nice contribution.

Greetings,

Blag.

Former Member
0 Kudos

Hi,

Could you try to explain what happens in the following snippet from your code:

---

var action

action = "http://www.sap.com/Z_MATANF_INTRANET_AUFTR";

var sURL= "http://brvsapp1v1.egv.at:8000/sap/bc/soap/rfc?services=Z_MATANF_INTRANET_AUFTR%3Fsap-client%3D011"

xmlhttp.Open("POST", sURL,false);

xmlhttp.setRequestHeader("SOAPAction", action);

xmlhttp.setRequestHeader("Content-Type", "text/xml");

---

Thx.

Former Member
0 Kudos

Hi Brian

xmlhttp.Open("POST", sURL,false); <---the xmlhttp Request is initialized with the address stored in sURL (which is the address of the BAPI Procedure of our SAP Server, Request Method is "POST", false means that the call is synchronous

xmlhttp.setRequestHeader("SOAPAction", action); <-- action must be www.sap.com / + Name of den BAPI Procedure

xmlhttp.setRequestHeader("Content-Type", "text/xml"); <-- these Header Variables must be set

I hope I could answer your question.