cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

VBA RFC uploading to table using Structures

gentrya
Discoverer
0 Likes
1,378

Hi,

I am having a problem uploading data using a Function Module that has an imput parameter of a table. See Img-1 "GOODSMVT_ITEM". As far as I am aware, because this is an input parameter of a table and not an associated Table (I am not sure the correct way to describe the differences here) like other function modules , I cannot use 'Function.tables("GOODSMVT_ITEM")'. I have to assign the data to a structure first then pass it back to the input parameter. However, I cannot figure out or find code samples of how to do this properly. I was able to use .CreateStructure to create the structure and then assing values to it, but I cannot seem to pass it back the "GOODSMVT_ITEM" I tried a bunch of diffent ways of doing that, but none seem to work.

From the few samples that I have found, "objSAPFUNC.Exports.Insert "GOODSMVT_ITEM", myStructure" should be what I need, but when you call the function, it returns the message of "No items were transferred", which is what happens if no items are added to the table if you manully add the record in SAP.

Img-1:

Img-2:

Img-3:

    Dim objSAPFUNC As Object
    Dim objMessages As Object
    Dim gmvt_Header As Object
    Dim gmvt_Code As Object
    Dim gmvt_Item As Object
    Dim myStructure As Object

    'Seperate function to logon
    Call SAPLogon
     
    Set objSAPFUNC = SAPObject.Add("/PGP/MOB_GOODS_MOVEMENT")
    
    'GOODSMVT_HEADER
    '-----------------------------------------------------
    Set gmvt_Header = objSAPFUNC.Exports("GOODSMVT_HEADER")
    gmvt_Header.Value("PSTNG_DATE") = "27/07/2021"
    gmvt_Header.Value("DOC_DATE") = "28/07/2021"
    gmvt_Header.Value("HEADER_TXT") = "Header Text"
    
    'GOODSMVT_CODE
    '-----------------------------------------------------
    Set gmvt_Code = objSAPFUNC.Exports("GOODSMVT_CODE")
    gmvt_Code.Value("GM_CODE") = "01"
    
    'GOODSMVT_ITEM
    '-----------------------------------------------------
    'Set gmvt_Item = objSAPFUNC.Exports("GOODSMVT_ITEM")
    'Set gmvt_Item = objSAPFUNC.Exports("/PGP/MOB_GOODS_MOVE_ITEM_T")
    Set myStructure = SAPObject.CreateStructure("/PGP/MOB_GOODS_MOVE_ITEM_T")
    
    myStructure.Value("PLANT") = "XXXX"
    myStructure.Value("MATERIAL") = "999999999"
    myStructure.Value("STGE_LOC") = "0001"
    myStructure.Value("BATCH") = "XXXX"
    myStructure.Value("ENTRY_QNT") = "100"
    myStructure.Value("Entry_UOM") = "LB"
    myStructure.Value("ORDERID") = "99999999"
    myStructure.Value("MOVE_TYPE") = "999"
    
    'commented code are different things that I have tried 
    'gmvt_Item.Value("GOODSMVT_ITEM") = myStructure      'error - Wrong number of arguments or invalid property assignment
    'gmvt_Item.Value("/PGP/MOB_GOODS_MOVE_ITEM_CR_S") = myStructure   'error - Wrong number of arguments or invalid property assignment

    objSAPFUNC.Exports.Insert "GOODSMVT_ITEM", myStructure                   ' No error
    'objSAPFUNC.Exports.Insert "/PGP/MOB_GOODS_MOVE_ITEM_T", myStructure     ' No error
    'objSAPFUNC.Exports.Insert 1, myStructure                                ' No error
    'objSAPFUNC.Exports("GOODSMVT_ITEM") = myStructure                       ' No error


    If objSAPFUNC.Call = False Then
        Debug.Print objSAPFUNC.Exception
    Else
        Debug.Print objSAPFUNC.Imports("MESSAGE")      'msg = No items were transferred
    End If

I used Call SAP function from VB - Structure member not found as by base, but it didnt work for me.

So my main question is, What is the correct way to take my table struture and pass it back to the Input parameter of this function module?

Does anyone have any code snippets or examples of "CreateStruture()" being used to upload data?

Where can I find SAP VBA RFC documendation?

Thanks in advance!

Accepted Solutions (0)

Answers (0)