dbTalk Databases Forums  

Cognos Impromptu Script Editor - problem with macro

comp.databases.olap comp.databases.olap


Discuss Cognos Impromptu Script Editor - problem with macro in the comp.databases.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Phil Latio
 
Posts: n/a

Default Cognos Impromptu Script Editor - problem with macro - 12-29-2005 , 10:53 AM






Using Cognos Impromptu (Version 7) Script Editor, I'm trying to create
a Sub so that it can be re-used - macro code at the bottom of the post.

The Sub takes three arguments to copy a file from one location and dump
it to another location, appending the date to the filename along the
way.
A further parameter is the intended file extension of the file being
moved - to give some flexibility if this sub is called multiple times.

When I run it in the CognosScript Editor window, it highlights in red,
the single line in the Sub Main and saying '1 Error .... etc etc" - it
doesn't even compile, let alone run & fail!!!

If I hardcode the parameters into the Sub ArchiveDataFiles it works
fine, but is not what I want as I intend to call it numerous times,
passing in various parameters.

Can anyone point me off with what I'm doing wrong! It must be me - I
can't beleive that a routine can't take variable/parameters!!!

Thanks in advance

Phil
================================================== ==============
Sub Main()

Call ArchiveDataFiles("C:\Test.txt", "C:\Test2", "csv")

End Sub


Sub ArchiveDataFiles (strFile As String, strDest As String, strExt As
String)
Dim strFileToCopy as String
Dim strDestination as String
Dim strFileTag as String

On Error Resume Next

strFileTag = "_" & Format(Date,"YYYYMMDD")
strFileToCopy = strFile
strDestination = strDest & strFileTag & "." & strExt

FileCopy strFileToCopy, strDestination

End Sub


Reply With Quote
  #2  
Old   
Phil Latio
 
Posts: n/a

Default Re: Cognos Impromptu Script Editor - problem with macro - 12-29-2005 , 06:03 PM






I forgot to mention that I did add a Declare statement at the top of
the macro code.

thanks

phil

Phil Latio wrote:
Quote:
Using Cognos Impromptu (Version 7) Script Editor, I'm trying to create
a Sub so that it can be re-used - macro code at the bottom of the post.

The Sub takes three arguments to copy a file from one location and dump
it to another location, appending the date to the filename along the
way.
A further parameter is the intended file extension of the file being
moved - to give some flexibility if this sub is called multiple times.

When I run it in the CognosScript Editor window, it highlights in red,
the single line in the Sub Main and saying '1 Error .... etc etc" - it
doesn't even compile, let alone run & fail!!!

If I hardcode the parameters into the Sub ArchiveDataFiles it works
fine, but is not what I want as I intend to call it numerous times,
passing in various parameters.

Can anyone point me off with what I'm doing wrong! It must be me - I
can't beleive that a routine can't take variable/parameters!!!

Thanks in advance

Phil
================================================== ==============
Sub Main()

Call ArchiveDataFiles("C:\Test.txt", "C:\Test2", "csv")

End Sub


Sub ArchiveDataFiles (strFile As String, strDest As String, strExt As
String)
Dim strFileToCopy as String
Dim strDestination as String
Dim strFileTag as String

On Error Resume Next

strFileTag = "_" & Format(Date,"YYYYMMDD")
strFileToCopy = strFile
strDestination = strDest & strFileTag & "." & strExt

FileCopy strFileToCopy, strDestination

End Sub


Reply With Quote
  #3  
Old   
ya
 
Posts: n/a

Default Re: Cognos Impromptu Script Editor - problem with macro - 01-10-2006 , 05:31 PM



CognosScript is basically Visual Basic. Drop your code in MS VB and check
for a syntax error, then copy and paste the code back into the CognosScript
editor and you should be good to go. As an alternative, you could just
write the entire app inside of Visual Basic, after all you are just using
ole automation calls. Cheers
ya


"Phil Latio" <phil.latio (AT) lycos (DOT) co.uk> wrote

Quote:
I forgot to mention that I did add a Declare statement at the top of
the macro code.

thanks

phil

Phil Latio wrote:
Using Cognos Impromptu (Version 7) Script Editor, I'm trying to create
a Sub so that it can be re-used - macro code at the bottom of the post.

The Sub takes three arguments to copy a file from one location and dump
it to another location, appending the date to the filename along the
way.
A further parameter is the intended file extension of the file being
moved - to give some flexibility if this sub is called multiple times.

When I run it in the CognosScript Editor window, it highlights in red,
the single line in the Sub Main and saying '1 Error .... etc etc" - it
doesn't even compile, let alone run & fail!!!

If I hardcode the parameters into the Sub ArchiveDataFiles it works
fine, but is not what I want as I intend to call it numerous times,
passing in various parameters.

Can anyone point me off with what I'm doing wrong! It must be me - I
can't beleive that a routine can't take variable/parameters!!!

Thanks in advance

Phil
================================================== ==============
Sub Main()

Call ArchiveDataFiles("C:\Test.txt", "C:\Test2", "csv")

End Sub


Sub ArchiveDataFiles (strFile As String, strDest As String, strExt As
String)
Dim strFileToCopy as String
Dim strDestination as String
Dim strFileTag as String

On Error Resume Next

strFileTag = "_" & Format(Date,"YYYYMMDD")
strFileToCopy = strFile
strDestination = strDest & strFileTag & "." & strExt

FileCopy strFileToCopy, strDestination

End Sub




Reply With Quote
  #4  
Old   
Georg Dewenter (Offline)
Junior Member
 
Posts: 1
Join Date: Aug 2006

Default Arguments for Main in Cognos Macros???? - 08-24-2006 , 10:39 AM



Hi Phil,
have you ever found a solution for your issue. I'm working on the same problem. Is there a way to handle additional arguments for the main routine?

Thanks for your answer

Georg Dewenter

gd@dewenter-consulting.de

Reply With Quote
  #5  
Old   
Phil Latio
 
Posts: n/a

Default Re: Cognos Impromptu Script Editor - problem with macro - 09-22-2006 , 03:38 AM



Hi Georg
Apologies for not replying sooner - I've only just read your post.

Anyhow, I did get my issue resolved and here's an example (code posted
below) of how I managed it...

I wanted to have a macro run and create a CSV file and write either a
success or failure into a log.
I found out through a Tek-Tips forum
(http://www.tek-tips.com/threadminder.cfm?pid=401)
that I need to declare the additional Sub procedures (and any
parameters they use) at the top of the macro.

Then it was a case of the Sub Main doing it's stuff and calling the
other Subs when required.
I recollect something about the order of Subs, where if Sub Main is at
the top and the remaining Subs are below it, it has an affect on the
Declares section - however I'm entirly sure about the accuracy of what
I've just stated !!

'==========CODE STARTS=====================================
Declare Sub fLogError(strMacro As String, strError As String, varError
as Variant)
Declare Sub fLogSuccess(strMacro As String)

Sub Main()

'Purpose:
'To open and export the Sales Order Lines data into a CSV file
'----------------
' Mod History
'----------------
' JH 22-8-06 - Added 2nd Trigger file to trigger PickTicket.xls
' JH 24-8-06 - Added 3rd Trigger file to trigger PickTicket_Top20.xls


On Error goto error_handler

Dim objImpApp As Object
Dim objImpRep As Object
Dim strTemplateFile, strTriggerFile, strTriggerFile2,
strTriggerFile3 as String

strTemplateFile =
"\\myServer\OSL_Reporting\Trigger_Files\template_t rigger"
strTriggerFile =
"\\myServer\OSL_Reporting\Trigger_Files\SalesOrder LinesDM.txt"
strTriggerFile2 =
"\\myServer\OSL_Reporting\Trigger_Files\SalesOrder LinesDM2.txt"
strTriggerFile3 =
"\\myServer\OSL_Reporting\Trigger_Files\SalesOrder LinesDM3.txt"

Set objImpApp = CreateObject("CognosImpromptu.Application")

objImpApp.OpenCatalog
"\\myServer\Cognos\Sysmanager\Catalog\stylemannew. cat", "User"

Set objImpRep =
objImpApp.OpenReport("\\myServer\Cognos\Sysmanager \Reports\salesorderlinesdm.imr")

objImpRep.Export
"\\myServer\OSL_Reporting\Source_Files\salesorderl inesdm.csv",
"x_ascii.flt"
objImpRep.Export
"\\myServer\OSL_Reporting\salesorderlinesdm.cs v", "x_ascii.flt"

objImpRep.CloseReport
objImpApp.ActiveCatalog.Close

FileCopy strTemplateFile, strTriggerFile
FileCopy strTemplateFile, strTriggerFile2
FileCopy strTemplateFile, strTriggerFile3

call fLogSuccess("mcrSalesOrderLinesDM.mac")

exit_routine:

Set objImpRep = Nothing
Set objImpApp = Nothing

exit sub

error_handler:
call fLogError("mcrSalesOrderLinesDM.mac", Error$, err)
goto exit_routine

End Sub

Sub fLogError(strMacro As String, strError As String, varError as
Variant)
Open "\\myServer\OSL_Reporting\Log_Files\MacroError.log " For Append
As #1
Print #1, strMacro, Now, varError, strError
Close #1
End Sub
Sub fLogSuccess(strMacro As String)
Open "\\myServer\OSL_Reporting\Log_Files\MacroSuccess.l og" For
Append As #1
Print #1, strMacro, Now
Close #1
End Sub
'==========CODE STARTS=====================================

Anyhow, I hope this helps and gives you something to go on with - you
may have even resolved this yourself by now

BTW - after reviewing the code, I can now see many areas of
improvement, but that's an exercise for another day! <g>

Best regards

Phil


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.