cancel
Showing results for 
Search instead for 
Did you mean: 

RFC connection to SAP with Yahoo Widgets

CountZero
Explorer
0 Kudos

Hi,

I am trying to create an RFC connection to SAP with the Yahoo Widget engine. I can do this fine with ordinary JavaScript files on my PC so everything is registered correctly.

My Jscript code (which works) is

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

However when I update the syntax for the Yahoo Widget engine to be

var BAP = COM.createObject( "SAP.Functions" );

I get the following error message "Invalid Callee".

Has anyone tried the RFC method to access SAP data in this way? I cannot use the example of BSP pages given in the weblogs as we do not have this set up yet. Is this a problem with the Yahoo Widget engine?

Many thanx for any help.

Nathan

Accepted Solutions (0)

Answers (3)

Answers (3)

johna69
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Nathan,

Was it possible for you to use a web service call rather than SAPRFC? The decision over RFC or Web Service is something that frequently crops up in the PHP Scripting forum.

Regards

JohnA

CountZero
Explorer
0 Kudos

Hi,

I am sure it is possible to use webservices to do this - however I chose this approach for a number of reasons. 1, I needed something which would require no extra development/config within SAP. 2, we don't use webservices at our organisation yet and 3, this solution would work as far back as 4.0b version of SAP.

If I get chance I will have a go at using web services as I would like an approach which doesn't involve shelling out to a script and would also provide a cross platform solution.

Thanx

Nath

martinlang
Advisor
Advisor
0 Kudos

Hi Nathan,

thanks a ton for this example, I actually implemented it on my machine and it works great.

Through using the RFC_READ_TABLE it's so generic, it can easily be re-packaged for all kinds of things.

Somehow I cannot convert the *.kon and *.vbs file into a .widget though.

It can't find the .vbs file as soon as it's "flattened" into a .widget . Is that the way it is, or is there a way to get around it?

Thanks

Martin

CountZero
Explorer
0 Kudos

Hi Martin,

To use this example as a widget, just add the two files to a zip file and then rename the zip to widget. So for example data_read.zip becomes data_read.widget. Don't flatten out the widget as it will not work.

Hope this helps.

Nath

martinlang
Advisor
Advisor
0 Kudos

Thanks!! This works great! Sometimes it's so easy, but I never knew, that I can just zip and rename as a second option as well.

Is there any news from the Konfabulator Developer about the "Invalid Callee" error? I guess if it worked directly from Javascript it might give us a few more options in terms of easier formatting/working with the data returned, right?

All the best

Martin

former_member188973
Participant
0 Kudos

I have seen Widgets at TechEd in Amsterdam. I would like to play a bit around with it and need some code to connect to SAP (RFC) are you able to send me a copy of the code for RFC you did yet?

Kindest regards

Roman Becker

CountZero
Explorer
0 Kudos

Hi Roman,

I can send you the code - however the connection to SAP does not work. It errors with the message "Invalid Callee". I reference SAP.Functions.

I have emailed the developer for the Yahoo Widgets with the controls that are causing the question and am waiting to hear back from them about possible solutions.

I am currently trying other solutions, one of which is to use a product called Samurize - but it doesn't give me the functionality I need.

If I get something working then I will post it but until then there isn't much point.

Sorry I can't be more help - but I am trying other solutions.

Nath

CountZero
Explorer
0 Kudos

Ok,

I have something working now, it is a major cludge but it seems to do the job and "works for me!".

This monitors an SAP system for a particular job (with today's date) and reports on its status.

Here is the widget code save this bit as SAPMon.Kon.


<?xml version="1.0" encoding="UTF-8"?>
<widget>
	<debug>off</debug>
	<window>
		<name>main_window</name>
		<title>My First Widget</title>
		<visible>true</visible>
		<text>
			<vOffset>20</vOffset>
			<size>12</size>
			<name>Header</name>
		</text>
		<textarea>
			<vOffset>30</vOffset>
			<scrollbar>yes</scrollbar>
			<name>myText</name>
			<columns>20</columns>
			<lines>8</lines>
			<size>12</size>
			<editable>false</editable>
			<alignment>left</alignment>
		</textarea>
	</window>
	<pre><code>
		<title>Job Name:</title>
		<name>SAPJob</name>
	</code></pre>	
	
	<pre><code>
		<title>Application Server:</title>
		<name>SAPAppServ</name>
	</code></pre>	
	<pre><code>
		<title>Client:</title>
		<name>SAPClient</name>
	</code></pre>
	<pre><code>
		<title>System Number:</title>
		<name>SAPSysNo</name>
	</code></pre>	
	<pre><code>
		<title>User ID:</title>
		<name>SAPUId</name>
	</code></pre>	
	<pre><code>
		<title>Password:</title>
		<name>SAPPassword</name>
		<secure>yes</secure>
	</code></pre>	
	<pre><code>
		<title>Update Interval:</title>
		<type>slider</type>
		<minLength>1</minLength>
		<maxLength>15</maxLength>
		<ticks>15</ticks>
		<tickLabel>1</tickLabel>
		<tickLabel>Minutes</tickLabel>
		<tickLabel>15</tickLabel>
		<defaultValue>1</defaultValue>
		<description>Select how often you want the SAP information to update.</description>
	</code></pre>	
	
	<timer>
		<name>timer</name>
		<interval>1</interval>
		<ticking>true</ticking>
		<onTimerFired>
			<![CDATA[
				QuerySAP();
			
		
	
	
		myText.data = info;
	
	
		function updateBehavior()
		{
			timer.interval = preferences.timerIntervalPref.value * 60;
		}
		function QuerySAP()
		{
			var info;
			var cmdLine;
			cmdLine = "cscript.exe //nologo sap.vbs ";
			cmdLine = cmdLine + preferences.SAPJob.value + " ";
			cmdLine = cmdLine + preferences.SAPAppServ.value + " ";
			cmdLine = cmdLine + preferences.SAPClient.value + " ";
			cmdLine = cmdLine + preferences.SAPSysNo.value + " ";
			cmdLine = cmdLine + preferences.SAPUId.value + " ";
			cmdLine = cmdLine + preferences.SAPPassword.value + " ";
			runCommandInBg(cmdLine, "info");
			Header.data = "Job: " + preferences.SAPJob.value;
		}		
		updateBehavior();
		QuerySAP();
	
	
	
		updateBehavior();
	

]]>

The SAP.vbs file looks like the following (save as SAP.vbs in the same directory as the above file).


'*********************************************
main()
Sub Main()
	dim objBAPIControl
	dim objConnection
	dim objTableRead
	dim objTable
	dim objOptions
	dim objFields
	dim objData
	dim objItem
	dim sData
	const Job = 0
	const AppServ = 1
	const Client = 2
	const SysNo = 3
	const UId = 4
	const Pwd = 5
	Set objArgs = WScript.Arguments

	Set objBAPIControl = CreateObject("SAP.Functions")
	Set objConnection = objBAPIControl.Connection
	objConnection.ApplicationServer = objArgs(AppServ)
	objConnection.Client = objArgs(Client)
	objConnection.SystemNumber = objArgs(SysNo)
	objConnection.User = objArgs(UId)
	objConnection.Password = objArgs(Pwd)
	
	if objConnection.logon(0,true) = false then
		wscript.echo "Error Logging in"
		exit sub
	end If
	
	set objTableRead = objBAPIControl.Add("RFC_READ_TABLE")
	set objTable = objTableRead.exports("QUERY_TABLE")
	objTable.Value = "TBTCO"
	set objOptions = objTableRead.tables("OPTIONS")
	objOptions.Rows.Add
	objOptions(1, "TEXT") = "JOBNAME = '" & objArgs(Job) & "'"
	objOptions.Rows.Add
	objOptions(2, "TEXT") = "AND STRTDATE = '" & formatdate() & "'"

	set objFields = objTableRead.tables("FIELDS")
	objFields.Rows.Add
	objFields(1, "FIELDNAME") = "STATUS"
	objFields.Rows.Add
	objFields(2, "FIELDNAME") = "STRTTIME"
	set objData = objTableRead.tables("DATA")
	objTableRead.Call
	for each objItem in objData.Rows
		select case left(objItem("WA"),1)
			case "F"
				sData = sData & "Completed " & vbtab
			case "C"
				sData = sData & "Canceled " & vbtab
			case "A"
				sData = sData & "Active " & vbtab
		end select
		sData = sData & mid(objItem("WA"),2,2) & ":" & mid(objItem("WA"),4,2)
		sData = sData & vbcrlf
	next
	wscript.echo sData
end sub

private function FormatDate()
	dim sDate
	sDate = date()
	formatDate = right(sDate,4) & mid(sdate,4,2) & left(sdate,2)
end function

When you first run the widget you will get errors until you set up the preferences.

Please let me know if you find something that doesn't work.

If you want to test your VBS file it will work stand alone (just double click on it or write a test harness).

To run - just double click on the SAPMon.KON file!

Nath

Message was edited by: Nathan Jones with a working example

Former Member
0 Kudos

Hi Nathan,

I tried to create the Widget in the way you mentioned.I tried passing the parameters of SysId, AppServer,Client in SAP.vbs code instead of 1,2,3,4,5 . When I am trying to execute this file , its throwing an error for this line of code

Set objBAPIControl = CreateObject("SAP.Functions")

saying that ActiveX Component cant create Object : SAP.Functions,

Can you please resolve & guide or

Can you please provide me some code of a simple widget using vbs or javascript to connect to SAP through RFC/ Webservices .. Your response would be very usefull..

CountZero
Explorer
0 Kudos

Hi,

It looks like the following files are not registered on your PC.

wdtfuncs.ocx (In SAP GUI directory)

wdtlog.OCX (In SAP GUI directory)

LIBRFC32.DLL (In windows\system32).

If you can't find the files (usually because the SAPGUI has not not installed them or is not on your machine). Then I would get the necessary files, put them in your windows\system32 directory then run the following commands from the command prompt

regsvr32 c:\windows\system32\wdtfuncs.ocx

regsvr32 c:\windows\system32\wdtlog.ocx

regsvr32 c:\windows\system32\librfc32.dll

That shouuld sort you out.

The sample code I mentioned is above in the messages.

I have not had a look at the webservices method yet.

If you are still having problems then I would suggest waiting until SAP Foundation gets released.

Thanx

Nath

Former Member
0 Kudos

Thanks Nathan, Can u get me the necessary files as u mentioned. I will try runnig the commands after having that in my system.

Regards,

Santhosh

athavanraja
Active Contributor
0 Kudos

Welcome to SDN.

I am also looking into this and not successful so far.

did you check this forum

http://www2.konfabulator.com/forums/index.php?act=idx

i will update this thread with my findings

Regards

Raja

CountZero
Explorer
0 Kudos

I did have a look on the Yahoo forums. It seems like the COM interface with the Yahoo widgets has some problems with the current version, I believe it is being totally overhauled. When a new version appears I will see if that works with SAP's RFC interface.

In the meantime I have solved my immediate problem using the Samurize product but I was hoping to do it all with the Yahoo widget engine.