Practice (102) - Test All SGC Command

<< Click to Display Table of Contents >>

Navigation:  All About SAP Interface > SAP r/3 and VB 6.0 > Create Desktop Application using SGC Server > Basic Knowledge >

Practice (102) - Test All SGC Command

Objective

Creating Program

Result

SGC Server

v1.0, v1.1

Support

Source Code is available (Download)

 

No

Description

 

1

Difficulty Level

Easy

2

ActiveX (OCX) library

Microsoft Winsock Control 6.0

 

Creating Program

1.Copy Folder \Practice101\  to  \Practice102\

2.Run file \Practice102\Practice101.dpr

3.Save as Project of "Practice101.vbp" to "Practice102.vbp"

4.Delete all file with name "Practice101" at folder  \Practice102\, and the result like this bellow

VB_6.0_da0005

5.Rename Project name with "Practice102"

6.Add and design a components according to component list bellow

No

Component

Properties

Value

Design

1

Button

Name

bConnect

VB_6.0_da0006

 

 

Text

&Connect

2

TextBox

Name

eIPAddress

 

 

Text

127.0.0.1

3

TextBox

Name

sePort1

 

 

Value

10001

5

Button

Text

bLogin

 

 

Caption

&Login

 

 

Enabled

False

5

TextBox

Name

Memo1

 

 

ScrollBars

Both

 

 

Multiline

True

 

 

WordWarp

False

6

TextBox

Name

Memo2

 

 

ScrollBars

Both

 

 

Multiline

True

 

 

WordWarp

False

7

TextBox

Name

mSLog

 

 

ScrollBars

Vertical

 

 

Multiline

True

8

Winsock

Name

TCpClient

9

ComboBox

Name

cbCommand

 

 

Items

Get Server String

Get SAP Logon Info

Get User Menu List

Get Function Info

Run Function

Login

Logout

 

 

DropDownStyle

DropDownList

10

Button

Name

bExecute

 

 

Text

&Execute

 

 

Enabled

False

 

7.Modified Event Connect at TCpClient and add code of "bExecute.Enabled = True"

Before

...

  bLogin.Enabled = True

 

  'Sending command to SGC Server

  TCpClient.SendData ClientString

...

     

After

...

  bLogin.Enabled = True

  bExecute.Enabled = True

 

  'Sending command to SGC Server

  TCpClient.SendData ClientString

...

 

8.Modified Event Procedure "Main_Load"

Before

...

    LoginString = LoginString & vbCrLf & "</SGC_CLIENT>"

    LoginString = LoginString & vbCrLf & " " 'Add empty line after "</SGC_CLIENT>"

    

End Sub

...

 

After

...

    LoginString = LoginString & vbCrLf & "</SGC_CLIENT>"

    LoginString = LoginString & vbCrLf & " " 'Add empty line after "</SGC_CLIENT>"

 

    cbCommand.ListIndex = 1

    

End Sub

...

 

9.Add Event Click at bExecute button and then write code to executing a selected Command at cbCommand

Private Sub bExecute_Click()

    Dim NumDate, NumTime As Double

    Dim tmpRequest, tmpReceive As String

    Dim Parameter1, Parameter2, Parameter3 As String

 

    NumDate = Format(Date, "###")

    NumTime = Format(Time, "###0.0000000000")

    

    Memo1.Text = ""

    Memo2.Text = ""

 

    '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 & vbCrLf & "<SGC_CLIENT DATE=""" & NumDate & """ TIME=""" & NumTime & """>"

    tmpRequest = tmpRequest & vbCrLf & "  <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 & vbCrLf & "<FUNCTION>"

      tmpRequest = tmpRequest & vbCrLf & "    <IMPORTS>"

      tmpRequest = tmpRequest & vbCrLf & "      <IMPORT NAME=""QUERY_TABLE"" DEFAULT_VALUE=""T001"" STRUCTURE=""False""/>"

      tmpRequest = tmpRequest & vbCrLf & "      <IMPORT NAME=""DELIMITER"" DEFAULT_VALUE="";"" STRUCTURE=""False""/>"

      tmpRequest = tmpRequest & vbCrLf & "      <IMPORT NAME=""ROWSKIPS"" DEFAULT_VALUE=""0"" STRUCTURE=""False""/>"

      tmpRequest = tmpRequest & vbCrLf & "      <IMPORT NAME=""ROWCOUNT"" DEFAULT_VALUE=""1000"" STRUCTURE=""False""/>"

      tmpRequest = tmpRequest & vbCrLf & "    </IMPORTS>"

      tmpRequest = tmpRequest & vbCrLf & "    <TABLES>"

      tmpRequest = tmpRequest & vbCrLf & "      <TABLE NAME=""OPTIONS"">"

      tmpRequest = tmpRequest & vbCrLf & "        <LINE TEXT=""SPRAS = &apos;EN&apos;""/>"

      tmpRequest = tmpRequest & vbCrLf & "      </TABLE>"

      tmpRequest = tmpRequest & vbCrLf & "    </TABLES>"

      tmpRequest = tmpRequest & vbCrLf & "  </FUNCTION>"

 

    End If

    tmpRequest = tmpRequest & vbCrLf & "</SGC_CLIENT>"

 

    'Don't forget to adding an empty line after "</SGC_CLIENT>"

    tmpRequest = tmpRequest & vbCrLf & " "

 

    'Sending command to SGC Server

    TCpClient.SendData tmpRequest

 

    'Display XML Data

    Memo1.Text = tmpRequest

 

    'Free temporary data

    tmpRequest = ""

    tmpReceive = ""

End Sub

 

10.Save and Run the application

 

 

Result

Screen 1. Connected to SGC Server

VB_6.0_da0007

 

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

VB_6.0_da0008

 

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

VB_6.0_da0009

 

Screen 4. Execute Command of "Get Function Info"

VB_6.0_da0010

 

Screen 5. Execute Command of "Run Function"

VB_6.0_da0011