on 07-14-2010 12:57 PM
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
Add code for Basic Auth
xmlhttp.setRequestHeader("Authorization", "Basic RVhUX0FCQVwewewwenRlbGxvMTA2NA==");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rainer,
How do you pass SAP user id and password ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This wasn't a question but a nice contribution.
Greetings,
Blag.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.