project QadFinancials > class BAPMatching > method AdditionalUpdatesAll

Description

AdditionalUpdatesAll


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AdditionalUpdates


program code (program6/bapmatching.p)

/* ======================== */
/* Set default ReturnStatus */
/* ======================== */
assign oiReturnStatus = -98.

/* ===================================================================================== */
/* Empty all instance-less temp-tables that are used in input for calls in other classes */
/* ===================================================================================== */
empty temp-table tExtAllocateCInvoiceAPM.
empty temp-table tExtQCrossCyPostingAPM.
empty temp-table tExtCInvoiceVat.

/* ============================================================================================== */
/* First check if we need to do all these actions: only needed in case some matchings were set to */
/* Finished.  Go through all Finished and non-deleted matchings                                   */
/* ============================================================================================== */
assign vlFinishedMatchingsFound = false.
for each tAPMatching where
         tAPMatching.tc_Status        <> "D":U and
         tAPMatching.APMatchingStatus = {&APMATCHINGSTATUS-FINISHED} :
    /* skip the ones that were already matched at load-time */
    if can-find (first t_iAPMatching where 
                       t_iAPMatching.tc_rowid         = tAPMatching.tc_rowid and 
                       t_iAPMatching.APMatchingStatus = tAPMatching.APMatchingStatus)
    then next.
    assign vlFinishedMatchingsFound = true.
    Leave.    
end. /* for each tAPMatching where  */

/* ====================================== */
/* Get the Cirec-account and its division */
/* ====================================== */
if vlFinishedMatchingsFound
then do:
    <Q-11 run GLByGLSystemType (all) (Read) (NoCache)
       (input viCompanyID, (CompanyId)
        input {&GLSYSTEMTYPE-CIREC}, (GLSystemTypeCode)
        input {&GLTYPECODE-SYST}, (GlTypeCode)
        input ?, (GlIsDivisionAccount)
        output dataset tqGLByGLSystemType) in BGL >
    find first tqGLByGLSystemType no-lock no-error.
    if not available(tqGLByGLSystemType)
    then do:
        assign oiReturnStatus  = -1
               vcMsgAPMatching = trim(substitute(#T-10'No &1 GL account found of type &2.':234(56033)T-10#, {&GLTYPECODE-SYST-TR}, {&GLSYSTEMTYPE-CIREC-TR})).
        <M-12 run SetMessage (input  vcMsgAPMatching (icMessage), 
                          input  '':U (icArguments), 
                          input  '':U (icFieldName), 
                          input  '':U (icFieldValue), 
                          input  'E':U (icType), 
                          input  3 (iiSeverity), 
                          input  '':U (icRowid), 
                          input  'QadFin-5402':U (icFcMsgNumber), 
                          input  '':U (icFcExplanation), 
                          input  '':U (icFcIdentification), 
                          input  '':U (icFcContext), 
                          output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        Return.
    end. /* if not available(tqGLByGLSystemType) */
    else assign vcCirecGLCode      = tqGLByGLSystemType.tcGLCode
                vlCirecHasDivision = tqGLByGLSystemType.tlGLIsDivisionAccount.
end. /* if vlFinishedMatchingsFound */

/* =================================================================================== */
/* Get cross company G/L account for intercompany posting                              */
/* This is only needed when at least one pending voucher is comming from another       */
/* company then company of supplier invoice                                            */
/* =================================================================================== */
for each tAPMatching where
         tAPMatching.tc_Status       <> 'D':U                        and
         tAPMatching.APMatchingStatus = {&APMATCHINGSTATUS-FINISHED},
    each tAPMatchingLn where
         tAPMatchingLn.tc_ParentRowid          = tAPMatching.tc_Rowid   and
         tAPMatchingLn.tc_Status              <> 'D':U                  and
         tAPMatchingLn.APMatchingLnPvodCompID <> tAPMatching.Company_ID:
    leave.
end.
if available tAPMatchingLn
then do:
    <Q-90 run DomainForInterCompany (all) (Read) (NoCache)
       (input viDomainID, (DomainID)
        input ?, (DomainCode)
        input ?, (CompanyID)
        output dataset tqDomainForInterCompany) in BDomain >
    find first tqDomainForInterCompany no-error.
    if not available  tqDomainForInterCompany       or
       tqDomainForInterCompany.tiIntercoAPGL_ID = 0 or
       tqDomainForInterCompany.tiIntercoAPGL_ID = ?
    then do:
        assign oiReturnStatus  = -1
               vcMsgAPMatching = trim(substitute(#T-92'Cannot get cross company GL accounts definition for domain &1.':255(59427)T-92#, vcDomainCode)).
        <M-91 run SetMessage
           (input  vcMsgAPMatching (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-5995':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching> 
        Return.
    end. /* if not available  tqDomainForInterCompany       or */
end. /* if available tAPMatchingLn */

/* =================================================================================== */
/* Open BJournalEntry as we will need it several times in the mentioned block. It will */
/* be closed after the block; you cannot do a 'Return.' in the block itself. Every     */
/* error/warning should be captured in viBlockReturnStatus                             */
/* =================================================================================== */   
if vlFinishedMatchingsFound
then do:
    if viBJournalEntryAPMID <> 0  and
       viBJournalEntryAPMID <> ?
    then do :
        <I-114 {bFcOpenInstance
             &CLASS           = "BJournalEntry"}>
    end. /* if viBJournalEntryAPMID <> 0  and */
    else do :
        <I-115 {bFcStartAndOpenInstance
                &ADD-TO-TRANSACTION = "true"
                &CLASS              = "BJournalEntry"}>
        assign vlBJournalEntryStart = true.                                                                
    end. /* Not if viBJournalEntryAPMID <> 0  and */ 
end. /* if vlFinishedMatchingsFound */

/* =============== */
/* Start the block */
/* =============== */
MAJORADDUPDLOOPBLOCK : DO :
    
    /* ====================================================================================================================== */
    /* Optionaly Start queries used in the block from here onwards                                                            */
    /* StartComponent in BMfgPOReceipt as we will repetitively call the instance-less method GetAccountInformationOnPOReceipt */
    /* in it and it is more performing to use the StartComponent+EndComponent then to use vhFcComponent=? in this case        */
    /* ====================================================================================================================== */
    if vlFinishedMatchingsFound
    then do:
        <M-98 run AdditionalUpdatesAllQueriesStart
           (output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        if viFcReturnSuper <> 0 
        then assign viBlockReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then Leave MAJORADDUPDLOOPBLOCK.
    end. 
    
    /* ================================================= */
    /* Go through all Finished and non-deleted matchings */
    /* ================================================= */
    for each tAPMatching where 
             tAPMatching.tc_status        <> "D":U and
             tAPMatching.APMatchingStatus  = {&APMATCHINGSTATUS-FINISHED} :
        
        /* ===================================================== */
        /* skip the ones that were already finished at load-time */
        /* ===================================================== */
        if can-find (first t_iAPMatching where 
                           t_iAPMatching.tc_rowid         = tAPMatching.tc_rowid and 
                           t_iAPMatching.APMatchingStatus = tAPMatching.APMatchingStatus)
        then next.
        
        /* ==================================================================================== */
        /* Get the CInvoice for some details (query-result is used later on in the flow)        */
        /* ==================================================================================== */
        <Q-38 run CInvoiceByMatchingInfo (all) (Read) (NoCache)
           (input tAPMatching.Company_ID, (CompanyId)
            input tAPMatching.CInvoice_ID, (CInvoiceID)
            output dataset tqCInvoiceByMatchingInfo) in BCInvoice >
        find first tqCInvoiceByMatchingInfo where 
                   tqCInvoiceByMatchingInfo.tiCInvoice_ID = tAPMatching.CInvoice_ID
                   no-error.
        if not available tqCInvoiceByMatchingInfo
        then do: 
            assign vcMsgAPMatching     = trim(substitute(#T-83'Internal error: Cannot find the supplier invoice based on its ID (&1).':252(56460)T-83#,string(tAPMatching.CInvoice_ID)))
                   viBlockReturnStatus = -3.
            <M-82 run SetMessage
               (input  vcMsgAPMatching (icMessage), 
                input  '':U (icArguments), 
                input  'tAPMatching.CInvoice_ID':U (icFieldName), 
                input  string(tAPMatching.CInvoice_ID) (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-5699':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            Leave MAJORADDUPDLOOPBLOCK.
        end. /* if not available tqCInvoiceByMatchingInfo */
        
        /* =============================================================================================== */
        /* Assign the posting-text: used for the posting and for its lines                                 */
        /* Create a posting in case there was none yet / if it was already there then get its postingRowid */
        /* =============================================================================================== */
        assign vcPostingText = trim(#T-87'AP Matching':20(49266)T-87#) + ": ":U + string(tAPMatching.tiPeriodYear, "9999":U) + "/":U + string(tAPMatching.tiPeriodPeriod, "99":U) + "/":U + tAPMatching.tcJournalCode.
        if tAPMatching.Posting_ID = 0  or 
           tAPMatching.Posting_ID = ?
        then do:
            /* Fill ExternalInvoiceReference for the new matching posting */
            assign vcPostingInvoiceReferenceText = string(tqCInvoiceByMatchingInfo.tiCInvoicePostingYear, "9999":U)  + "/":U +
                                                   string(tqCInvoiceByMatchingInfo.tiCInvoicePostingPeriod ,"99":U)  + " ":U +
                                                   tqCInvoiceByMatchingInfo.tcJournalCode                            + " ":U +
                                                   string(tqCInvoiceByMatchingInfo.tiCInvoiceVoucher, "999999999":U) + " ":U +
                                                   trim(tqCInvoiceByMatchingInfo.tcCInvoiceReference).
            /* Create the posting-header */ 
            <M-4 run AddPostingHeader
               (input  tAPMatching.Company_ID (iiCompanyId), 
                input  tAPMatching.tiPeriodYear (iiPeriodYear), 
                input  tAPMatching.tiPeriodPeriod (iiPeriodPeriod), 
                input  tAPMatching.tcJournalCode (icJournalCode), 
                input  '' (icReportingJournalCode), 
                input  tAPMatching.tiPostingVoucher (iiVoucher), 
                input  tAPMatching.APMatchingDate (itPostingDate), 
                input  ? (itValueDate), 
                input  vcPostingText (icPostingText), 
                input  tAPMatching.tcBusinessRelationCode (icPostingBusinessRelationText), 
                input  vcPostingInvoiceReferenceText (icPostingInvoiceReferenceText), 
                input  {&POSTINGPARENTTEXT-APMATCHING} (icPostingParentText), 
                input  ? (iiBPeriodId), 
                input  tAPMatching.tcCreditorCode (icPostingOriginAddressCode), 
                input  ? (icPostingOriginDocument), 
                input  ? (icPostingOriginDocumentType), 
                input  tqCInvoiceByMatchingInfo.tcCInvoiceBatchNumber (icBatchNumber), 
                input  ? (icBankImpLineRef), 
                output tAPMatching.Posting_ID (oiPostingId), 
                output vcAPMatchingPostingRowID (ocRowid), 
                output tAPMatching.tiPostingVoucher (oiPostingVoucher), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper <> 0 then assign viBlockReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then Leave MAJORADDUPDLOOPBLOCK.
        end. /* if tAPMatching.Posting_ID = 0  or */
        else do:
            <M-5 run GetPostingRowidBasedOnPostingID (input  tAPMatching.Posting_ID (iiPostingID), 
                                          output vcAPMatchingPostingRowID (ocPostingRowid), 
                                          output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            if viFcReturnSuper > 0 and 
               (vcAPMatchingPostingRowID = "":U or 
                vcAPMatchingPostingRowID = ?)
            then assign viFcReturnSuper = -3.
            if viFcReturnSuper <> 0 then assign viBlockReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 
            then do: 
                assign vcMsgAPMatching = trim(substitute(#T-6'Internal error: No posting has been found for the specified instance.':222(49267)T-6#)) + 
                                         trim(substitute(#T-7'Posting ID: &1':222(49268)T-7#,string(tAPMatching.Posting_ID))).
                <M-8 run SetMessage (input  vcMsgAPMatching (icMessage), 
                     input  '':U (icArguments), 
                     input  'tAPMatching.Posting_ID':U (icFieldName), 
                     input  string(tAPMatching.Posting_ID) (icFieldValue), 
                     input  'E':U (icType), 
                     input  3 (iiSeverity), 
                     input  '':U (icRowid), 
                     input  'QadFin-5401':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
                Leave MAJORADDUPDLOOPBLOCK.
            end. /* if viFcReturnSuper <> 0 */
        end. /* if tAPMatching.Posting_ID <> 0 */
        
        /* =============================================================================================================== */
        /* Reset the sum of the positive values on the lines for the Amount-TC of the usage-variance and the rate-variance */
        /* =============================================================================================================== */
        assign vdSumPosVarUsageTCPosVarRateTC = 0.
        
        /* Give all default saf concept values from Creditor and Business Relation */
        empty temp-table tDefaultSafsCreditor.
        <Q-52 run CreditorPrim (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input tqCInvoiceByMatchingInfo.tiCreditor_ID, (CreditorId)
            input ?, (CreditorCode)
            output dataset tqCreditorPrim) in BCreditor>

        find tqCreditorPrim where
             tqCreditorPrim.tiCreditor_ID = tqCInvoiceByMatchingInfo.tiCreditor_ID
        no-lock no-error.
        if available tqCreditorPrim
        then do:

            <Q-61 run CreditorSafDefaultByCreditor (all) (Read) (NoCache)
               (input viCompanyId, (CompanyId)
                input tqCreditorPrim.tcCreditorCode, (CreditorCode)
                output dataset tqCreditorSafDefaultByCreditor) in BCreditor>

            for each tqCreditorSafDefaultByCreditor where
                     tqCreditorSafDefaultByCreditor.tcCreditorCode = tqCreditorPrim.tcCreditorCode:

                create tDefaultSafsCreditor.
                assign tDefaultSafsCreditor.tcSafCode        = tqCreditorSafDefaultByCreditor.tcSafCode
                       tDefaultSafsCreditor.tcSafConceptCode = tqCreditorSafDefaultByCreditor.tcSafConceptCode.
            end. /* for each tqCreditorSafDefaultByCreditor */

            /* Give all default saf concept values from Business relation but don't override default values from Creditor */
            <Q-63 run BusRelationSafDefaultByBRID (all) (Read) (NoCache)
               (input tqCreditorPrim.tiBusinessRelation_ID, (BusinessRelationID)
                output dataset tqBusRelationSafDefaultByBRID) in BBusinessRelation>

            for each tqBusRelationSafDefaultByBRID where
                     tqBusRelationSafDefaultByBRID.tiBusinessRelation_ID = tqCreditorPrim.tiBusinessRelation_ID:
                if can-find(tDefaultSafsCreditor where 
                            tDefaultSafsCreditor.tcSafConceptCode = tqBusRelationSafDefaultByBRID.tcSafConceptCode)
                then next.
    
                create tDefaultSafsCreditor.
                assign tDefaultSafsCreditor.tcSafCode        = tqBusRelationSafDefaultByBRID.tcSafCode
                       tDefaultSafsCreditor.tcSafConceptCode = tqBusRelationSafDefaultByBRID.tcSafConceptCode.
            end. /* for each tqBusRelationSafDefaultByBRID */
        end. /* if available tqCreditorPrim */

        /* I19 requirement for Brazil =============================================================== */
        /* If the AP matching is for the Legal document, all posting lines needs to contain reference */
        /* to this legal document                                                                     */
        /* ========================================================================================== */
        assign vcLegalDocNbr = ?.
        if vlDomainIsFiscalConfirm and
           tqCInvoiceByMatchingInfo.tlCInvoiceIsERS
        then assign vcLegalDocNbr = entry(1, tAPMatching.tcCInvoiceReference).

        /* ====================================== */
        /* Go through all lines of the APMatching */
        /* ====================================== */
        for each tAPMatchingLn where 
                 tAPMatchingLn.tc_ParentRowid  = tAPMatching.tc_rowid and 
                 tAPMatchingLn.tc_status      <> "D":U :
            
            /* ===================================================================== */
            /* Call a sub-method because this method cannot contain all program-code */
            /* ===================================================================== */
            <M-37 run AdditionalUpdatesAllLines
               (input  vcAPMatchingPostingRowID (icAPMatchingPostingRowidID), 
                input  vcPostingText (icPostingText), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            if viFcReturnSuper <> 0 then assign viBlockReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then Leave MAJORADDUPDLOOPBLOCK.
            
            /* =============================================================================================================== */
            /* Reset the sum of the positive values on the lines for the Amount-TC of the usage-variance and the rate-variance */
            /* =============================================================================================================== */
            if tAPMatchingLn.APMatchingLnVarRateTC > 0 
            then assign vdSumPosVarUsageTCPosVarRateTC = vdSumPosVarUsageTCPosVarRateTC + tAPMatchingLn.APMatchingLnVarRateTC.
            if tAPMatchingLn.APMatchingLnVarUsageTC > 0 
            then assign vdSumPosVarUsageTCPosVarRateTC = vdSumPosVarUsageTCPosVarRateTC + tAPMatchingLn.APMatchingLnVarUsageTC.
            
            /* ============================================================= */
            /* Call one method that will handle all taxes of a matching-line */
            /* ============================================================= */
            <M-104 run AdditionalUpdatesAllTax
               (input  vcAPMatchingPostingRowID (icAPMatchingPostingRowID), 
                input  vcPostingText (icPostingText), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            if viFcReturnSuper <> 0 then assign viBlockReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then Leave MAJORADDUPDLOOPBLOCK.
            
        end. /* for each tAPMatchingLn where */
        
        /* ========================================================================================================= */
        /* Get the AccountsPayableControl-file flag that indicates if the whole balance should be put on hold or not */
        /* ========================================================================================================= */
        if vdSumPosVarUsageTCPosVarRateTC > 0
        then do:

            <Q-86 run AccountsPayableCtrlByDomain (all) (Read) (NoCache)
               (input vcDomainCode, (DomainCode)
                output dataset tqAccountsPayableCtrlByDomain) in BMfgAccountPayableCtrl>

            if can-find(first tqAccountsPayableCtrlByDomain where
                              tqAccountsPayableCtrlByDomain.tcapc_domain         = vcDomainCode and
                              tqAccountsPayableCtrlByDomain.tlapc_holdinvoiceamt = false
                        no-lock)
            then assign vdSumPosVarUsageTCPosVarRateTC = abs(tqCInvoiceByMatchingInfo.tdCInvoiceBalanceTC).

        end. /* if vdSumPosVarUsageTCPosVarRateTC > 0 */

        /* ==================================== */
        /* Go through all additional cost lines */
        /* ==================================== */
        for each tAPMatchingCost where
                 tAPMatchingCost.tc_ParentRowid = tAPMatching.tc_Rowid and
                 tAPMatchingCost.tc_Status     <> 'D':
            <M-29 run AdditionalUpdatesAllCosts
               (input  vcAPMatchingPostingRowID (icAPMatchingPostingRowID), 
                input  vcPostingText (icPostingText), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            if viFcReturnSuper <> 0 then assign viBlockReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 then Leave MAJORADDUPDLOOPBLOCK.                
        end. /* for each tAPMatchingCost where */                 
        
        /* ==================================================================================== */
        /* Create the CIREC posting line in submethod using BJournalEntry.AddStandardPosting()  */
        /* and hold the ID of this posting-line inf tAPMatching.CirecPostingLine_ID             */
        /* The amount of the posting-line equals tAPMatching.APMatchingTotalAmountTC            */
        /* Create a tCInvoiceForAPMatching record and assign all fields properly                */
        /* ==================================================================================== */
        <M-85 run AdditionalUpdatesAllCreatePLCirec
           (input  vcAPMatchingPostingRowID (icAPMatchingPostingRowidID), 
            input  vcCirecGLCode (icCirecGLCode), 
            input  if vlCirecHasDivision then tqCInvoiceByMatchingInfo.tcDivisionCode else '':U (icCirecDivisionCode), 
            input  vcPostingText (icPostingText), 
            input  vdSumPosVarUsageTCPosVarRateTC (idSumPosVarUsageTCPosVarRateTC), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        if viFcReturnSuper <> 0 then assign viBlockReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 then Leave MAJORADDUPDLOOPBLOCK.
        
    end. /* for each tAPMatching where  */
    
END. /* MAJORADDUPDLOOPBLOCK */

/* ====================================================================================================================== */
/* Stop queries used in the block from here onwards                                                                       */
/* StopComponent in BMfgPOReceipt as we will repetitively call the instance-less method GetAccountInformationOnPOReceipt  */
/* in it and it is more performing to use the StartComponent+EndComponent then to use vhFcComponent=? in this case        */
/* ====================================================================================================================== */
if vlFinishedMatchingsFound
then do:
    <M-118 run AdditionalUpdatesAllQueriesStop  (output viFcReturnSuper (oiReturnStatus)) in BAPMatching>   
    if viFcReturnSuper <> 0 then assign viBlockReturnStatus = viFcReturnSuper.
end.

/* =================================================== */
/* Close BJournalEntry as it was started for the block */
/* =================================================== */
if vlFinishedMatchingsFound
then.   /* ========================================================================================================= */
        /* Normally we would here close BJournalEntry but we will not do it for performance                          */
        /* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it.     */
        /* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the  */
        /* appserver that is executed after each call to the appserver                                               */
        /* ========================================================================================================= */
        
/* =========================================== */
/* Check for errors/warnings in previous block */
/* =========================================== */
if viBlockReturnStatus <> 0 
then do: 
    assign oiReturnStatus = viBlockReturnStatus.
    if viBlockReturnStatus < 0  then return.
end. /* if viAdditionalReturnStatus <> 0 */

/* =============================================================================== */
/* Call a sub-method that holds all calls to sub-methods that access other classes */
/* =============================================================================== */
if vlFinishedMatchingsFound
then do:
    <M-101 run AdditionalUpdatesAllExt  (output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 then Return.
end.

/* ================================================================ */
/* Call method in BJournalEntry to run ValidateBC&AdditionalUpdates */
/* ================================================================ */
if viBJournalEntryAPMID <> 0 and
   viBJournalEntryAPMID <> ?
then do:
    <I-64 {bFcOpenInstance
         &CLASS           = "BJournalEntry"}>
    <M-66 run ValidateBCAndAdditionalUpdates  (output viExternalReturnStatus (oiReturnStatus)) in BJournalEntry>     
    /* ========================================================================================================= */
    /* Normally we would here close BJournalEntry but we will not do it for performance                          */
    /* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it.     */
    /* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the  */
    /* appserver that is executed after each call to the appserver                                               */
    /* ========================================================================================================= */
    if viExternalReturnStatus <> 0
    then assign oiReturnStatus = viExternalReturnStatus.
    if viExternalReturnStatus < 0 
    then Return. 
end.

/* ================================================================ */
/* Call method in BCInvoice to run ValidateBC&AdditionalUpdates     */
/* ================================================================ */
if vlBCInvoiceStart
then do :
    <I-121 {bFcOpenInstance
         &CLASS           = "BCInvoice"}>
     
    <M-119 run ValidateBCAndAdditionalUpdates  (output viExternalReturnStatus (oiReturnStatus)) in BCInvoice>

    /* ========================================================================================================= */
    /* Normally we would here close BCInvoice but we will not do it for performance                              */
    /* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it.     */
    /* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the  */
    /* appserver that is executed after each call to the appserver                                               */
    /* ========================================================================================================= */
    
    if viExternalReturnStatus <> 0 then assign oiReturnStatus = viExternalReturnStatus.
    if viExternalReturnStatus <  0 then return.
end. /* if vlBCInvoiceStart */

/* ======================================================================================= */
/* Everything went OK:                                                                     */
/* - Empty all instance-less temp-tables that are used in input for calls in other classes */
/*   as we do no longer need this information and as it will free up some memory           */
/*   (you can find the same piece of code in method StopExternalInstances)                 */
/* - Set ReturnStatus = OK                                                                 */
/* ======================================================================================= */
empty temp-table tExtAllocateCInvoiceAPM.
empty temp-table tExtQCrossCyPostingAPM.
empty temp-table tExtCInvoiceVat.

if oiReturnStatus = -98
then assign oiReturnStatus = 0.