|
<< Click to Display Table of Contents >> Navigation: All About SAP Interface > SAP r/3 and VB.Net > Create Desktop Application using SGC Server > Basic Knowledge > Practice (102) - Test All SGC Command |
Objective |
|
SGC Server |
v1.0, v1.1 |
Support |
Source Code is available (Download) |
No |
Description |
|
1 |
Difficulty Level |
Easy |
2 |
.Net Library |
System System.Data System.Deployment System.Drawing System.Windows.Forms System.XML |
1.Run Microsoft Visual Studio
2.Create New Project
3.Enter Project name as "Practice102" Save into \Desktop-Application\Practice102\

4.Delete Form1.vb
5.Open Folder \Practice101\
6.Select Main1.*, clsClientSocket.vb and mdlGlobalVariabel.vb

7.Copy and paste into Folder \Practice102\

8.Right click on Solution Explorer and select menu Add > Existing Item...

9.Select Main1.vb, clsClientSocket.vb and mdlGlobalVariabel.vb and then press Add button

10.Double Click My Project to Open properties of "Project102"
11.Change Startup Form to "Main1"

12.Open Desain of Main1.vb
13.Add and design a components according to component list bellow
No |
Component |
Properties |
Value |
Design |
1 |
Forms.Button |
Name |
bConnect |
|
|
|
Text |
&Connect |
|
2 |
Forms.TextBox |
Name |
eIPAddress |
|
|
|
Text |
127.0.0.1 |
|
3 |
Forms.NumericUpDown |
Name |
sePort1 |
|
|
|
Value |
10001 |
|
5 |
Forms.Button |
Text |
bLogin |
|
|
|
Caption |
&Login |
|
|
|
Enabled |
False |
|
5 |
Forms.TextBox |
Name |
Memo1 |
|
|
|
ScrollBars |
Both |
|
|
|
Multiline |
True |
|
|
|
WordWarp |
False |
|
6 |
Forms.TextBox |
Name |
Memo2 |
|
|
|
ScrollBars |
Both |
|
|
|
Multiline |
True |
|
|
|
WordWarp |
False |
|
7 |
Forms.TextBox |
Name |
mSLog |
|
|
|
ScrollBars |
Vertical |
|
|
|
Multiline |
True |
|
8 |
Forms.ComboBox |
Name |
cbCommand |
|
|
|
Items |
Get Server String Get SAP Logon Info Get User Menu List Get Function Info Run Function Login Logout |
|
|
|
DropDownStyle |
DropDownList |
|
9 |
Forms.Button |
Name |
bExecute |
|
|
|
Text |
&Execute |
|
|
|
Enabled |
False |
14.Modified Event Click at bConnect button and add code of " bExecute.Enabled = TCPClient.isConnected"
Before
...
isConnected = TCPClient.isConnected
bLogin.Enabled = TCPClient.isConnected
End Sub
...
After
...
isConnected = TCPClient.isConnected
bLogin.Enabled = TCPClient.isConnected
bExecute.Enabled = TCPClient.isConnected
End Sub
...
15.Modified Event Procedure "Main_Load"
Before
...
LoginString = LoginString & Environment.NewLine & "</SGC_CLIENT>"
LoginString = LoginString & Environment.NewLine & " " 'Add empty line after "</SGC_CLIENT>"
End Sub
...
After
...
LoginString = LoginString & Environment.NewLine & "</SGC_CLIENT>"
LoginString = LoginString & Environment.NewLine & " " 'Add empty line after "</SGC_CLIENT>"
cbCommand.SelectedIndex = 1
End Sub
...
16.Add Event Click at bExecute button and then write code to executing a selected Command at cbCommand
Private Sub bExecute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bExecute.Click
Dim NumDate, NumTime As Double
Dim tmpRequest, tmpReceive As String
Dim Parameter1, Parameter2, Parameter3 As String
NumDate = Date.Today.ToOADate
NumTime = DateAndTime.TimeOfDay.ToOADate
'In SGC Server version 1.0, Parameters is used for "Get Function Info" and "Run Function" command.
'Parameter 1 = Menu Function
'Parameter 2 = Function Name
'Note: First, you must register the SAP Function Module (RFC/BAPI) in SGC Server.
'Open Client_Example_02 to show an advanced demo about "Run Function" command.
'Set Parameters
If cbCommand.Text = "Get Function Info" Or cbCommand.Text = "Run Function" Then
Parameter1 = "SAP Tools" 'Menu Function
Parameter2 = "RFC_READ_TABLE" 'Function Name
End If
'Write the Top of SGC Command
tmpRequest = "<?xml version=""1.0"" encoding=""utf-8""?>"
tmpRequest = tmpRequest & Environment.NewLine & "<SGC_CLIENT DATE=""" & NumDate & """ TIME=""" & NumTime & """>"
tmpRequest = tmpRequest & Environment.NewLine & " <CLIENT_STRING COMMAND=""" & cbCommand.Text & """ " & _
"USERNAME=""" & cUserID & """ " & _
"PASSWORD=""" & cPassword & """ " & _
"COMPANY_CODE=""" & cCompanyCode & """ " & _
"PROGRAM_TYPE=""" & cProgramType & """ " & _
"PROGRAM_CODE=""" & cProgramCode & """ " & _
"PARAMETER1=""" & Parameter1 & """ " & _
"PARAMETER2=""" & Parameter2 & """ " & _
"PARAMETER3=""" & Parameter3 & """/>"
'Addtional String for Command of 'Run Function'
If cbCommand.Text = "Run Function" Then
'This() 's example of XML code for executing 'RFC_READ_TABLE' function.
tmpRequest = tmpRequest & Environment.NewLine & "<FUNCTION>"
tmpRequest = tmpRequest & Environment.NewLine & " <IMPORTS>"
tmpRequest = tmpRequest & Environment.NewLine & " <IMPORT NAME=""QUERY_TABLE"" DEFAULT_VALUE=""T001"" STRUCTURE=""False""/>"
tmpRequest = tmpRequest & Environment.NewLine & " <IMPORT NAME=""DELIMITER"" DEFAULT_VALUE="";"" STRUCTURE=""False""/>"
tmpRequest = tmpRequest & Environment.NewLine & " <IMPORT NAME=""ROWSKIPS"" DEFAULT_VALUE=""0"" STRUCTURE=""False""/>"
tmpRequest = tmpRequest & Environment.NewLine & " <IMPORT NAME=""ROWCOUNT"" DEFAULT_VALUE=""1000"" STRUCTURE=""False""/>"
tmpRequest = tmpRequest & Environment.NewLine & " </IMPORTS>"
tmpRequest = tmpRequest & Environment.NewLine & " <TABLES>"
tmpRequest = tmpRequest & Environment.NewLine & " <TABLE NAME=""OPTIONS"">"
tmpRequest = tmpRequest & Environment.NewLine & " <LINE TEXT=""SPRAS = 'EN'""/>"
tmpRequest = tmpRequest & Environment.NewLine & " </TABLE>"
tmpRequest = tmpRequest & Environment.NewLine & " </TABLES>"
tmpRequest = tmpRequest & Environment.NewLine & " </FUNCTION>"
End If
tmpRequest = tmpRequest & Environment.NewLine & "</SGC_CLIENT>"
'Don't forget to adding an empty line after "</SGC_CLIENT>"
tmpRequest = tmpRequest & Environment.NewLine & " "
'Sending command to SGC Server
TCPClient.SendText(mSLog, tmpRequest, tmpReceive)
'Display XML Data
Memo1.Text = tmpRequest
Memo2.Text = tmpReceive
'Free temporary data
tmpRequest = ""
tmpReceive = ""
End Sub
17.Save and Run the application
▪Screen 1. Connected to SGC Server

▪Screen 2. Execute Command of "Get Sap Logon Info"

▪Screen 3. Execute Command of "Get User Menu List"

▪Screen 4. Execute Command of "Get Function Info"

▪Screen 5. Execute Command of "Run Function"
