1. install necessary DLL
Install the sap gui application on the machine where Javascript is required to call the sap RFC.
2 webpage example
<Script language = "JavaScript">
<! -- Retcm = 0; Exceptions = 0; // *** saplogon () creates an object that has the methods to // execute a call to an SAP function module function saplogon (){
FNS = new activexobject ("sap. functions "); Trans = FNS. transactions; Conn = FNS. connection;/* Get a new connection object */Conn. system = "Dev";/* set the System ID (see: SY-SYSID) */Conn. user = "userid";/* Set userid (blank for dialog) */Conn. password = "";/* Set Password (blank for dialog) */Conn. client = "100";/* Set Password (blank for dialog) */Conn. language = "e";/* set language (blank for default) */Conn. tracelevel = 6;/* Set Password (blank for dialog) */Conn. rfcwithdialog = 1;/* true: opens visible session window */Exceptions = 0; Conn. logon (0, 0);/***** this call creates the object ****/};
Function saplogoff () {conn. logoff (0, 0); Exceptions = 0 ;};
// *** Execute the sap function module "rfc_call_transaction_using" // as a method execution of object type sap. functionsfunction sapcalltransaction (tcode ){
Exceptions = 0; callta = FNS. add ("rfc_call_transaction_using"); callta. exports ("tcode") = "va02"; callta. exports ("Mode") = "e"; retcm = callta. call; Conn. logoff (); alert (retcm); sapcalltransaction = retcm ;}; // --> </SCRIPT> <body> <! -Create an HTML button with a javascript call attached --> call va02 <input type = "Submit" value = "va02" onclick = "saplogon (); sapcalltransaction (& quot; va02 & quot;); saplogoff () "> </body>