Skip to Content
0
Sep 27, 2010 at 05:26 PM

Calling SAP BAPI's via Excel VBA

836 Views

Hi, I have been exploring the use of BAPI's via Excel VBA and have found examples from various sites. I have been successful at calling the BAPI where the import parameter is a field. For example, in the BAPI object 'Customer' I was able to call the Method 'GetList', which returns a list of customer addressess. The import parameter for this is Customer Number, which is a single data element.

The issue that I am having is where the import parameter of the BAPI is a structure. More specifically, I am trying to use the BAPI Method 'Post' of the BAPI object 'AcctngDocument' (bapi BAPI_ACC_DOCUMENT_POST). Within this BAPI, the import parameter 'DOCUMENTHEADER' is required, which is a structure with 24 fields. However, when I set this parameter to my corresponding Object in VBA, the value of the object says 'Error=0'. I do not receive a run-time error in VBA.

I saw another SDN post from a couple of years ago where someone was having the same issue, but a solution was not offered up.

This is an excerpt of the VBA code that I am using:

Set oDoc = oBAPICtrl.getsapobject("AcctngDocument")

Set oDocHead = oBAPICtrl.DimAs(oDoc, "Post", "DocumentHeader")

Set oGLLine = oBAPICtrl.DimAs(oDoc, "Post", "ACCOUNTGL")

colcount = oDocHead.ColumnCount

The Parameter DocumentHeader is an import parameter, and ACCOUNTGL is a table. The object oGLLine is an accurately defined structure after the statement Set oGLLine = oBAPICtrl.DimAs(oDoc, "Post", "ACCOUNTGL"); however, the object oDocHead is issuing the error mentioned above. The strange thing is that the variable 'colcount' accurately counts the number of columns in the oDocHead, but I cannot perform any other functions on oDocHead. I have tried variations of 'DocumentHeader' like 'DOCUMENTHEADER', 'documentheader', etc. to no avail.

I have tried this using the OCX 'SAPBAPIControlLib' and 'SAPFunctions', which requires different syntax. Both approaches yield this same error in VBA.

Any suggestions? We are on ECC 6.04 and I am using Excel 2007.

Thanks

Kory