Hello SAP, It's Ruby Calling
Posted by Stijn Pint on Feb 10, 2010
In one of our projects we need communication between a custom Ruby on Rails application and an SAP system.
In short: the Rails application is analyzing data from different sources, doing some calculations with it and the results should be sent to SAP.
The way we do this now is by writing csv files to a specific location on a fileserver, in SAP there is job that polls this directory every 15 minutes.
As a first step, and to test a real SAP-Ruby interface, we would like to send an event to SAP when the csv files are in place, so that we can eliminate the polling job.
Here are the different steps I took for this experiment:
First of all, you need the SAP RFC SDK libraries for your specific OS (nwrfcsdk)
You can get these from the SAP marketplace, but this sounds a lot easier than it is:
- You need to be customer or partner to get an account
- When you've found the files you need on this website, you'll notice you have to install the "SAP Download manager" first (OMG!)
- But you're still not done... believe it or not, you will need an additional SAP tool "SAPCAR" to extract the archived files you just downloaded :-s
How crazy is this ?
If you're lucky (like me), you have a SAP helpdesk at your company that has the files available for you...
Next, you need the appropriate Ruby libraries: sapnwrfc
Download them here,
the docs you'll find here. (With thanks to Piers Harding)
Installation instructions are in the docs and in the README.
I wasn't able to get it to work on MacOSX (Snow Leopard) or Windows (2003),
but it worked fine on a clean Ubuntu installation (VM with Virtualbox)
Once installed, you can quickly check if it's working through irb:
require 'sapnwrfc'
=> true
Now, we'll try to establish a connection with our SAP system.
There is an example in the sapnwrfc docs to get you started.
Also the different tests that come with the spanwrfc library give you a good overview of the functionality.
Basically, the following ruby script should do it:
require 'sapnwrfc'
TEST_FILE = 'your_config.yml'
# # specify the YAML config source and load
SAPNW::Base.config_location = TEST_FILE
SAPNW::Base.load_config
conn = SAPNW::Base.rfc_connect
#
# # Inspect the connection attributes
attrib = conn.connection_attributes
$stderr.print "Connection Attributes: #{attrib.inspect}\n"
#
# # pull in your RFC definitions
rfcd = conn.discover("BAPI_YOUR_THING")
rfc = fld.new_function_call
#
# set the parameters for the call
# skipped here, depends on your RFC
#
rfc.invoke
# # close the RFC connection and destroy associated resources
conn.close
Important here is the your_config.yml file where you specify your specific connection parameters.
It should look something like this:
ashost: your.sap_host.com
sysnr: "00"
client: "510"
user: your_user
passwd: your_pass
lang: EN
trace: 1
Next to ashost, user and passwd, also sysnr and client are important and depend on your SAP installation.
You won't be able to establish a connection if they are wrong... you can trust me on that one ;-)
Of course, you'll also need the name of the RFC you're going to call in SAP ("BAPI_YOUR_THING" in the example above).
There is still some more testing to be done before we can put this functionality in production.
And I'll also have to get this running on Windows...(or finally convince the client to move to linux ;-)
However, I think this can be considered a very successful experiment.
It definitely opens up a lot of new possibilities to tightly integrate our Ruby and Rails applications with existing enterprise infrastructure.
Entries per category
- 6 pages are tagged with docpublisher
- 11 pages are tagged with events
- 14 pages are tagged with rails
- 30 pages are tagged with ruby
- 7 pages are tagged with sharepoint
