execute program via Excel

Question: hi,

I want to execute my program ("YTEST")via Excel.
This program is for create Batch Input. Following is
my codes. Once I execute it, message "The transaction
was terminated by user" was displays and no Batch Input
created. What's wrong?

Regards,
anek




*****************************
Public Sub CreatBatch()
Dim Functions As Object
Dim RfcCallTransaction As Object
Dim Messages As Object
Dim BdcTable As Object

Set Functions = CreateObject("SAP.Functions")

Functions.Connection.System = ""
Functions.Connection.client = ""
Functions.Connection.user = ""
Functions.Connection.Password = ""
Functions.Connection.Language = "EN"

If Functions.Connection.Logon(0, False) <> True Then
Exit Sub
End If

Dim j As Integer
Dim vField As Variant

Set RfcCallTransaction = Functions.Add("RFC_CALL_TRANSACTION")

RfcCallTransaction.exports("TRANCODE") = "SA38"
RfcCallTransaction.exports("UPDMODE") = "S"

Set BdcTable = RfcCallTransaction.Tables("BDCTABLE")

add_bdcdata BdcTable, "SAPMS38M", "0101", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=STRT"
add_bdcdata BdcTable, "", "", "", "RS38M-PROGRAMM", "YTEST"
add_bdcdata BdcTable, "YTEST", "1000", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=ONLI"
add_bdcdata BdcTable, "", "", "", "PC_FILE", "C:\TEST.TXT"
add_bdcdata BdcTable, "", "", "", "BDCGROUP", "TESTNAME"

If RfcCallTransaction.Call = True Then
Set Messages = RfcCallTransaction.imports("MESSG")
MsgBox Messages.Value("MSGTX")

Else
MsgBox " Call Failed! error: " + GetCustomers.Exception
Functions.Connection.Logoff
End If

Functions.Connection.Logoff

End Sub

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(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

Debug.Print BdcTable.Value(j, "FVAL")
End Sub

Answer:
You may have a "commit" issue in YTEST.
With BAPI, you have usually to commit with a special BAPI but I don't know about self developped RFC enabled routines.
_________________
Remi

Answer:
hi,

I want to execute my program ("YTEST")via Excel.
This program is for create Batch Input. Following is
my codes. Once I execute it, message "The transaction
was terminated by user" was displays and no Batch Input
created. What's wrong?

Regards,
anek




*****************************
Public Sub CreatBatch()
Dim Functions As Object
Dim RfcCallTransaction As Object
Dim Messages As Object
Dim BdcTable As Object

Set Functions = CreateObject("SAP.Functions")

Functions.Connection.System = ""
Functions.Connection.client = ""
Functions.Connection.user = ""
Functions.Connection.Password = ""
Functions.Connection.Language = "EN"

If Functions.Connection.Logon(0, False) <> True Then
Exit Sub
End If

Dim j As Integer
Dim vField As Variant

Set RfcCallTransaction = Functions.Add("RFC_CALL_TRANSACTION")

RfcCallTransaction.exports("TRANCODE") = "SA38"
RfcCallTransaction.exports("UPDMODE") = "S"

Set BdcTable = RfcCallTransaction.Tables("BDCTABLE")

add_bdcdata BdcTable, "SAPMS38M", "0101", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=STRT"
add_bdcdata BdcTable, "", "", "", "RS38M-PROGRAMM", "YTEST"
add_bdcdata BdcTable, "YTEST", "1000", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=ONLI"
add_bdcdata BdcTable, "", "", "", "PC_FILE", "C:\TEST.TXT"
add_bdcdata BdcTable, "", "", "", "BDCGROUP", "TESTNAME"

If RfcCallTransaction.Call = True Then
Set Messages = RfcCallTransaction.imports("MESSG")
MsgBox Messages.Value("MSGTX")

Else
MsgBox " Call Failed! error: " + GetCustomers.Exception
Functions.Connection.Logoff
End If

Functions.Connection.Logoff

End Sub

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(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

Debug.Print BdcTable.Value(j, "FVAL")
End Sub


first of all, you cannot use a local file with background task.

second, it's better to call a FM in RFC to run your program YTEST using SUBMIT command.

let me know if you want more help.
SSII

Answer:
Thanks to remi and ssii,

Where do I have to put "SUBMIT" command in my vba codes?
Please suggest..

Answer:
Thanks to remi and ssii,

Where do I have to put "SUBMIT" command in my vba codes?
Please suggest..

Hi Anek, sorry I can't help you for vba codes but what you should do is to ask an Abap developper to create for you in SAP a FM which can be called in RFC mode. In this FM, he should use SUBMIT instruction to execute the report that you want passing the file name as parameter.

Don't forget, the file should be on server side and not on your workstation.

in VBA, a function like "RFC_CALL_TRANSACTION" should exist to call a RFC FM.

Good luck
SSII

Answer:
Excuse-me but why all this fuss about calling a custom program from custom rfc function? Either I don't understand your point OR just code your stuff that you have in YTEST right in your RFC function.
Copyright ?2007 - 2008 www.jt77.com