Page 1 of 1

Routine for writing Log to Sequential file

Posted: Thu Jun 02, 2005 2:30 am
by Prashantoncyber
I ran the below routine which writes logs to Sequential somewhere picked up from this forum.

But it is just writing very fews logs instead of whole logs.

Pls guide what changes are required in this routine to get whole log written to sequential file.

Thanks
Prashant


$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

StartDate = DSGetJobInfo (DSJ.ME, DSJ.JOBSTARTTIMESTAMP)
SummaryArray = DSGetLogSummary (DSJ.ME,DSJ.LOGINFO,StartDate,"9999-12-31", 0)
Answer=""
NLines=0
Loop
Str = Field(SummaryArray,@FM,NLines+1)
If Str<>"" Then
NLines=NLines+1
EventId=Field(Str,"\",1)
TimeStamp=Field(Str,"\",2)
EventMessage=Field(Str,"\",6)
Answer<-1>=EventId:" ":TimeStamp:" ":EventMessage
End
Until Str=""
Repeat

Answer=OConv(Answer,"MCP")
Loop
I= Index(Answer,"'",1)
If I>0 Then Answer=Answer[1,I-1]:Answer[I+1,Len(Answer)]
Until I=0
Repeat

x=Answer
ValidOpen = @FALSE
filename = "/ascl/dsadm/Ascential/DataStage/Projects/LETS/LogToSequentialFile_PA.txt"
OPENSEQ filename TO FILE Then
ValidOpen = @TRUE
End Else
CREATE FILE Then ValidOpen = @TRUE
End
If NOT(ValidOpen) Then
Call DSLogFatal("Could not create the file: ":filename, "OutputFile")
End

AM.CNT = DCOUNT(x, @AM)
For i=1 to AM.CNT
WRITESEQ x TO FILE else
Call DSLogFatal("Could not update the file: ":filename, "OutputFile")
End
Next i
WEOFSEQ FILE
ErrorCode = 0 ;* set this to non-zero to stop the stage/job

Ans =1


ErrorCode = 0 ;* set this to non-zero to stop the stage/job

Posted: Thu Jun 02, 2005 2:54 am
by ArndW
Please lookup up the documentation on the DSGetLogSummary routine - especially the description of the third parameter. Then compare that with the output of your DSGetJobInfo() call.

Posted: Thu Jun 02, 2005 5:22 am
by ray.wurlod
EventMessage is wrong. The message begins in field number 4, and may include backslashes.

You want something like

Code: Select all

Field(Str, "\", 4, 999)
Str was a poor choice of variable name, since it is also the name of an intrinsic function.

Your code is horribly cumbersome. You process the log information twice. Further, you're reading the log from a job that is still running; you will never get the "job finished" event.

Presumably the middle loop is intended to remove double quote characters. You could more easily have used:

Code: Select all

Answer = Convert('"', '', Answer)
to achieve this end.