edited as per ray's suggestion:
<CODE>
$INCLUDE DSINCLUDE DSD_STAGE.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$INCLUDE DSINCLUDE DSD.H
$INCLUDE DSINCLUDE DSD_RTSTATUS.H
Deffun DSRMessage(A1, A2, A3) Calling "*DataStage*DSR_MESSAGE"
Equate RoutineName To "JobLogMail"
* Passing JobName for which log is to be seen
Call DSLogInfo("Job Name is ":JobName, RoutineName)
* Creating a Job Handle fot that particular job
JobHandle=DSAttachJob(JobName,DSJ.ERRNONE)
* Get The Start Time of job
StartTime=DSGetJobInfo(JobHandle,DSJ.JOBSTARTTIMESTAMP)
Call DSLogInfo("Start Time of job is ":StartTime, RoutineName)
* Get The End Time of job run
EndTime=DSGetJobInfo(JobHandle,DSJ.JOBLASTTIMESTAMP)
Call DSLogInfo("Start Time of job is ":EndTime, RoutineName)
*Get the job log for the run between start and end times.
SummaryArray = DSGetLogSummary(JobHandle, DSJ.LOGANY, StartTime, EndTime,0)
* -----------------------------------------------------------------
* Decription: Get last warning.
* -----------------------------------------------------------------
* 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 RT.LOG else goto TheEnd
* -----------------------------------------------------------------
Cmd = 'SSELECT ':FileName :' UNLIKE "//..." BY-DSND @ID '
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, ' '))
EventMsg = lower(EventMsg)
* -----------------------------------------------------------------
if EventType = 'Warning' then
print 'RtLogId=':RtLogId
for i=1 to NoOfLines
print i 'R#5':'. ':EventMsgSave<1, i>
next i
print
print
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 i=1 to NoOfLines
ThisLine = trim(MsgLine)
NoWords = dcount(ThisLine, ' ')
ColumnName = trim(field(ThisLine, ' ', NoWords))
NextLine = trim(MsgLine<i+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 i
Ans = ColumnNames
Ans<2> = Values
Ans<3> = ValLens
goto TheEnd
end
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
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
* -----------------------------------------------------------------
TheEnd:
CLEARSELECT ALL
for MvNo=1 to Cnt
print MvNo 'R#5':'. ':Ans<1, MvNo>:'(':Ans<3, MvNo>:') = ':Ans<2, MvNo>
next MvNo
* -----------------------------------------------------------------
Reply = DSSendMail("From: <sender mail id>\nTo:
xxxx.xxxx@xx.com, \nSubject:"<subject>":JobName:"\nBody:":JobLogs)
Begin Case
Case Reply = DSJE.NOERROR
GoTo SuccessExit
Case @True
GoTo ErrorExit
End Case
SuccessExit:
ErrorCode = 0
GoTo NormalExit
ErrorExit:
ErrorCode = 1
GoTo NormalExit
NormalExit:
<CODE>