Skip to Content
author's profile photo Former Member
Former Member

Why my "rowCount" don't work?

Hello everyone.

I recorded a script with the "Record and Playback" in the Sap.

Well, I need to create a script to save emails on transaction "XD02". The emails must be written at last row after I click on button "Add new line"

My script recorded:

If Not IsObject(application) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

Set connection = application.Children(0)

End If

If Not IsObject(session) Then

Set session = connection.Children(0)

End If

If IsObject(WScript) Then

WScript.ConnectObject session, "on"

WScript.ConnectObject application, "on"

End If

session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").text = "xd02"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[1]/usr/ctxtRF02D-KUNNR").text = "156008760"

session.findById("wnd[1]/usr/ctxtRF02D-KUNNR").caretPosition = 9

session.findById("wnd[1]").sendVKey 0

session.findById("wnd[0]/usr/subSUBTAB:SAPLATAB:0100/tabsTABSTRIP100/tabpTAB07").select

session.findById("wnd[0]/usr/subSUBTAB:SAPLATAB:0100/tabsTABSTRIP100/tabpTAB07/ssubSUBSC:SAPLATAB:0201/subAREA1:SAPMF02D:7360/btnPUSH-PARTNER").press

session.findById("wnd[0]/usr/subADDRESS:SAPLSZA5:0900/btnG_ICON_SMTP").press

session.findById("wnd[1]/tbar[0]/btn[13]").press

session.findById("wnd[1]/usr/tblSAPLSZA6T_CONTROL6/txtADSMTP-SMTP_ADDR[0,1]").text = "test@test.com"

session.findById("wnd[1]/usr/tblSAPLSZA6T_CONTROL6/txtADSMTP-SMTP_ADDR[0,1]").caretPosition = 13

session.findById("wnd[1]/tbar[0]/btn[0]").press

session.findById("wnd[0]/tbar[0]/btn[11]").press

So, my script must add a new line and then insert email in the last row.

I can't count rows with the command "rowCount".

I tried insert the code below after the step session.findById("wnd[1]/tbar[0]/btn[13]").press (Insert new line)

Rows = session.FindById("wnd[1]/usr/shellcont/shell").rowCount - 1

session.findById("wnd[1]/usr/tblSAPLSZA6T_CONTROL6/txtADSMTP-SMTP_ADDR[0,Rows]").text = "test@test.com"

When I execute the script a message box shows "The control could not be found by id. - "

Anyone could help me please?

PS: Sorry for my BAD English.


Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on May 13, 2013 at 07:34 PM

    Hi Wagner - I had an issue like that some time ago and it was resolved (Cheers, ScriptMan!) this way:

    ---------------------------------

    for Ct = 0 to 16

    Script_Line = "session.findById(" & chr(34) & "wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1107/tabsTS_1100/tabpMUEB/ssubSUB_AUFTRAG:SAPLCOMK:3020/tblSAPLCOMKTCTRL_3020/ctxtRESBD-POSTP[6," & int(Ct) & "]" & chr(34) & ").text = " & chr(34) & "n" & chr(34)

    TextFile.WriteLine Script_Line

    next

    --------------------------------------

    Keep in mind this is just an example and the reference is to a different screen. The key is to look at the variable 'Ct' and observe how it was used in a line/field reference.

    You can read the discussion if you search the forum with this text: "Referencing a variable in 'session findbyId' command (SAP GUI Scripting)"

    Good luck

    Best regards

    Umur

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Holger,

      although the solution for more than 3 addresses is not particularly complicated:

      . . .

      session.findById("wnd[1]/tbar[0]/btn[13]").press

      for i = 0 to 100

      session.findById("wnd[1]/usr/tblSAPLSZA6T_CONTROL6").verticalScrollbar.position = i

      if session.findById("wnd[1]/usr/tblSAPLSZA6T_CONTROL6/txtADSMTP-SMTP_ADDR[0,0]").text = "" then exit for

      next

      session.findById("wnd[1]/usr/tblSAPLSZA6T_CONTROL6/txtADSMTP-SMTP_ADDR[0,0]").text = "test@test.com"

      . . .

      If the length of address is less than 15, the next command produces an error.

      session.findById("wnd[1]/usr/tblSAPLSZA6T_CONTROL6/txtADSMTP-SMTP_ADDR[0," & i & "]").caretPosition = 15

      For this reason, I would omit it completely. 😎

      Regards,

      ScriptMan

  • author's profile photo Former Member
    Former Member
    Posted on May 23, 2013 at 08:04 PM

    Thanks all for the answers. I got a solution by doing this:

    If Not IsObject(Application) Then

    Set SapGuiAuto = GetObject()

    Set Application = SapGuiAuto.GetScriptingEngine

    End If

    If Not IsObject(Connection) Then

    Set Connection = Application.Children(0)

    End If

    If Not IsObject(session) Then

    Set session = Connection.Children(0)

    End If

    If IsObject(WScript) Then

    WScript.ConnectObject session, "on"

    WScript.ConnectObject Application, "on"

    End If

    session.findById("wnd[0]/tbar[0]/okcd").Text = "/NXD02"

    session.findById("wnd[0]").sendVKey 0

    On Error Resume Next

    session.findById("wnd[1]/usr/ctxtRF02D-KUNNR").text = "100202030"

    If Err.Number > 0 Then

    session.findById("wnd[1]/tbar[0]/btn[0]").press

    session.findById("wnd[0]").sendVKey 0

    session.findById("wnd[1]/usr/ctxtRF02D-KUNNR").text = "100202030"

    End If

    On Error GoTo 0

    session.findById("wnd[1]/usr/ctxtRF02D-KUNNR").text = "100202030"

    session.findById("wnd[1]").sendVKey 0

    session.findById("wnd[0]/usr/subSUBTAB:SAPLATAB:0100/tabsTABSTRIP100/tabpTAB07").select

    session.findById("wnd[0]/usr/subSUBTAB:SAPLATAB:0100/tabsTABSTRIP100/tabpTAB07/ssubSUBSC:SAPLATAB:0201/subAREA1:SAPMF02D:7360/btnPUSH-PARTNER").press

    session.findById("wnd[0]/usr/subADDRESS:SAPLSZA5:0900/btnG_ICON_SMTP").press

    session.findById("wnd[1]/tbar[0]/btn[13]").press 'Add new blank row

    Rows = session.findById("wnd[1]/usr/tblSAPLSZA6T_CONTROL6").rowCount - 1 'Count the number of rows in the grid

    For j = 0 To Rows

    If (session.findById("wnd[1]/usr/tblSAPLSZA6T_CONTROL6/txtADSMTP-SMTP_ADDR[0," & CStr(j) & "]").Text = "") Then

    session.findById("wnd[1]/usr/tblSAPLSZA6T_CONTROL6/txtADSMTP-SMTP_ADDR[0," & CStr(j) & "]").Text = "test@mail.com"

    Exit For

    End If

    Next

    session.findById("wnd[1]/tbar[0]/btn[0]").press 'Press button OK

    session.findById("wnd[0]/tbar[0]/btn[11]").press 'Press button SAVE

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.