cancel
Showing results for 
Search instead for 
Did you mean: 

Macro/VBA to read structure

Former Member
0 Kudos

Dear experts.

I'm doing downloads with SAP to Excel. I'm using a macro that allow querys to SAP tables and the result's save on the Excel Sheets. This is the same that the transaction SE16 but only I use Excel/Macro, My question is...Is posible to make a Macro that allow querys to SAP structure instead of SAP tables? and the result save in Excel.

For example the transaccions FBL3N and GR55

Sorry for my English.

Thanks.

Hola buenas tardes, estoy realizando bajadas de SAP a EXCEL, estoy usando una macro que permite bajar tablas de SAP y las pego a Excel.

Adapte un código para que ingresando parámetros en el VBA se conecte a SAP y me baje los resultados al EXCEL lo que equivaldría a usar la transacción SE16.

Mi pregunta es, ¿Es posible que en vez de hacer consultas a tablas, se pueda hacer consultas a estructuras o programas para ciertas transacciones ingresando los criterios en el código desde excel? Por ejemplo para la transaccion FBL3N y GR55

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks Stefan.

Other solution that I think can work is use the funcion trancode for example

        Set Funcion = Funciones.Add("ZRFC_CALL_TRANSACTION")

        Set camp= Funcion.Tables("BDCTABLE")

        Set camp2= Funcion.Imports("MESSG")

        Funcion.Exports("TRANCODE") = "Transaction"

But I dont know how to use it.

stefan_schnell
Active Contributor
0 Kudos

Hello Hector,

I don't know your function module ZRFC_CALL_TRANSACTION but you can use the standard function module RFC_CALL_TRANSACTION_USING. I don't have an example for SAP ActiveX control SAP.functions, which is deprecated, but you can find here a working example with COM Connector, or search in the forum for BDC (Batch Data Command).

Cheers

Stefan

stefan_schnell
Active Contributor
0 Kudos

Hello Hector,

welcome in the Scripting Language forum.

I am not sure that I understand your question correctly. A structure comprises only components (fields) and it doesn't contain any data. You can find more information here. From this perspective it isn't possible to get data from a structure via SE16 or similar.

I find your question also here in Spanish language forum. Here contains your title the abbreviation RFC (Remote Function Call). An interface of a function module could contain a structure and in this case you can get data from or set data to a structure. But only in context of a function module call.

What would you like to do? Can you explain your requirement a litte more detail please, then we can help you better.

Cheers

Stefan

Former Member
0 Kudos

Hi Stefan,

For example, with this macro I connect with SAP, and download data in my excel spreadsheet

Sub CallFunctionModule()

Dim sap As Object

Dim conn As Object

Dim fb As Object

Dim tOptions As Object

Dim tFields As Object

Dim tData As Object

Dim RowData$()

Dim j&, i&, k&

Set sap = CreateObject("SAP.Functions")

Set conn = sap.Connection

conn.System = ""

conn.client = ""

conn.user = ""

conn.Password = ""

conn.Language = ""

If conn.logon(0, True) <> True Then

    MsgBox "No connection to R/3!", vbOKOnly, "comment"

Else

    Set fb = sap.Add("RFC_READ_TABLE")

    With fb

        .exports("QUERY_TABLE") = "SKB1"

        .exports("DELIMITER") = "|"

    End With

    Set tOptions = fb.tables("OPTIONS")

    Set tFields = fb.tables("FIELDS")

    Set tData = fb.tables("DATA")

  

    tOptions.Rows.Add

    tOptions(1, "TEXT") = "BUKRS = ''soc "

    tOptions.Rows.Add

   

    If fb.call Then

        j = tData.RowCount

        If j Then

           For i = 1 To j

                RowData = Split(tData(i, "WA"), "|")

                For k = 1 To 9

              

                    Cells(i, k).Value = RowData(k - 1)

                

                Next

           Next

        End If

    Else

     MsgBox fb.Exception, vbOKOnly, "comment"

    End If

    Set tFields = Nothing

    Set tData = Nothing

    Set tOptions = Nothing

    Set fb = Nothing

    conn.logoff

End If

Set conn = Nothing

Set sap = Nothing

End Sub

credits by Script Man

But I want to download data of the transaccion fbl3n and gr55 and this transaccions use multiple tables. I don't know how could do something like that.

stefan_schnell
Active Contributor
0 Kudos

Hello Hector,

if you want to use RFC_READ_TABLE you have no choice, you must download each table separately. An alternative could be an own or existing FM which collects the data, or a view which offers the data for you. Analyze for your requirement the possibilities in the corresponding packages.

Cheers

Stefan