cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute one sap gui script in different SAP system component versions.

khagendra_padhy
Explorer
0 Kudos

Hi Experts,

I am having a task to write a script which can be executed in different SAP systems , explained as below.

I have created a script to do password reset for mass users in one system (TC6) & it's working fine. But when i load same script in other system(QR5) to do the same activity , the system unable to execute the same script.

One thing i found that by comparing in the two systems that the screen-ids in QR5 system is different than TC6 system.

My question

1-> why it is different even though the scripting language is same.

2-> How can i overcome it & make a common script for all the systems.

Please help me to resolve this.

Thanks in Advance,

Khagendra

Accepted Solutions (0)

Answers (3)

Answers (3)

holger_khn
Contributor
0 Kudos

Hello.

The easiest way will be create an own script for each System where you find differences (your original script is not working).

Regards,

Holger

khagendra_padhy
Explorer
0 Kudos

Hi Holger & Stefan,

Sorry for late response first.

Now i have attached the recorded program-me for two systems for SU01 (simple user maintenance) with highlighted the text. I have highlighted both for easy understanding .

In system QR5 (upgraded one)

  1. session.findById("wnd[0]").maximize
  2. session.findById("wnd[0]/tbar[0]/okcd").text = "/nsu01"
  3. session.findById("wnd[0]").sendVKey 0
  4. session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").text = "test"
  5. session.findById("wnd[0]").sendVKey 0
  6. session.findById("wnd[0]/tbar[1]/btn[18]").press
  7. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_LAST").text = "rest"
  8. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_LAST").setFocus
  9. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_LAST").caretPosition = 4
  10. session.findById("wnd[0]").sendVKey 0
  11. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_FIRST").text = "user"
  12. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_FIRST").setFocus
  13. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_FIRST").caretPosition = 4
  14. session.findById("wnd[0]").sendVKey 0
  15. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").text = "test.user@noreply.com"
  16. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").setFocus
  17. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").caretPosition = 21
  18. session.findById("wnd[0]").sendVKey 0
  19. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO").select
  20. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/cmbSUID_ST_NODE_LOGONDATA-USTYP").setFocus
  21. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/cmbSUID_ST_NODE_LOGONDATA-USTYP").key = "A"
  22. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/pwdSUID_ST_NODE_PASSWORD_EXT-PASSWORD").text = "********"
  23. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/pwdSUID_ST_NODE_PASSWORD_EXT-PASSWORD2").text = "********"
  24. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/pwdSUID_ST_NODE_PASSWORD_EXT-PASSWORD2").setFocus
  25. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUID_MAINTENANCE:1101/pwdSUID_ST_NODE_PASSWORD_EXT-PASSWORD2").caretPosition = 9
  26. session.findById("wnd[0]").sendVKey 0
  27. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG").select
  28. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG/ssubMAINAREA:SAPLSUID_MAINTENANCE:1106/cntlG_ROLES_CONTAINER/shellcont/shell").modifyCell 0,"AGR_NAME","Z:T5_UK_WIPRO_DEV_NONBASIS"
  29. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG/ssubMAINAREA:SAPLSUID_MAINTENANCE:1106/cntlG_ROLES_CONTAINER/shellcont/shell").currentCellColumn = "AGR_NAME"
  30. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG/ssubMAINAREA:SAPLSUID_MAINTENANCE:1106/cntlG_ROLES_CONTAINER/shellcont/shell").pressEnter
  31. session.findById("wnd[0]").sendVKey 11

In system DR0 (Not upgraded)

  1. session.findById("wnd[0]").maximize
  2. session.findById("wnd[0]/tbar[0]/okcd").text = "/nsu01"
  3. session.findById("wnd[0]").sendVKey 0
  4. session.findById("wnd[0]/usr/ctxtUSR02-BNAME").text = "test"
  5. session.findById("wnd[0]/usr/ctxtUSR02-BNAME").caretPosition = 4
  6. session.findById("wnd[0]").sendVKey 0
  7. session.findById("wnd[0]/tbar[1]/btn[18]").press
  8. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_LAST").text = "test"
  9. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_LAST").setFocus
  10. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_LAST").caretPosition = 4
  11. session.findById("wnd[0]").sendVKey 0
  12. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_FIRST").text = "user"
  13. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_FIRST").setFocus
  14. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_FIRST").caretPosition = 4
  15. session.findById("wnd[0]").sendVKey 0
  16. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtSZA5_D0700-SMTP_ADDR").text = "test.user@noreply.com"
  17. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtSZA5_D0700-SMTP_ADDR").setFocus
  18. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtSZA5_D0700-SMTP_ADDR").caretPosition = 21
  19. session.findById("wnd[0]").sendVKey 0
  20. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO").select
  21. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/cmbUSLOGOND-USTYP").setFocus
  22. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/cmbUSLOGOND-USTYP").key = "A"
  23. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD1").text = "********"
  24. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD2").text = "********"
  25. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD2").setFocus
  26. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD2").caretPosition = 9
  27. session.findById("wnd[0]").sendVKey 0
  28. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG").select
  29. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG/ssubMAINAREA:SAPLSUU5:0106/tblSAPLSUU5TC_AGR/ctxtUSAGR-AGR_NAME[1,5]").text = "Z:T5_UK_WIPRO_DEV_NONBASIS"
  30. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG/ssubMAINAREA:SAPLSUU5:0106/tblSAPLSUU5TC_AGR/ctxtUSAGR-AGR_NAME[1,5]").setFocus
  31. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpACTG/ssubMAINAREA:SAPLSUU5:0106/tblSAPLSUU5TC_AGR/ctxtUSAGR-AGR_NAME[1,5]").caretPosition = 26
  32. session.findById("wnd[0]").sendVKey 0
  33. session.findById("wnd[0]").sendVKey 11

From the above it's clear that the screen IDs in both the systems are different as the program-me name is different for the same TA (SU01) in both the systems.

Now can you please advise how i will go with both to handle in one script (I can't put a check condition to call different scripts for the specific systems as in my landscape there are more that 100 systems).

Please help me on this.

Thanks in Advance,

Khagendra

stefan_schnell
Active Contributor
0 Kudos

Hello Khagendra,

a possible solution could be to check the existence of an object. Look here for a way to do this.

Change the sub routine C to a function:

  '-Sub C---------------------------------------------------------------
    Function C(ByVal Cmd)
      Dim Check
      Set Check = New cCheck : Check.Exe Cmd : Set Check = Nothing

      If QuitFlag Then

        C = 0

      Else

        C = 1

      End If
    End Function

And your call like this:

If C("session.findById(""wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME"").text = ""test""") = 0 Then

  'Do this

Else

  'Do that

End If

With this way you can differentiate whether an object exists or not and then go different paths, depending from the result and independent from the system.

Cheers

Stefan

khagendra_padhy
Explorer
0 Kudos

Hi Stefan,

Thanks for the valuable reply. This way can be processed with my objective. But when i dig more on my project landscape today , i found 3 more different systems with different upgrade version & different screen IDs for each.For this i need to define individual screen-ID path check in each case But i found one common pattern SAP follows as below.

  1. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_LAST").text

  1. session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA: SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_PERSON_NAME-NAME_LAST").text

   

RED letters- common in every system

BLUE letters- Program name & screen number from the image

GREEN letters- Table name & field name                      

This Program name-screen number & Field name varies only for each system (different version). We can see it by putting F1 over the field of a TA.

No doubt the way you gave can be proceeded but if we can find any method that SAP follows (if available in SAP GUI Scripting API) that will be more versatile.

Please put your ideas.


Thanks in Advance,

Khagendra

Former Member
0 Kudos

Hi Khagendra,

  I normally use the "findbyname" to solve these problems of possible changes ids in different systems. Normally a field in SAP has a unique name, which can facilitate in time to make the script. In your example I would do the following:

set oLastName = session.findById("wnd[0]").findByName("SUID_ST_NODE_PERSON_NAME-NAME_LAST","GuiTextField")

msgbox oLastName.text


I believe that the above three expressions in their work environments without the need to know the "id" fields.

   To use findbyname you need to pass the field name and type (in the case GuiTextField)

Here's an example that I use in my scripts:

Set scrx = session.children.item (session.children.length-1) 'Define a window0

Set oINSPETORA = scrx.findByName("CI_EKKODB-YY_ENT_INSPETORA", "GuiCTextField")

Set oGERENTE   = scrx.findByName("CI_EKKODB-YYGERENTE", "GuiCTextField")

Set oCCUSTOGER = scrx.findByName("CI_EKKODB-YYCENTRO_CUSTO", "GuiCTextField")

Set oACUSTO    = scrx.findByName("CI_EKKODB-YYAREA_CONT", "GuiTextField")

msgbox oINSPETORA.text

msgbox oGERENTE.text

msgbox oCCUSTOGER.text

msgbox oACUSTO.text

Set oINSPETORA = Nothing

Set oGERENTE   = Nothing

Set oCCUSTOGER = Nothing

Set oACUSTO    = Nothing

   Hope this helps,

Evando

stefan_schnell
Active Contributor
0 Kudos

Hello Evando,

cool tip

Thank you for sharing.

Cheers

Stefan

Former Member
0 Kudos

Hello Stephan,

Glad to help.

Evando

khagendra_padhy
Explorer
0 Kudos

Hi Evando,

Thanks for the very cool tip .

The snippet is fantastic solved lots of things. Can i ask one little question

set oLastName = session.findById("wnd[0]").findByName("SUID_ST_NODE_PERSON_NAME-NAME_LAST","GuiTextField").

How can i set the highlighted unique name (table name of field data) as input not by giving manually.

Thanks in Advance,

khagendra

Former Member
0 Kudos

Hi khagendra,

The name field is information that needs to be informed. Typically the stages of preparation of the script requirement, we investigate the actions that the script will run. This time is that the fields are identified using the recording tool of SAP own scripts. What can be done is to use a variable instead of the literal, but anyway mapping name field is required. In my opinion is much more "elegant" map the field names than ids (even because they can sometimes change).

Another interesting tip yet on this issue is that sometimes on the same screen, we have more than one field with the same name. At this time we use the commad FindAllByname with the same syntax. The difference is that in FindAllByname a collection is returned with all fields with the same name.

Evando

khagendra_padhy
Explorer
0 Kudos

Thanks Evando

Former Member
0 Kudos

Hi, Expert

By following your idea, I try to modify some code about controlling the value in the table lines, but no idea how to change it, such as below one, I don't know where can I put the code to change the line..

Before:

Session.findById("wnd[0]/usr/subSUB0:SAPLMEGUI:0019/subSUB3:SAPLMEVIEWS:1100/subSUB2:SAPLMEVIEWS:1200/subSUB1:SAPLMEGUI:1301/subSUB2:SAPLMEGUI:1303/tabsITEM_DETAIL/tabpTABIDT14/ssubTABSTRIPCONTROL1SUB:SAPLMEVIEWS:1101/subSUB2:SAPLMEGUI:1332/subSUB0:SAPLEINB:0300/tblSAPLEINBTC_0300/ctxtRM06E-EEIND[2," & l & "]").Text

After:

Session.findById("wnd[0]").findByName("RM06E-EEIND", "GuiTextField").Text  '??? always point to line one

Former Member
0 Kudos

Peikun Chen,

Your example is a (RM06E-EEIND) field that is inside a GuiTableControl. For each line you need to access a different object to be able to handle the same. If you directly use the findByName, the return will be the first field in the table and not the entire contents. In these cases I use a different form which is traverse the entire table and read line by line, accessing the field using the GetCell function. Following example of how to read a table control, making the paging control:


ReadTableControl - Google Docs


Hope this helps

Evando

khagendra_padhy
Explorer
0 Kudos

Hi Peikin Chen,

If you are trying to change the value of a table line by line , than you need to traverse the whole table line by line.
1-> count no. of rows in the table , otherwise after paging table line number will reset to first.
2-> then traverse thorugh it with a for loop.

Cheers,

Khagendra

khagendra_padhy
Explorer
0 Kudos

Hello experts,

Hope any body will reply my question to look at.

Thanks,

Khagendra

stefan_schnell
Active Contributor
0 Kudos

Hello Khagendra,

you can use this solution to solve your problem:

'-Begin-----------------------------------------------------------------

    If Not IsObject(application) Then
      Set SapGuiAuto = GetObject("SAPGUI")
      Set application = SapGuiAuto.GetScriptingEngine
    End If

    If Not IsObject(connection) Then
      Set connection = application.Children(1)
    End If

    If Not IsObject(session) Then
      Set session = connection.Children(0)
    End If

    Set Info = session.Info()
    If Info.SystemName() = "QR5" Then
      'Here you can set a variable for the screen ID of QR5
    ElseIf Info.SystemName() = "TC6" Then
      'Here you can set a variable for the screen ID of TC6
    End If

    'Here your code, with the variable of the screen ID

'-End-------------------------------------------------------------------


Cheers

Stefan

khagendra_padhy
Explorer
0 Kudos

Hi Stefan,

Thanks for your nice reply. But still i can't solve my complete problem. Because in the landscape i can't find which systems is upgraded one & which is not. Can you please help me for any other solution like platform independent methods which can be called for a certain task or can we make regular expression for GUICOMPONENT.

Any other solution if having also welcome.

Thanks in Advance,

Khagendra