|
|
|
|
Most popular way to logon to SAP is to go with ActiveX object. This utilizes the ActiveX module in :...SAP/FrontEnd/Controls/wdtfuncs.OCX.
(A) Logon to the system hard coded in the VBA/VB macro
If you want to hide the logon system, user name or password from end user, you can put them in this VBA/VB macro and lock with password.
Sub TempLogon1()
Dim sapConn As Object 'Declare connection object
Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
'Specify user
sapConn.Connection.user = "USER"
'Then password
sapConn.Connection.Password = "PASSWORD"
'Client
sapConn.Connection.client = "001"
'Target server address
sapConn.Connection.ApplicationServer = "127.0.0.1"
'Language code
sapConn.Connection.Language = "EN"
'Finally, try to logon to the specified system and check if the connection established
If sapConn.Connection.Logon(0, True) <> True Then
MsgBox "Cannot Log on to SAP" 'Issue message if cannot logon
Else
MsgBox "Logged on to SAP!"
End If
End Sub
|
(B) Logon to SAP with dialog
Here we will see how we do the server selection with dialog box like saplogon. In case if the system is fixed or the number of the selectable system is as little enough to control with user defined form then the above works ok. But you may need users to select the target system actively from the list of servers. Then this code doesn't work. (or work with effort on the dialog module creation) As written in the below code, if you specify "False" in the second parameter for Logon method, then the dialog screen below will come up and users can select the system from it. The dialog will derive the servers and settings from the saplogon.
Sub TempLogon2()
Dim sapConn as object
Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
If sapConn.Connection.Logon(0, False) <> True Then 'Try Logon
Msgbox "Cannot Log on to SAP"
end if
End Sub
|
(C) Logon to SAP with dialog
Instead of let the system to do the whole process, you may want to let users to use SAP screen during RFC. By giving True to the RfcWithDialog property, SAP screen will be ready hidden in background. This is required in case if you try to execute function module which will show SAP screen (e.g. CAD dialog).
Sub TempLogon3()
Dim sapConn as object
Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
sapConn.Connection.RfcWithDialog = True
If sapConn.Connection.Logon(0, False) <> True Then 'Try Logon
msgbox "Cannot Logon to SAP"
end if
End Sub
|
(D) Appendix - Methods for connection object
Copy | Boolean
(Void) | Create another session from Same connection. |
LastError | None
(Void) | Show last error issued by SAP. |
Logoff | None
(Void) | Logoff from SAP for the connection. |
Logon | hWnd:Long
bSilent:Boolean
(Boolean) | Logon to SAP. |
Reconnect | None (Boolean) |
Re-Logon to SAP with
same user, password and etc information which were provided last
time. |
SystemInformation |
hWnd (Void) |
Show system
information in detail with built-in dialog. |
SystemMessages |
None (Void) |
Show system
messages. |
(E) Appendix - Properties for connection object
ABAPDebug | Boolean |
@ |
ApplicationServer |
String |
Logon Application
server name. |
AutoLogon | Long |
@ |
Client | String |
Logon client. (Read/Write) |
CodePage | String |
Logon code page. (Read/Write) |
ConnectionHandle |
Long |
Connection handle
number. (Read/Write) |
Destination | String |
Destination name (xxx) |
GatewayHost | String |
Gateway host name |
GatewayService |
String |
Gateway service name |
GroupName | String |
Group name (xxx) |
GroupSelection |
Boolean |
@ |
GRTData | String |
@ |
HostName | String |
Turn on ABAP Debug |
IsConnected | Enum(Long) |
Represents connection
status with following values (Read)
tloRfcNotConnected = 0
tloRfcConnected = 1
tloRfcConnectCancel = 2
tloRfcConnectFailed = 8
tloRfcConnectParameterMissing = 4 |
Language |
String | Logon language (Read/Write) |
LowSpeedConnection |
Boolean | Turn on ABAP Debug |
MessageServer |
String |
Turn on ABAP Debug |
Parent | Object |
Turn on ABAP Debug |
Password | String |
Password (Read/Write) |
RfcWithDialog |
Long |
Connection go through SAP GUI.
*Any other values than 0 will be treated as "On". (Read/Write) |
SAPRelease | String |
SAP Release of connected
system (Read) |
SAPRouter | String |
@ |
SNC | Boolean |
SNC enabled connection.
(Read/Write) |
SNCName | String |
SNC name |
SNCQuality | String |
@ |
System | String |
@ |
SystemID | String |
System ID name |
SystemNumber |
Long |
Logon system number.
(Read/Write) |
Ticket | String |
@ |
TraceLevel | Long |
@ |
UseDefaultSystem |
Boolean |
@ |
User | String |
User name. (Read/Write) |
UseSAPLogonIni |
Boolean |
Reference to Saplogon.ini file |
UseSAPRFCIni |
Boolean |
Reference to Saprfc.ini file |
|
|
|
|
17-Sep-2005
|
|
|
|
|