project QadFinancials > class BClosingPostingsReport > method HistoryPostingsCheck

report procedure


Parameters


icLanguageCodeinputcharacterLanguage Code.
tFilterinputtemp-tableTemp table to store input parameters.
dcrHistoryPostingsCheckoutputdatasetDataset of HistoryPostingsCheck.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bclosingpostingsreport.p)

empty temp-table tqHistoryPostingsCheck.
empty temp-table tPrevPHist.
empty temp-table tPrevPHistSaf.
<M-1 run GetReportLabels
   (input  'HistoryPostingsCheck':U (icReportName), 
    input  icLanguageCode (icLanguageCode), 
    input  tFilter (tFilter), 
    output tqHeader (tqHeader), 
    output tqFilter (tqFilter), 
    output tqText (tqText), 
    output oiReturnStatus (oiReturnStatus)) in BClosingPostingsReport>
if oiReturnStatus <> 0
then return.
<M-2 run SetDataItemsBasedOnFilterTT (output viFcReturnSuper (oiReturnStatus)) in BClosingPostingsReport>

/* Validate filter */
<M-10 run HistoryPostingsCheckValidate (output viFcReturnSuper (oiReturnStatus)) in BClosingPostingsReport>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus <> 0
then return.

/* Check if current period is first one in given year and retreive previous period number */
<Q-3 run PeriodPrim (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input ?, (PeriodId)
    input viPeriodYearFilter, (PeriodYear)
    input ?, (PeriodPeriod)
    output dataset tqPeriodPrim) in BPeriod >

for first tqPeriodPrim by tqPeriodPrim.tiPeriodPeriod:
    if viPeriodPeriodFilter = tqPeriodPrim.tiPeriodPeriod
    then assign vlCheckPreviousPeriod = false.
    else assign vlCheckPreviousPeriod = true
                viPreviousPeriod      = viPeriodYearFilter * 100 + (viPeriodPeriodFilter - 1).    
end.

/* Specified period is first in the given year, we need to retreive last period in previous year */
if not vlCheckPreviousPeriod
then do:
    <Q-4 run PeriodPrim (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input ?, (PeriodId)
        input viPeriodYearFilter - 1, (PeriodYear)
        input ?, (PeriodPeriod)
        output dataset tqPeriodPrim) in BPeriod >

    for each tqPeriodPrim break by tqPeriodPrim.tiPeriodPeriod:
        if last(tqPeriodPrim.tiPeriodPeriod)
        then assign viPreviousPeriod = (viPeriodYearFilter - 1) * 100 + tqPeriodPrim.tiPeriodPeriod.
    end.
end.
/* Call query to retreive values from previous period in order to summarize balances */
<Q-5 run PostingHistByYearPeriod (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input ?, (Period)
    input viPreviousPeriod, (TillPeriod)
    input 999999, (MaxPeriod)
    output dataset tqPostingHistByYearPeriod) in BClosingPostingsReport >
for each tqPostingHistByYearPeriod:
    create tPrevPHist.
    buffer-copy tqPostingHistByYearPeriod to tPrevPHist.
end.
<Q-6 run PostingSafCombinedByPeriod (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input ?, (FromPeriod)
    input viPreviousPeriod, (TillPeriod)
    output dataset tqPostingSafCombinedByPeriod) in BClosingPostingsReport >
for each tqPostingSafCombinedByPeriod:
    create tPrevPHistSaf.
    buffer-copy tqPostingSafCombinedByPeriod to tPrevPHistSaf.
end.

/* Transactions */
<Q-9 run BasePostingHistoryCheck (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input viPeriodYearFilter * 100 + viPeriodPeriodFilter, (Period)
    output dataset tqBasePostingHistoryCheck) in BClosingPostingsReport >
/* History */
<Q-7 run PostingHistByYearPeriod (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input viPeriodYearFilter * 100 + viPeriodPeriodFilter, (Period)
    input ?, (TillPeriod)
    input 999999, (MaxPeriod)
    output dataset tqPostingHistByYearPeriod) in BClosingPostingsReport >
<Q-8 run PostingSafCombinedByPeriod (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input viPeriodYearFilter * 100 + viPeriodPeriodFilter, (FromPeriod)
    input ?, (TillPeriod)
    output dataset tqPostingSafCombinedByPeriod) in BClosingPostingsReport >
for each tqPostingSafCombinedByPeriod:
    create tPrevPHistSaf.
    buffer-copy tqPostingSafCombinedByPeriod to tPrevPHistSaf.
end. 

for each tqBasePostingHistoryCheck break by tqBasePostingHistoryCheck.tiPostingLine_ID:
    /* First we need to gather all info aboout SAFs */
    if first-of(tqBasePostingHistoryCheck.tiPostingLine_ID)
    then assign vcProjectSaf1 = ?
                vcProjectSaf2 = ?
                vcProjectSaf3 = ?
                vcProjectSaf4 = ?
                vcProjectSaf5 = ?
                vcProjectSafStructure = ?
                vcGLSaf1 = ?
                vcGLSaf2 = ?
                vcGLSaf3 = ?
                vcGLSaf4 = ?
                vcGLSaf5 = ?
                vcGLSafStructure = ?
                vcCCSaf1 = ?
                vcCCSaf2 = ?
                vcCCSaf3 = ?
                vcCCSaf4 = ?
                vcCCSaf5 = ?
                vcCCSafStructure = ?
                viCCSafStructure_ID = 0
                viGLSafStructure_ID = 0
                viProjectSafStructure_ID = 0
                viGLSaf1_ID = 0
                viGLSaf2_ID = 0
                viGLSaf3_ID = 0
                viGLSaf4_ID = 0
                viGLSaf5_ID = 0
                viCCSaf1_ID = 0
                viCCSaf2_ID = 0
                viCCSaf3_ID = 0
                viCCSaf4_ID = 0
                viCCSaf5_ID = 0
                viProjectSaf1_ID = 0
                viProjectSaf2_ID = 0
                viProjectSaf3_ID = 0
                viProjectSaf4_ID = 0
                viProjectSaf5_ID = 0.
    /* Distribute SAF Values to correct variables */
    case tqBasePostingHistoryCheck.tcPostingSafParentType:
        when {&POSTINGSAFPARENTTYPE-COSTCENTRE}
        then do:
            case tqBasePostingHistoryCheck.tiPostingSafInputSequence:
                when 1 then assign vcCCSaf1 = tqBasePostingHistoryCheck.tcSafCode
                                   viCCSaf1_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 2 then assign vcCCSaf2 = tqBasePostingHistoryCheck.tcSafCode
                                   viCCSaf2_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 3 then assign vcCCSaf3 = tqBasePostingHistoryCheck.tcSafCode
                                   viCCSaf3_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 4 then assign vcCCSaf4 = tqBasePostingHistoryCheck.tcSafCode
                                   viCCSaf4_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 5 then assign vcCCSaf5 = tqBasePostingHistoryCheck.tcSafCode
                                   viCCSaf5_ID = tqBasePostingHistoryCheck.tiSaf_ID.
            end case.
            if tqBasePostingHistoryCheck.tcSafStructureCode <> ?
            then assign vcCCSafStructure = tqBasePostingHistoryCheck.tcSafStructureCode
                        viCCSafStructure_ID = tqBasePostingHistoryCheck.tiSafStructure_ID.
        end.
        when {&POSTINGSAFPARENTTYPE-GL}
        then do:
            case tqBasePostingHistoryCheck.tiPostingSafInputSequence:
                when 1 then assign vcGLSaf1 = tqBasePostingHistoryCheck.tcSafCode
                                   viGLSaf1_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 2 then assign vcGLSaf2 = tqBasePostingHistoryCheck.tcSafCode
                                   viGLSaf2_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 3 then assign vcGLSaf3 = tqBasePostingHistoryCheck.tcSafCode
                                   viGLSaf3_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 4 then assign vcGLSaf4 = tqBasePostingHistoryCheck.tcSafCode
                                   viGLSaf4_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 5 then assign vcGLSaf5 = tqBasePostingHistoryCheck.tcSafCode
                                   viGLSaf5_ID = tqBasePostingHistoryCheck.tiSaf_ID.
            end case.
            if tqBasePostingHistoryCheck.tcSafStructureCode <> ?
            then assign vcGLSafStructure = tqBasePostingHistoryCheck.tcSafStructureCode
                        viGLSafStructure_ID = tqBasePostingHistoryCheck.tiSafStructure_ID.
        end.
        when {&POSTINGSAFPARENTTYPE-PROJECT}
        then do:
            case tqBasePostingHistoryCheck.tiPostingSafInputSequence:
                when 1 then assign vcProjectSaf1 = tqBasePostingHistoryCheck.tcSafCode
                                   viProjectSaf1_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 2 then assign vcProjectSaf2 = tqBasePostingHistoryCheck.tcSafCode
                                   viProjectSaf2_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 3 then assign vcProjectSaf3 = tqBasePostingHistoryCheck.tcSafCode
                                   viProjectSaf3_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 4 then assign vcProjectSaf4 = tqBasePostingHistoryCheck.tcSafCode
                                   viProjectSaf4_ID = tqBasePostingHistoryCheck.tiSaf_ID.
                when 5 then assign vcProjectSaf5 = tqBasePostingHistoryCheck.tcSafCode
                                   viProjectSaf5_ID = tqBasePostingHistoryCheck.tiSaf_ID.
            end case.
            if tqBasePostingHistoryCheck.tcSafStructureCode <> ?
            then assign vcProjectSafStructure = tqBasePostingHistoryCheck.tcSafStructureCode
                        viProjectSafStructure_ID = tqBasePostingHistoryCheck.tiSafStructure_ID.
        end.
    end case.
    /* Now we have all info about SAF for our postingline so we can start comparing 
       In first step we need to find if the line already exists, if not we need to sety it up */
    if last-of(tqBasePostingHistoryCheck.tiPostingLine_ID)
    then do:
        find first tHistoryCheckStore
            where tHistoryCheckStore.tcBusinessRelationCode = tqBasePostingHistoryCheck.tcBusinessRelationCode and
                  tHistoryCheckStore.tcCostCentreCode   = tqBasePostingHistoryCheck.tcCostCentreCode and
                  tHistoryCheckStore.tcCurrencyCode     = tqBasePostingHistoryCheck.tcCurrencyCode and
                  tHistoryCheckStore.tcDivisionCode     = tqBasePostingHistoryCheck.tcDivisionCode and
                  tHistoryCheckStore.tcGLCode           = tqBasePostingHistoryCheck.tcGLCode and
                  tHistoryCheckStore.tcJournalCode      = tqBasePostingHistoryCheck.tcJournalCode and
                  /* tHistoryCheckStore.tcPeriodMarkCode   = tqBasePostingHistoryCheck.tcPeriodMarkCode and */
                  tHistoryCheckStore.tcProjectCode      = tqBasePostingHistoryCheck.tcProjectCode and
                  tHistoryCheckStore.tiCostCentre1Saf_ID = viCCSaf1_ID and
                  tHistoryCheckStore.tiCostCentre2Saf_ID = viCCSaf2_ID and
                  tHistoryCheckStore.tiCostCentre3Saf_ID = viCCSaf3_ID and
                  tHistoryCheckStore.tiCostCentre4Saf_ID = viCCSaf4_ID and
                  tHistoryCheckStore.tiCostCentre5Saf_ID = viCCSaf5_ID AND                  
                  tHistoryCheckStore.tiGL1Saf_ID         = viGLSaf1_ID and
                  tHistoryCheckStore.tiGL2Saf_ID         = viGLSaf2_ID and
                  tHistoryCheckStore.tiGL3Saf_ID         = viGLSaf3_ID and
                  tHistoryCheckStore.tiGL4Saf_ID         = viGLSaf4_ID and
                  tHistoryCheckStore.tiGL5Saf_ID         = viGLSaf5_ID AND                  
                  tHistoryCheckStore.tiProject1Saf_ID    = viProjectSaf1_ID and
                  tHistoryCheckStore.tiProject2Saf_ID    = viProjectSaf2_ID and
                  tHistoryCheckStore.tiProject3Saf_ID    = viProjectSaf3_ID and
                  tHistoryCheckStore.tiProject4Saf_ID    = viProjectSaf4_ID and
                  tHistoryCheckStore.tiProject5Saf_ID    = viProjectSaf5_ID and
                  tHistoryCheckStore.tiGLSafStructure_ID = viGLSafStructure_ID and
                  tHistoryCheckStore.tiCostCentreSafStructure_ID = viCCSafStructure_ID and
                  tHistoryCheckStore.tiProjectSafStructure_ID = viProjectSafStructure_ID no-error.
        
        if not available tHistoryCheckStore
        then do:
            create tHistoryCheckStore.            
            buffer-copy tqBasePostingHistoryCheck to tHistoryCheckStore.
            /* ========================================= */
            /* Write initial values from previous period */
            /* ========================================= */
            if vcProjectSaf1 <> ? or vcProjectSaf2 <> ? or vcProjectSaf3 <> ? or 
               vcProjectSaf4 <> ? or vcProjectSaf5 <> ? or vcProjectSafStructure <> ? or
               vcGLSaf1 <> ? or vcGLSaf2 <> ? or vcGLSaf3 <> ? or vcGLSaf4 <> ? or
               vcGLSaf5 <> ? or vcGLSafStructure <> ? or vcCCSaf1 <> ? or vcCCSaf2 <> ? or
               vcCCSaf3 <> ? or vcCCSaf4 <> ? or vcCCSaf5 <> ? or vcCCSafStructure <> ? 
            then do:
                for first tPrevPHistSaf            
                where tPrevPHistSaf.tiCostCentre1Saf_ID = viCCSaf1_ID and
                      tPrevPHistSaf.tiCostCentre2Saf_ID = viCCSaf2_ID and
                      tPrevPHistSaf.tiCostCentre3Saf_ID = viCCSaf3_ID and
                      tPrevPHistSaf.tiCostCentre4Saf_ID = viCCSaf4_ID and
                      tPrevPHistSaf.tiCostCentre5Saf_ID = viCCSaf5_ID and
                      tPrevPHistSaf.tiGL1Saf_ID = viGLSaf1_ID and
                      tPrevPHistSaf.tiGL2Saf_ID = viGLSaf2_ID and
                      tPrevPHistSaf.tiGL3Saf_ID = viGLSaf3_ID and
                      tPrevPHistSaf.tiGL4Saf_ID = viGLSaf4_ID and
                      tPrevPHistSaf.tiGL5Saf_ID = viGLSaf5_ID and
                      tPrevPHistSaf.tiProject1Saf_ID = viProjectSaf1_ID and
                      tPrevPHistSaf.tiProject2Saf_ID = viProjectSaf2_ID and
                      tPrevPHistSaf.tiProject3Saf_ID = viProjectSaf3_ID and
                      tPrevPHistSaf.tiProject4Saf_ID = viProjectSaf4_ID and
                      tPrevPHistSaf.tiProject5Saf_ID = viProjectSaf5_ID and
                      tPrevPHistSaf.tiCostCentreSafStructure_ID = viCCSafStructure_ID and
                      tPrevPHistSaf.tiGLSafStructure_ID         = viGLSafStructure_ID and
                      tPrevPHistSaf.tiProjectSafStructure_ID    = viProjectSafStructure_ID :
                end. /*for first tPrevPHistSaf */
                if available tPrevPHistSaf
                then do:
                    /* This will copy only the saf values */
                    buffer-copy tPrevPHistSaf to tHistoryCheckStore.
                    assign viSafCombined_ID = tPrevPHistSaf.tiPostingSafCombined_ID.
                end.
                else assign viSafCombined_ID = 0.
            end.
            else assign viSafCombined_ID = 0.
            find first tPrevPHist
                where tPrevPHist.tcBusinessRelationCode = tqBasePostingHistoryCheck.tcBusinessRelationCode and
                      tPrevPHist.tcCostCentreCode       = tqBasePostingHistoryCheck.tcCostCentreCode and
                      tPrevPHist.tcCurrencyCode         = tqBasePostingHistoryCheck.tcCurrencyCode and
                      tPrevPHist.tcDivisionCode         = tqBasePostingHistoryCheck.tcDivisionCode and
                      tPrevPHist.tcGLCode               = tqBasePostingHistoryCheck.tcGLCode and
                      tPrevPHist.tcJournalCode          = tqBasePostingHistoryCheck.tcJournalCode and
                      tPrevPHist.tcProjectCode          = tqBasePostingHistoryCheck.tcProjectCode and
                      tPrevPHist.tiPostingSafCombined_ID = viSafCombined_ID no-error.
            if available tPrevPHist
            then do:
                /* First .. balance for all P&L accounts if we have first period in year starts with 0 */
                if tPrevPHist.tlGLIsBalanceAccount
                then assign tHistoryCheckStore.tdPostingBalanceCreditCC = tPrevPHist.tdPostingHistBalanceCreditCC
                            tHistoryCheckStore.tdPostingBalanceCreditLC = tPrevPHist.tdPostingHistBalanceCreditLC
                            tHistoryCheckStore.tdPostingBalanceCreditTC = tPrevPHist.tdPostingHistBalanceCreditTC
                            tHistoryCheckStore.tdPostingBalanceDebitCC  = tPrevPHist.tdPostingHistBalanceDebitCC 
                            tHistoryCheckStore.tdPostingBalanceDebitLC  = tPrevPHist.tdPostingHistBalanceDebitLC 
                            tHistoryCheckStore.tdPostingBalanceDebitTC  = tPrevPHist.tdPostingHistBalanceDebitTC.
                else if vlCheckPreviousPeriod and integer(substring(string(tPrevPHist.tiPostingHistYearPeriodFrom),1,4,"character")) = viPeriodYearFilter
                then assign tHistoryCheckStore.tdPostingBalanceCreditCC = tPrevPHist.tdPostingHistYTDCreditCC
                            tHistoryCheckStore.tdPostingBalanceCreditLC = tPrevPHist.tdPostingHistYTDCreditLC
                            tHistoryCheckStore.tdPostingBalanceCreditTC = tPrevPHist.tdPostingHistYTDCreditTC
                            tHistoryCheckStore.tdPostingBalanceDebitCC  = tPrevPHist.tdPostingHistYTDDebitCC 
                            tHistoryCheckStore.tdPostingBalanceDebitLC  = tPrevPHist.tdPostingHistYTDDebitLC 
                            tHistoryCheckStore.tdPostingBalanceDebitTC  = tPrevPHist.tdPostingHistYTDDebitTC.
            end. 
            /* ================================= */
            /* Get The values for current period */
            /* ================================= */
            find first tqPostingHistByYearPeriod
                where tqPostingHistByYearPeriod.tcBusinessRelationCode = tqBasePostingHistoryCheck.tcBusinessRelationCode and
                      tqPostingHistByYearPeriod.tcCostCentreCode   = tqBasePostingHistoryCheck.tcCostCentreCode and
                      tqPostingHistByYearPeriod.tcCurrencyCode     = tqBasePostingHistoryCheck.tcCurrencyCode and
                      tqPostingHistByYearPeriod.tcDivisionCode     = tqBasePostingHistoryCheck.tcDivisionCode and
                      tqPostingHistByYearPeriod.tcGLCode           = tqBasePostingHistoryCheck.tcGLCode and
                      tqPostingHistByYearPeriod.tcJournalCode      = tqBasePostingHistoryCheck.tcJournalCode and
                      tqPostingHistByYearPeriod.tcProjectCode      = tqBasePostingHistoryCheck.tcProjectCode and
                      tqPostingHistByYearPeriod.tiPostingSafCombined_ID = viSafCombined_ID no-error.
            if available tqPostingHistByYearPeriod
            then do:
                buffer-copy tqPostingHistByYearPeriod to tHistoryCheckStore.
                /* start --- defect 10249-0245 zhc */
                assign tHistoryCheckStore.tdPostingHistMovementCreditCC = tqPostingHistByYearPeriod.tdPostingHistMovemntCreditCC
                       tHistoryCheckStore.tdPostingHistMovementCreditLC = tqPostingHistByYearPeriod.tdPostingHistMovemntCreditLC
                       tHistoryCheckStore.tdPostingHistMovementCreditTC = tqPostingHistByYearPeriod.tdPostingHistMovemntCreditTC
                       tHistoryCheckStore.tdPostingHistMovementDebitCC  = tqPostingHistByYearPeriod.tdPostingHistMovemntDebitCC
                       tHistoryCheckStore.tdPostingHistMovementDebitLC  = tqPostingHistByYearPeriod.tdPostingHistMovemntDebitLC
                       tHistoryCheckStore.tdPostingHistMovementDebitTC  = tqPostingHistByYearPeriod.tdPostingHistMovemntDebitTC.
                /* end --- defect 10249-0245 zhc */
                if tqPostingHistByYearPeriod.tlGLIsBalanceAccount = no
                then assign tHistoryCheckStore.tdPostingHistBalanceCreditCC = tqPostingHistByYearPeriod.tdPostingHistYTDCreditCC
                            tHistoryCheckStore.tdPostingHistBalanceCreditLC = tqPostingHistByYearPeriod.tdPostingHistYTDCreditLC
                            tHistoryCheckStore.tdPostingHistBalanceCreditTC = tqPostingHistByYearPeriod.tdPostingHistYTDCreditTC
                            tHistoryCheckStore.tdPostingHistBalanceDebitCC  = tqPostingHistByYearPeriod.tdPostingHistYTDDebitCC 
                            tHistoryCheckStore.tdPostingHistBalanceDebitLC  = tqPostingHistByYearPeriod.tdPostingHistYTDDebitLC 
                            tHistoryCheckStore.tdPostingHistBalanceDebitTC  = tqPostingHistByYearPeriod.tdPostingHistYTDDebitTC.
            end.

            /* assign SAF Values */
            assign tHistoryCheckStore.tcCC1Saf = vcCCSaf1
                   tHistoryCheckStore.tcCC2Saf = vcCCSaf2
                   tHistoryCheckStore.tcCC3Saf = vcCCSaf3
                   tHistoryCheckStore.tcCC4Saf = vcCCSaf4
                   tHistoryCheckStore.tcCC5Saf = vcCCSaf5
                   tHistoryCheckStore.tcGL1Saf = vcGLSaf1
                   tHistoryCheckStore.tcGL2Saf = vcGLSaf2
                   tHistoryCheckStore.tcGL3Saf = vcGLSaf3
                   tHistoryCheckStore.tcGL4Saf = vcGLSaf4
                   tHistoryCheckStore.tcGL5Saf = vcGLSaf5
                   tHistoryCheckStore.tcProject1Saf = vcProjectSaf1
                   tHistoryCheckStore.tcProject2Saf = vcProjectSaf2
                   tHistoryCheckStore.tcProject3Saf = vcProjectSaf3
                   tHistoryCheckStore.tcProject4Saf = vcProjectSaf4
                   tHistoryCheckStore.tcProject5Saf = vcProjectSaf5
                   tHistoryCheckStore.tcCCSafStructure = vcCCSafStructure         
                   tHistoryCheckStore.tcGLSafStructure = vcGLSafStructure          
                   tHistoryCheckStore.tcProjectSafStructure = vcProjectSafStructure.
        end.
        /* We have initialized the line now we can Aggregate values */
        assign tHistoryCheckStore.tdPostingBalanceCreditCC  = tHistoryCheckStore.tdPostingBalanceCreditCC + tqBasePostingHistoryCheck.tdPostingLineCreditCC
               tHistoryCheckStore.tdPostingBalanceCreditLC  = tHistoryCheckStore.tdPostingBalanceCreditLC + tqBasePostingHistoryCheck.tdPostingLineCreditLC
               tHistoryCheckStore.tdPostingBalanceCreditTC  = tHistoryCheckStore.tdPostingBalanceCreditTC + tqBasePostingHistoryCheck.tdPostingLineCreditTC
               tHistoryCheckStore.tdPostingBalanceDebitCC   = tHistoryCheckStore.tdPostingBalanceDebitCC + tqBasePostingHistoryCheck.tdPostingLineDebitCC
               tHistoryCheckStore.tdPostingBalanceDebitLC   = tHistoryCheckStore.tdPostingBalanceDebitLC + tqBasePostingHistoryCheck.tdPostingLineDebitLC
               tHistoryCheckStore.tdPostingBalanceDebitTC   = tHistoryCheckStore.tdPostingBalanceDebitTC + tqBasePostingHistoryCheck.tdPostingLineDebitTC
               tHistoryCheckStore.tdPostingMovementCreditCC = tHistoryCheckStore.tdPostingMovementCreditCC + tqBasePostingHistoryCheck.tdPostingLineCreditCC
               tHistoryCheckStore.tdPostingMovementCreditLC = tHistoryCheckStore.tdPostingMovementCreditLC + tqBasePostingHistoryCheck.tdPostingLineCreditLC
               tHistoryCheckStore.tdPostingMovementCreditTC = tHistoryCheckStore.tdPostingMovementCreditTC + tqBasePostingHistoryCheck.tdPostingLineCreditTC
               tHistoryCheckStore.tdPostingMovementDebitCC  = tHistoryCheckStore.tdPostingMovementDebitCC + tqBasePostingHistoryCheck.tdPostingLineDebitCC
               tHistoryCheckStore.tdPostingMovementDebitLC  = tHistoryCheckStore.tdPostingMovementDebitLC + tqBasePostingHistoryCheck.tdPostingLineDebitLC
               tHistoryCheckStore.tdPostingMovementDebitTC  = tHistoryCheckStore.tdPostingMovementDebitTC + tqBasePostingHistoryCheck.tdPostingLineDebitTC.
    end.
end.

for each tHistoryCheckStore:
    if tHistoryCheckStore.tcGL1Saf <> "":U
    then assign vcConcatinatedSaf = tHistoryCheckStore.tcGL1Saf + " ":U + tHistoryCheckStore.tcGL2Saf + " ":U + tHistoryCheckStore.tcGL3Saf + " ":U   /* GL Safs */
                                  + tHistoryCheckStore.tcGL4Saf + " ":U + tHistoryCheckStore.tcGL5Saf.
    else if tHistoryCheckStore.tcProject1Saf <> "":U
         then assign vcConcatinatedSaf = tHistoryCheckStore.tcProject1Saf + " ":U + tHistoryCheckStore.tcProject2Saf + " ":U + tHistoryCheckStore.tcProject3Saf + " ":U   
                                  + tHistoryCheckStore.tcProject4Saf + " ":U + tHistoryCheckStore.tcProject5Saf. /* Project Safs */
         else assign vcConcatinatedSaf = tHistoryCheckStore.tcCC1Saf + " ":U + tHistoryCheckStore.tcCC2Saf + " ":U + tHistoryCheckStore.tcCC3Saf + " ":U  
                                  + tHistoryCheckStore.tcCC4Saf + " ":U + tHistoryCheckStore.tcCC5Saf. /* CC Safs */
         
    /* Debit diff */
    if tHistoryCheckStore.tdPostingBalanceDebitLC  <> tHistoryCheckStore.tdPostingHistBalanceDebitLC or
       tHistoryCheckStore.tdPostingMovementDebitLC <> tHistoryCheckStore.tdPostingHistMovementDebitLC
    then do:
        create tqHistoryPostingsCheck.
        buffer-copy tHistoryCheckStore to tqHistoryPostingsCheck.
        assign tqHistoryPostingsCheck.tdMovementHistory = tHistoryCheckStore.tdPostingHistMovementDebitLC
               tqHistoryPostingsCheck.tdMovementTrans   = tHistoryCheckStore.tdPostingMovementDebitLC  
               tqHistoryPostingsCheck.tdBalanceHistory  = tHistoryCheckStore.tdPostingHistBalanceDebitLC
               tqHistoryPostingsCheck.tdBalanceTrans    = tHistoryCheckStore.tdPostingBalanceDebitLC
               tqHistoryPostingsCheck.tcSafConcatination = vcConcatinatedSaf
               tqHistoryPostingsCheck.tcMark     = {&CREDITDEBITABBREVIATION-DEBIT-TR}
               tqHistoryPostingsCheck.tcCurrType = {&CURRENCYTYPE-ABBREV-LC-TR}.
    end.
    if tHistoryCheckStore.tdPostingBalanceDebitTC  <> tHistoryCheckStore.tdPostingHistBalanceDebitTC or
       tHistoryCheckStore.tdPostingMovementDebitTC <> tHistoryCheckStore.tdPostingHistMovementDebitTC
    then do:
        create tqHistoryPostingsCheck.
        buffer-copy tHistoryCheckStore to tqHistoryPostingsCheck.
        assign tqHistoryPostingsCheck.tdMovementHistory = tHistoryCheckStore.tdPostingHistMovementDebitTC
               tqHistoryPostingsCheck.tdMovementTrans   = tHistoryCheckStore.tdPostingMovementDebitTC  
               tqHistoryPostingsCheck.tdBalanceHistory  = tHistoryCheckStore.tdPostingHistBalanceDebitTC
               tqHistoryPostingsCheck.tdBalanceTrans    = tHistoryCheckStore.tdPostingBalanceDebitTC
               tqHistoryPostingsCheck.tcSafConcatination = vcConcatinatedSaf
               tqHistoryPostingsCheck.tcMark     = {&CREDITDEBITABBREVIATION-DEBIT-TR}
               tqHistoryPostingsCheck.tcCurrType = {&CURRENCYTYPE-ABBREV-TC-TR}.      
    end.  
    if tHistoryCheckStore.tdPostingBalanceDebitCC  <> tHistoryCheckStore.tdPostingHistBalanceDebitCC or 
       tHistoryCheckStore.tdPostingMovementDebitCC <> tHistoryCheckStore.tdPostingHistMovementDebitCC
    then do:
        create tqHistoryPostingsCheck.
        buffer-copy tHistoryCheckStore to tqHistoryPostingsCheck.
        assign tqHistoryPostingsCheck.tdMovementHistory = tHistoryCheckStore.tdPostingHistMovementDebitCC
               tqHistoryPostingsCheck.tdMovementTrans   = tHistoryCheckStore.tdPostingMovementDebitCC  
               tqHistoryPostingsCheck.tdBalanceHistory  = tHistoryCheckStore.tdPostingHistBalanceDebitCC
               tqHistoryPostingsCheck.tdBalanceTrans    = tHistoryCheckStore.tdPostingBalanceDebitCC
               tqHistoryPostingsCheck.tcSafConcatination = vcConcatinatedSaf
               tqHistoryPostingsCheck.tcMark     = {&CREDITDEBITABBREVIATION-DEBIT-TR}
               tqHistoryPostingsCheck.tcCurrType = {&CURRENCYTYPE-ABBREV-CC-TR}.
    end.
    /* Credit diff */
    if tHistoryCheckStore.tdPostingBalanceCreditLC  <> tHistoryCheckStore.tdPostingHistBalanceCreditLC or 
       tHistoryCheckStore.tdPostingMovementCreditLC <> tHistoryCheckStore.tdPostingHistMovementCreditLC
    then do:
        create tqHistoryPostingsCheck.
        buffer-copy tHistoryCheckStore to tqHistoryPostingsCheck.
        assign tqHistoryPostingsCheck.tdMovementHistory = tHistoryCheckStore.tdPostingHistMovementCreditLC
               tqHistoryPostingsCheck.tdMovementTrans   = tHistoryCheckStore.tdPostingMovementCreditLC  
               tqHistoryPostingsCheck.tdBalanceHistory  = tHistoryCheckStore.tdPostingHistBalanceCreditLC
               tqHistoryPostingsCheck.tdBalanceTrans    = tHistoryCheckStore.tdPostingBalanceCreditLC
               tqHistoryPostingsCheck.tcSafConcatination = vcConcatinatedSaf
               tqHistoryPostingsCheck.tcMark     = {&CREDITDEBITABBREVIATION-CREDIT-TR}
               tqHistoryPostingsCheck.tcCurrType = {&CURRENCYTYPE-ABBREV-LC-TR}.
    end.
    if tHistoryCheckStore.tdPostingBalanceCreditTC  <> tHistoryCheckStore.tdPostingHistBalanceCreditTC or 
       tHistoryCheckStore.tdPostingMovementCreditTC <> tHistoryCheckStore.tdPostingHistMovementCreditTC
    then do:
        create tqHistoryPostingsCheck.
        buffer-copy tHistoryCheckStore to tqHistoryPostingsCheck.
        assign tqHistoryPostingsCheck.tdMovementHistory = tHistoryCheckStore.tdPostingHistMovementCreditTC
               tqHistoryPostingsCheck.tdMovementTrans   = tHistoryCheckStore.tdPostingMovementCreditTC  
               tqHistoryPostingsCheck.tdBalanceHistory  = tHistoryCheckStore.tdPostingHistBalanceCreditTC
               tqHistoryPostingsCheck.tdBalanceTrans    = tHistoryCheckStore.tdPostingBalanceCreditTC
               tqHistoryPostingsCheck.tcSafConcatination = vcConcatinatedSaf
               tqHistoryPostingsCheck.tcMark     = {&CREDITDEBITABBREVIATION-CREDIT-TR}
               tqHistoryPostingsCheck.tcCurrType = {&CURRENCYTYPE-ABBREV-TC-TR}.
    end.
    if tHistoryCheckStore.tdPostingBalanceCreditCC  <> tHistoryCheckStore.tdPostingHistBalanceCreditCC or
       tHistoryCheckStore.tdPostingMovementCreditCC <> tHistoryCheckStore.tdPostingHistMovementCreditCC
    then do:
        create tqHistoryPostingsCheck.
        buffer-copy tHistoryCheckStore to tqHistoryPostingsCheck.
        assign tqHistoryPostingsCheck.tdMovementHistory = tHistoryCheckStore.tdPostingHistMovementCreditCC 
               tqHistoryPostingsCheck.tdMovementTrans   = tHistoryCheckStore.tdPostingMovementCreditCC  
               tqHistoryPostingsCheck.tdBalanceHistory  = tHistoryCheckStore.tdPostingHistBalanceCreditCC
               tqHistoryPostingsCheck.tdBalanceTrans    = tHistoryCheckStore.tdPostingBalanceCreditCC
               tqHistoryPostingsCheck.tcSafConcatination = vcConcatinatedSaf
               tqHistoryPostingsCheck.tcMark = {&CREDITDEBITABBREVIATION-CREDIT-TR}
               tqHistoryPostingsCheck.tcCurrType = {&CURRENCYTYPE-ABBREV-CC-TR}.               
    end.
end.

if not available tqHistoryPostingsCheck
then do:
    create tqHistoryPostingsCheck.
    assign tqHistoryPostingsCheck.tiExceptionNbr = -1
           tqHistoryPostingsCheck.tcExceptionMsg = #T-12'No differences found for the selected period':255(57229)T-12#. 
end.