1

I am trying to pull a list of every Functional Location out of SAP ERP using BAPI. When I run this code it returns with an empty table. I don't have very much experience with BAPI and I am trying to teach myself. Can someone please help with what I'm missing to make this work.

Thanks.

See code below:

Dim sapFunc As New SAPFunctionsOCX.SAPFunctions
    Dim objServer = sapFunc.Connection
    objServer.Client = "101"
    objServer.User = "MyUserName"
    objServer.Ticket = "MyKey"
    objServer.system = "PEC"
    objServer.MessageServer = "MyMessagerServer"
    objServer.GroupName = "PUBLIC"
    If objServer.logon(0, True) <> True Then
        MsgBox("Key Rejected")
        Exit Sub
    End If


    Dim objRfcFunc As SAPFunctionsOCX.Function
    objRfcFunc = sapFunc.Add("BAPI_FUNCLOC_GETLIST")
    'System.Console.Write(objRfcFunc.Description)

    If objRfcFunc.Call = False Then
        MsgBox("Error occured - " & objRfcFunc.Exception)
        Exit Sub
    End If

    Dim tab = objRfcFunc.Tables("FUNCLOC_LIST")
    System.Console.WriteLine("Input start:")
    For I = 1 To tab.RowCount
        For j = 1 To tab.ColumnCount
            System.Console.Write(tab.ColumnName(j) + ":")
            System.Console.WriteLine(tab.Cell(I, j))
        Next
    Next
    System.Console.WriteLine("Input end.")
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
cbkrunch
  • 45
  • 8
  • What is it returning? – LeppyR64 May 21 '14 at 17:30
  • if I do "objRfcFunc.imports("Return")" It is a 0 The consol looks like this after execution: "Input start:" '\n' "Input End." – cbkrunch May 21 '14 at 17:53
  • What does the parameter `RETURN` contain? Remember it is an EXPORTING parameter, not an IMPORTING parameter... – vwegert May 21 '14 at 18:31
  • Documentation from the SAP website "IMPORTING return = " bapiret2 Return Parameter". Im not sure what this value is. I have a hard time with SAP because of the lack of documentation. When I test the value in this script it returns '0' – cbkrunch May 21 '14 at 18:44
  • I'm relatively new to BAPI too. What transaction would you use to view those in SAP? – LeppyR64 May 21 '14 at 19:30
  • IW38 and search funclocs from "N-\*S-\*" – cbkrunch May 21 '14 at 21:36
  • I usually find that you need to fill in at least some selection criteria. Take table funcloc_ra, add a row to it. Use the options I, EQ, and set low to a funcloc that you know for sure and then try to execute it. – LeppyR64 May 22 '14 at 01:33
  • Im not quite sure what you mean. Can you post a code example? – cbkrunch May 22 '14 at 11:55
  • This is from my BAPI_PRODORD_GET_LIST code: – LeppyR64 May 22 '14 at 13:54

1 Answers1

1

I don't intend for this to be an answer, but if it helps then that's good. If it doesn't, I'll delete it.

With objRfcFunc.tables("funcloc_ra")
    If .RowCount < 1 Then .Rows.Add
    .cell(1, 1) = "I"
    .cell(1, 2) = "EQ"
    .cell(1, 3) = "Your Func Loc"
End With

Do this after setting objRfcFunc and before calling it. The call will use these parameters.

I means to Include, EQ means you want to find items equal to the value in low.

LeppyR64
  • 5,251
  • 2
  • 30
  • 35
  • Thank you so much. funcloc_ra is like the query I tried to upvote but I dont have enough Rep. I changed the EQ to NE and the cells(1.3) to "" and it works perfectly. – cbkrunch May 22 '14 at 14:28