Query SAP database from Python?

Question:

Can Python be used to query a SAP database?

Asked By: ilya n.

||

Answers:

Python SAP RFC module seems inactive – last (insignificant ) commit 2 years ago – but may serve you:

Pysaprfc is a wrapper around SAP librfc (librfc32.dll on Windows, librfccm.so or librfc.so on Linux). It uses the excellent ctypes extension package by Thomas Heller to access librfc and to define SAP compatible datatypes.

Modern SAP versions go the Web Service way – you could build a SAP Web Service and consume it from Python.

With SAP NetWeaver, developers can connect applications and data sources to integrate processes using Web services.

In particular, developers can use one infrastructure to define, implement, and use Web services in an industry standards based way. SAP NetWeaver supports synchronous, asynchronous, stateful and stateless web service models – enabling developers to support different integration scenarios.

sapnwrfc supports this SAP NetWeaver functionality, supersedes the older RFC SDK, and is actively maintained.

Answered By: gimel

Sap is NOT a database server.
But with the Python SAP RFC module you can query most table quite easily. It is using some sap unsupported function ( that all the world is using). And this function has some limitation on field size and datatypes.

Answered By: Igal Serban

If you’re talking about (what used to be named) the SAP Database AKA SapDb, and is now MaxDB (for a while distributed also by MySql Inc, now again by SAP only — and so named SAP MaxDB), it comes with several Python access modules, documented here.

This is the only meaning I can attach to “SAP as the database engine” — that you want to access SAP MaxDB. Other answers make different assumptions and (I believe) are also correct… under those different assumptions.

Answered By: Alex Martelli

As stated above, when you just want to read tables or do RFC or BAPI calls, you can use CPython with the unmaintained Python SAP RFC module or Piers Harding’s SAP RFC. The RFC calls to just read a table are RFC_GET_TABLE_ENTRIES or RFC_READ_TABLE, where the former is preferred, but also not released to customers.

For a more official way, you can use SAP’s JCO connector with Jython or SAP’s .Net Connector with Ironpython; both connectors can be downloaded from SAP’s service marketplace and both allow to call the RFC functionality including the two calls listed above.

As also stated above, the way proposed by SAP to access backend functionality is via SAP’s vast SOA infrastructure. Here you can use Jython with e.g. the Axis library or Ironpython with Microsofts WCF. Note, that the services provided by SAP obviously won’t allow you to access the plain tables, instead you just can call, what a service provides. SAP already delivers about 3.000 services (see the ES Wiki on SDN), and creating your own service is in fact dead simple, once you have your business logic in a remote-enabled function module.

Answered By: Frank Bechmann

Python RFC connector is now available as open source: PyRFC

Answered By: bsrdjan

SAP now has a Python RFC connector called pyrfc. This supersedes sapnwrfc.

This can be found at: https://github.com/SAP/PyRFC

“The pyrfc Python package provides Python bindings for SAP NetWeaver RFC Library, for a comfortable way of calling ABAP modules from Python and Python modules from ABAP, via SAP Remote Function Call (RFC) protocol.”

Answered By: hansonap

Python is one of the most used object-oriented programming languages which is very easy to code and understand.

In order to use Python with SAP, we need to install Python SAP RFC module which is known as PyRFC. One of its available methods is RFC_READ_TABLE which can be called to read data from a table in SAP database.

Also, the PyRFC package provides various bindings which can be utilized to make calls either way. We can use to make calls either from ABAP modules to Python modules or the other way round. One can define equivalent SAP data types which are used in data exchange.

Also, we can create Web Service in Python which can be used for inter-communication. SAP NetWeaver is fully compatible with web services either state full or stateless.

Answered By: Asish Antony
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.