Tuesday, July 3, 2012

SAP GUI Functions

Hi Friends ,
I will be writting all SAP GUI functions under the label "SAP GUI Functions"  :


1) SAP Function for Login to SAP GUI
    * Function Usage : Login to SAP GUI 
     *Arguments: strServerDescription - SAP Server
                        strClient - SAP Client
                        strUser - User ID
                        strPassword - Password
                       strLan - Language
   * Function Type   : Utility Function
    *Return values:         :Return SAP main screen name, otherwise returns '-1', if fail
'##################################################################

Public Function fn_Login(strServerDescription,strClient,strUser,strPassword,strLan)
'*Calling Autolog-in function
  SAPGuiUtil.AutoLogon strServerDescription,strClient,strUser,strPassword,strLan
'*Checking for the existing session
If    SAPGuiSession("guicomponenttype:=12").SAPGuiWindow("guicomponenttype:=21").Exist  Then
  Set ScreenObj = SAPGuiSession("guicomponenttype:=12").SAPGuiWindow("guicomponenttype:=21")
ElseIf   SAPGuiSession("guicomponenttype:=12","name:=ses\[2\]").SAPGuiWindow("guicomponenttype:=21").Exist Then
Set ScreenObj = SAPGuiSession("guicomponenttype:=12","name:=ses\[2\]").SAPGuiWindow("guicomponenttype:=21")
ElseIf   SAPGuiSession("guicomponenttype:=12","name:=ses\[1\]").SAPGuiWindow("guicomponenttype:=21").Exist Then
Set ScreenObj = SAPGuiSession("guicomponenttype:=12","name:=ses\[1\]").SAPGuiWindow("guicomponenttype:=21")
    End If
'*GetROProperty of active session object
If ScreenObj.Exist Then
fn_Login= ScreenObj.GetROProperty("screennumber")
Else
fn_Login= False
Reporter.ReportEvent micFail,"fn_Login","Login was unsuccessful"
End If    
End Function

'##################################################################
2) Logout from SAP
*Function Usage : Logout from SAP  
*Arguments: : N/A 
*Function Type  : Global Utility Function
*Return values:           : N/A
'##################################################################

Public Function fn_LogOut()
'*Closing all SAP sessions
    SAPGuiUtil.CloseConnections
'*Reporting to QTP
Reporter.ReportEvent micPass, "LogOff" , "Logged out of SAP"
End Function

'##################################################################
3) SAP Function for to close PDF fine by using QTP Script : 
    *Function Description: fn_ClosePDF
    *Function Usage:When required to Close the PDF use this function
    *Transactional Input Data   :None
    *Master Input Data   : None
     *Return values:           :None
'##################################################################

Public Function fn_ClosePDF()
'*Declaring variables
     Dim ShellObj
        '*Create Shell Object for Shortcut Keys
Set ShellObj = CreateObject("WScript.Shell")
'*Attach a receipt (pdf) to the Printed PDF file.
Window("micclass:=Window","regexpwndtitle:=Adobe Acrobat Professional").Close
SystemUtil.CloseProcessByName "Acrobat.exe"
'*Releasing variables
Set ShellObj=Nothing
End Function

'##################################################################


2 comments: