Showing posts with label SAP GUI Functions. Show all posts
Showing posts with label SAP GUI Functions. Show all posts

Tuesday, February 26, 2013

Navigating to one t-code from another using QTP

Navigating to one t-code from another using QTP By Ankesh Pandey  

Many of us may be aware of this topic which i am posting. But for me it took almos 5 months to discover this trick.:(

Let me explain what i use to do before discovering this cool trick.
Suppose you are on a t-code page , say VA01. After completing your operation, you need to navigate back to home page. I use to click on back button for this, which inturn was increasing OR size. This was not reliable too.
'Navigate back
SAPGuiSession("Session").SAPGuiWindow("").SAPGuiButton("Back").click

'Or to jump to another T-code from here, i was using /n in the t-code box

SAPGuiSession("Session").SAPGuiWindow("").SAPGuiOKCode("OK").Set "/nVA03"

For the above code to run, all the objects must be present in OR. Miss of any will result in error.

To resolve this we can use the 'Reset' option available in QTP.


SAPGuiSession("Session").Reset  // This code will take you to home page, doesnt matter where you are.
SAPGuiSession("Session").Reset "VA03"  //This code will take you to VA03 t-page from anywhere.

This will save lot of time and will optimize memory as well.

Wasn't it cool? Go ahead, use this option in your code.

Tuesday, December 11, 2012

CRM Click WebButton

Given below code will work for the clicking for CRM WebButton .

Public Sub CRM_Click_WebButton(obj_container, str_WebButtonID)
 Dim i
 Dim j,m
 Dim objs
                'gets all Links from container
              Set objs = obj_container.Object.documentElement.GetElementsByTagName("BUTTON")
    'for each object - check if the expected link is found
                For j = 0 to objs.length - 1
     If Instr (1,objs(j).id,str_WebButtonID,1)>0Then
      objs(j).Click
     End If                   
                  Exit for
    Next
       End Sub

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

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