SpiderFlight
Programmer
Its there a way to run the Cognos scheduler as a service?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
start "c:\Program Files\\Cognos\\cer3\\bin\\runmac32.exe" "\\server\\Macros Admin\\BATCH_CONTROL_MACRO.MCX"
Sub main
' *!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*
' *!* N.B.B. Impromptu on the server must be in Single Instance Mode (see Impromptu help: *!*
' *!* "Change the Number of Instances of Impromptu"), or each call will open another Impromptu session! *!*
' *!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*
' This macro is the core of a facility that allows PSenterprise users to schedule Impromptu reports to run outside
' normal hours and save the file in any of the following formats:
' dbf; csv; Excel with Format, pdf
' The macro is called by a batch file held in the Windows Scheduler set to run once a day. Initially set to 22:00 hours,
' but can be changed if this causes a load etc.
' It is controlled by \\server\Control Files\Batch_Control.txt '
' Creates a log file (Batch_Control_Log_N) for every day of the month where N is the day of the month
' The data in Batch_Control.txt has the following format with 1 line per report:
' There are 4 'pieces to the line separated by semicolons.
' 1) Date to be run: D (Daily), W (Weekly - every Sunday); F (Fortnightly - Sunday of every odd week);
' M (Monthly - 1st day on the month)
' 2) Type of output: D (dbf); C (csv) using ` as separator; E (Excel); P(pdf)
' 3) Report Name: The full report name using the full formal path without mapping e.g.:
' \\server\\Reports\report1.imr
' 4) Any responses to prompts in the report. These must be in the order dictated by the report and separated by |
' N.B. There must be a semicolon after the report name whether or not there is a prompt and no unnecessary spaces
' Here is an example of an entry to create a weekly pdf output for a report called Dummy that has the prompts "C" and "NUR"
' W;D;\\server\\Reports\report1.imr r;C|NUR
' If it is also needed in Excel format at monthly intervals another line would need to be added:
' M;E; \\server\\Reports\report1.imr r;C|NUR
' *!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*
' *!* N.B.B. Impromptu on the server must be in Single Instance Mode (see Impromptu help: *!*
' *!* "Change the Number of Instances of Impromptu"), or each call will open another Impromptu session! *!*
' *!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*
Dim impApp As object
Dim impRep As Object
Dim impPub as Object
Dim CPath as String
Dim Batch_Name as String
Dim CF_File as String
Dim Log_File as String
Dim Line_In as String
Dim Date_Type as String
Dim OP_Type as String
Dim Report_File as String
Dim Prompt_String as String
Dim pwd as String
Dim Cat_File as String
Dim Run_Now as Variant
Dim P as Integer
Dim File_Name as string
Dim b_error as variant
CPath="\\server\Control Files\"
Batch_Name="Batch_Control"
CF_File=CPath & Batch_Name & ".txt"
Log_File=CPath & Batch_Name & "_Log_" & format(Now,"ww") & ".txt"
Open Log_File for Output as #1
Print #1, "Log opened: " & format(now, "dd/mm/yy") & " " & format(now,"hh:mm")
if Dir(CF_File)="" then
Print #1,"Control file is missing: " & CF_File
goto End_Prog
end if
pwd=[The Password]
Cat_File="\\server \catalogs\catalog.cat"
Set impApp = CreateObject("Impromptu.Application")
impApp.Visible False
On error resume next
impApp.OpenCatalog Cat_File[UserClassID],[UserClassPassword],[DatabaseID],[DatabasePassword],1
if not impApp.DatabaseConnected then
Print #1,"Catalog is missing or UseriD/Password in valid. " & Cat_File
goto End_Prog
end if
if err=440 then
Print #1,"Catalog is missing: " & Cat_File
goto End_Prog
elseif err<>0 then
Print #1,"Error: " & Err & " " & Error$
end if
Open CF_File For Input as #2
Do While not EOF(2)
Line Input #2, Line_In
Date_Type=Ucase(getfield(Line_In,1,";"))
OP_Type=UCase(getfield(Line_In,2,";"))
Report_File=getfield(Line_In,3,";")
Prompt_String=getfield(Line_In,4,";")
If instr("DWFM",Date_Type)=0 then
Print #1,"***WARNING Date Type '" & Date_Type & "' invalid for " & Report_File
end if
Run_Now= False
Select Case Date_Type
Case "D"
Run_Now=True
Case "W"
if Weekday(Now)=7 then Run_Now=True
Case "F"
if Weekday(Now)=1 and val(format(Now,"ww")) mod 2 = 0 then Run_Now=True
Case "M"
if day(Now)=1 then Run_Now=True
End Select
if Run_Now=False then goto Next_File
Err=0 ' EOF sets Err to 62
Report_Name=left(Report_File,Len(Report_file)-4)
on error resume next
set impRep = impApp.OpenReport(Report_File,Prompt_String)
b_error=err
if err<>0 then
Print #1, "Error: " & Err & " " & Error$
else
Print #1, "Report opened: " & Report_File
' Want file name, this is last "\" piece of Report_Name string but can only find it by looking backwards
For P=20 to 1 step -1 '
if getfield(Report_Name,P,"\")<>"" then
File_Name=getfield(Report_File,P,"\")
File_Name=left(File_Name,len(File_name)-4)
Exit for
End if
Next
Select Case OP_Type
Case "C"
impRep.ExportAscii Report_Name & ".csv",True, True,"`" ' Retain Headers, User quotes, "`" as separator
Print #1, Spc(5), "'" & File_Name & "' saved as csv"
Case "D"
impRep.ExportdBase Report_Name & ".dbf"
Print #1, Spc(5), "'" & File_Name & "' saved as dbf"
' dbf file names cannot be >8 characters. Won't truncate the name here as this could leave to overwriting.
' So save as is and send error message to log file if >8 bytes
if len(File_Name)>8 then
Print #1, "**WARNING '" & File_Name & ".dbf' is not a valid name - truncate to 8 or less characters"
end if
Case "E"
impRep.ExportExcelWithFormat Report_Name & ".xls"
Print #1, Spc(5), "'" & File_Name & "' saved as xls"
Case "P"
Set impPub = ImpRep.PublishPDF
impPub.publish Report_Name & ".pdf"
Print #1, Spc(5), "'" & File_Name & "' saved as pdf"
Case Else
Print #1, Spc(5), "***WARNING - Output type '" & OP_Type & "' not recognised for " & File_Name
End Select
impRep.CloseReport
set impRep=Nothing
end if
Next_File:
Loop
Close #2
ImpApp.ActiveCatalog.Close
ImpApp.Quit
Set ImpApp=Nothing
End_Prog:
Print #1, "Log closed: " & format(now, "dd/mm/yy") & " " & format(now,"hh:mm")
Close #1
End Sub