Report sometimes returns 0 records in SAP GUI script - vbscript

So I've recorded a script using the SAP GUI recorder. I'm basically just running 7 reports and saving the contents to an excel file. The code is uninspiring, just some variation of.
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "SAP_ALL.TXT"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 11
But sometimes there are no records in the report.
I suspect there is something I can check to either save the report or move on using if/then/else but cannot find a good example. How do I catch and recover from this or other errors?
Is there a way to to sapshcut�or structure the script to avoid this problem?
Also, is there a way to execute the script from the command line, passing in the userid and password as parameters?
Relevant examples welcome. I'd RTFM but I don't have one.

If the report is a grid, then you could try the following.
for example:
...
session.findById("wnd[0]/tbar[1]/btn[8]").press
on error resume next
'This command must be recorded once in your environment. It's a mouseclick in the first line.
session.findById("wnd[0]/usr /subSUB_AREA_ROOT:SAPLREIS_GUI_CONTROLLER:0200/subSUB_AREA:SAPLREIS_GUI_CONTROLLER:1000/cntlCC_LIST/shellcont/shell").currentCellRow = 1
if err.number = 0 then
on error goto 0
...
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "SAP_ALL.TXT"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 11
...
else
on error goto 0
...
end if
...
Please take a look at the following link:
VBA 2010 - Hide all SAP windows using .iconify
Regards,
ScriptMan

Related

Checking out data models in power designer with VBScript

Through a VBS code I need to check out some data models from the power designer.
The requirements are: Connect to the power designer repository, check out some data models. can anybody help me?
I found this code in SAP documentation, but when i execute it the following error appears.
Dim rc : Set rc = RepositoryConnection
'Check out model
Dim TargetModel
Set TargetModel = rc.FindChildByPath("MyFolder/MyPDM", PdRMG.Cls_RepositoryModel)
TargetModel.CheckOut()
Output "Checked"
The error messege:
Microsoft VBScript Runtime Error
Required object (0x800A01A8)
on line 5
As mentioned by the first comment, at least, verify the FindChildByPath return value:
Set TargetModel = rc.FindChildByPath("MyFolder/MyPDM", PdRMG.Cls_RepositoryModel)
if targetmodel is nothing then
output "nothing"
else
TargetModel.CheckOut()
Output "Checked out"
end if
Apart from that, the sample works for me, and opens the PDM I have checked in.

SAS Enterprise Guide with VBScript. Looping through SAS programs get stuck

I'm facing a random problem. When executing SAS programs with VBScript and the SASEGObjectModel.Application.7.1, looping through CodeCollection get stuck sometimes, even if the program execution was succeeded (the final data bases are correctly created in our server). The script simple doesn't go to the next program of CodeCollection (the prompt executing the script still open... ad infinitum). The SAS program It happens is random, also the frequency. I'm going with something like this:
Dim oSasApp
Set oSasApp = CreateObject("SASEGObjectModel.Application.7.1")
oSasApp.SetActiveProfile("some-profile")
Dim oSasProj
Set oSasProj = oSasApp.Open("some-project.egp", "")
Dim oProgramList
Set oProgramList = oSasProj.CodeCollection
Dim programOrder
Set programOrder = ...here I assign the SAS programs order array reading from a .txt...
For Each program in programOrder
For Each sasProgram in oProgramList
If sasProgram.Name = program Then
sasProgram.Run
sasProgram.Log.SaveAs "some-folder/" & sasProgram.Name & ".txt"
End If
Next
Next
oSasProj.Close
oSasApp.Quit
The problem is not the Log saving, as the log txt file of the stucked program is also correctly created.
Any idea? Maybe problems in our SAS server? Should I declare some kind of options?
SAS Guide version: 7.15
Windows: 10
Tks
So... for people facing the same problem. As I commented above, if I press enter on prompt the script flows again. So it is waiting for my input, for reasons I can't tell. I did 2 things to get around it. Not sure if all of them are necessary or if only one solves it, but here it goes:
First, by VBScript I turned off a list of generations and I applied a delay after the SAS program runs:
For Each program in programOrder
For Each sasProgram i oProgramList
If sasProgram.Name = program Then
sasProgram.GenSasReport = False
sasProgram.GenHTML = False
sasProgram.GenListing = False
sasProgram.GenPDF = False
sasProgram.GenRTF = False
sasProgram.Run
WScript.Sleep(2000)
sasProgram.Log.SaveAs "some-folder/" & sasProgram.Name & ".txt"
End If
Next
Next
Them, in my batch file, wich I use to call the VBScript with the "cscript" command, I set it to apply "y" to every single message the VBScript could ask:
cd ./script-folder
echo y | cscript script-file-name.vbs
And that is it.

Only launch first row of all tests in UFT

We have many UFT test scripts with many datasets.
In order to perform a quick check of the scripts, we want to run every script using only, for each script, the first dataset of the data table.
We know how to do it unitary (with the "Test settings" window) but not globally.
We don't even know if it's possible, if you have some info please tell me!
Thank you
Use the below VBscript and change the path C:\QTP\Scripts\MyScript with your script path. This scripts will open and run the UFT test and set the data table iteration to 1st row only. You can also loop this script to execute all UFT Tests with one iteration only.
Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
Set qtResultOpt=CreateObject("QuickTest.RunResultsOptions")
qtResult.ResultsLocation="C:\Temp\"
App.Launch
App.Visible = True
App.Test.Settings.Run.IterationMode = "rngIterations"
App.Test.Settings.Run.StartIteration = 1
App.Test.Settings.Run.EndIteration = 1
App.Open "C:\QTP\Scripts\MyScript", True
Set objTest=qtApp.Test
objTest.Run qtResultOpt

How can I use OpenArgs to print multiple reports in a loop situation?

I am slimming down my databases, eliminating duplicate reports where I can and creating better code. I have one database that involves our welders and foremen. In this code, I can print a report for an individual foreman, which sends the string "strActive" through openargs The report looks at strActive and on the OpenForm action, sets the filter for active, inactive, or all welders, based on the string value passed through.
It works perfectly for the single page at a time code. There, the user chooses a foreman from a list or enters the foreman's clock number. The query the report is based on uses the global string "ForemanCLK" to only get results for that welder.
Formerly, I had three reports; one for all welders, one for active welders, and one for inactive welders.
Previously, I would set a variable based on strActive and open the appropriate report using another variable in the code in place of the report name. The loop worked fine and opened the report 39 times, each time with a new foreman name and data.
I'm baffled as to why opening the report now, with an openarg, doesn't work. I only get the first foreman name, 39 times. I've verified that I get the foremanCLK variable of the different foremen by commenting out the docmd line and debug.print(ing) the various values needed by the form. The report simply doesn't load it correctly.
Set rec = CurrentDb.OpenRecordset(sql)
rec.MoveFirst
For ctr = 0 To rec.RecordCount - 1
ForemanCLK = rec(0).Value
DoCmd.OpenReport "rptForeman", acViewNormal, , , , strActive
'DoCmd.OpenReport "rptForeman", acViewNormal
rec.MoveNext
Next
The above code gets me many copies of the same foreman's report filtered by strActive
For ctr = 0 To rec.RecordCount - 1
ForemanCLK = rec(0).Value
'DoCmd.OpenReport "rptForeman", acViewNormal, , , , strActive
DoCmd.OpenReport "rptForeman", acViewNormal
rec.MoveNext
But this gets me all the different foremen, except it is not filtered.
I've tried passing in a Where clause.
acViewNormal, ,"[active]=" & True
and
acViewNormal, ,"[active]=" & False
and
acViewNormal, ,"[active]=" & True & " OR [active]=" & False
I did the same verification with the single report, and it filters correctly, but in the loop, it does not filter at all. It does, however give me the different foremen.
The big question here is...
WHY? Does access not have enough time between reports to close it and therefore it doesn't perform the operations on the open event?
Any other ideas?
You must close the report explicitly inside your loop: DoCmd.Close acReport, "rptForeman". If OpenReport is called a second time on an already-open report, the object gets the focus in access, but it doesn't re-run the Open event.
Okay, I must hang my head in shame.
I error checked the hell out of that code above using every variable except strActive.
When I added that to my debug.print line, it came up with nothing. How can that be!?!!??
I simply forgot to set that at the beginning of the sub, like I did with the other action that opens a single report. strActive is a global variable, but was not set at any other point in the code up until this piece.
Once this was added to the beginning of the sub, all worked fine.

VB6 ADODB Record Set Update

So I'm pretty new to Visual Basic and inherited this VB6 code that i need to work on now. Right now, I'm trying to update a SQL database using an ADODB.RecordSet. I have a Select SQL statement that pulls the right data from the database into the ADODB.RecordSet, but I'm having problems updating all the rows. What I am trying to do is to update the same column for each row with the same value. Right now, its updating a few of the records, but I'm getting an error pop up. The error I get is:
Run Time error 3021: Either BOF or EOF
is True or the current record has been
deleted. Requested operation requires
a current record.
When I click to debug, it takes me to rsUpdate.fields(TargetFieldName) = value
The project itself is huge and too large to post, but the part of the code that I'm working on now is this:
If rsUpdate.State = adStateOpen Then
If rsUpdate.EOF Then
rsUpdate.Close
Exit Function
End If
rsUpdate.MoveFirst
Dim i as Integer
For i = 0 To rsUpdate.recordCount
rsUpdate.fields(TargetFieldName) = value
rsUpdate.MoveNext
Next i
On Error GoTo canupdaterecord
rsUpdate.Update
On Error GoTo 0
rsUpdate.Close
End If
Exit function
So any help you guys can give me would be greatly appreciated. Like I said, I'm pretty new to VB and am kind of learning this all as I go.
I would guess the problem is an off-by-one error:
For i = 0 To rsUpdate.recordCount
rsUpdate.fields(TargetFieldName) = value
rsUpdate.MoveNext
Next i
If recordcount returns 5, this loop will make 6 runs: 0,1,2,3,4,5.
I'd write it like this:
while not rsUpdate.EOF do
rsUpdate.fields(TargetFieldName) = value
rsUpdate.MoveNext
wend
Try this also:
If reUpdate.EOF Then
Exit Sub
End If

Resources