project QadFinancials > class BHistoryDaemonProcessor > method PerformWorkItem

Description

This is the method that contains the call to the specific method in the appropriate class to perform the request.
This method should be extended on the specific daemon level.
In order to have a proper logging of the errors/warnings you get from the business method that is used for processing the work, you need to fill in tPassMessages temp-table parameter, as a copy of tFcMessages from the called business component.


Parameters


iiDaemonQueueIdinputintegerID of the daemon queue record that indicates the work that needs to be done.
olSuccessoutputlogicalWas the operation successful?
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program/bhistorydaemonprocessor.p)

<ANCESTOR-CODE>
    
    
    /* ================== */
    /* Exception handling */
    /* ================== */
    assign olSuccess      = false
           oiReturnStatus = -98. 
                                   
    /* ================================================= */
    /* Find the QpostingLineID                           */
    /* ================================================= */
    <Q-12 run DaemonQueueByRefID (all) (Read) (NoCache)
       (input iiDaemonQueueId, (DaemonQueueID)
        input ?, (DaemonQueueRef)
        input '', (DaemonName)
        output dataset tqDaemonQueueByRefID) in BBaseDaemonQueue >
    find tqDaemonQueueByRefID where
         tqDaemonQueueByRefID.tiDaemonQueueId = iiDaemonQueueId
         no-lock no-error.
    if not available tqDaemonQueueByRefID
    then do:
        assign vcHistoryDaemonProcessorMsg = trim(#T-5'Daemon queue record not found.':100(262)T-5#) + chr(10) +
                                             trim(substitute('DaemonQueueID = &1.':U, trim(string(iiDaemonQueueId))))
               oiReturnStatus = -3.
        <M-2 run SetMessage (input  vcHistoryDaemonProcessorMsg (icMessage),
                         input  '':U (icArguments),
                         input  '':u (icFieldName),
                         input  string(iiDaemonQueueId) (icFieldValue),
                         input  'E':U (icType),
                         input  3 (iiSeverity),
                         input  '':U (icRowid),
                         input  'QADFIN-1423':U (icFcMsgNumber),
                         input  '' (icFcExplanation),
                         input  '' (icFcIdentification),
                         input  '' (icFcContext),
                         output viFcReturnSuper (oiReturnStatus)) in BHistoryDaemonProcessor>       
        return.                 
    end. /* if not available tqDaemonQueueByRefID */
    
    /* ============================================ */
    /* Check if the fcDaemonQueue is to process:    */
    /* - all the QPostingLines or                   */
    /* - a speciifc action or                       */
    /* - just about a single QPostingLine           */
    /* ============================================ */
    if tqDaemonQueueByRefID.tcDaemonQueueRef = {&DAEMONQUEUEREFERENCE-MULTIPLE}
    then do :    
        
        /* ====================================================================================================== */
        /* The fcDaemonQueue is to process all the QPostingLines: call a sub-method doing direct db-access        */
        /* ====================================================================================================== */
        <M-41 run PerformWorkItemXDIRECT
           (input  iiDaemonQueueID (iiDaemonQueueID), 
            output viDummy (oiNbrOfDeletedQPostingLine), 
            output viDummy (oiNbrOfDeletedQPostingSAF), 
            output viFcReturnSuper (oiReturnStatus)) in BHistoryDaemonProcessor>
        if viFcReturnSuper < 0
        then do:
            assign olSuccess      = false
                   oiReturnStatus = viFcReturnSuper.            
            return.
        end. /* if viFcReturnSuper < 0 */
        /* This is normally always successful */
        assign olSuccess = yes.
        
    end. /* if tqDaemonQueueByRefID.tcDaemonQueueRef = {&DAEMONQUEUEREFERENCE-MULTIPLE} */
    
    else do :
        
        if tqDaemonQueueByRefID.tcDaemonQueueRef = {&DAEMONQUEUEREFERENCE-SPECIFICACTION}
        then do :    
            
            /* ================================================================================================================================= */
            /* Call the empty sub-method PerformWorkItemSpecific that provides the NI-Customisations the possibility to execute specific actions */
            /* ================================================================================================================================= */    
            <M-85 run PerformWorkItemSpecific
               (input  iiDaemonQueueID (iiDaemonQueueID), 
                input  tqDaemonQueueByRefID.tcDaemonQueueRef (icDaemonQueueRef), 
                input  tqDaemonQueueByRefID.tcDaemonQueueRefDescription (icDaemonQueueRefDescription), 
                output olSuccess (olSuccess), 
                output viFcReturnSuper (oiReturnStatus)) in BHistoryDaemonProcessor>
            if viFcReturnSuper < 0
            then do:
                assign olSuccess      = false
                       oiReturnStatus = viFcReturnSuper.            
                return.
            end. /* if viFcReturnSuper < 0 */
            
        end. /* if tqDaemonQueueByRefID.tcDaemonQueueRef = {&DAEMONQUEUEREFERENCE-SPECIFICACTION} */
        
        else do :
        
            /* ================================================================ */
            /* The fcDaemonQueue is to process just about a single QPostingLine */
            /* ================================================================ */
            
            /* ============================================ */
            /* State the Company of the Daemon Queue record */
            /* ============================================ */
            assign vcCompanyIDForNewSession = trim(substring(tqDaemonQueueByRefID.tcDaemonQueueRefDescription, index(tqDaemonQueueByRefID.tcDaemonQueueRefDescription, '((':U) + 2,-1,"CHARACTER":U))      
                   viCompanyIDForNewSession = integer(substring(vcCompanyIDForNewSession, 1, length(vcCompanyIDForNewSession,"CHARACTER":U) - 2,"CHARACTER":U)) no-error.
            if viCompanyIDForNewSession = 0 or 
               viCompanyIDForNewSession = ? or
               error-status:error 
            then do :
                assign vcHistoryDaemonProcessorMsg = trim(#T-6'Internal History daemon error: cannot state the entity based on the queue information':100(56542)t-6#) + chr(10) +
                                                     trim(substitute("Queue-information = &1.":U, trim(tqDaemonQueueByRefID.tcDaemonQueueRefDescription))) + chr(10) + 
                                                     trim(substitute("Company = &1.":U, string(viCompanyIDForNewSession))) + chr(10) + 
                                                     trim(substitute("Error-details = &1.":U, trim(ERROR-STATUS:GET-MESSAGE(1))))                
                       oiReturnStatus              = -3.
                <M-4 run SetMessage (input  vcHistoryDaemonProcessorMsg (icMessage),
                                 input  '':U (icArguments),
                                 input  '':u (icFieldName),
                                 input  string(iiDaemonQueueId) (icFieldValue),
                                 input  'E':U (icType),
                                 input  3 (iiSeverity),
                                 input  '':U (icRowid),
                                 input  'QADFIN-2840':U (icFcMsgNumber),
                                 input  '' (icFcExplanation),
                                 input  '' (icFcIdentification),
                                 input  '' (icFcContext),
                                 output viFcReturnSuper (oiReturnStatus)) in BHistoryDaemonProcessor>       
                return.            
            end. /* if viCompanyIDForNewSession = 0 or  */
            
            /* ================================================================== */
            /* As the input fot method ApiProcessQPostingLineSaf is a temp-table, */
            /* we have to create a single record in this table                    */
            /* ================================================================== */
            empty temp-table tQPostingLineToProcessFromDmn.
            create tQPostingLineToProcessFromDmn.
            assign tQPostingLineToProcessFromDmn.tiQPostingLineID = integer(tqDaemonQueueByRefID.tcDaemonQueueRef) no-error.
            if tQPostingLineToProcessFromDmn.tiQPostingLineID = 0 or 
               tQPostingLineToProcessFromDmn.tiQPostingLineID = ? or
               error-status:error 
            then do :
                assign vcHistoryDaemonProcessorMsg = trim(#T-8'Internal History daemon error: cannot state the QPostingLine ID based on the queue information':249(56543)t-8#) + chr(10) +
                                                     trim(substitute("Queue-information = &1.":U, trim(tqDaemonQueueByRefID.tcDaemonQueueRef))) + chr(10) + 
                                                     trim(substitute("Error-details = &1.":U, trim(ERROR-STATUS:GET-MESSAGE(1))))                
                       oiReturnStatus              = -3.
                <M-7 run SetMessage (input  vcHistoryDaemonProcessorMsg (icMessage),
                                 input  '':U (icArguments),
                                 input  '':u (icFieldName),
                                 input  string(iiDaemonQueueId) (icFieldValue),
                                 input  'E':U (icType),
                                 input  3 (iiSeverity),
                                 input  '':U (icRowid),
                                 input  'QadFin-5738':U (icFcMsgNumber),
                                 input  '' (icFcExplanation),
                                 input  '' (icFcIdentification),
                                 input  '' (icFcContext),
                                 output viFcReturnSuper (oiReturnStatus)) in BHistoryDaemonProcessor>       
                return.            
            end. /* if error-status:error */
            
            /* ============================ */
            /* Process Daemon Queue record */
            /* ============================ */
            <M-55 run SwitchSessionCy
               (input  '' (icCompanyCode), 
                input  viCompanyIDForNewSession (iiCompanyId), 
                output viFcReturnSuper (oiReturnStatus)) in BHistoryDaemonProcessor>
            if viFcReturnSuper < 0
            then do:
                assign olSuccess = false
                       oiReturnStatus = viFcReturnSuper.            
                return.
            end. /* if viFcReturnSuper < 0 */
            <M-34 run api/bqposting/apiprocessqpostinglinesaf.p
               (input  '' (icApiLogin), 
                input  '' (icApiPassword), 
                input  '' (icApiExtra), 
                input  viSessionID (iiApiSessionId), 
                input  dataset tQPostingLineToProcessFromDmn (tQPostingLineToProcess), 
                input  true (ilClearData), 
                input  -1 /* already set in the session viExternalDebugLevel, */ (iiExternalDebugLevel), 
                input  ?  /* already set in the session vcExternalDebugDirectory, */ (icExternalDebugDirectory), 
                output dataset tFcMessages (ozFcMessagesDS), 
                output viFcReturnSuper (oiReturnStatus))>
            if viFcReturnSuper < 0
            then assign olSuccess = false.
            else assign olSuccess = true.
        
        end. /* Not if tqDaemonQueueByRefID.tcDaemonQueueRef = {&DAEMONQUEUEREFERENCE-SPECIFICACTION} */
                
    end. /* Not if tqDaemonQueueByRefID.tcDaemonQueueRef = {&DAEMONQUEUEREFERENCE-MULTIPLE} */ 
    
    /* ================== */
    /* Exception handling */
    /* ================== */
    assign oiReturnStatus = 0.