SAP R/3 automation with win32com

obou at my-deja.com obou at my-deja.com
Tue Dec 5 02:49:57 EST 2000


In article <kl5n2tsfk3hud1c37gjo56290sueccuegk at 4ax.com>,
  dale at out-think.NOSPAM.co.uk wrote:
> obou at my-deja.com wrote:
>
> >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.
>
> I can't see anything obviously wrong so there's a chance that the
error might be in the preceding
> code. Have you tried running through this interactively and checking
that the objects you are
> creating all look OK?
>
> Also, do you know to what table the error refers?
> --
> Dale Strickland-Clark
> Out-Think Ltd
> Business Technology Consultants
>
>

Thanks for your answer!

I've run the whole thing in an interactive window and my objects are
ok. I'm "translating" a Visual Basic example that works on my system.
So I thought I made something wrong in the last function call.
I don't know VB at all and don't really know how to translate VB
functions calls to Python function calls. Especially when using COM.
There are some strange differences. In my example, there are in VB
function calls that takes 3 parameters where in Python I have to put
only 2 parameters in the brackets and get the third as a return value.
The salesOrd.DimAs function calls are such cases. In VB the return
value is written as a third parameter and the function has no return
value.
Is there a way to identify which parameter have to stay in the brackets
and which ones will be sent as return value?

Olivier Boudry



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



More information about the Python-list mailing list