cancel
Showing results for 
Search instead for 
Did you mean: 

RFC Connect to SAP with JavaScript

former_member188973
Participant
0 Kudos

Dear all,

is there a way to directly connect to SAP via RFC using JavaScript. Are there any tutorials or code snipplets?

Kind regards

Roman

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

very nice!

sounds like you two collaborate to develop a trojan horse application for SAP systems ))

Thank god, Javascript prohibits cross domain scripting.

Message was edited by:

Anton Wenzelhuemer

CountZero
Explorer
0 Kudos

Hi,

If you are running in a windows environment you can use COM functionality to connect to SAP. Here is some example code for you.

[code]

main()

function main()

{

var txt;

var Row;

var Row2;

var BAPI = new ActiveXObject( "SAP.Functions" );

var Connection = BAPI.Connection;

Connection.ApplicationServer = "xxx";

Connection.Client = "xxx";

Connection.SystemNumber = xxx;

Connection.User = "xxx";

Connection.Password = "xxx";

Connection.logon(0,true);

var Running = BAPI.Add("EW_TH_WPINFO");

var Servers = BAPI.Add("TH_SERVER_LIST");

var Tables = Servers.tables("LIST");

var Dest = Running.exports("DESTINATION");

Dest.value = "NONE";

var CPU = Running.exports("WITH_CPU");

CPU.value = "00";

var List = Running.tables("WPLIST");

Running.Call;

Servers.Call;

for (var enumerator = new Enumerator(Tables.Rows) ;

!enumerator.atEnd(); enumerator.moveNext())

{

Row = enumerator.item();

Dest.value = Row("NAME");

Running.Call;

for (var enumerator2 = new Enumerator(List.Rows);

!enumerator2.atEnd(); enumerator2.moveNext())

{

Row2 = enumerator2.item();

if (Row2("WP_REPORT").length > 0){

txt = txt + "\n" + Row2("WP_PID") + "\t" + Row2("WP_REPORT") + "\t" + Row2("WP_BNAME");

}

}

}

WScript.echo(txt);

}

function jsTrim(strInput)

{

var strResult;

var objRegex = new RegExp("(^
s)|(
s
$)");

strResult = strInput.replace(objRegex, "");

return(strResult);

}

[/code]

This code just gets a list of current users. Save the file as running.js and fill in the xxx parameters with what is relevent for your system.

You will need wdtfuncs.ocx and librfc32.dll registered on your machine.

Hope this helps.

PS in the widgets forum I have given you an example of how to connect to SAP via RFC within widgets.

Nathan

Message was edited by: Nathan Jones

Former Member
0 Kudos

Hi.

Thanx very much for the example, it's been very helpful.

My problem is that it works fine when the html is run from my computer (by double-clicking on it), but when i try to download it from a web server (say JBoss), it doesn't work, because the ActiveX is not signed, and IE doesn't let it run.

Do you have any solution for that?

Thank you very much,

Issahar

gregorw
Active Contributor
0 Kudos

Hi Issahar,

have you the possibility to run the RFC as a Web Service? Then this Blog should be interresting for you:

<a href="/people/andre.fischer/blog/2006/11/05/single-sign-on-of-windows-based-web-service-clients-using-sap-logon-tickets">Single Sign-On of Windows-based Web Service Clients using SAP Logon Tickets</a>

Regards

Gregor

Former Member
0 Kudos

I need to run the RFC on 4.6C, and there aren't Web Services there. Also, the RFC I want to run is a Z program i wrote.

Any other advice please?

Please?

gregorw
Active Contributor
0 Kudos

Hello,

do you have a ITS or some WebAS 6.20 or higher in place?

Regards

Gregor

Former Member
0 Kudos

I need to run it from my site (deployed on JBoss), and not from any SAP web component.

I can only assume that the user has the SAPGUI installed (and therefore has the ActiveX installed).

somehow, this activeX doesn't work in IE, and others do.

Thanx very much for the help.

Issahar.

CountZero
Explorer
0 Kudos

It looks like your IE settings are set up so that the option "Download unsigned ActiveX controls" is set to Disabled. If you renable this option then it should work. However if you do you are opening up your machine to a major security risk.

SAP would have to make sure that the necessary stuff is signed.

Former Member
0 Kudos

thanx Nathan.

I figured it out:

The Sap.Function activeX is not signed as "safe for scripting" and therefore there isn't any problem loading it, but calling it from JavaScript it not allowed.

The "safe for scripting" is something rather new (since October 2005 or so).

The problem is that the default settings in IE is to disable unsigned activex scripting, and i can't change it in the customers computer - it is a web application for the public, not an Intranet product.

Someone has any idea what to do?

gregorw
Active Contributor
0 Kudos

Hello,

create a Web Service in your JBoss SErver which calls the SAP Backend RFC Functions using the SAP Java Connector.

Regards

Gregor

Former Member
0 Kudos

Hi.

Thanx very much for taking the time and answering me.

The Web Service doesn't help me.

I need the RFC to run on the client side, because if it will be in a web service on my Jboss, it will be outside the user's firewall, and won't work.

i need it to be a call from the client side.

Jus.

gregorw
Active Contributor
0 Kudos

Hi,

can you describe the connections in detail with a little picture like


Internet
Client-----
  |       |
 HTTP    RFC
  |       |
JBoss     |
        Firewall
          |
        SAP R/3

My suggestion is:


Internet
Client
  |
 HTTP
  |
JBoss-----
          |
         RFC
          |
        Firewall
          |
        SAP R/3

Regards

Gregor

Former Member
0 Kudos

Hi.

i tried to draw a diagram, but this posting software mixed it all up.

so i'll explain in words:

we have a web site which is an application. when the user enters our application (a web page that is downloaded into his machine), we want to run some RFC on HIS/HER sap system, and send the results to our server.

This is running RFC inside the customer's organization, and there isn't any firewall problem.

we can't make the web page call the RFC on the server side, because that way the RFC call will be blocked by the firewall (it will be called from OUR servers, which are outside the customer's firewall).

This is the situation.

help. please.

Issahar.

gregorw
Active Contributor
0 Kudos

Hello Issahar,

you can use the [ code ] tag to draw. Is this picture correct:


JBoss
  | 
HTTP
  |  
Firewall
  |
  ---------
  |       |
Client   RFC
          |
        SAP R/3

Regards

Gregor

Former Member
0 Kudos

i think it is correct.

the rfc call is on the client side, protected by firewall, and the jboss is at our site.

gregorw
Active Contributor
0 Kudos

Hello,

why can't the application run on the Customers own JBoss Server?

Regards

Gregor

Former Member
0 Kudos

that way it won't be an Internet service, but will need an installation on each of our customers' servers...

It's a big problem...

gregorw
Active Contributor
0 Kudos

Hello,

perhaps the easy solution is a DNS alias from the customer domain:

externalapp.company.com to jboss.asp.com

The domain company.com is in the Browsers Intranet Zone and can be trusted. That way it could work.

Regards

Gregor

gregorw
Active Contributor
0 Kudos

Hello Roman,

there is no JavaScript RFC connector. And I don't think that they will ever be one. There is a connector for Java. What you can do with JavaScript is to call Web Services.

Regards

Gregor

eddy_declercq
Active Contributor
0 Kudos

Hi,

You can opt for Ajax too.

Check things like /people/daniel.mcweeney/blog/2005/05/26/how-to-create-ajax-applications-in-sap

/people/sap.user72/blog/2005/08/15/ajax-and-htmlb--a-sample-bsp-application

...

etc

Eddy