[53772] in SAPr3-news

home help back first fref pref prev next nref lref last post

Re: Aufruf des Programms RSUSR002 per EXCEL

daemon@ATHENA.MIT.EDU (Christian Zalto)
Sat Mar 12 15:16:20 2005

To: sapr3-news@mit.edu
Date: Sat, 12 Mar 2005 21:14:13 +0100
From: "Christian Zalto" <zalto@t-online.de>
Message-ID: <d0vigq$jr1$00$1@news.t-online.com>

"Ralf Meier" <meier@medisoco.com> schrieb:
> ich habe mal wieder eine Frage, ist es irgendwie möglich mittels einer
> Schnittstelle (RFC, BAPI oder ähnliches) das Programm RSUSR002 zu
> starten und die Ergebnisse wieder an EXCEL zu übergeben?
>
Ja, man kann über den Funktionsbaustein RFC_CALL_TRANSACTION
eine BDC-Tabelle übergeben, mit der über Transaktion SA38 der
Report RSUSR002 gestartet wird. Das Ergebnis wird dann per
Download in eine Datei auf dem Frontend übertragen. Vor vier
Jahren hatte ich ein passendes Script in dieser Newsgroup für
Release 3.1H veröffentlicht - anbei die Version für 4.6c.

-- 
Mit freundlichen Grüßen,
Christian Zalto

Option Explicit
Sub Main()
'Execute a report in SAP R/3 and save the list to a file.
'This script was developed using R/3 Release 4.6c.
'Author: Christian Zalto zalto@t-online.de

'Declaration
Dim my_filename As String
Dim fso As Object
Dim FileExists As Boolean
Dim FunctionCtrl As Object
Dim BdcTable As Object
Dim conn As Object
Dim RfcCallTransaction As Object

'list output filename
my_filename = "C:\list.txt"

'before: check wether the text file already exists
'because the dynpro chain depends on this
Set fso = CreateObject("Scripting.Filesystemobject")
If fso.FileExists(my_filename) Then
  FileExists = True
End If
Set fso = Nothing

Set FunctionCtrl = CreateObject("SAP.Functions")
Set conn = FunctionCtrl.Connection

'this is needed for frontend download
conn.RfcWithDialog = True

'log on with logon dialog
If Not conn.Logon(0, False) Then
  MsgBox "Logon not succesful"
  Set conn = Nothing
  Exit Sub
End If

'call report using transaction SA38
Set RfcCallTransaction = FunctionCtrl.Add("RFC_CALL_TRANSACTION")
RfcCallTransaction.Exports("TRANCODE") = "SA38"
RfcCallTransaction.Exports("UPDMODE") = "S"
Set BdcTable = RfcCallTransaction.Tables("BDCTABLE")

'enter program name RSUSR002
add_bdcdata BdcTable, "SAPMS38M", "101", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_CURSOR", "RS38M-PROGRAMM"
add_bdcdata BdcTable, "", "", "", "RS38M-PROGRAMM", "RSUSR002"
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=STRT"

'enter current user name in first report dynpro
add_bdcdata BdcTable, "RSUSR002", "1000", "X", "", ""
add_bdcdata BdcTable, "", "", "", "USER-LOW", conn.User
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=ONLI"

'press F9 for data download
add_bdcdata BdcTable, "SAPLSLVC_FULLSCREEN", "500", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "/9"

'select format
add_bdcdata BdcTable, "SAPLSPO5", "101", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_CURSOR", "SPOPLI-SELFLAG(01)"
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=OK"

'select filename for download
add_bdcdata BdcTable, "SAPLGRAP", "200", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_CURSOR", "RLGRAP-FILENAME"
add_bdcdata BdcTable, "", "", "", "RLGRAP-FILENAME", my_filename
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=SEND"

'confirm overwrite when file exists
If FileExists Then
  add_bdcdata BdcTable, "SAPLGRAP", "200", "X", "", ""
  add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=REPL"
End If

'exit screen
add_bdcdata BdcTable, "SAPLSLVC_FULLSCREEN", "500", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "=&F15"

'exit transaction
add_bdcdata BdcTable, "RSUSR002", "1000", "X", "", ""
add_bdcdata BdcTable, "", "", "", "BDC_OKCODE", "/EENDE"

'call the function and if the result is false, display a message
If RfcCallTransaction.Call = True Then
    MsgBox RfcCallTransaction.Imports("MESSG").Value("MSGTX")
Else
    MsgBox "Call Failed!"
End If

'logoff and free objects
conn.Logoff
Set conn = Nothing
End Sub

Public Sub add_bdcdata(BdcTable As Object, program As String, _
dynpro As String, dynbegin As String, fnam As String, fval As String)
    BdcTable.Rows.Add
    BdcTable.Value(BdcTable.Rows.Count, "PROGRAM") = program
    BdcTable.Value(BdcTable.Rows.Count, "DYNPRO") = dynpro
    BdcTable.Value(BdcTable.Rows.Count, "DYNBEGIN") = dynbegin
    BdcTable.Value(BdcTable.Rows.Count, "FNAM") = fnam
    BdcTable.Value(BdcTable.Rows.Count, "FVAL") = fval
End Sub



home help back first fref pref prev next nref lref last post