0
votes

After hours on hours of googling, I fail to find the solution to my problem.

Goal Create a simple Excel application to post "return delivery" for multiple material documents in SAP.

My assumption is that I would need to utilize the BAPI "BAPI_GOODSMVT_CREATE".

Firstly I initiate the SAP Logon Prompt:

'------'
'Logon to SAP
'------'
    Dim sapConn As Object                                ' Declare variant
    Set sapConn = CreateObject("SAP.Functions")          ' Create ActiveX object
    
    With sapConn.Connection
        .Destination = "somehost"                             
        .ApplicationServer = "someserver.com"      
        .Client = "someclient"
        .User = "someuser"                              
        .Password = "somepassword"                       
        .SystemNumber = "somesystem"                      
    End With
    
    If sapConn.Connection.Logon(1, False) <> True Then 'Try Logon
        MsgBox "Cannot Log on to SAP"
    End If

Then I define the function

'------'
'Define function
'------'
    Dim objRfcFunc As Object
    Set objRfcFunc = sapConn.Add("BAPI_GOODSMVT_CREATE")

Now, here is where it all stops. I've used this method to run other BAPI's by populating it through worksheet-iteration (looking at cell values).

Lastly (at the end of the function) I do the error handling:

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

What I truly fail to understand, is which fields are the minimum required in order to execute the BAPI? What BAPI field sto I need to populate?

If I do it manually in SAP through MIGO transaction, I require: Material Document and Material Document Year.

Function I selected are "Return Delivery" -> "Material Document".

Obviously I lack some code to fill the data, but I simply do not know where to start out. I've worked through this post, without any luck. Any help or pointers to the right direction are greatly appreciated.

1
Does it connect? - siggi_pop
Please explain an exact scenario to reproduce your (first) problem. Note that I have added an answer to the other "question" you have mentioned, in case you have trouble with just running the SAP GUI RFC SDK in 32/64 bits. - Sandra Rossi
The SAP GUI connects and works properly. - Havard Kleven
It is still unclear to me if you want to write to a specific field in the application - siggi_pop
Hm, well I would like to Return delivery for a specific material document number (or multiple, if possible, but I can always have excel iterate it multiple times). Transaction would return the delivery and return a new material document number. - Havard Kleven

1 Answers

1
votes

for a specific material document number (or multiple, if possible)

Not possible. BAPI_GOODSMVT_CREATE documentation denotes this in first lines that You can only create one material document each time you call up the method.

You should use GM_CODE 01 for goods movement 122 (return delivery), and the BAPI docu lists following mandatory fields for this GM_CODE:

  • Purchase order
  • Purchase order item
  • Movement type
  • Movement indicator
  • Quantity in unit of entry
  • ISO code unit of measurement for unit of entry or quantity proposal

For known PO:

The following fields may have to be populated (this is not a complete list):

- Reason for movement (if set up in the system)
- Batch (if the material is handled in batches and no automatic batch assignment has been set up)
- Storage location (if no storage location us specified in the purchase order item)

The following fields can be populated (this is not a complete list):

- Item text
- Unloading point
- Delivery completed indicator

The following fields must not be populated (this is not a complete list):

- Reservation
- Receiving/issuing material
- Receiving/issuing plant
- Receiving/issuing storage location

It's all depends on the PO known/unknown and whether it should be created or not. Just RTFM.

The absolute minimum fields to be filled:

**Header**
DOC_DATE = 20050513 | Document date in document BLDAT
REF_DOC_NO = 345060A| Reference document number XBLNR
PR_UNAME = JOHNDOE  | User name UNAME
GM_CODE = 01        | Assign code to transaction for BAPI goods movement

**Item**
MOVE_TYPE = 122     | Movement type (inventory management)
VENDOR = 1008056    | Vendor’s account number
ENTRY_QNT = 1.00    | Quantity in unit of entry
ENTRY_UOM = EA      | Unit of entry
PO_NUMBER = ASA99834| Purchase order number
PO_ITEM = 00001     | Item Number of Purchasing Document
MVT_IND = B         | Goods movement for purchase order Movement indicator