Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error running an Impromptu macro 1

Status
Not open for further replies.

sfitz454

Programmer
Mar 18, 2002
3
US
I have included the macro code that I am having a problem running. The macro creates a comma delimited CSV file that is used as the input for an Impromptu report that passes in 2 prompt values. The CSV file is read until the end of the file is reached and a separate PDF file is created for every code that is read in. However, when I step through the macro in debug mode it completes successfully by creating a PDF files for each input record, but when the macro is executed in run mode the following error message is generated: "Visual C++ runtime error program: c:\progra~1\Cognos\cer1\bin\ImpAdmin.exe abnormal program termination."

Thanks in advance for any help that is provided.

MACRO CODE:

Sub Main()

' ***** Declare Objects *****
Dim ImpAppObj as Object
Dim ImpRepObj as Object
Dim objPDFPub as Object

' ***** Declare variables *****
Dim RowCnt as Integer
Dim EmailName as String
Dim EmailCo as String
Dim EmailTrdSqN as String
Dim cad_string as String
Dim cad_code as String
Dim seq_num as String
Dim ConfirmPrompt as String

' ***** Assigns Variables *****
ImpAppStr = "CognosImpromptu.Application"
AtomCat = "C:\ATOM\Impromptu\Catalogs\ATOMTEST.CAT"
UserClassId = "User"
UserClassPW = " "
DatabaseID = "SOMEID"
DatabasePW = "SOMEPW"
ConfirmRpt = "C:\ATOM\PromptEMReport_gdcp.imr "
ConfirmCdsRpt = "C:\ATOM\CfmTrdCds.imr"
RptOutputDir = "C:\ATOM\"
EmailOutputDir = "C:\ATOM"
ErrorLogFile = "C:\ATOM\Error.log"
RowCnt = 1

On Error Goto LogError
set ImpAppObj = CreateObject(ImpAppStr)
ImpAppObj.OpenCatalog AtomCat, UserClassId, UserClassPW, DatabaseID, DatabasePW

' ***** CREATES THE COMMA DELIMITED FILE FOR INPUT *****
set ImpRepObj = ImpAppObj.OpenReport(ConfirmCdsRpt)
ImpRepObj.RetrieveAll
ImpRepObj.ExportASCII RptOutputDir & "CfmTrdCds.csv"
ImpRepObj.CloseReport
set ImpRepObj = Nothing

' ***** OPEN OUTPUT FILE FOR READING IN CONFIRM ADDRESS CODES *****
Open "C:\ATOM\CfmTrdCds.csv" For Input Access Read As #1
Line Input #1, cad_string
Do While Not EOF(1)
Line Input #1, cad_string
cad_code = GetField(cad_string, 1, ",")
seq_num = GetField(cad_string, 2, ",")
ConfirmPrompt = cad_code & "|" & seq_num
set ImpRepObj = ImpAppObj.OpenReport(ConfirmRpt, ConfirmPrompt)
set ImpRepObj = ImpAppObj.ActiveDocument
ImpRepObj.RetrieveAll
set objPDFPub = ImpRepObj.PublishPDF
EmailName = ImpRepObj.GetDataValue(17,RowCnt)
EmailCo = ImpRepObj.GetDataValue(18,RowCnt)
EmailTrdSqN = ImpRepObj.GetDataValue(19,RowCnt)
objPDFPub.Publish EmailOutputDir & Rtrim(EmailName) & EmailCo & "_" & EmailTrdSqN & ".pdf"
ImpRepObj.CloseReport
set ImpRepObj = Nothing
Loop
Close #1

ImpAppObj.CloseCatalog
ImpAppObj.Quit
Goto EndMacro

LogError:
filenumber = FreeFile
Open ErrorLogFile For Output As filenumber
ErrStr = "EMAILCONFIRM.mac error: " & Err & " occured at line: " & Erl
Print #filenumber, ErrStr
Close #filenumber
Exit Sub


EndMacro:
End Sub
 
sfitz,

Whenever I have this kind of error (executes fine while stepping through code, but errors out when running compiled) I usually start by putting in a timer loop between the primary execution steps, especially those that involve file I/O. I've had problems in the past where an operation wants exclusive use of a file, and the OS reports it still in use by the previous step. It doesn't happen often, but when it does a timer loop can usually free up the process to run without errors. You lose some execution performance, but at least you're back up and running. I don't see obvious potential for this type of problem here, but this can be a tricky problem to find.

I'd start with adding a delay to the end of the loop. If that doesn't help, move to another location in the process. Ultimately you should not need more than one. Let me know if you need any help with the loop. It helps if it is processor independent. Otherwise faster machines may force you to increase the delay factor.

HTH,

Dave Grifin
The Decision Support Group
Reporting Consulting with Cognos BI Tools
"Magic with Data"
[pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top