on 04-01-2014 2:01 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
In system DR0 (Not upgraded)
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
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
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.
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
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
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
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
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
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
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
Hello experts,
Hope any body will reply my question to look at.
Thanks,
Khagendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.