project QadFinancials > class BDebtorMassChange > method OwnBankNumberChange


Parameters


oiNumberOfProcessedRecordsoutputinteger
oiNumberOfErrorRecordsoutputinteger
olIsEndOfFileoutputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program6/bdebtormasschange.p)

/* =================================================================================================== */
/* Method      : SaveAndProcess                                                                        */
/* Desc        : This method performs processing of the imported line records, first of all it updates */
/*               records based on the changes on the UI and if required also processing of the records */
/*               is done.                                                                              */
/*               All data for processing has be already passed to BL by method SaveAndProcessInit      */
/*               This method passes to UI number of processed records                                  */
/*               Processing of the imported records is done in separate transactions. One processed    */
/*               record is one transactions                                                            */
/* --------------------------------------------------------------------------------------------------- */
/* Params:  (O) ProcessRecordsNumber  Number of the processed records in current batch                 */
/*          (O) ErrorRecordsNumber    Number of the records with errors                                */
/*          (O) IsEndOfFile           Flag indicating, whether all records has been processed          */
/* =================================================================================================== */

assign oiReturnStatus = -98.

/* =================================================================================================== */
/* Default output values                                                                               */
/* =================================================================================================== */
assign oiNumberOfProcessedRecords = 0
       oiNumberOfErrorRecords     = 0
       olIsEndOfFile              = false.

/* =================================================================================================== */
/* System does execution in about 15sec blocks                                                         */
/* =================================================================================================== */
assign viStartTime = time.

MAIN_BLOCK:
do while true:
    /* =============================================================================================== */
    /* Get next record to be processed                                                                 */
    /* =============================================================================================== */
    find first tOwnBankNumberChange where
               tOwnBankNumberChange.tlIsProcessed = false no-error.
    if not available tOwnBankNumberChange
    then do:
        assign olIsEndOfFile  = true
               oiReturnStatus = 0.
        return.
    end.

 /*   /* =============================================================================================== */
    /* Sometimes, one action can be splitted to two separate actions, depending on processing flags    */
    /* =============================================================================================== */
    <M-? run TranslateAction
       (input  tBankImpLineProcRef.BankImpLineAction (icActionCode), 
        output vcTransactionActionList (ocActionsCodesToExecute), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLineProcess>    
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper <  0 then return. */

    /* =================================================================================================== */
    /* Execute one action by one                                                                           */
    /* =================================================================================================== */
/*    do viIndex = 1 to num-entries(vcTransactionActionList):

        assign vcTransactionAction    = entry(viIndex, vcTransactionActionList)
               viSaveProcReturnStatus = 0.

        /* =================================================================================================== */
        /* Create transaction for One record                                                                   */
        /* =================================================================================================== */
        <I-? {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION = "false"
             &CLASS              = "Transaction"}>
             
        <M-? run StartTransaction  (output viFcReturnSuper (oiReturnStatus)) in Transaction>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 then leave MAIN_BLOCK.
    
        <I-? {bFcCloseInstance
             &CLASS           = "Transaction"}>
             
        /* =============================================================================================== */
        /* Start instance                                                                                  */
        /* =============================================================================================== */
        <I-? {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION = "true"
             &CLASS              = "BBankImportLine"}>
             
        /* =============================================================================================== */
        /* Backup all system errors                                                                        */
        /* =============================================================================================== */
        empty temp-table tFcMessagesProcBackup.
        for each tFcMessages:
            create tFcMessagesProcBackup.
            buffer-copy tFcMessages to tFcMessagesProcBackup.
        end.
        empty temp-table tFcMessages.
        
        /* =============================================================================================== */
        /* Save and process current record                                                                 */
        /* =============================================================================================== */
        empty temp-table tBankImpLineCurrRef.
        empty temp-table tBankImpLineLogCurrRef.
    
        create tBankImpLineCurrRef.
        buffer-copy tBankImpLineProcRef to tBankImpLineCurrRef.
        for each tBankImpLineLogProcRef where
                 tBankImpLineLogProcRef.tc_ParentRowid = tBankImpLineCurrRef.tc_Rowid:
            create tBankImpLineLogCurrRef.
            buffer-copy tBankImpLineLogProcRef to tBankImpLineLogCurrRef.
            delete tBankImpLineLogProcRef.
         end.
    
         <M-? run SaveAndProcess
            (input-output tBankImpLineCurrRef (tBankImpLineRef), 
             input-output tBankImpLineLogCurrRef (tBankImpLineLogRef), 
             input  vcTransactionAction (icTransactionAction), 
             input  vcSubmitAction (icSubmitAction), 
             input  vlIsCreateNewDocInPaid (ilIsCreateNewDocInPaid), 
             input  vlIsCreateBankEntryForPaid (ilIsCreateBankEntryForPaid), 
             input  vlIsAllocateOtherEntity (ilIsAllocateOtherEntity), 
             output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

         /* If there was critical error, just stop */
         if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
         if viFcReturnSuper <  0 then leave MAIN_BLOCK.
         
         /* Copy all data from temporary table used for communication with BBankImportLine to main one */
         find first tBankImpLineCurrRef no-error.
         if available tBankImpLineCurrRef
         then do:
            buffer-copy tBankImpLineCurrRef to tBankImpLineProcRef.
            
            for each tBankImpLineLogCurrRef where
                     tBankImpLineLogCurrRef.tc_ParentRowid = tBankImpLineCurrRef.tc_Rowid:
                create tBankImpLineLogProcRef.
                /* add this part otherwise the tc_rowid in LogProcRef table will be the same '-1' */
                buffer-copy tBankImpLineLogCurrRef except tc_Rowid to tBankImpLineLogProcRef.
                assign tBankImpLineLogProcRef.tc_Rowid = string(rowid(tBankImpLineLogProcRef)).
            end.
        end.

        /* =============================================================================================== */
        /* Validate BC and Additional Updates                                                              */
        /* =============================================================================================== */
        <M-? run ValidateBCAndAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
        if viFcReturnSuper <> 0 then assign viSaveProcReturnStatus = viFcReturnSuper.

        if viSaveProcReturnStatus < 0
        then assign tBankImpLineProcRef.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-PROCESSED-ERROR}.
        
        /* =============================================================================================== */
        /* Take all messages realized during validate and additional update and copy to ref tables         */
        /* =============================================================================================== */
        for each tFcMessages:
            create tBankImpLineLogProcRef.
            assign tBankImpLineLogProcRef.tc_Rowid                  = string(rowid(tBankImpLineLogProcRef))
                   tBankImpLineLogProcRef.tc_ParentRowid            = tBankImpLineProcRef.tc_Rowid
                   tBankImpLineLogProcRef.BankImpLineLogRowid       = tFcMessages.tcFcRowid
                   tBankImpLineLogProcRef.BankImpLineLogFieldName   = tFcMessages.tcFcFieldName
                   tBankImpLineLogProcRef.BankImpLineLogFieldValue  = tFcMessages.tcFcFieldValue
                   tBankImpLineLogProcRef.BankImpLineLogLog         = "":U
                   tBankImpLineLogProcRef.BankImpLineLogMessage     = tFcMessages.tcFcMessage
                   tBankImpLineLogProcRef.BankImpLineLogSeverity    = tFcMessages.tiFcSeverity
                   tBankImpLineLogProcRef.BankImpLineLogType        = tFcMessages.tcFcType
                   tBankImpLineLogProcRef.BankImpLineLogFieldLabel  = tFcMessages.tcFcFieldLabel.
        end.
        empty temp-table tFcMessages.
    
        /* =============================================================================================== */
        /* Restore original tFcMessages                                                                    */
        /* =============================================================================================== */
        for each tFcMessagesProcBackup:
            create tFcMessages.
            buffer-copy tFcMessagesProcBackup to tFcMessages.
        end.
        
        /* =============================================================================================== */
        /* Complete transaction                                                                            */
        /* =============================================================================================== */
        <I-? {bFcOpenInstance
             &CLASS           = "Transaction"}>
             
        if viSaveProcReturnStatus >= 0
        then do:
            <M-? run CommitTransaction
               (input  true (ilStop), 
                input  ? (ihParentInstance), 
                output vcDummy (ocInstances), 
                output viFcReturnSuper (oiReturnStatus)) in Transaction>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        end.
        else do:
            <M-? run AbortTransaction
               (input  ? (ihParentInstance), 
                output vcDummy (ocInstances), 
                output viFcReturnSuper (oiReturnStatus)) in Transaction>
            if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        end.
    
        <I-? {bFcCloseAndStopInstance
             &CLASS           = "Transaction"}>
        assign viTransactionID = 0.

        /* =========================================================================================== */
        /* If there is processing error, stop processing                                               */
        /* =========================================================================================== */
        if tBankImpLineProcRef.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-PROCESSED-ERROR}
        then leave.
    end. /* of do viIndex = 1 to num-entries(vcTransactionActionList): */

    /* =============================================================================================== */
    /* Cumulate number of processed records                                                            */
    /* =============================================================================================== */
    assign tBankImpLineProcRef.tlIsProcessed = true
           oiNumberOfProcessedRecords        = oiNumberOfProcessedRecords + 1.
    
    if tBankImpLineProcRef.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-PROCESSED-ERROR}
    then assign oiNumberOfErrorRecords = oiNumberOfErrorRecords + 1.
    
    /* =============================================================================================== */
    /* Calculate time in seconds elapsed from start of processing                                      */
    /* =============================================================================================== */
    assign viEndTime     = time
           viElapsedTime = (if viEndTime >= viStartTime
                            then viEndTime - viStartTime
                            else viEndTime + 24 * 60 * 60 - viStartTime).

    if viElapsedTime > 15 then leave.

    /* =============================================================================================== */
    /* If there was system error, just stop                                                            */
    /* =============================================================================================== */
    if oiReturnStatus <> -98 and oiReturnStatus < 0 then leave.
end.

/* =================================================================================================== */
/* Check, whether instance of the transaction is stopped.                                              */
/* =================================================================================================== */
if valid-handle(vhTransactionInst)
then do:
    <I-? {bFcCloseAndStopInstance
         &CLASS           = "Transaction"}>
    assign viTransactionID = 0.
end.
else if viTransactionID <> 0 and
        viTransactionID <> ?
then do:
    <I-? {bFcStopInstance
         &CLASS           = "Transaction"}>
    assign viTransactionID = 0. */
end.

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.