‎2008 Jun 17 5:38 PM
HI,
I AM USING THE FOLLOWING EXCEL VBA CODE TO TRY AND CALL A TRANSACTION LX02 DIRECT INTO EXCEL.
Public Sub add_bdcdata(BdcTable As Object, program As String, dynpro As String, dynbegin As String, fnam As String, fval As String)
Dim vField As Variant
j = j + 1
BdcTable.Rows.Add
BdcTable.Value(BdcTable.Rows.Count, "PROGRAM") = "RLS10020"
BdcTable.Value(BdcTable.Rows.Count, "DYNPRO") = "1000"
BdcTable.Value(BdcTable.Rows.Count, "DYNBEGIN") = "X"
BdcTable.Value(BdcTable.Rows.Count, "FNAM") = "BDC_OKCODE"
BdcTable.Value(BdcTable.Rows.Count, "FVAL") = "NEXT"
Debug.Print BdcTable.Value(j, "FVAL")
End Sub
Public Sub rfc_call_transaction()
Dim Functions As Object
Dim RfcCallTransaction As Object
Dim Messages As Object
Dim BdcTable As Object
'***************************************************************************
' Create the Function control (that is, the high-level Functions collection):
'***************************************************************************
Set Functions = CreateObject("SAP.Functions")
'***************************************************************************
' Set the rest of Connection object values:
'***************************************************************************
Functions.Connection.System = "QA2"
Functions.Connection.client = "900"
Functions.Connection.user = "mbrough"
Functions.Connection.Password = "st34lhv3"
Functions.Connection.Language = "EN"
If Functions.Connection.Logon(0, False) <> True Then
Exit Sub
End If
Dim iBOB As Integer
iBOB = Range("A1")
Do
'*****************************************************************************
' Retrieve the Function object (the Connection object must be set up before Function objects can be created):
'*****************************************************************************
Set RfcCallTransaction = Functions.Add("RFC_CALL_TRANSACTION")
'*****************************************************************************
' Set the export parameters
'*****************************************************************************
RfcCallTransaction.exports("TRANCODE") = "LX02"
RfcCallTransaction.exports("UPDMODE") = "S"
Set BdcTable = RfcCallTransaction.Tables("BDCTABLE")
'*****************************************************************************
' Set the tables parameter and add the data for the call transaction
'*****************************************************************************
add_bdcdata BdcTable, "RLS10020", "1000", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_CURSOR", "S1_LGNUM"
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=ONLI"
add_bdcdata BdcTable, "", "", "", "S1_LGNUM", "900"
add_bdcdata BdcTable, "", "", "", "S1_LGNUM", "ActiveCell"
add_bdcdata BdcTable, "", "", "", "S1_LGTYP-LOW", "K01"
add_bdcdata BdcTable, "", "", "", "BDC_SUBSCR", "SAPLSSEL"
add_bdcdata BdcTable, "", "", "", "BDC_SUBSCR", "SAPLSSEL"
add_bdcdata BdcTable, "SAPMSSYO", "0120", "X", "", ""
add_bdcdata BdcTable, "", "0", "", "BDC_OKCODE", "=BACK"
add_bdcdata BdcTable, "RLS10020", "1000", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "/EE"
add_bdcdata BdcTable, "", "", "", "BDC_CURSOR", "S1_LGNUM"
add_bdcdata BdcTable, "", "", "", "S1_LGNUM", ActiveCell.Value
'******************************************************************************
'End SubCall the function (if the result is false, then display a message):
'******************************************************************************
If RfcCallTransaction.Call = True Then
Set Messages = RfcCallTransaction.imports("MESSG")
MsgBox Messages.Value("MSGTX")
Else
MsgBox " Call Failed! error: " + GetCustomers.Exception
End If
iBOB = iBOB + 1
Loop Until IsEmpty(ActiveCell.Offset(iBOB, 0))
Functions.Connection.Logoff
End SubI KEEP GETTING AN ERROR MESSAGE SAYING 'MAKE AN ENTRY IN ALL REQUIRED FIELDS' AND THEN NOTHING DOWNLOADS INTO EXCEL.
CAN ANYONE HELP PLEASE?
THANKS
‎2008 Jun 17 5:41 PM
‎2008 Jun 18 11:41 AM
When I run this transaction through SAPgui I only have to fill out the field S1_LGNUM, and I have specified this in my code.
Is my code below correct?
Public Sub add_bdcdata(BdcTable As Object, program As String, dynpro As String, dynbegin As String, fnam As String, fval As String)
Dim vField As Variant
Static j As Integer
j = j + 1
BdcTable.Rows.Add
BdcTable.Value(j, "PROGRAM") = "RLS10020" ' Program Name
BdcTable.Value(j, "DYNPRO") = "1000" ' Dynpro Number
BdcTable.Value(j, "DYNBEGIN") = "X" ' X if a screen
BdcTable.Value(j, "FNAM") = "BDC_OKCODE" ' Field Name
BdcTable.Value(j, "FVAL") = "NEXT" ' Field Value
End SubAs i have seen this in examples where it looks like below.
Public Sub add_bdcdata(BdcTable As Object, program As String, dynpro As String, dynbegin As String, fnam As String, fval As String)
Dim vField As Variant
Static j As Integer
j = j + 1
BdcTable.Rows.Add
BdcTable.Value(j, "PROGRAM") = program ' Program Name
BdcTable.Value(j, "DYNPRO") = dynpro ' Dynpro Number
BdcTable.Value(j, "DYNBEGIN") = dynbegin ' X if a screen
BdcTable.Value(j, "FNAM") = fnam ' Field Name
BdcTable.Value(j, "FVAL") = fval ' Field Value
End SubThanks
‎2009 Feb 13 9:09 AM