Last Error

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

sonia jacob
Participant
Posts: 122
Joined: Mon Jul 05, 2004 1:33 pm
Location: MA

Post by sonia jacob »

Here is the first version of the routine that would get the latest log details for a specific job, and write the log desc. for any warning / fatal errors onto a sequential file (logfile.txt)

The main changes that were done to Kim's KgdGetLastWarning(JobName) are made bold. And once again thanks to Kim for helping me with them.

The WriteLogFile routine is a simple "Write to File" routine. That open a file / creates a file and Writes to the File.

Now as a next step I would like to read all the job names of a sequence and then create a log file for each sequence.

There are couple of things in the routine which I am unlcear about, But I have left it as the same. eg. 1) Search for the string 'The value of the row is:'
2) The following control break.
if TextSw then
..........................
..........................
..........................
..........................
end
DEFFUN WriteLogFile(Data, FilePath) Calling "DSU.WriteLogFile"
* -----------------------------------------------------------------
* KgdGetLastWarning(JobName)
* Decription: Get last warning.
* Written by: Kim Duke
* Modified By: Sonia Jacob
* -----------------------------------------------------------------
* Notes:
* -----------------------------------------------------------------
Ans = ''
* -----------------------------------------------------------------
* initialize standard variables
* -----------------------------------------------------------------
ProgId = 'KgdGetLastWarning'
CrLf = char(13) : char(10)
SearchStr = 'The value of the row is:'
LenSearchStr = len(SearchStr)
JobLogs = ''
ColumnNames = ''
Values = ''
ValLens = ''
open 'DS_JOBS' to DsJobsPtr else goto TheEnd
TextSw = @false
* -----------------------------------------------------------------
open 'DICT','RT_LOG' to DictRtLog then
read FullText from DictRtLog, "FULL.TEXT" then
TextSw = @true
end
end
RealJobName = JobName
if index(RealJobName, '.', 1)>0 then
RealJobName = field(JobName, '.', 1)
end
* -----------------------------------------------------------------
read JobRec from DsJobsPtr, RealJobName then
JobNo = JobRec<5>
FileName = 'RT_LOG':JobNo
* -----------------------------------------------------------------
open FileName to RtLog else
goto TheEnd
end
read RtLogJobStart from RtLog, '//JOB.STARTED.NO' else
RtLogRec = 0
end
JobStartNo = RtLogJobStart<1,1>
* -----------------------------------------------------------------

* -----------------------------------------------------------------
open FileName to RT.LOG else goto TheEnd
* -----------------------------------------------------------------
DblQuote = '"'
EventNo = JobStartNo
Cmd = 'SSELECT ' : FileName : ' WITH @ID >= ' : EventNo : ' BY TIMESTAMP'
if RealJobName <> JobName then
Cmd := ' AND WITH F5 LIKE ':JobName:'...'
end
execute Cmd capturing Output

Cnt = 0
* -----------------------------------------------------------------
loop while readnext RtLogId do
read RtLogRec from RT.LOG, RtLogId then
tmp = RtLogRec
TypeNo = RtLogRec<1>
EventTime = RtLogRec<3>
EventUser = RtLogRec<6>
EventType = 'Control'
* -----------------------------------------------------------------
begin case
case TypeNo = 1
EventType = 'Info'
case TypeNo = 2
EventType = 'Warning'
case TypeNo = 3
EventType = 'Fatal'
case TypeNo = 4
EventType = 'Reject'
case TypeNo = 5
EventType = 'Control'
case TypeNo = 6
EventType = 'Reset'
case TypeNo = 7
EventType = 'Error'
case TypeNo = 8
EventType = 'Debug'
end case
* -----------------------------------------------------------------
if TextSw then
@ID = fmt(RtLogId, "10'0'R")
@RECORD = RtLogRec
@RECCOUNT = 1
MSG.ARGS = RtLogRec<5>
MSG.TEXT = RtLogRec<10>
EventMsg = SUBR("*DataStage*DSR_MESSAGE", @ID, MSG.TEXT, RAISE(MSG.ARGS))
end else
EventMsg = lower(RtLogRec<10>)
EventMsg = change(EventMsg, '%s', JobName)
EventMsg = change(EventMsg, '%1', JobName)
end
EventMsg = change(EventMsg, char(13), '')
EventMsg = change(EventMsg, char(10), @VM)
NoOfLines = dcount(EventMsg, @VM)
EventMsgSave = EventMsg
EventMsg = trim(change(EventMsg, @VM, ' '))
* -----------------------------------------------------------------
if (EventType = 'Warning' or EventType = 'Fatal' or EventType = 'Error') then
Found = index(EventMsg, SearchStr, 1)
if Found > 0 then
MsgLine = trim(EventMsg[Found + LenSearchStr, len(EventMsg) - Found - LenSearchStr + 1])
convert '=' to @FM in MsgLine
NoOfLines = dcount(MsgLine, @FM)
for j=1 to NoOfLines
ThisLine = trim(MsgLine<j>)
NoWords = dcount(ThisLine, ' ')
ColumnName = trim(field(ThisLine, ' ', NoWords))
NextLine = trim(MsgLine<j+1>)
NoWordsNext = dcount(NextLine, ' ')
Value = field(NextLine, ' ', 1, NoWordsNext-1)
Cnt += 1
ColumnNames<1, Cnt> = ColumnName
Values<1, Cnt> = Value
ValLens<1, Cnt> = len(Value)
next j
Ans = ColumnNames
Ans<2> = Values
Ans<3> = ValLens
goto TheEnd
end
* -----------------------------------------------------------------
tmp2 = ''
tmp2<1, 1> = RtLogId
tmp2<1, 2> = EventType
tmp2<1, 3> = EventTime
tmp2<1, 4> = EventUser
tmp2<1, 5> = EventMsg
* -----------------------------------------------------------------
JobLogs = tmp2 : @FM : JobLogs
* if Cnt >= 100 then goto TheEnd
end
end
repeat
end
* -----------------------------------------------------------------
NoOfLogs = dcount(JobLogs, @FM)
if trim(JobLogs<NoOfLogs, 1>) = '' then
del JobLogs<NoOfLogs, 1>
if trim(JobLogs<NoOfLogs-1, 1>) = '' then
del JobLogs<NoOfLogs-1, 1>
end
end
if trim(JobLogs<1, 1>) = '' then
del JobLogs<1, 1>
end

* -----------------------------------------------------------------
Ans = WriteLogFile(change(change(JobLogs,@FM,char(13):char(10)),@VM,' : '), FilePath:'\LogFile.txt')
* -----------------------------------------------------------------
* -----------------------------------------------------------------
TheEnd:
CLEARSELECT ALL
for MvNo=1 to Cnt
print MvNo 'R#5':'. ':Ans<1, MvNo>:'(':Ans<3, MvNo>:') = ':Ans<2, MvNo>
next MvNo
* print JobLogs
* return
Regards
Sonia Jacob
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

The whole section starting with

Code: Select all

if (EventType = 'Warning' or EventType = 'Fatal' or EventType = 'Error') then
is not needed. I used this to pull out the column names on a metadata mismatch error. I do not use this routine in any production jobs. I use it for debuging purposes.

The same is true for TextSw. The routine "*DataStage*DSR_MESSAGE" is a DataStage supplied routine. They take place holders in the actual text and replace them with the job name. Like %s and %1 are both placeholders for job name. I am not sure this routine will work without @RECORD and the @ID lines that you removed. You will need to look at the results. I am pretty sure that is why I added them.

I gave these routines out as examples and not complete solutions. It appears a lot of people have tried to use this routine to archive logs. Maybe I need to post a more complete solution.

When you post your code then use the Code button and not the Quote button. It works better.
Mamu Kim
Post Reply