SAP BAPI with Excel - BAPI_PLANNEDORDER_GET_DETAIL

I know there has been a few questions regarding this earlier. However none of which sufficiently have led me to a solution to the issue at hand.

Code so far

Sub GetPlannedOrderNums()

    '--------
    'Logon
    '--------
    Dim ws As Worksheet
    Dim fRow As Long
    Set ws = ThisWorkbook.Worksheets("Sheet1")

    Dim sapConn As Object                               'Declare variant
    Set sapConn = CreateObject("SAP.Functions")         'Create ActiveX object

    With sapConn.CONNECTION
        .Destination = "**"                            'SAP HOST
        .ApplicationServer = "**"      'SAP SYSTEM 
        .Client = "**"
        .User = "**"                               'SOME VALID SAP LONG
        .Password = "**"                                  'valid password
        .SystemNumber = "**"                            'for multiple logical systems
    End With

    If sapConn.CONNECTION.Logon(1, False) <> True Then 'Try Logon
       MsgBox "Cannot Log on to SAP"
    End If


    If sapConn.CONNECTION.IsConnected Then
    
    
        '--------
        'Define function
        '--------
    
        Dim objRfcFunc As Object
        Set objRfcFunc = sapConn.Add("BAPI_PLANNEDORDER_GET_DETAIL")
    
    
        '--------
        'Then set values
        '--------
    
        With ws
            fRow = .Cells(.Rows.Count, 5).End(xlUp).Row
        End With
    
 
                objRfcFunc.Value("MATNR") = "**"
                objRfcFunc.Value("WERKS") = "**"
                objRfcFunc.Value("DISPO") = "**"
                objRfcFunc.Value("Production Scheduler") = "**"
    

        If objRfcFunc.Call = False Then
           MsgBox "Call failure" + objRfcFunc.Exception
        End If

    End If

End Sub

End goal of code

Run the BAPI for n number of materials, and retrieve 1 planned order number for each unique material number. I've failed to move on to the unique part, as I feel like I need to get the BAPI working properly first.

Open issues

I know this code is not complete. I'm stuck on where and how to move forward, and I've failed to find any information on this particular problem. The required fields for the BAPI is material number, plant, MRP Controller and Production Scheduler. The logon part works properly, but code breaks at the object (most probably due to wrong fields).

Questions

  1. How to I know the parameters required for a BAPI? I do not have access to SE37 nor SE80. The names I found here were found using Google the almighty.
  2. How is the syntax for a BAPI through Excel? The logon part is OK, but I struggle to find any answers as to how to properly set up and program it.

Any pointers to the right direction or general help would be much appreciated!


You can use abap-api-tools to extract the signature of BAPI to console and js/ts file along with data type and length.

For example

abap call MME stfc_structure -s

will return stfc_connection.js with input/output structures.