Python is an easy to learn programming language. As the documentation on the official Python page says, "Python can be easy to pick up whether you're a first time programmer or you're experienced with other languages. Python is powerful... and fast; plays well with others; runs everywhere; is friendly & easy to learn; is Open".
The PyRFC module is the newest way to get externally running Python code integrated with SAP. Srdjan Boskovic explains nicely why you would want a Python/ABAP stack. As he says, "Our language of choice for the web development is Python and a frequent question we hear is why we are using Python and not Java, the de-facto standard for the enterprise."
Setup and installation of PyRFC isn't too difficult on GNU/Linux and OS X. On Windows, it can be a little painful for Python noobies as the C-extension needs to be compiled, and by default Windows doesn't ship with a compiler. These instructions are geared more towards beginners and get you started in the barest possible time without having to compile, as I've pre-compiled the module for you. I've tested this process on Windows 7 and 8.
SAPCAR_315-20010451.EXE -xvf NWRFC_24-20004566
(Note that I used the Windows/IA32 versions of these files, and that the version numbers of the files that you download might not be the same, adjust accordingly!)
It will be necessary to adjust your environmental variables for the install location. Open environmental variables editor, which can be opened as follows: open Control Panel, go to System and Security, then "System", "Advanced System Settings", then click the "Environmental Variables" button. Edit the "Path" environmental variable. This should already have C:\Python\27\ added to it, but we need to also add:
;C:\Python27\nwrfcsdk\lib
to the end of the list. Obviously put another path in if your path isn't C:\Python27\nwrfcsdk\lib
If you forget to set the Path, then your Python code won't be able to use the C-connector and you'll get an error message: "ImportError: DLL load failed"
python distribute_setup.py
From a cmd prompt install as follows:
C:\Python27\Scripts\easy_install-2.7.exe pyrfc-1.9.4-py2.7-win32.egg
Create a config file, sapnwrfc.cfg and insert content like this, obviously set the correct ashost (sap system), client, sysnr, user, passwd:
[connection]
# sap system ip
ashost = xxxxxxx
# sap client id
client = 001
# sap router string, optional, format like /H/x.x.x.x/...
saprouter =
# sap system number
sysnr = 00
# sap username
user = DEVELOPER
# sap password
passwd = xxxxxxx2
[gateway]
# gateway host name
gwhost =
# gateway server name
ghserv =
# name under which the python connector will register itself
program_id = PYRFC_SERVER1
# sap router string, optional
saprouter =
Create a test program file "get_system_info.py" and paste the following into it:
#!/usr/bin/env python
from pyrfc import Connection, ABAPApplicationError, ABAPRuntimeError, LogonError, CommunicationError
from ConfigParser import ConfigParser
from pprint import PrettyPrinter
def main():
try:
config = ConfigParser()
config.read('sapnwrfc.cfg')
params_connection = config._sections['connection']
conn = Connection(**params_connection)
result = conn.call('RFC_SYSTEM_INFO')
pp = PrettyPrinter(indent=4)
pp.pprint(result)
except CommunicationError:
print u"Could not connect to server."
raise
except LogonError:
print u"Could not log in. Wrong credentials?"
raise
except (ABAPApplicationError, ABAPRuntimeError):
print u"An error occurred."
raise
if __name__ == '__main__':
main()
Now, if you run:
python get_system_info.py
You should get a response with system information, like this:
{ u'CURRENT_RESOURCES': 7,
u'MAXIMAL_RESOURCES': 9,
u'RECOMMENDED_DELAY': 0,
u'RFCSI_EXPORT': { u'RFCCHARTYP': u'4103',
u'RFCDATABS': u'NPL',
u'RFCDAYST': u'',
u'RFCDBHOST': u'WDFLBMD6865',
u'RFCDBSYS': u'ADABAS D',
u'RFCDEST': u'wdflbmd6865_NPL_00',
u'RFCFLOTYP': u'IE3',
u'RFCHOST': u'wdflbmd6',
u'RFCHOST2': u'wdflbmd6865',
u'RFCINTTYP': u'LIT',
u'RFCIPADDR': u'172.31.xx.xxx',
u'RFCIPV6ADDR': u'172.31.xx.xxx',
u'RFCKERNRL': u'740',
u'RFCMACH': u' 390',
u'RFCOPSYS': u'Linux',
u'RFCPROTO': u'011',
u'RFCSAPRL': u'740',
u'RFCSI_RESV': u'',
u'RFCSYSID': u'NPL',
u'RFCTZONE': u' 0'}}
It works! And how easy was that?
Notes:
User | Count |
---|---|
1 | |
1 | |
1 | |
1 |