cancel
Showing results for 
Search instead for 
Did you mean: 

Upload Data from VBA Using Function Module

Former Member
0 Kudos

Dear Experts,

Please guide me in writing the VBA Code to update the structure in a FM.

My scenario is as follows:

I need to use the Function Module "PROCESS_MESS_UPLOAD" using VBA and update the Structure MSEL and MSHD.

MSHD is the header and MSEL has many items.

Please help me how do I code it in VBA.

Any inputs will be rewarded.

Regards

Vinod

Accepted Solutions (1)

Accepted Solutions (1)

michael_hobbins
Active Participant
0 Kudos

Hello Vinod, see the following code (I assume you have a item data on columns A and B as from row 4, and header data on row 2)


    Set rfcctl = CreateObject("sap.functions")
    Set conn = rfcctl.Connection
    conn.Client = "<client>"
    conn.hostname = "<server>"
    conn.user = user "<username>"
    conn.Language = "<lang>"
    conn.password = "<password>"
    conn.SystemNumber = "<system number>"

    If conn.Logon(0, True) Then
       Set rfc = rfcctl.Add("PROCESS_MESS_UPLOAD")
        
       Set data = rfc.Tables("MSHD").Rows.Add
       item("WERK") = Range("A2").Value
       item("MSCLA") = Range("B2").Value
       item("SEDAT") = Range("C2").Value
       'add all necessary table columns

        i = 4
        While Range("A" & i).Value <> ""
            Set item = rfc.Tables("MSEL").Rows.Add
            item("ATNAM") = Range("A" & i).Value
            item("ATWRT") = Range("B" & i).Value
            'add all necessary table columns
            i = i + 1
        Wend
        If rfc.Call Then
          'CHECK FOR SUCCESS OR ERRORS
        Else
            MsgBox "Call error", vbOKOnly
            Exit Sub
        end if
    Else
        MsgBox "Logon error", vbOKOnly
        Exit Sub
    End If
    
    Set rfcctl = Nothing
    Set conn = Nothing

Note: I haven't used this FM before, so I'm guessing which table fields may be useful to you

Cheers

Michael

Answers (0)