SAP R/3 automation with win32com

obou at my-deja.com obou at my-deja.com
Mon Dec 4 03:49:03 EST 2000


Hello!

I'm trying to do SAP R/3 automation with win32com using the SAP DCOM
Connector (a tool that presents SAP Business objects as COM Components).
The business objects (BAPI) are kind of objects with parameters and
methods.
Everything works fine, except the function call (the most important
part of course), and it could be because of the way I have to give the
different parameters to the BAPI method. I have a VB example and don't
know if the way I convert the VB function call to python function call
is correct.
Maybe someone who knows both VB and Python could help me.

Here's the Python code:

from win32com.client import Dispatch

# Create a connection object
sapConn = Dispatch('SAP.CCSession.1')

# Insert connection informations
syst = raw_input('System :')
uname = raw_input('Username: ')
pwd = raw_input('Password: ')
client = raw_input('Client: ')
sapConn.PutSessionInfo(syst, uname, pwd, 'EN', client)

# Log in
sapConn.Logon()

# Create a sales order business object
salesOrd = sapConn.CreateInstance('SAP.SalesOrder.1')

# Create the parameters for calling the method CreateFromData
header = salesOrd.DimAs('BapiCreateFromData', 'OrderHeaderIn')
itemsIn = salesOrd.DimAs('BapiCreateFromData', 'OrderItemsIn')
partners = salesOrd.DimAs('BapiCreateFromData', 'OrderPartners')
ret = salesOrd.DimAs('BapiCreateFromData', 'Return')

# Initialize structure with data.
partners.AddNew()
partners.Fields("Partn_Role").Value = 'AG'
partners.Fields("Partn_Numb").Value = '0000001234'
partners.Update()

# Method call. Everything works fine up to this call!!!
salesOrd.BapiCreateFromData(OrderHeaderIn = header,
                            OrderItemsIn = itemsIn,
                            OrderPartners = partners,
                            Return = ret)

In VB this function call looks like this:
salesOrd.BapiCreateFromData OrderHeaderIn:=header,_
                          OrderItemsIn:=itemsIn,_
                          OrderPartners:=partners,_
                          Return:=ret

I tried it with or without the parameter names, with or without the
return value in the parameters list, I always get this exception:

Traceback (most recent call last):
  File "d:\python20\pythonwin\pywin\framework\scriptutils.py", line
301, in RunScript
    exec codeObject in __main__.__dict__
  File "d:\sapconn.py", line 35, in ?
    Return = ret)
  File "<COMObject CreateInstance>", line 2, in BapiCreateFromData
  File "d:\python20\win32com\client\dynamic.py", line 234, in
_ApplyTypes_
    result = apply(self._oleobj_.InvokeTypes, (dispid, LCID, wFlags,
retType, argTypes) + args)
com_error: (-2147352567, 'Exception occurred.', (0, None, "Table
doesn't contain 1 record\015\012(COM_PARAMETER_NO_SINGLE_RECORD): error
code 16388", None, 0, -2147467260), None)

Thank you for your assistance,

Olivier Boudry



Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list