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