Showing results for 
Search instead for 
Did you mean: 

Newbie: python hetting started with BAPI_PO_CREATE

Former Member
0 Kudos


After studying the documentation and looking for some source code as an example, I am at a total loss and looking for some help. I do not understand how the PO_HEADER (LIKE BAPIEKKOC STRUCTURE BAPIEKKOC) parameter should be filled with data and how the table PO_ITEMS (STRUCTURE BAPIEKPOC) should be handled in the program.

Is there somebody that has some examples or could help me with a basic program setup?

Thanks in advance,


Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Installing the sap rfc module on Windows turned out to become a nightmare. On Linux it was no problem but under Windows it gets very hard. We are using SAP R/3 v4.6C and the Python applicatioin MUST run both on both Linux and Windows.

So I went for the pysaprfc module, which is just a wrapper for the librfc library using ctypes. On Windwos installation is really easy since the librfc library comes with the SAP GUI. On Linux, you have to hunt down a suitable librfc library from the download area on

This is a small example to get the data from a purchase order:"

import pysap

import sys

import ctypes

from mx.DateTime import *





func_res=\['PO_HEADERS', 'PO_ITEMS'\])

print func.desc

po_header, po_items = func(PURCHASEORDER='4500341734')

for t in po_header:

print t

print '----


for t in po_items:

print t


except pysap.SapRfcError,desc:

print "Error making py function for BAPI': %s" % desc

except Exception, e:

print e

Or just read a table with some simple SQL:

data = conn.read_table('EQUI',

options=\["sernr eq '%s'" % sernr\],

fields=\["sernr", 'equnr', 'matnr', 'kunde'\],


The examples directory has some very helpfull code.

The pysap module solved my problem and works great within a Plone / Zope portal. It's efficient and turns out to be very reliant.

Former Member
0 Kudos


Since I don't have a binary for Windows, I tried to install it from source. I had to install the .Net SDK to run build with, but that does give me an error telling me that Python was built with a different compiler. So lets forget Windows.

On Linux I got myself a fresh copy from the latest Python source code and compiled it. Trying to build the sapnwrfc now breaks since I do not have the header files. I have been looking on for the NW SDK but it seems to have disappeared into some area that I can't access. It is not in the download area.

Could somebody point out where the header files are?



Former Member
0 Kudos

Hi -

The SDK is described in Ulrichs post => [original link is broken] [original link is broken] [original link is broken] [original link is broken] Here he mentions OSS note: 1025361 for details.


Former Member
0 Kudos

The syntax looks much better already.

Installing the module with 'python install' gets me the error:

selecting win32 libraries...

running install

running build

running build_py

creating build

creating build\lib.win32-2.4

creating build\lib.win32-2.4\sapnwrfc

copying sapnwrfc/ -> build\lib.win32-2.4\sapnwrfc

creating build\lib.win32-2.4\sapnwrfc\rfc

copying sapnwrfc/rfc/ -> build\lib.win32-2.4\sapnwrfc/rfc

running build_ext

error: The .NET Framework SDK needs to be installed before building extensions for Python.

The documentation only mentions the Unix build process. I looked for the SDK but could not find it. Any chance somebody having a prebuild version?



Former Member
0 Kudos

I am using the saprfc module that comes with 'Scripting in a Box' Version 0.1.0 Date: May 16, 2006. Could it be version 0.11?

I have to make calls to a SAP version 46C system.


Former Member
0 Kudos

Well - you can still use the next generation connector ->

The advantage of this is that the interface should be more intuitive.

saprfc for Python requires syntax something like this to deal with tables:

i ="Z_ORDERS")
oh = i.ORDERS.structure
oh.PARTNER.value = 'V002'
oh.HDRTEXT.value = 'Get me some books please'
oh.DATUM.value = '20030609'
oh.UZEIT.value = '110000'
i.ORDERS.setValue( [ oh.Value() ] )
items = []
oi = i.ORDERITEMS.structure
oi.MATERIAL.value = 'M002'
oi.PRICE.value = 92
oi.QUANTITY.value = 3
oi.MATERIAL.value = 'M001'
oi.PRICE.value = 12
oi.QUANTITY.value = 5
i.ORDERITEMS.setValue( items )
conn.callrfc( i )

Think of the i.XXXX.structure objects as helper classes that format complex values that are then either assigned to structured parameters (i.XXXX.setValue(str.Value())), or appended to arrays that are then assigned to the values of tables (i.ORDERITEMS above).


Former Member
0 Kudos

Can you give me details of which connector you are using?