LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

SAP BAPI ActiveX Interface

Hello,

 

This is a cross post from LAVA forum...

 

I'm trying to integrate our test stations to SAP ERP. SAP stores data in busines objects in busines object repository. The objects are exposed over BAPI interface. There is a lot of different busines objects in the repository. SAP developers can also build new objects if they want. The objective is to read inspection characeristics from quality management module of SAP. I haven't done much ActiveX stuff, neither know much about SAP, so I started with a simple example that I found searching for BAPI examples. The example works fine in Excel. The example just reads some data from a sales order object.

  Sub BAPI1()Dim
        oBook As Workbook
        Dim oSheet As Worksheet
        Dim oBAPICtrl As Object
        Dim oBAPILogon As Object
        Dim oSalesOrder As Object
        Dim oItem As Object
        Dim iIndex As Integer
        Set oBook = Application.ActiveWorkbook
        Set oSheet = oBook.Worksheets(1)
        '---------------------------------
        ' Initialize SAP ActiveX Control.
        '---------------------------------
        Set oBAPICtrl = CreateObject("sap.bapi.1")
        '---------------------------------
        ' Initialize SAP ActiveX Logon.
        '---------------------------------
        Set oBAPILogon = CreateObject("sap.logoncontrol.1")
        '-----------------------------------
        ' Initialize the connection object.
        '-----------------------------------
        Set oBAPICtrl.Connection = oBAPILogon.newconnection
        '--------------------
        ' Logon with prompt.
        '--------------------
        oBAPICtrl.Connection.System = "Q02"
        oBAPICtrl.Connection.Client = 101
        oBAPICtrl.Connection.Logon
        '---------------------------------
        ' Retrieve a sales order.
        '---------------------------------
        Set oSalesOrder = oBAPICtrl.GetSAPObject("SalesOrder","0010732181")
        '-----------------------------------
        ' Display Sales Order header data.
        '-----------------------------------
        oSheet.Cells(2, 1).Value = oSalesOrder.salesdocument
        oSheet.Cells(2, 2).Value = oSalesOrder.netvalue
        oSheet.Cells(2, 3).Value = oSalesOrder.orderingparty.customerno
        oSheet.Cells(2, 4).Value = oSalesOrder.documentdate
        oSheet.Cells(2, 5).Value = oSalesOrder.items.Count
        '-----------------------------------
        ' Logoff SAP and close the control.
        '-----------------------------------
        oBAPICtrl.Connection.logoff
        Set oBAPILogon = Nothing
        Set oBAPICtrl = Nothing
  End Sub

 I tried to implement that in LabVIEW. The logon and logout part works, I can also obtain SalesOrder object with GetSAPObject method. There is no error and probing the Object output from GetSAPObject methods gives an integer value - probably a reference to the SalesOrder object.

 

LV code.png

Now I can't figure out how do I read the object properties. It's very simple in VBA. I also don't know how do I call object methods. This is apicture from SAP BAPI documentatios showing available properties and methods.

 

SalesOrder details.png

 

I would appreciate any hints...

 

bye, Mirko

 

0 Kudos
Message 1 of 11
(6,091 Views)

Dear Mirko,

like it is mentioned on the lavag.org forum, you have to cast the SAP Object variant to the ActiveX reference. Did you manage to find the right type of reference?

 

BR,

0 Kudos
Message 2 of 11
(5,967 Views)

No, there isn't any reference type that matches BAPI Object. In fact, there can't be a fixed type reference, since BAPI object are actually function modules that SAP programmers write themselves using language called ABAP. I concluded that we can't call the object methods or read/write properties in LabVIEW, if we don't know the right type at development time. So, I gave up on BAPI API.

 

There are also other methods of SAP integration. O step down on abstraction scale is Remote Function Call (RFC) API. The API is much more involved, but it allows us to call functions that are behind BAPI objects. In a few test that I did it worked fine. The interface is exposed over three ActiveX controls - SAP Remote Function Call ControlSAP Table Factory Control and SAP Logon Control.

 

There is also .NET assembly and web services which I didn't tried.

 

Regards, Mirko

 

 

0 Kudos
Message 3 of 11
(5,954 Views)

Hi Mirko,
I tried to collect datas from our SAP system, but as you, I did not succed in collecting datas with BAPI object.

Do you have any example with RFC functions ?

 

Best Regards,

V-F
0 Kudos
Message 4 of 11
(5,384 Views)

Hi Mirko,

 

I tried to reproduce your screenshot in LabVIEW, with no success. Can you please provide me a link or a tutorial hoe to build that code? I googled several hours to find any good material, with no result. I place an activex container on the front panel, insert a SAPLogonControl into that, setting the properties regarding to the server/user, so I have an indicator on the block diagram. As next step, I place the automation open.vi from the activeX plaette (like you), so I have a reference (valid number). Does it mean, that I made a succesful logon? How to step on? I cannot create that property nodes, which would be essential.

 

Thanks for your help!

tzs

 

I work on Win7 + LabVIEW2009 + SAPgui installed (if it counts)

// Electrical Engineering, MSc (software engineering) //
0 Kudos
Message 5 of 11
(4,415 Views)

I was able to Export data from SAP server using ActiveX.The BAPI  information (Name,Index,etc) have to be provided by SAP Backend Administrator.ActiveXexport.png

 

 

Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 6 of 11
(2,406 Views)

Hello, ohiofudu

your diagram is not so clear, could you please send another one, thanks a lot.

0 Kudos
Message 7 of 11
(2,368 Views)

Hello Henrylau,

Here is the SAP BAPI ActiveX Diagramm broken down 

1.Connect to SAP with SAP Connection Information

2.Send SAP BAPI Command to SAP Server

3.Get SAP BAPI Responds (Import) from SAP Server

SAP Connection InformationSAP Connection InformationSend API InformationSend API InformationGet (Import) BAPI Information from SAPGet (Import) BAPI Information from SAP

if you need more information let me know.

Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 8 of 11
(2,356 Views)

Hello ohiofudu,

 

Thanks for your infomation. Now i can call a RFC and get the response from SAP, here is my VI, it looks like a little differrent with yours, i think just because we used different version of SAPgui.

 

I still face a another problem to write a parameter(Values) to the tables whitch looks like below. It's not a real table, it is a structure, Do you get any idea how to write it?

捕获.PNG

 

0 Kudos
Message 9 of 11
(2,344 Views)

Hi henrylau,

Try the Export Funktion.

what is the error message? 

Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 10 of 11
(2,329 Views)