Python and SAP RFC Connections

Firstly download and install the latest stable version of Python. Once done , then download and install the Python library pysaprfc. Copy somewhere in your PYTHONPATH (site-packages for example). Then you can then communicate with your SAP instance utilising code like this.

# Retrieve data from SAP/R3
import pysap

# Variables
WhereSQL    = "IDOCTYP like '%Z_CONN%'"
SQLTable    = "EDIFCT" 
MaxRows     = "5000"
CONN_FILE   = "C:/Python26/pysaprfc/examples/sapconn.ini"

# Change next line to be able to connect to your SAP system

# Read entries from SQLTable 
# Print some fields from itab to show it worked
for p in itab:
 print '%(FCTNAM)s %(FCTVRS)s %(IDOCTYP)s %(CIMTYP)s %(MESTYP)s %(MESCOD)s %(MESFCT)s %(OBJNAM)s %(DIRECT)s' % p