on 05-24-2013 8:34 AM
Hello,
I started a project just yesterday after realizing I can control SAP through VBA. I've been doing pretty good figuring things out with the awesome answers provided here to other people's questions. I have the automated login as well as 2 of the 3 total major functions I wish to accomplish all figured out. A good lot of it comes from recording scripts to see how things are done. I've ran into a minor snag that I had a question about and not sure where to turn for this one, so figured I'd ask the professionals.
In my office, we have 2 different computers. PC1 is set to a screen resolution of 1024x768. PC2 is set to 1280x1024.
On PC1 when manually navigating the GUI to a particular SAP screen I have 4 rows of a data input table with 1 more row hidden that I have to scroll down one click to get to the last row. On PC2 at the higher screen resolution, I don't have to scroll, it shows all 5 rows. I'm doing all of my scripting/recording/testing on PC1.
This is a small snippet from that script on PC1.
'Travel Time
session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,0]").Text = "60"
'Time Onsite
session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,3]").Text = "240"
'scroll 1 for Mileage
session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS").verticalScrollbar.Position = 1
session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,3]").Text = "48"
I left a couple comments in to refer to them by their name.
After the initial recording and looking at it. I expected the mileage line to be...
.../txtG_WRK_OPERATION-ISMNW[3,4]").Text = "48"
but it wasn't. If I do the same thing on PC2, then that is exactly what the mileage line is, but because I scrolled down one notch it's [3,3] just like the Time Onsite line, which tells me that the reference is to what is on-screen and not a direct label to that entry. I double checked that by recording again and this time before making that 5th line entry, I scrolled down far enough so it was in the 1st position and sure enough, it recording it as [3,0].
Now to the pertinent question. Can I use [3,4] in the script even though technically that position is off-screen or will I end up having to add screen resolution checking to ensure things get done the right way no matter the screen resolution?
I would test it, but I have to keep my testing to a minimum as I only have access to the live database and I do have to be careful what I'm doing with the live data.
Thanks, Much Appreciated.
RJ
Hello.
That is the best option to go. When working from MS VBA another one could be to read screen resolution and change temporary to an available screen resolution which ensure, having same fields available as in developed procedure with another screen resolution. But the best practice is always to design an procedure in that way that manipulate PC-settings is not required.
Good job. SAP Gui Scripting documentation help a lot to find several methods and properties to design good scripts.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The answer to the above question is no. You cannot address a field that is not visible. 😕
I have been playing with a variety of work-arounds to address the different screen resolution issue.
This is the best I've come up with so far....
Sub testoperations()
'Logs onto SAP, unless already connected it'll bind the connection
Call SapLogin
Dim TravelTime As String
Dim TimeOnsite As String
Dim Mileage As String
TravelTime = "0"
TimeOnsite = "240"
Mileage = "0"
AppActivate Session.findById("wnd[0]").Text
Dim TestForField As String
'**************
'Operations tab
'**************
Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2").Select
'Travel Time
Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,0]").Text = TravelTime
'Time Onsite
Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,3]").Text = TimeOnsite
Session.findById("wnd[0]").sendVKey 0
On Error Resume Next
' Test to see if 5th row is visible
TestForField = Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,4]").Text
'MsgBox Err.Description & " " & Err.Number
If Err.Number = 619 Then
'Do this if 5th row not visible
Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS").verticalScrollbar.Position = 1
Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,3]").Text = Mileage
Else
'do this if 5th row is visible
Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,4]").Text = Mileage
End If
Session.findById("wnd[0]").sendVKey 0
On Error GoTo 0
End Sub
The above does work, but it requires trapping the error when it can't see a particular field. The only issue with doing it this way is that the 3 fields are mandatory and right when it executes the test portion of the code (in bold) SAP throws a quick error because of the mandatory field. It didn't matter where I tested it, I tried at the beginning without doing anything yet, as well as where you see it in this example.
There's just something about testing for an error that bothers me. I've been able to avoid error trapping in most VBA situations, but it seems this is the only way I could come up with short of actually checking for screen resolution, but even then, I'm not entirely sure that all monitors will display it all at the higher screen resolution, so checking for what is and isn't visible seems to be the best way to do it. I would just like to avoid the additional SAP error if possible.
Any ideas, suggestions or a better way to accomplish the same task?
Thanks,
RJ
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi RJ,
until recently I did not know the property. You could use it to try though.
for example:
. . .
if Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,4]").changeable then
TestForField = Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,4]").Text
else
. . .
end if
. . .
Regards,
ScriptMan
That was a nice idea, but because [3,4] is not on the screen it still produces 619 Control ID could not be found. It gave me an idea though.....
Is there a simple way to do something like....
If Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,4]").VISIBLE Then
I tried it blindly just for grins, but didn't work.
I picked up some SAPGUI scripting help information last night. I'll go over it and see what I can find. Hopefully there is a property to check if a line is visible or not.
Thanks for the assist Script Man. You pointing out other properties lead me to the "visiblerowcount" property and this works as expected to check for the 5th row....
Dim OperationsRowCnt As Long | |
OperationsRowCnt = Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS").visiblerowcount | |
If OperationsRowCnt = 4 Then | |
Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS").verticalScrollbar.Position = 1 | |
Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,3]").Text = Mileage | |
Else | |
Session.findById("wnd[0]/usr/tabsTB_CLOSER/tabpTB_CLOSER_FC2/ssubTB_CLOSER_SCA:SAPMZCS_CALL_CLOSER:0220/tblSAPMZCS_CALL_CLOSERTC_OPERATIONS/txtG_WRK_OPERATION-ISMNW[3,4]").Text = Mileage | |
End If |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.