project QadFinancials > class BConsolid > method AdditionalUpdatesConsolidationBlock

Description

Part of the AdditionalUpdates. This NEEDS to be in segment 1 to be able to work.


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BConsolid.AdditionalUpdates


program code (program1/bconsolid.p)

/* ================================================================================== */
/* Flow:                                                                              */
/*    for each selected ConsolidPeriod                                                */
/*      1 Get the Data from PostingHist                                               */
/*      2 Get the Unique combinations from PostingHist (GL DIV CC PRJ)                */
/*      3 Get the Target GL DIV CC PRJ (calling GetCOACrossRef.BCOACrossRef)          */
/*      4 Determine Target DIV GL CC PRJ and SAF to use                               */
/*               (calling BConsolid.AdditionalUpdatesConsolidationBlockDef)           */
/*      5 for each PostingHist                                                        */
/*            Get the target values to use and make the posting/postinglines          */
/*    end                                                                             */
/* ================================================================================== */

/* Return when it is not needed to run it */
find first tConsolid where
           (tConsolid.tc_Status  = 'N':U or tConsolid.tc_Status  = 'C':U) and
           (tConsolid.Posting_ID = 0  or tConsolid.Posting_ID = ?)        and
            tConsolid.ConsolidStatus = {&CONSOLIDSTATUS-EXECUTED}
            no-error.
if not available tConsolid
then return.

assign viRowid                = 0
       viConsPostingXrefRowid = 0
       viLocalReturnStatus    = 0
       oiReturnStatus         = -98.

/* Instance started for performance reasons */
if viBCOACrossRefConsolidID = ? or viBCOACrossRefConsolidID = 0
then do:
    <I-21 {bFcStartAndOpenInstance
         &ADD-TO-TRANSACTION   = "false"
         &CLASS                = "BCOACrossRef"}>
end.
else do:
    <I-22 {bFcOpenInstance
         &CLASS           = "BCOACrossRef"}>
end.

CONSOLIDATIONBLOCK:
for each tConsolid where
        (tConsolid.tc_Status  = 'N':U or
         tConsolid.tc_Status  = 'C':U   ) and
        (tConsolid.Posting_ID = 0     or
         tConsolid.Posting_ID = ?       ) and
         tConsolid.ConsolidStatus = {&CONSOLIDSTATUS-EXECUTED}:

    empty temp-table tConsPosting.
    empty temp-table tConsCOACrossRefResult.
    
    <M-40 run AdditionalUpdatesConsolidationBlockVal  (output viFcReturnSuper (oiReturnStatus)) in BConsolid>

    if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then leave CONSOLIDATIONBLOCK.
            
    if tConsolid.ConsolidTargetLayerTypCode = {&CONSOLIDTARGETLAYERTYPE-OFFICIAL}
    then assign vcJournalCode = tqConsolidCycleByCompanies.tcOfficialJournalCode.
    else 
    if tConsolid.ConsolidTargetLayerTypCode = {&CONSOLIDTARGETLAYERTYPE-MANAGEMENT}
    then assign vcJournalCode = tqConsolidCycleByCompanies.tcManagementJournalCode.
    else assign vcJournalCode = tqConsolidCycleByCompanies.tcTransientJournalCode.

    assign vcCurrencyCode = tqConsolidCycleByCompanies.tcCurrencyCode.
    
    /* Get Source periods to translate */
    <Q-9 run ConsolidPeriodXrefByPeriod (all) (Read) (NoCache)
       (input tConsolid.SourceCompany_ID, (CompanyId)
        input tConsolid.ConsolidCompany_ID, (ConsolidCompanyID)
        input '':U, (ConsolidCompanyCode)
        input ?, (SourceYear)
        input ?, (SourcePeriod)
        input ?, (TargetYear)
        input ?, (TargetPeriod)
        output dataset tqConsolidPeriodXrefByPeriod) in BConsolidPeriodXref>

    for each tqConsolidPeriodXrefByPeriod where
             tqConsolidPeriodXrefByPeriod.tiCompany_ID              = tConsolid.SourceCompany_ID           and
             tqConsolidPeriodXrefByPeriod.tiConsolidationCompany_ID = tConsolid.ConsolidCompany_ID         and
             ((tqConsolidPeriodXrefByPeriod.tiConsolidPeriodYear      = tConsolid.tiFromPeriodYear and
               tqConsolidPeriodXrefByPeriod.tiConsolidPeriodPeriod   >= tConsolid.tiFromPeriodPeriod)  or
               tqConsolidPeriodXrefByPeriod.tiConsolidPeriodYear      > tConsolid.tiFromPeriodYear)        and
             ((tqConsolidPeriodXrefByPeriod.tiConsolidPeriodYear      = tConsolid.tiToPeriodYear   and
               tqconsolidperiodxrefbyperiod.ticonsolidperiodperiod   <= tConsolid.tiToPeriodPeriod)    or
               tqConsolidPeriodXrefByPeriod.tiConsolidPeriodYear      < tConsolid.tiToPeriodYear)
             no-lock: 

        /* ============================================================================================= */
        /* STEP 1: Get the postinghist records to consolidate                                            */
        /* ============================================================================================= */
        <Q-80 run PostingHistByYPLayerCyForMov (all) (Read) (NoCache)
           (input tConsolid.SourceCompany_ID, (CompanyId)
            input (tqconsolidperiodxrefbyperiod.tiperiodYear * 100) + tqconsolidperiodxrefbyperiod.tiperiodperiod, (YearPeriod)
            input tConsolid.ConsolidSourceLayerTypCode, (LayerTypeCode)
            output dataset tqPostingHistByYPLayerCyForMov) in BPostingHist>

        /* Get the unique combinations of GL DIV CC PRJ which are used                                   */
        empty temp-table tConsCOACrossRefResult.

        for each tqPostingHistByYPLayerCyForMov where
                 tqPostingHistByYPLayerCyForMov.tiCompany_ID                = tConsolid.SourceCompany_ID                                                                      and
                 tqPostingHistByYPLayerCyForMov.tiPostingHistYearPeriodFrom = (tqConsolidPeriodXrefByPeriod.tiPeriodYear * 100) + tqConsolidPeriodXrefByPeriod.tiPeriodPeriod and
                 tqPostingHistByYPLayerCyForMov.tcLayerTypeCode             = tConsolid.ConsolidSourceLayerTypCode
                 break by tqPostingHistByYPLayerCyForMov.tiCompany_ID
                       by tqPostingHistByYPLayerCyForMov.tiPostingHistYearPeriodFrom
                       by tqPostingHistByYPLayerCyForMov.tcLayerTypeCode
                       by tqPostingHistByYPLayerCyForMov.tiGL_ID
                       by tqPostingHistByYPLayerCyForMov.tiIntercoBusinessRelation_ID         
                       by tqPostingHistByYPLayerCyForMov.tiDivision_ID:

            if tqPostingHistByYPLayerCyForMov.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING}
            then next.

            /* Check if the LayerCode of the postinghist record was selected to consolidate */
            if not can-find(tConsolidLayer where
                            tConsolidLayer.tc_ParentRowid = tConsolid.tc_Rowid                        and
                            tConsolidLayer.tcLayerCode    = tqPostingHistByYPLayerCyForMov.tcLayerCode and
                            tConsolidLayer.tc_Status     <> "D":U)
            then next.
            
            /* keep the unique combinations of GL DIV CC PRJ in a tempt-table for later usage */
            find tConsCOACrossRefResult where
                 tConsCOACrossRefResult.tcGLCode         = tqPostingHistByYPLayerCyForMov.tcGLCode        and
                 tConsCOACrossRefResult.tcDivisionCode   = tqPostingHistByYPLayerCyForMov.tcDivisionCode   and
                 tConsCOACrossRefResult.tcCostCentreCode = tqPostingHistByYPLayerCyForMov.tcCostCentreCode and
                 tConsCOACrossRefResult.tcProjectCode    = tqPostingHistByYPLayerCyForMov.tcProjectCode
                 no-error.
            if not available tConsCOACrossRefResult
            then do:
                /* Create temp-table record to retrieve correct mapping */
                create tConsCOACrossRefResult.
                assign tConsCOACrossRefResult.tcGLCode           = tqPostingHistByYPLayerCyForMov.tcGLCode
                       tConsCOACrossRefResult.tcDivisionCode     = tqPostingHistByYPLayerCyForMov.tcDivisionCode
                       tConsCOACrossRefResult.tcCostCentreCode   = tqPostingHistByYPLayerCyForMov.tcCostCentreCode
                       tConsCOACrossRefResult.tcProjectCode      = tqPostingHistByYPLayerCyForMov.tcProjectCode 
                       tConsCOACrossRefResult.tlGLIsSafAccount   = tqPostingHistByYPLayerCyForMov.tlGLIsSafAccount.

            end. /* if not available tConsCOACrossRefResult */

        end. /* for each tqPostingHistByYPLayerCyForMov where */

        /* ============================================================================================= */
        /* Get translations for GL, Division, CostCentre & Project - tConsCOACrossRefResult is used here */
        /* This is done using some logic of BCOACrossRef - the type of COA Xref is important here        */
        /* ============================================================================================= */
        <M-20 run GetCOACrossRef
           (input  tqConsolidCycleByCompanies.tiDomain_ID (iiSourceDomainID), 
            input  tqConsolidCycleByCompanies.tcCOACrossRefCode (icCOACrossRefCode), 
            input  tqConsolidCycleByCompanies.tiCOACrossRef_ID (iiCOACrossRefID), 
            input  tqConsolidCycleByCompanies.tcCOACrossRefType (icCOACrossRefType), 
            input  tDummyCOACrossRefDet (tApiCOACrossRefDet), 
            input  true (ilSkipMessages), 
            input-output tConsCOACrossRefResult (tCOACrossRefResult), 
            output viReturnGetCOACrossRef (oiReturnStatus)) in BCOACrossRef>   

        if viReturnGetCOACrossRef <> 0 and viLocalReturnStatus >= 0
        then assign viLocalReturnStatus = viReturnGetCOACrossRef.

        /* If mapping returned error, next record */
        if viReturnGetCOACrossRef < 0
        then leave CONSOLIDATIONBLOCK.
        
        /* Get all the target accounts */
        <Q-54 run GLAnalysisInfoForOperationals (all) (Read) (NoCache)
           (input viCompanyId, (CompanyID)
            output dataset tqGLAnalysisInfoForOperationals) in BGL>

        /* Process each Summary line again, add the SAF info and create the Posting and PostingLines     */
        HISTORYBLOCK:
        for each tqPostingHistByYPLayerCyForMov where
                 tqPostingHistByYPLayerCyForMov.tiCompany_ID                = tConsolid.SourceCompany_ID                                                                      and
                 tqPostingHistByYPLayerCyForMov.tiPostingHistYearPeriodFrom = (tqConsolidPeriodXrefByPeriod.tiPeriodYear * 100) + tqConsolidPeriodXrefByPeriod.tiPeriodPeriod and
                 tqPostingHistByYPLayerCyForMov.tcLayerTypeCode             = tConsolid.ConsolidSourceLayerTypCode
                 break by tqPostingHistByYPLayerCyForMov.tiCompany_ID
                       by tqPostingHistByYPLayerCyForMov.tiPostingHistYearPeriodFrom
                       by tqPostingHistByYPLayerCyForMov.tcLayerTypeCode
                       by tqPostingHistByYPLayerCyForMov.tiGL_ID
                       by tqPostingHistByYPLayerCyForMov.tiIntercoBusinessRelation_ID         
                       by tqPostingHistByYPLayerCyForMov.tiDivision_ID:

            if tqPostingHistByYPLayerCyForMov.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING}
            then next.

            /* Check if the LayerCode of the postinghist record was selected to consolidate */
            if not can-find(tConsolidLayer where
                            tConsolidLayer.tc_ParentRowid = tConsolid.tc_Rowid                        and
                            tConsolidLayer.tcLayerCode    = tqPostingHistByYPLayerCyForMov.tcLayerCode and
                            tConsolidLayer.tc_Status     <> "D":U)
            then next.

            find tConsCOACrossRefResult where
                 tConsCOACrossRefResult.tcGLCode         = tqPostingHistByYPLayerCyForMov.tcGLCode        and
                 tConsCOACrossRefResult.tcDivisionCode   = tqPostingHistByYPLayerCyForMov.tcDivisionCode   and
                 tConsCOACrossRefResult.tcCostCentreCode = tqPostingHistByYPLayerCyForMov.tcCostCentreCode and
                 tConsCOACrossRefResult.tcProjectCode    = tqPostingHistByYPLayerCyForMov.tcProjectCode
                 no-error.
            if not available tConsCOACrossRefResult
            then do:
                assign vcMessage           = trim(substitute(#T-3'Could not find the correct mapping record for &1, &2, &3 and &4.':255(269248895)T-3#,
                                                   tqPostingHistByYPLayerCyForMov.tcGLCode,
                                                   tqPostingHistByYPLayerCyForMov.tcDivisionCode,
                                                   tqPostingHistByYPLayerCyForMov.tcCostCentreCode,
                                                   tqPostingHistByYPLayerCyForMov.tcProjectCode))
                       viLocalReturnStatus = -3.
                <M-98 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'S':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'qadfin-54817':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BConsolid>
                leave CONSOLIDATIONBLOCK.
            end. /* if not available tConsCOACrossRefResult */
                
            /* Skip if no mapping was found before (error was already created */
            if tConsCOACrossRefResult.tcTargetGLCode = ? or
               tConsCOACrossRefResult.tcTargetGLCode = '':U
            then do:
                assign vcMessage = trim(#T-59'Unable to find a COA Cross Reference for this combination.':255(71410)T-59#)                                          + chr(10) +
                                   trim(substitute(#T-35'COA Cross Reference Code: &1':255(71384)T-35#, trim( tqConsolidCycleByCompanies.tcCOACrossRefCode) ))      + chr(10) +
                                   trim(substitute(#T-85'COA Cross Reference ID: &1':255(71412)T-85#, trim(string( tqConsolidCycleByCompanies.tiCOACrossRef_ID)) )) + chr(10) +
                                   trim(substitute(#T-42'GL Account Code: &1':255(71413)T-42#, trim(tConsCOACrossRefResult.tcGLCode) ))           + chr(10) +
                                   trim(substitute(#T-30'Sub-Account Code: &1':255(71414)T-30#, trim(tConsCOACrossRefResult.tcDivisionCode) ))    + chr(10) +
                                   trim(substitute(#T-24'Cost Center Code: &1':255(71415)T-24#, trim(tConsCOACrossRefResult.tcCostCentreCode) ))  + chr(10) +
                                   trim(substitute(#T-37'Project Code: &1':255(71416)T-37#, trim(tConsCOACrossRefResult.tcProjectCode) )) 
                vcFieldValueMsg =  tConsCOACrossRefResult.tcGLCode         + '-' +
                                   tConsCOACrossRefResult.tcDivisionCode   + '-' +
                                   tConsCOACrossRefResult.tcCostCentreCode + '-' + 
                                   tConsCOACrossRefResult.tcProjectCode.
 
                viLocalReturnStatus = -1.
                
                <M-95 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'qadfin-732815':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BConsolid>
               
                leave CONSOLIDATIONBLOCK.
            end. /* if tConsCOACrossRefResult.tcTargetGLCode */

            /* Get the defaults */            
            <M-13 run AdditionalUpdatesConsolidationBlockDef
               (output viDummy (oiCount), 
                output vcConsolidDivision (ocDivisionCode), 
                output vcConsolidCostCentre (ocCostCentreCode), 
                output vcConsolidProject (ocProjectCode), 
                output vcConsolidSafParentType (ocSafParentType), 
                output vcConsolidSafStructureCode (ocSafStructureCode), 
                output vcConsolidSaf1Code (ocSaf1Code), 
                output vcConsolidSaf2Code (ocSaf2Code), 
                output vcConsolidSaf3Code (ocSaf3Code), 
                output vcConsolidSaf4Code (ocSaf4Code), 
                output vcConsolidSaf5Code (ocSaf5Code), 
                output vcConsolidSafConcept1Code (ocSafConcept1Code), 
                output vcConsolidSafConcept2Code (ocSafConcept2Code), 
                output vcConsolidSafConcept3Code (ocSafConcept3Code), 
                output vcConsolidSafConcept4Code (ocSafConcept4Code), 
                output vcConsolidSafConcept5Code (ocSafConcept5Code), 
                output viFcReturnSuper (oiReturnStatus)) in BConsolid>
    
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viLocalReturnStatus >= 0)
            then assign viLocalReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then leave CONSOLIDATIONBLOCK.

            /* Create or update temp-table record */
            find tConsPosting where
                 tConsPosting.tcConsPostingSourceCompanyCode = tConsolid.tcSourceCompanyCode         and                 
                 tConsPosting.tcConsPostingGLCode            = tConsCOACrossRefResult.tcTargetGLCode and
                 tConsPosting.tcConsPostingDivisionCode      = vcConsolidDivision         and 
                 tConsPosting.tcConsPostingCostCenterCode    = vcConsolidCostCentre       and
                 tConsPosting.tcConsPostingProjectCode       = vcConsolidProject          and
                 tConsPosting.tcSafStructureCode             = vcConsolidSafStructureCode and
                 tConsPosting.tcPostingSafParentType         = vcConsolidSafParentType    and
                 tConsPosting.tcSaf1Code                     = vcConsolidSaf1Code         and
                 tConsPosting.tcSaf2Code                     = vcConsolidSaf2Code         and
                 tConsPosting.tcSaf3Code                     = vcConsolidSaf3Code         and
                 tConsPosting.tcSaf4Code                     = vcConsolidSaf4Code         and
                 tConsPosting.tcSaf5Code                     = vcConsolidSaf5Code         and
                 tConsPosting.tcSafConcept1Code              = vcConsolidSafConcept1Code  and
                 tConsPosting.tcSafConcept2Code              = vcConsolidSafConcept2Code  and
                 tConsPosting.tcSafConcept3Code              = vcConsolidSafConcept3Code  and
                 tConsPosting.tcSafConcept4Code              = vcConsolidSafConcept4Code  and
                 tConsPosting.tcSafConcept5Code              = vcConsolidSafConcept5Code  and
                 tConsPosting.tcConsPostingJournalCode       = vcJournalCode              and
                 tConsPosting.tiConsPostingPeriodYear        = tConsolid.tiToPeriodYear   and
                 tConsPosting.tiConsPostingPeriodPeriod      = tConsolid.tiToPeriodPeriod and
                 tConsPosting.tcConsPostingIntercoRelation   = tqPostingHistByYPLayerCyForMov.tcBusinessRelationICCode                 
                 no-error.

            if not available tConsPosting
            then do:
                create tConsPosting.
                assign viRowid                                     = viRowid + 1
                       tConsPosting.tiCompanyId                    = tConsolid.ConsolidCompany_ID
                       tConsPosting.tcConsPostingSourceCompanyCode = tConsolid.tcSourceCompanyCode
                       tConsPosting.tcConsPostingGLCode            = tConsCOACrossRefResult.tcTargetGLCode       
                       tConsPosting.tcConsPostingDivisionCode      = vcConsolidDivision
                       tConsPosting.tcConsPostingCostCenterCode    = vcConsolidCostCentre
                       tConsPosting.tcConsPostingProjectCode       = vcConsolidProject
                       tConsPosting.tcSafStructureCode             = vcConsolidSafStructureCode
                       tConsPosting.tcPostingSafParentType         = vcConsolidSafParentType
                       tConsPosting.tcSaf1Code                     = vcConsolidSaf1Code
                       tConsPosting.tcSaf2Code                     = vcConsolidSaf2Code
                       tConsPosting.tcSaf3Code                     = vcConsolidSaf3Code
                       tConsPosting.tcSaf4Code                     = vcConsolidSaf4Code
                       tConsPosting.tcSaf5Code                     = vcConsolidSaf5Code
                       tConsPosting.tcSafConcept1Code              = vcConsolidSafConcept1Code
                       tConsPosting.tcSafConcept2Code              = vcConsolidSafConcept2Code
                       tConsPosting.tcSafConcept3Code              = vcConsolidSafConcept3Code
                       tConsPosting.tcSafConcept4Code              = vcConsolidSafConcept4Code
                       tConsPosting.tcSafConcept5Code              = vcConsolidSafConcept5Code                       
                       tConsPosting.tcConsPostingJournalCode       = vcJournalCode
                       tConsPosting.tiConsPostingPeriodYear        = tConsolid.tiToPeriodYear
                       tConsPosting.tiConsPostingPeriodPeriod      = tConsolid.tiToPeriodPeriod
                       tConsPosting.tcConsPostingIntercoRelation   = tqPostingHistByYPLayerCyForMov.tcBusinessRelationICCode
                       tConsPosting.tcConsPostingConsolidRowid     = tConsolid.tc_Rowid
                       tConsPosting.tdConsPostingPercentage        = tqConsolidCycleByCompanies.tdConsolidCycleCompanyPerc
                       tConsPosting.tcCurrencyCode                 = vcCurrencyCode
                       tConsPosting.tcConsPostingRoundGLCode       = tqConsolidCycleByCompanyID.tcGLCode
                       tConsPosting.tc_Rowid                       = String(viRowid). 
            end. /* if not available tConsPosting */
            
            /* Create tConsPostingXref record */
            create tConsPostingXref.
            assign viConsPostingXrefRowid          = viConsPostingXrefRowid + 1
                   tConsPostingXref.tc_ParentRowid = tConsPosting.tc_Rowid
                   tConsPostingXref.tc_Rowid       = string(viConsPostingXrefRowid)
                   tConsPostingXref.PostingHist_ID = tqPostingHistByYPLayerCyForMov.tiPostingHist_ID.
    
            assign vcExchangeRateTypeCodeCurEntity = "":U.
            /* Check the exchange method that is needed */    
            if tConsCOACrossRefResult.tcGLExchangeMethod <> {&EXCHANGEMETHOD-HISTORICAL}
            then do:

                <Q-48 run GLConsolidCyByCompany (first) (Read) (NoCache)
                   (input tConsolid.SourceCompany_ID, (CompanyId)
                    input tConsCOACrossRefResult.tiTargetGL_ID, (GlId)
                    output dataset tqGLConsolidCyByCompany) in BGL>

                find first tqGLConsolidCyByCompany no-error.
                if available tqGLConsolidCyByCompany 
                then assign vcExchangeRateTypeCodeCurEntity = tqGLConsolidCyByCompany.tcExchangeRateTypeCode.
                else assign vcExchangeRateTypeCodeCurEntity = tConsCOACrossRefResult.tcExchangeRateTypeCode.

                if vcCurrencyCode <> vcPrevCurrencyCode or
                   tConsolid.ConsolidDate <> vtPrevConsolidDate or
                   tConsCOACrossRefResult.tcGLExchangeMethod <> vcPrevGLExchangeMethod or
                   vcExchangeRateTypeCodeCurEntity <> vcPrevExchangeRateTypeCode or
                   tqConsolidPeriodXrefByPeriod.ttConsolidPeriodStartDate <> vtPrevConsolidPeriodStartDate or
                   tqConsolidPeriodXrefByPeriod.ttConsolidPeriodEndDate <> vtPrevConsolidPeriodEndDate
                then do:
                    <M-14 run GetExchangeRates
                       (input  vcCurrencyCode (icCurrencyCode), 
                        input  tConsolid.ConsolidDate (itExchangeRateDate), 
                        input  tConsCOACrossRefResult.tcGLExchangeMethod (icGLExchangeMethod), 
                        input  vcExchangeRateTypeCodeCurEntity (icUsrDefExchangeRateType), 
                        input  tqConsolidPeriodXrefByPeriod.ttConsolidPeriodStartDate (itPeriodStartDate), 
                        input  tqConsolidPeriodXrefByPeriod.ttConsolidPeriodEndDate (itPeriodEndDate), 
                        output vdExchangeRate (odExchangeRate), 
                        output vdExchangeRateScale (odExchangeRateScale), 
                        output viFcReturnSuper (oiReturnStatus)) in BConsolid>
                    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viLocalReturnStatus >= 0)
                    then assign viLocalReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0
                    then leave CONSOLIDATIONBLOCK.

                    assign vcPrevCurrencyCode            = vcCurrencyCode
                           vtPrevConsolidDate            = tConsolid.ConsolidDate
                           vcPrevExchangeRateTypeCode    = vcExchangeRateTypeCodeCurEntity
                           vcPrevGLExchangeMethod        = tConsCOACrossRefResult.tcGLExchangeMethod
                           vtPrevConsolidPeriodStartDate = tqConsolidPeriodXrefByPeriod.ttConsolidPeriodStartDate
                           vtPrevConsolidPeriodEndDate   = tqConsolidPeriodXrefByPeriod.ttConsolidPeriodEndDate.                
                end.

                assign tConsPosting.tdConsPostingMovementDebitTC  = tConsPosting.tdConsPostingMovementDebitTC  + tqPostingHistByYPLayerCyForMov.tdPostingHistMovemntDebitLC
                       tConsPosting.tdConsPostingMovementCreditTC = tConsPosting.tdConsPostingMovementCreditTC + tqPostingHistByYPLayerCyForMov.tdPostingHistMovemntCreditLC
                       tConsPosting.tdConsPostingMovementDebitLC  = tConsPosting.tdConsPostingMovementDebitLC  + (tqPostingHistByYPLayerCyForMov.tdPostingHistMovemntDebitLC * vdExchangeRate * vdExchangeRateScale)
                       tConsPosting.tdConsPostingMovementCreditLC = tConsPosting.tdConsPostingMovementCreditLC + (tqPostingHistByYPLayerCyForMov.tdPostingHistMovemntCreditLC * vdExchangeRate * vdExchangeRateScale)
                       tConsPosting.tdConsPostingMovementQTY      = tConsPosting.tdConsPostingMovementQTY      + tqPostingHistByYPLayerCyForMov.tdPostingHistMovemntQTY.               
            end. /* if tqConsolidGLXrefByCompanyGL.tcConsolidGLExchangeMethod <> {&EXCHANGEMETHOD-HISTORICAL} */            
            else do: 
                if first-of(tqPostingHistByYPLayerCyForMov.tiDivision_ID)
                then do:
                    assign vdDebitLC  = 0
                           vdCreditLC = 0
                           vdDebitTC  = 0
                           vdCreditTC = 0
                           vdQty      = 0.
                           
                    <Q-15 run PostingForPostingHist (all) (Read) (NoCache)
                       (input tqPostingHistByYPLayerCyForMov.tiCompany_ID, (CompanyId)
                        input tqConsolidPeriodXrefByPeriod.tiSourcePeriod_ID, (PeriodID)
                        input tqPostingHistByYPLayerCyForMov.tiGL_ID, (GLId)
                        input tqPostingHistByYPLayerCyForMov.tcLayerTypeCode, (LayerType)
                        input tqPostingHistByYPLayerCyForMov.tiDivision_ID, (DivisionId)
                        input tqPostingHistByYPLayerCyForMov.tcBusinessRelationICCode, (BusinessRelationICCode)
                        output dataset tqPostingForPostingHist) in BPosting >
                        
                    for each tqPostingForPostingHist where
                             tqPostingForPostingHist.tiCompany_ID             = tqPostingHistByYPLayerCyForMov.tiCompany_ID             and
                             tqPostingForPostingHist.tiPeriod_ID              = tqConsolidPeriodXrefByPeriod.tiSourcePeriod_ID         and
                             tqPostingForPostingHist.tiGL_ID                  = tqPostingHistByYPLayerCyForMov.tiGL_ID                  and
                             tqPostingForPostingHist.tcLayerTypeCode          = tqPostingHistByYPLayerCyForMov.tcLayerTypeCode          and
                             tqPostingForPostingHist.tcBusinessRelationICCode = tqPostingHistByYPLayerCyForMov.tcBusinessRelationICCode and
                            (tqPostingForPostingHist.tiDivision_ID            = tqPostingHistByYPLayerCyForMov.tiDivision_ID  or
                             (tqPostingForPostingHist.tiDivision_ID = 0 and tqPostingHistByYPLayerCyForMov.tiDivision_ID = ?) or
                             (tqPostingForPostingHist.tiDivision_ID = ? and tqPostingHistByYPLayerCyForMov.tiDivision_ID = 0)):
                             
                        if not can-find(tConsolidLayer where
                                        tConsolidLayer.tc_ParentRowid = tConsolid.tc_Rowid                  and
                                        tConsolidLayer.tcLayerCode    = tqPostingForPostingHist.tcLayerCode and
                                        tConsolidLayer.tc_Status     <> "D":U)
                        then next.
    
                        /* Get the exchange Rate */
                        find tExchangeRateCache where
                             tExchangeRateCache.tcFromCurrencyCode     = vcCurrencyCode                 and
                             tExchangeRateCache.tiToCurrencyId         = viCompanyLCId                  and
                             tExchangeRateCache.tcExchangeRateTypeCode = {&EXCHANGERATETYPE-ACCOUNTING} and
                             tExchangeRateCache.ttValidityDate         = tqPostingForPostingHist.ttPostingDate
                             no-error.
                        if available tExchangeRateCache
                        then assign vdExchangeRate      = tExchangeRateCache.tdMultiplyExchangeRate
                                    vdExchangeRateScale = tExchangeRateCache.tdExchangeRateScaleFactor.
                        else do:
                            <M-10 run GetExchangeRate
                               (input  viCompanyId (iiCompanyID), 
                                input  ? (iiFromCurrencyID), 
                                input  vcCurrencyCode (icFromCurrencyCode), 
                                input  viCompanyLCId (iiToCurrencyID), 
                                input  ? (icToCurrencyCode), 
                                input  ? (iiExchangeRateTypeID), 
                                input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
                                input  tqPostingForPostingHist.ttPostingDate (itValidityDate), 
                                output vdExchangeRate (odExchangeRate), 
                                output vdExchangeRateScale (odExchangeScaleFactor), 
                                output viFcReturnSuper (oiReturnStatus)) in BConsolid>
                            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and viLocalReturnStatus >= 0)
                            then assign viLocalReturnStatus = viFcReturnSuper.
                            if viFcReturnSuper < 0
                            then next HISTORYBLOCK.
                            create tExchangeRateCache.
                            assign tExchangeRateCache.tcFromCurrencyCode        = vcCurrencyCode                 
                                   tExchangeRateCache.tiToCurrencyId            = viCompanyLCId                  
                                   tExchangeRateCache.tcExchangeRateTypeCode    = {&EXCHANGERATETYPE-ACCOUNTING} 
                                   tExchangeRateCache.ttValidityDate            = tqPostingForPostingHist.ttPostingDate
                                   tExchangeRateCache.tdMultiplyExchangeRate    = vdExchangeRate
                                   tExchangeRateCache.tdExchangeRateScaleFactor = vdExchangeRateScale.
                        end. /* else do: */

                        assign vdDebitTC  = vdDebitTC  + tqPostingForPostingHist.tdPostingLineDebitLC
                               vdCreditTC = vdCreditTC + tqPostingForPostingHist.tdPostingLineCreditLC
                               vdDebitLC  = vdDebitLC  + (tqPostingForPostingHist.tdPostingLineDebitLC * vdExchangeRate * vdExchangeRateScale)
                               vdCreditLC = vdCreditLC + (tqPostingForPostingHist.tdPostingLineCreditLC * vdExchangeRate * vdExchangeRateScale)
                               vdQty      = vdQty      + tqPostingForPostingHist.tdPostingLineQTY.
                    end. /* for each tqPostingForPostingHist where */
                    
                    assign tConsPosting.tdConsPostingMovementDebitTC  = tConsPosting.tdConsPostingMovementDebitTC  + vdDebitTC
                           tConsPosting.tdConsPostingMovementCreditTC = tConsPosting.tdConsPostingMovementCreditTC + vdCreditTC
                           tConsPosting.tdConsPostingMovementDebitLC  = tConsPosting.tdConsPostingMovementDebitLC  + vdDebitLC
                           tConsPosting.tdConsPostingMovementCreditLC = tConsPosting.tdConsPostingMovementCreditLC + vdCreditLC
                           tConsPosting.tdConsPostingMovementQTY      = tConsPosting.tdConsPostingMovementQTY      + vdQty.            
                end.
            end. /* else do: */ 
        end. /* for each tqPostingHistByYPLayerCyForMov */
    end. /* for each tqConsolidPeriodXrefByPeriod where ... */
end. /* for each tConsolid where ... */ 

<I-23 {bFcCloseAndStopInstance
     &CLASS           = "BCOACrossRef"}>
     
assign oiReturnStatus = viLocalReturnStatus.