project BLF > class BReportRequest > method AdditionalUpdates
Description
This method is part of the SetPublicTables flow.
When executed, data in the input class tables (prefix t_s) is validated and found correct, and copied into the class tables (prefix t_o).
This method can be extended to do updates that do not require a validation or that involve running business methods of other business classes. These classes should be started with ADD-TO-TRANSACTION = 'true'. Also make sure to add these classes in method StopExternalInstances.
Parameters
oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/breportrequest.p)
<ANCESTOR-CODE>
if viTimeOffset = ?
then viUseTimeOffset = timezone(now).
else viUseTimeOffset = viTimeOffset.
/* ================================================================= */
/* If this is a report schedule, the date and time is mandatory. */
/* ================================================================= */
for each t_sReportSchedule where
t_sReportSchedule.ttScheduleStartDate = ? on error undo, throw:
assign t_sReportSchedule.ttScheduleStartDate = today
t_sReportSchedule.tiScheduleStartTime = time.
end.
for each bRequest where
bRequest.ttRequestRequiredStartDate = ?,
each t_sReportSchedule where
t_sReportSchedule.tc_Rowid = bRequest.tc_Rowid on error undo, throw:
assign bRequest.ttRequestRequiredStartDate = t_sReportSchedule.ttScheduleStartDate
bRequest.tiRequestRequiredStartTime = t_sReportSchedule.tiScheduleStartTime.
end.
/* ================================================================= */
/* Create a Schedule */
/* ================================================================= */
for each bRequest where bRequest.tc_Status = "N",
each t_sReportSchedule where t_sReportSchedule.tc_Rowid = bRequest.tc_Rowid on error undo, throw:
if not vlSchedule
then do:
<I-23 {bFcAddToTransaction
&CLASS = "BReportSchedule"}>
vlSchedule = yes.
end.
<M-9 run CreateSchedule
(input t_sReportSchedule.tcScheduleName (icName),
input t_sReportSchedule.tcScheduleDescription (icDescription),
input t_sReportSchedule.ttScheduleStartDate (itStartDate),
input t_sReportSchedule.tiScheduleStartTime (iiStartTime),
input t_sReportSchedule.tiScheduleNumIterations (iiNumIterations),
input t_sReportSchedule.tcScheduleFrequency (icFrequency),
output bRequest.RptRequestSchedule_ID (oiScheduleID),
output viFcReturnSuper (oiReturnStatus)) in BReportSchedule>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-10 {bFcCloseAndStopInstance
&CLASS = "BReportSchedule"}>
return.
end.
assign bRequest.RptRequestDescription = #T-22'Scheduled Report (&1) (&2)':50(9233)T-22#.
do viteration = 1 to (t_sReportSchedule.tiScheduleNumIterations - 1):
<M-11 run AddDetailLine
(input 'RptRequest' (icTable),
input '' (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BReportRequest>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-12 {bFcCloseAndStopInstance
&CLASS = "BReportSchedule"}>
return.
end.
/* should be available */
if not available tRptRequest
then find tRptRequest where tRptRequest.tc_Rowid = vcLastCreatedRowid.
buffer-copy bRequest except RptRequest_ID RptRequestDescription tc_Rowid tc_ParentRowid tc_Status to tRptRequest.
assign tRptRequest.RptRequestDescription = substitute(bRequest.RptRequestDescription,
string(viteration + 1),
t_sReportSchedule.tcScheduleName).
case t_sReportSchedule.tcScheduleFrequency:
when {&SCHEDULEPERIODTYPE-DAILY}
then tRptRequest.ttRequestRequiredStartDate = bRequest.ttRequestRequiredStartDate + viteration.
when {&SCHEDULEPERIODTYPE-WEEKLY}
then tRptRequest.ttRequestRequiredStartDate = bRequest.ttRequestRequiredStartDate + (viteration * 7).
when {&SCHEDULEPERIODTYPE-MONTHLY}
then tRptRequest.ttRequestRequiredStartDate = add-interval (bRequest.ttRequestRequiredStartDate, viteration, "months").
when {&SCHEDULEPERIODTYPE-YEARLY}
then tRptRequest.ttRequestRequiredStartDate = date (month(bRequest.ttRequestRequiredStartDate),
day(bRequest.ttRequestRequiredStartDate),
year(bRequest.ttRequestRequiredStartDate) + viteration) no-error.
end case.
for each bRequestCBF where
bRequestCBF.tc_ParentRowid = bRequest.tc_Rowid on error undo, throw:
<M-14 run AddDetailLine
(input 'RptRequestCBF' (icTable),
input tRptRequest.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BReportRequest>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-15 {bFcCloseAndStopInstance
&CLASS = "BReportSchedule"}>
return.
end.
/* should be available */
if not available tRptRequestCBF
then find tRptRequestCBF where tRptRequestCBF.tc_Rowid = vcLastCreatedRowid.
buffer-copy bRequestCBF except RptRequestCBF_ID RptRequest_ID tc_Rowid tc_ParentRowid tc_Status to tRptRequestCBF
assign tRptRequestCBF.RptRequest_ID = tRptRequest.RptRequest_ID.
end.
for each bRequestFilter where
bRequestFilter.tc_ParentRowid = bRequest.tc_Rowid on error undo, throw:
<M-16 run AddDetailLine
(input 'RptRequestFilter' (icTable),
input tRptRequest.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BReportRequest>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-17 {bFcCloseAndStopInstance
&CLASS = "BReportSchedule"}>
return.
end.
/* should be available */
if not available tRptRequestFilter
then find tRptRequestFilter where tRptRequestFilter.tc_Rowid = vcLastCreatedRowid.
buffer-copy bRequestFilter except RptRequestFilter_ID RptRequest_ID tc_Rowid tc_ParentRowid tc_Status to tRptRequestFilter
assign tRptRequestFilter.RptRequest_ID = tRptRequest.RptRequest_ID.
end.
for each bRequestMail where
bRequestMail.tc_ParentRowid = bRequest.tc_Rowid on error undo, throw:
<M-18 run AddDetailLine
(input 'RptRequestMail' (icTable),
input tRptRequest.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BReportRequest>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-19 {bFcCloseAndStopInstance
&CLASS = "BReportSchedule"}>
return.
end.
/* should be available */
if not available tRptRequestMail
then find tRptRequestMail where tRptRequestMail.tc_Rowid = vcLastCreatedRowid.
buffer-copy bRequestMail except RptRequestMail_ID RptRequest_ID tc_Rowid tc_ParentRowid tc_Status to tRptRequestMail
assign tRptRequestMail.RptRequest_ID = tRptRequest.RptRequest_ID.
end.
for each bRequestContext where
bRequestContext.tc_ParentRowid = bRequest.tc_Rowid on error undo, throw:
<M-20 run AddDetailLine
(input 'RptRequestContext' (icTable),
input tRptRequest.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BReportRequest>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-21 {bFcCloseAndStopInstance
&CLASS = "BReportSchedule"}>
return.
end.
/* should be available */
if not available tRptRequestContext
then find tRptRequestContext where tRptRequestContext.tc_Rowid = vcLastCreatedRowid.
buffer-copy bRequestContext except RptRequestContext_ID RptRequest_ID tc_Rowid tc_ParentRowid tc_Status to tRptRequestContext
assign tRptRequestContext.RptRequest_ID = tRptRequest.RptRequest_ID.
end.
end.
assign bRequest.RptRequestDescription = substitute(bRequest.RptRequestDescription,
"1",t_sReportSchedule.tcScheduleName).
end.
if vlSchedule
then do:
<M-24 run ValidateBCAndAdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BReportSchedule>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-25 {bFcCloseAndStopInstance
&CLASS = "BReportSchedule"}>
return.
end.
<I-13 {bFcCloseInstance
&CLASS = "BReportSchedule"}>
end.
/* ================================================================= */
/* Report requests to the report daemon. */
/* ================================================================= */
if can-find (first tRptRequest where tRptRequest.tc_Status <> "D")
then do:
if viBReportDaemonQueueID = 0
then do:
<I-1 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BReportDaemonQueue"}>
end.
else do:
<I-2 {bFcOpenInstance
&CLASS = "BReportDaemonQueue"}>
<M-3 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BReportDaemonQueue>
end.
for each tRptRequest where tRptRequest.tc_Status <> "D" on error undo, throw:
assign vtStartDateUTC = tRptRequest.ttRequestRequiredStartDate
viStartTimeUTC = tRptRequest.tiRequestRequiredStartTime - viUseTimeOffset * 60.
if viStartTimeUTC < 0
then assign vtStartDateUTC = vtStartDateUTC - 1
viStartTimeUTC = viStartTimeUTC + 24 * 60 * 60.
<M-4 run UpdateQueue
(input tRptRequest.RptRequest_ID (iiRequestID),
input vtStartDateUTC (itStartDate),
input viStartTimeUTC (iiStartTime),
input tRptRequest.RptRequestDescription (icDescription),
output viFcReturnSuper (oiReturnStatus)) in BReportDaemonQueue>
if viFcReturnSuper <> 0
then oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
<I-5 {bFcCloseAndStopInstance
&CLASS = "BReportDaemonQueue"}>
return.
end.
end.
<I-6 {bFcCloseInstance
&CLASS = "BReportDaemonQueue"}>
end.