<html>
<head>
<title>Calling SAP From Javascript</title>
<meta name="JAVASCRIPT" content="Active-X for SAP">
<meta name="AUTHOR" content="Axel Angeli Logos! Informatik GmbH">
<link rel="stylesheet" href="../../style.css" type="text/css">
<meta NAME="keywords"
CONTENT="SAP,R/3,javascript,logosworld,logos!,axel, angeli, axelangeli, activex,IDoc, IDoc, EDI, ALE,RFC, remotefunctioncall,Workflow
, ABAP IV, ABAB IV">
<meta NAME="description"
CONTENT="Axel Angeli's Logosworld - Example how to call SAP R/3 from JavaScript">
</head>
<body>
<h2>Calling SAP From Javascript</h2>
<p>This HTML document contains a small JavaScript which creates an Active-X object for SAP
Automation GUI. When you click on the button below it will try to call the transaction
VA02 using an RFC to the function RFC_CALL_TRANSACTION_USING. You must have SAP Automation
GUI DLLs installed, otherwise you will receive a message, that the Active-X object cannot
be created. To try it out you better install the complete SAP GUI including the RFC SDK. </p>
<p>You will be asked for userid and password. This example works with any ABAP function
that has RFC enabled. </p>
<hr>
<p><script language="JavaScript"><!--
retcd = 0;
exceptions = 0;
function SAPlogon()
{
fns = new ActiveXObject("SAP.Functions");
trans = fns.Transactions;
conn = fns.connection;
conn.System = "DEV";
conn.user = "FIXIONGF";
conn.password = "11894";
conn.Client = "400";
conn.Language = "E";
conn.tracelevel = 6;
conn.RFCWithDialog = 1;
conn.logon(0, 0);
exceptions = 0;
};
function SAPlogoff()
{
conn.logoff(0, 0);
exceptions = 0;
};
function SAPcallTransaction(tcode)
{
exceptions = 0;
callta = fns.add("RFC_CALL_TRANSACTION_USING");
callta.exports("TCODE") = "VA02";
callta.exports("MODE") = "E";
retcd = callta.call;
conn.logoff();
alert(retcd);
SAPcallTransaction = retcd;
};
// --></script> Call VA02 <input TYPE="submit" VALUE="VA02"
onClick="SAPlogon(); SAPcallTransaction("VA02"); SAPlogoff()"> </p>
<hr>
<h3>The following coding is contained in this HTML-Document</h3>
<div align="left">
<table border="0">
<tr>
<td colspan="2"><font FACE="Courier New" SIZE="2"><script
language="JavaScript"><!--</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">retcd = 0;</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">exceptions = 0;</font></td>
</tr>
<tr>
<td colspan="2"> <p><font FACE="Courier New" SIZE="2">function SAPlogon()</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">{</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">fns = new ActiveXObject("SAP.Functions");</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">trans = fns.Transactions;</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn = fns.connection;</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn.System = "DEV";</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn.user = "userid";</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn.password = "";</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn.Client = "100";</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn.Language = "E";</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn.tracelevel = 6;</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn.RFCWithDialog = 1; </font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn.logon(0, 0); </font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">exceptions = 0;</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">};</font></td>
</tr>
<tr>
<td colspan="2"> <p><font FACE="Courier New" SIZE="2">function SAPlogoff()</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">{</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn.logoff(0, 0); </font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">exceptions = 0;</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">};</font></td>
</tr>
<tr>
<td colspan="2"> <p><font FACE="Courier New" SIZE="2">function SAPcallTransaction(tcode)</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">{</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">exceptions = 0;</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">callta =
fns.add("RFC_CALL_TRANSACTION_USING");</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">callta.exports("TCODE") =
"VA02";</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">callta.exports("MODE") = "E";</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">retcd = callta.call;</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">conn.logoff(); </font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">alert(retcd);</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">SAPcallTransaction = retcd;</font></td>
</tr>
<tr>
<td></td>
<td><font FACE="Courier New" SIZE="2">};</font></td>
</tr>
<tr>
<td colspan="2"> <p><font size="2">// --></script></font></td>
</tr>
</table>
</div>
</body>
</html>