cancel
Showing results for 
Search instead for 
Did you mean: 

VB SCRIPT - POPUP MASSAGE HANDLING

Former Member
0 Kudos

HI

I'M RUNNING A VBSCRIPT (RECORDED AT SAP SYSTEM AND MODIFIED)

THE SCRIPT CONNECTS TO A SESSION AND ACTIVATE A TRANSACTION +

FILLS IN SOME FIELDS.

IN SOME SCENARIOS  A POPUP MASSAGE APPEAR.

I NEED TO RECOGNIZE THAT THE POPUP MASSAGE APPEARED AND

IN THIS CASE I WANT TO BE ABLE TO GIVE THE USER THE OPTION

TO READ THE MASSAGE , AND DECIDE (BY ENTER KEYSTROKE) TO CONTINUE THE SCRIPT FLOW

OR (BY ESC KEYSTROKE) TO STOP THE SCRIPT AND KEEP ON MANUALLY .

MY SCRIPT :

Set WshShell = WScript.CreateObject("WScript.Shell")

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

If (Wscript.Arguments.Count < 7) Then 

 

Wscript.Echo "Required Parameter missing" 

 

Do While Not WScript.StdIn.AtEndOfLine

    Input = WScript.StdiN.Read(1)

Loop

 

End If 

 

' Retrieve the first argument (index 0). 

 

PATNR = Wscript.Arguments(0) 

ORG = Wscript.Arguments(1) 

YOMAN = Wscript.Arguments(2)

SERV1 = Wscript.Arguments(3)

SERV2 = Wscript.Arguments(4)

SERV3 = Wscript.Arguments(5)

SERV4 = Wscript.Arguments(6)

SERV5 = Wscript.Arguments(7)

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

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

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

session.findById("wnd[0]/usr/ctxtZNRN04-PATNR").text = PATNR

session.findById("wnd[0]/usr/ctxtZNRN04-ORGPF").text = ORG

session.findById("wnd[0]/usr/ctxtZNRN04-PLOBJ").text = YOMAN

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,0]").text = SERV1

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,0]").setFocus

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,0]").caretPosition = 9

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

HERE THE MASSAGE MIGHT APPEAR

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

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

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,1]").text = SERV2

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,1]").setFocus

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,1]").caretPosition = 9

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

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE").verticalScrollbar.position = 1

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE").verticalScrollbar.position = 2

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,0]").text = SERV3

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,0]").setFocus

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,0]").caretPosition = 9

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

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,1]").text = SERV4

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,1]").setFocus

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,1]").caretPosition = 9

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

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE").verticalScrollbar.position = 3

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,1]").text = SERV5

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,1]").setFocus

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,1]").caretPosition = 9

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

WshShell.AppActivate "זימון מטופל אמבולטורי"

Accepted Solutions (1)

Accepted Solutions (1)

script_man
Active Contributor
0 Kudos

Hi Daniel,

You can try the following:

. . .

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,0]").caretPosition = 9

on error resume next

MESSAGE_TEXT = session.findById("wnd[1]").text

if MESSAGE_TEXT = "POPUP_TEXT"  then                    ' here is the text of the message

   answer = msgbox("Do you want to continue with the script?", vbOKCancel,"question")

   if answer = 2 then

      wscript.quit

   else

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

   end if

end if

on error goto 0

session.findById("wnd[0]/usr/tblSAPLZISH_SCHEDULINGTC_SERVICE/ctxtNLEI-LEIST[1,1]").text = SERV2

. . .

Regards,

ScriptMan

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello scriptman

Thank you very much for your solution.

It does the work when a pop-up massage appears .

But however when there is no pop-up massage i still receive the massage "Do you want to continue with the script?"

How can I avoid activating this question when it is not necessary ?

Another challenge I'm facing is that  in some scenarios the user gets

a warning massage on the bottom bar of the sap-gui .

I need to recognize that such a warning appeared  and act the same way as above .

(I couldn't identify the warning object name ) .

Thank you again

Daniel

script_man
Active Contributor
0 Kudos

Hi Daniel,

the variable MESSAGE_TEXT must still be cleared.

For Example:

. . .

on error resume next

MESSAGE_TEXT = ""

MESSAGE_TEXT = session.findById("wnd[1]").text

if MESSAGE_TEXT = "POPUP_TEXT"  then                    ' here is the text of the message

. . .

The status bar text could be evaluated as follows.

For example:

. . .

on error resume next

STATUS_BAR_TEXT = ""

STATUS_BAR_TEXT = session.findById("wnd[0]/sbar").text

if STATUS_BAR_TEXT = "WARNING_TEXT"  then          ' here is the text of the warning message

. . .

Regards,

ScriptMan

Former Member
0 Kudos

Hi Scriptman,

I have a BIG favor. Asked the quesion here somewhere, but got no answer. While working for P&G, they had a program (I'm sure they created it) called SAP GUI Scripting Automation Tool that ran from excel. It had an add in so you could pick it from the excel menu, record your actions, and it recorded the script. If I sent you (or posted here if possible) the pics, or even the file, would you be so kind to tell me how I might get this tool, or even cretae it. This would be a HUGE help for me @ my current job. Thanks in advance. Paul

script_man
Active Contributor
0 Kudos

Hi Paul,

In the past I was also confronted with this tool. It's not mine. I've written a similar tool outside of Excel. It was about 4 years and still works today. It bears the name of Script - Administration and probably works similar to the one you mentioned.

You can do a lot directly in Excel. Explore first e.g. link to: http://scn.sap.com/thread/1699675

Regards,

ScriptMan

Former Member
0 Kudos

thank you very much

Former Member
0 Kudos

Hi,

I will have to give it a read, but doubt I will understand it. I am capable of creating a macro, but that's it. VB is totally greek to me. I liked the tool they had since it broke out every value (and recoreded ea) in it's own cell. I'd primarily need it for downloading data. Right now I use the script in SAP R3, but for some reason, it gets buggy in just afew days, and doesn't download what it was set up to do. The SAP GUI worked virtually flawless.

Here is what I have from the file but again, just wanting to understand how this tool was created, and if a average Joe like me could recreate it? My goal would be to eventually use it for delivery schedules (download). Used before, I had it set up to go gewt the, pull the data down to it's own file name on a shared drive. Then all I had to do was run the macro that converetd the jiberish from SAP into a readable excel file.

Also note the problem I'm having with the script "in" SAP is that it creates a text file. No way can you modify a text file if we are talking a possible list of 100's of sku. Also, this was a direct download from their IT. Do you think there is a way to download it to a disk? I'm willing to ask someone there since I don't "think" it is "owned" by P&G.

script_man
Active Contributor
0 Kudos

Hi Paul,

You have written quite a lot. But it still does not know what the error message says.

You could try also for example a single loop to record with the tool "Script Recording and Playback" (ALT / F12) in SAP. Then one could compare the result with the Excel tool.

Regards,

ScriptMan