project QadFinancials > class TConCheck > method CrossCompany

Description

Consistency check of cross company.


Parameters


icFileinputcharacter
ocConCheckLineDetResultoutputcharacter
otConCheckLineDetStartDateoutputdate
oiConCheckLineDetStartTimeoutputinteger
oiConCheckLineDetDurationoutputinteger
iiCompanyIDinputinteger
iiPeriodIDinputinteger
iiSessionIDinputinteger
oiErrorNumbersoutputinteger
ocConCheckLineDetVersionoutputcharacter
icAppVersioninputcharacter
icSumFileinputcharacterSummary file
ihTranslationHandleinputhandle
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method TConCheck.MainEntry


program code (program1/tconcheck.p)

/* ============================================================================================ */
/* This is the method for checking Cross-Company                                                */
/* ============================================================================================ */
/* Validations:                                                                                 */
/* ERROR1		PostingLine.CrossCompanyPostingLine_ID field is empty                           */
/* ERROR2		Cross Company and Current company are the same, no Further validations done     */
/* ERROR3		CrossCyPostingLine not found                                                    */
/* ERROR4		Posting of CrossCyPostingLine not found                                         */
/* ERROR5		Posting of CrossCyPostingLine not found                                         */
/* ERROR6		Mismatch in Posting_ID                                                          */
/* ERROR7		Mismatch in Company_ID                                                          */
/* ERROR8		DayBook of CrossCyPostingLine not found                                         */
/* ERROR9		Mismatch between Source and Target fields                                       */
/* ERROR10		Target GL not found                                                             */
/* ERROR11		Target GL has wrong type:                                                       */
/* ERROR13		Mismatch in InterCoBusinessRelation_ID                                          */
/* ERROR12		ismatch in TC Amounts, they should be the inverse                               */
/* ERROR14 	    Multiple PostingLines found which reference the postingline with PostingLine_ID */
/* ERROR15		No PostingLine found which references this postingline with PostingLine_ID      */
/* ============================================================================================ */

/* define buffers */
DEFINE BUFFER   bPostingLine                FOR PostingLine.
DEFINE BUFFER   TargetPosting               FOR Posting.
DEFINE BUFFER   TargetPostingostingLine     FOR PostingLine.
DEFINE BUFFER   TargetCompany               FOR Company.
DEFINE BUFFER   TargetGL                    FOR GL.
DEFINE BUFFER   TargetCompanyProperty       FOR CompanyProperty.
DEFINE BUFFER   TargetBusinessRelation      FOR BusinessRelation.
DEFINE BUFFER   TargetJournal               FOR Journal.

empty temp-table tCrossCompanyBalance.

assign oiReturnStatus = -98.

assign vdStartEtime               = etime(no)
       otConCheckLineDetStartDate = now
       oiConCheckLineDetStartTime = time
       oiErrorNumbers             = 0
       ocConCheckLineDetVersion   = icAppVersion + '.1'.

/* open logfile stream */
OUTPUT STREAM sTechOut TO value(icFile) APPEND. 
OUTPUT STREAM sSumOut TO value(icSumFile) APPEND. 

put stream sTechOut unformatted ' 'skip.
put stream sTechOut unformatted '##### Cross-Company accounts #####' skip.
PUT STREAM sTechOut unformatted 'Version: ' ocConCheckLineDetVersion skip.
put stream sTechOut unformatted 'Validation Start At: '  string(now, '99/99/9999 HH:MM:SS') skip.

MAIN_BLOCK: 
do:
    /* init values */
    assign ocConCheckLineDetResult = {&CONCHECKRESULT-PASSED}.
    
    /* ====================================================== */
    /* Step1 - checking input parameters and initializing     */
    /* ====================================================== */
    if iiCompanyID = ? or iiCompanyID = 0 
    then do:
       assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
       PUT STREAM sTechOut unformatted "**Error** Input parameter CompanyID is null." skip. 
       LEAVE MAIN_BLOCK.
    end.

    find Company where
         Company.Company_ID = iiCompanyID
         no-lock no-error.
    if not available Company
    then do :
       assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
       PUT STREAM sTechOut unformatted "**Error** Company is not found with iiCompanyID= " iiCompanyID "." skip. 
       LEAVE MAIN_BLOCK.
    end.

    find CompanyProperty of Company 
         no-lock no-error.
         
    for each CompanySharedSet of Company no-lock, each SharedSet of CompanySharedSet where SharedSetType = "EXCHANGERATE":U no-lock:
        assign viLocalExchangeRateSharedSetId = SharedSet.SharedSet_Id.
    end. 

    if iiPeriodID = ? or iiPeriodID = 0 
    then do:
       assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
       PUT STREAM sTechOut unformatted "**Error** Input parameter PeriodID is null." skip. 
       LEAVE MAIN_BLOCK.
    end.
    
    /* get YearPeriod */
    find first Period where 
               Period.Period_ID = iiPeriodID 
               no-lock no-error.
    if not available Period
    then do:
        assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
        PUT STREAM sTechOut unformatted "**Error** Unable to find period year period during HistInvoice checking." skip. 
        LEAVE MAIN_BLOCK.
    end.
    assign viSelYearperiod = Period.PeriodYearPeriod.

   
    /* ========================================================================== */
    /* Step 2 - Start validations                                                 */
    /* Get tot debitlc/tc/cc & creditlc/tc/cc of CROSSCOMPANY from PostingLine    */
    /* Check the total debit/credit lc/tc/cc amount are equal for Cross-Company.  */
    /* ========================================================================== */
    assign vdTotDebitLC  = 0 
           vdTotDebitTC  = 0
           vdTotDebitCC  = 0
           vdTotCreditLC = 0
           vdTotCreditTC = 0
           vdTotCreditCC = 0.

    /* ========================================================================== */
    /* Run the validations                                                        */
    /* ========================================================================== */
    for each GL where
             GL.GLTYPECode = {&GLTYPECODE-CROSS}
             no-lock:
        
        /* for each postingLine on a CrossCy account we should exactly 1 PostingLine in the Target Company */
        for each PostingLine where
                 PostingLine.Company_ID        = Company.Company_ID and
                 PostingLine.GL_ID             = GL.GL_ID and
                 PostingLine.PostingYearPeriod = viSelYearPeriod,
            first Posting of PostingLine no-lock,
            first Journal of Posting no-lock :
            
            /* In case the PostingLine is still in the Daemon Queue we skip it */               
            if can-find (first QCrossCyPosting where
                               QCrossCyPosting.OriginatorPostingLine_ID = PostingLine.PostingLine_ID)
            then next.

            /* assign the Key based in both ID's so we can use this for sorting in xls */                                              
            assign vcKeyTechnical = if PostingLine.CrossCompanyPostingLine_ID > PostingLine.PostingLine_ID
                            then string (PostingLine.PostingLine_ID) + "-" + string (PostingLine.CrossCompanyPostingLine_ID)
                            else string (PostingLine.CrossCompanyPostingLine_ID) + "-" + string (PostingLine.PostingLine_ID)
                   vcKeyLogical = Company.CompanyCode + '/' +
                            string (Posting.PostingYearPeriod) + '/' + 
                            Journal.JournalCode + '/' + 
                            string (Posting.PostingVoucher) + '/' +
                            string (PostingLine.PostingLineSequence)
                   vcKeyTarget = ''. 

            assign vicnt1 = 0.
            for each bPostingLine where
                     bPostingLine.CrossCompanyPostingLine_ID = PostingLine.PostingLine_ID
                     no-lock :
                assign vicnt1 = vicnt1 + 1.    
            end.

            /* Multiple references found */
            if viCnt1 > 1
            then do :
                assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                assign oiErrorNumbers = oiErrorNumbers + 1.
                PUT STREAM sTechOut unformatted
                    'ERROR14;'                    
                    vcKeyLogical ';' 
                    vcKeyTechnical ';'
                    vcKeyTarget ';' 
                    'Multiple PostingLines found which reference the postingline with PostingLine_ID:' PostingLine.PostingLine_ID ';'
                     vicnt1 ';'
                   skip.
                next.
            end.

            /* No reference found */        
            if viCnt1 = 0
            then do :
                assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                assign oiErrorNumbers = oiErrorNumbers + 1.
                PUT STREAM sTechOut unformatted
                    'ERROR15;'
                    vcKeyLogical ';' 
                    vcKeyTechnical ';'
                    vcKeyTarget ';'                 
                    'No PostingLine found which references this postingline with PostingLine_ID:' PostingLine.PostingLine_ID ';'
                    vicnt1 ';'
                   skip.
                next.
            end.

            /* Check if the Cross Cy fields are empty */
            if PostingLine.CrossCompanyPostingLine_ID = 0 or PostingLine.CrossCompanyPostingLine_ID = ?
            then do:
                assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                assign oiErrorNumbers = oiErrorNumbers + 1.
                PUT STREAM sTechOut unformatted
                    'ERROR1;'
                    vcKeyLogical ';' 
                    vcKeyTechnical ';'
                    vcKeyTarget ';'                 
                   'PostingLine.CrossCompanyPostingLine_ID field is empty;'
                   skip.                
                next.               
            end.

            /* Check if the CrossCompany is really different */                              
            if PostingLine.CrossCompany_ID = PostingLine.Company_ID
            then do:
                assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                assign oiErrorNumbers = oiErrorNumbers + 1.
                PUT STREAM sTechOut unformatted
                    'ERROR2;'
                    vcKeyLogical ';'                
                    vcKeyTechnical ';'
                    vcKeyTarget ';'                                 
                   'Cross Company and Current company are the same, no Further validations done;'
                   skip.                
                next.               
            end. 

            /* ============================================================================================== */
            /* In case the CrossCompanyPostingLine_ID is filled in, we can do more validations                */
            /* ============================================================================================== */ 
            if PostingLine.CrossCompanyPostingLine_ID <> 0 and PostingLine.CrossCompanyPostingLine_ID <> ?
            then do:
                
                /* Get the Target Posting Line ussing CrossCy link*/            
                find TargetPostingostingLine where 
                     TargetPostingostingLine.PostingLine_ID = PostingLine.CrossCompanyPostingLine_ID 
                     no-lock no-error.
                if not available TargetPostingostingLine
                then do:
                    assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                    PUT STREAM sTechOut unformatted
                        'ERROR3; '
                        vcKeyLogical ';'                    
                        vcKeyTechnical ';'
                        vcKeyTarget ';'                                     
                        'CrossCyPostingLine not found: ' string (PostingLine.CrossCompanyPostingLine_ID) ';'
                        skip.                                    
                    next.    
                end.

                /* Get the Target Posting using normal relationship */
                find TargetPosting of TargetPostingostingLine no-lock no-error.
                if not available TargetPosting
                then do :
                    assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                    PUT STREAM sTechOut unformatted
                        'ERROR4; '
                        vcKeyLogical ';'                    
                        vcKeyTechnical ';'
                        vcKeyTarget ';'                                     
                        'Posting of CrossCyPostingLine not found: ' string (TargetPostingostingLine.Posting_ID) ';'
                        skip.    
                    next.
                end.

                /* Get the Target using normal relationship */
                find TargetCompany of TargetPosting no-lock no-error.
                if available TargetCompany            
                then find TargetCompanyProperty of TargetCompany no-lock no-error.
                
                if not available TargetCompany or not available TargetCompanyProperty
                then do :
                     assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                     assign oiErrorNumbers = oiErrorNumbers + 1.
                     PUT STREAM sTechOut unformatted
                        'ERROR5;'
                        vcKeyLogical ';'  
                        vcKeyTechnical ';'
                        vcKeyTarget ';'                                     
                        'Posting of CrossCyPostingLine not found: ' string (TargetPosting.Company_ID) ';'
                        skip.                    
                    next.
                end.

                /* Validate the consistency of these properties: Posting_ID  */
                if TargetPosting.Posting_ID <> PostingLine.CrossCompanyPosting_ID
                then do:
                    assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                    PUT STREAM sTechOut unformatted
                        'ERROR6;'
                        vcKeyLogical ';'  
                        vcKeyTechnical ';'
                        vcKeyTarget ';'                                     
                        'Mismatch in Posting_ID;' 
                        skip.                
                end.

                /* Validate the consistency of these properties: Company_ID  */
                if TargetCompany.Company_ID <> PostingLine.CrossCompany_ID
                then do:
                    assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                    PUT STREAM sTechOut unformatted
                        'ERROR7;'
                        vcKeyLogical ';' 
                        vcKeyTechnical ';'
                        vcKeyTarget ';'                                     
                        'Mismatch in Company_ID;' 
                        skip.                        
                end.

                /* Validate the consistency of these properties: InterCoBusinessRelation_ID  */
                find TargetBusinessRelation of TargetCompanyProperty 
                     no-lock no-error.
                     
                if PostingLine.InterCoBusinessRelation_ID <> TargetBusinessRelation.BusinessRelation_id
                then do:
                    assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                    PUT STREAM sTechOut unformatted
                        'ERROR13;'
                        vcKeyLogical ';' 
                        vcKeyTechnical ';'
                        vcKeyTarget ';'                                     
                        'Mismatch in InterCoBusinessRelation_ID;'
                        skip.
                end.

                /* Get other Properties */
                find TargetJournal of TargetPosting no-lock no-error.
                if not available TargetJournal
                then do :
                     assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                     assign oiErrorNumbers = oiErrorNumbers + 1.
                     PUT STREAM sTechOut unformatted
                        'ERROR8;'
                        vcKeyLogical ';'
                        vcKeyTechnical ';'
                        vcKeyTarget ';'                                     
                        'DayBook of CrossCyPostingLine not found: ' string (TargetPosting.Journal_ID) ';'
                        skip.                    
                    next.
                end.

                /* assign the Logical Key of the target posting */
                assign vcKeyTarget = TargetCompany.CompanyCode + '/' +
                                string (TargetPosting.PostingYearPeriod) + '/' + 
                                TargetJournal.JournalCode + '/' + 
                                string (TargetPosting.PostingVoucher) + '/' +
                                string(TargetPostingostingLine.PostingLineSequence).

                /* check if the Fields of the source matches the fields of the target */                                     
                if PostingLine.CrossCompanyPostingLine_ID <> TargetPostingostingLine.PostingLine_ID  or
                   TargetPostingostingLine.CrossCompanyPostingLine_ID <> PostingLine.PostingLine_ID              
                then do:
                    assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                    PUT STREAM sTechOut unformatted
                        'ERROR9;'
                        vcKeyLogical ';'                        
                        vcKeyTarget ';'
                        vcKeyTechnical ';'
                        'Mismatch between Source and Target fields;' 
                        Posting.Company_ID ';' TargetPostingostingLine.CrossCompany_ID ';' 
                        PostingLine.Posting_ID ';' TargetPostingostingLine.CrossCompanyPosting_ID ';'
                        PostingLine.PostingLine_ID ';' TargetPostingostingLine.CrossCompanyPostingLine_ID ';'  
                        skip.                                        
                end.

                /* get the Account of the Target PL */
                find TargetGL of TargetPostingostingLine no-lock no-error.
                if not available TargetGL
                then do :
                    assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                    PUT STREAM sTechOut unformatted
                        'ERROR10;'
                        vcKeyLogical ';'
                        vcKeyTechnical ';'
                        vcKeyTarget ';'              
                        'Target GL not found;'
                        skip.
                end.
                else
                if TargetGL.GLTYPECode <> 'CROSSCOMPANY'
                then do:
                    assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                    assign oiErrorNumbers = oiErrorNumbers + 1.
                    PUT STREAM sTechOut unformatted
                        'ERROR11;'
                        vcKeyLogical ';'
                        vcKeyTechnical ';'
                        vcKeyTarget ';'              
                        'Target GL has wrong type: ' TargetGL.GLTYPECode ';'
                        skip.                                    
                end.

                find first tCrossCompanyBalance where tCrossCompanyBalance.tiGLID = PostingLine.GL_ID and
                                                      tCrossCompanyBalance.tiCurrencyID = PostingLine.Currency_ID and
                                                      tCrossCompanyBalance.tiTargetCompanyID = TargetPostingostingLine.Company_ID and
                                                      tCrossCompanyBalance.tiTargetGLID = TargetPostingostingLine.GL_ID and
                                                      tCrossCompanyBalance.tiTargetCurrencyID = TargetPostingostingLine.Currency_ID no-error.

                if not available tCrossCompanyBalance
                then do:
                    create tCrossCompanyBalance.
                    assign tCrossCompanyBalance.tiGLID = PostingLine.GL_ID
                           tCrossCompanyBalance.tiCurrencyID = PostingLine.Currency_ID
                           tCrossCompanyBalance.tiTargetCompanyID = TargetPostingostingLine.Company_ID
                           tCrossCompanyBalance.tiTargetGLID = TargetPostingostingLine.GL_ID
                           tCrossCompanyBalance.tiTargetCurrencyID = TargetPostingostingLine.Currency_ID
                           tCrossCompanyBalance.tcGLCode = GL.GLCode
                           tCrossCompanyBalance.tcTargetGLCode = TargetGL.GLCode
                           tCrossCompanyBalance.tcTargetCompanyCode = TargetCompany.CompanyCode.
                    for first Currency where Currency.Currency_ID = PostingLine.Currency_ID no-lock:
                        assign tCrossCompanyBalance.tcCurrencyCode = Currency.CurrencyCode.
                    end.
                    for first Currency where Currency.Currency_ID = TargetPostingostingLine.Currency_ID no-lock:
                        assign tCrossCompanyBalance.tcTargeCurrencyCode = Currency.CurrencyCode.
                    end.
                    for first DomainProperty where DomainProperty.Domain_ID = Company.Domain_ID no-lock:
                        for first Currency where Currency.Currency_ID = DomainProperty.Currency_ID no-lock:
                            assign tCrossCompanyBalance.tcCompanyLC = Currency.CurrencyCode.
                        end.
                        for first Currency where Currency.Currency_ID = DomainProperty.StatutoryCurrency_ID no-lock:
                            assign tCrossCompanyBalance.tcCompanyCC = Currency.CurrencyCode.
                        end.
                    end.
                    for first DomainProperty where DomainProperty.Domain_ID = TargetCompany.Domain_ID no-lock:
                        for first Currency where Currency.Currency_ID = DomainProperty.Currency_ID no-lock:
                            assign tCrossCompanyBalance.tcTargetCompanyLC = Currency.CurrencyCode.
                        end.
                        for first Currency where Currency.Currency_ID = DomainProperty.StatutoryCurrency_ID no-lock:
                            assign tCrossCompanyBalance.tcTargetCompanyCC = Currency.CurrencyCode.
                        end.
                    end.     
                end.
                assign tCrossCompanyBalance.tdPostingLineBalanceTC = tCrossCompanyBalance.tdPostingLineBalanceTC + PostingLine.PostingLineDebitTC - PostingLine.PostingLineCreditTC
                       tCrossCompanyBalance.tdPostingLineBalanceLC = tCrossCompanyBalance.tdPostingLineBalanceLC + PostingLine.PostingLineDebitLC - PostingLine.PostingLineCreditLC
                       tCrossCompanyBalance.tdPostingLineBalanceCC = tCrossCompanyBalance.tdPostingLineBalanceCC + PostingLine.PostingLineDebitCC - PostingLine.PostingLineCreditCC
                       tCrossCompanyBalance.tdTargetPostingLineBalanceTC = tCrossCompanyBalance.tdTargetPostingLineBalanceTC + TargetPostingostingLine.PostingLineDebitTC - TargetPostingostingLine.PostingLineCreditTC
                       tCrossCompanyBalance.tdTargetPostingLineBalanceLC = tCrossCompanyBalance.tdTargetPostingLineBalanceLC + TargetPostingostingLine.PostingLineDebitLC - TargetPostingostingLine.PostingLineCreditLC
                       tCrossCompanyBalance.tdTargetPostingLineBalanceCC = tCrossCompanyBalance.tdTargetPostingLineBalanceCC + TargetPostingostingLine.PostingLineDebitCC - TargetPostingostingLine.PostingLineCreditCC.
                assign viTargetExchangeRateSharedSetId = 0.
                for each CompanySharedSet where CompanySharedSet.Company_ID =  tCrossCompanyBalance.tiTargetCompanyID no-lock, 
                    each SharedSet of CompanySharedSet where SharedSetTypeCode = "EXCHANGERATE":U no-lock:
                    assign viTargetExchangeRateSharedSetId = SharedSet.SharedSet_Id.
                end. 
                /* Check the TC Amounts */                                                  
                if TargetPostingostingLine.Currency_ID  = PostingLine.Currency_ID and
                   TargetPostingostingLine.PostingDate = PostingLine.PostingDate and
                   viTargetExchangeRateSharedSetId  = viLocalExchangeRateSharedSetId   
                then do:
                    if TargetPostingostingLine.PostingLineDebitTC  <> Postingline.PostingLineCreditTC or
                       TargetPostingostingLine.PostingLineCreditTC <> Postingline.PostingLineDebitTC              
                    then do:
                        assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                        assign oiErrorNumbers = oiErrorNumbers + 1.
                        PUT STREAM sTechOut unformatted
                            'ERROR12;'
                            vcKeyLogical ';'
                            vcKeyTechnical ';'
                            vcKeyTarget ';'
                            'Mismatch in TC Amounts, they should be the inverse;' 
                            'DtTC:' PostingLine.PostingLineDebitTC ';'
                            'CtTC:' PostingLine.PostingLineCreditTC ';'
                            'Target DtTC:' TargetPostingostingLine.PostingLineDebitTC ';'
                            'Target CtTC:' TargetPostingostingLine.PostingLineCreditTC ';'
                            skip.                                                        
                    end.

                end. /* check TC Amounts */
                
                /* Check the BC Amounts */                                                  
                if tCrossCompanyBalance.tcCompanyLC = tCrossCompanyBalance.tcTargetCompanyLC and
                   TargetPostingostingLine.PostingDate = PostingLine.PostingDate and
                   viTargetExchangeRateSharedSetId  = viLocalExchangeRateSharedSetId                  
                then do:
                    if TargetPostingostingLine.PostingLineDebitLC  <> Postingline.PostingLineCreditLC or
                       TargetPostingostingLine.PostingLineCreditLC <> Postingline.PostingLineDebitLC              
                    then do:
                        assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                        assign oiErrorNumbers = oiErrorNumbers + 1.
                        PUT STREAM sTechOut unformatted
                            'ERROR12;'
                            vcKeyLogical ';'
                            vcKeyTechnical ';'
                            vcKeyTarget ';'
                            'Mismatch in BC Amounts, they should be the inverse;' 
                            'DtBC:' PostingLine.PostingLineDebitLC ';'
                            'CtBC:' PostingLine.PostingLineCreditLC ';'
                            'Target DtBC:' TargetPostingostingLine.PostingLineDebitLC ';'
                            'Target CtBC:' TargetPostingostingLine.PostingLineCreditLC ';'
                            skip.                                                        
                    end.

                end. /* check BC Amounts */
                
                /* Check the SC Amounts */                                                  
                if tCrossCompanyBalance.tcCompanyCC = tCrossCompanyBalance.tcTargetCompanyCC and
                   TargetPostingostingLine.PostingDate = PostingLine.PostingDate and
                   viTargetExchangeRateSharedSetId  = viLocalExchangeRateSharedSetId                  
                then do:
                    if TargetPostingostingLine.PostingLineDebitCC  <> Postingline.PostingLineCreditCC or
                       TargetPostingostingLine.PostingLineCreditCC <> Postingline.PostingLineDebitCC              
                    then do:
                        assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.
                        assign oiErrorNumbers = oiErrorNumbers + 1.
                        PUT STREAM sTechOut unformatted
                            'ERROR12;'
                            vcKeyLogical ';'
                            vcKeyTechnical ';'
                            vcKeyTarget ';'
                            'Mismatch in SC Amounts, they should be the inverse;' 
                            'DtSC:' PostingLine.PostingLineDebitCC ';'
                            'CtSC:' PostingLine.PostingLineCreditCC ';'
                            'Target DtSC:' TargetPostingostingLine.PostingLineDebitCC ';'
                            'Target CtSC:' TargetPostingostingLine.PostingLineCreditCC ';'
                            skip.                                                        
                    end.

                end. /* check SC Amounts */


            end. /* if PostingLine.CrossCompanyPostingLine_ID <> 0 and PostingLine.CrossCompanyPostingLine_ID <> ? */

        end. /* for each PostingLine of GL no-lock */
         
    end. /* for each GL where */


end. /* MAIN_BLOCK: */

assign oiConCheckLineDetDuration = etime - vdStartEtime.

if oiErrorNumbers > 0
then assign ocConCheckLineDetResult = {&CONCHECKRESULT-FAILED}.

/* to format the total duration time */
assign viMilliSecs = oiConCheckLineDetDuration
       viSecs = TRUNCATE (oiConCheckLineDetDuration / 1000, 0)
       viMilliSecs = viMilliSecs mod 1000
       vcTotalTime = string(viSecs, 'HH:MM:SS')  +  '.'  +  string(viMilliSecs).

/* log passed or failed status */
put stream sTechOut unformatted 'Execution Duration: ' vcTotalTime skip. 
put stream sTechOut unformatted 'Execution Result: ' ocConCheckLineDetResult skip.
put stream sTechOut  unformatted '<Error Count:> ' oiErrorNumbers skip.
put stream sTechOut unformatted '**********************************************************************' skip.

/* close log file stream */
OUTPUT STREAM sTechOut CLOSE. 
put stream sSumOut unformatted ' ' skip.
PUT STREAM sSumOut unformatted trim({&CONCHECKLINEDETTYPE-CROSSCOMPANY-TR}) skip.
PUT STREAM sSumOut unformatted '----------------------' skip.
put stream sSumOut unformatted trim(#T-5'Execution Result':255(510391963)T-5#) + ': ' + ocConCheckLineDetResult skip.

if oiErrorNumbers > 0
then do:

     put stream sSumOut unformatted 
                        trim(#T-61'Total number of errors':100(376712702)T-61#)
                        + ': ' + string(oiErrorNumbers) skip.
     put stream sSumOut unformatted 
                        '(' 
                        trim(#T-48'Please see details in the file':150(806040074)T-48#) ' ' icFile ')' skip.        
end.
if can-find (first tCrossCompanyBalance)
then do:
    put stream sSumOut unformatted ' ' skip.
    put stream sSumOut unformatted 
                    trim(#T-3'Summary of totals':20(886252833)T-3#)
    ':' skip.
    put stream sSumOut unformatted 
                    trim(#T-2'Side':20(442868025)T-2#) at 1
                    trim(#T-51'Entity':20(210)T-51#) to 20
                    trim(#T-14'GL':20(199)T-14#)  to 32
                    trim(#T-79'Amount TC':15(68576)T-79#) to 52
                    trim(#T-17'Curr':10(1003)T-17#) to 58  
                    trim(#T-57'Amount BC':15(246632698)T-57#) to 78
                    trim(#T-32'Curr':10(1003)T-32#) to 83
                    trim(#T-84'Amount SC':20(130157251)T-84#) to 103 
                    trim(#T-68'Curr':10(1003)T-68#) to 108
                                   skip.
                                   
    for each tCrossCompanyBalance:
        <M-63 run RoundAmount
           (input-output tCrossCompanyBalance.tdPostingLineBalanceTC (bdUnroundedAmount), 
            input  tCrossCompanyBalance.tiCurrencyID (iiCurrencyId), 
            input  ? (icCurrencyCode), 
            output vcFormatedAmountTC (ocFormatedAmount), 
            output viFcReturnSuper (oiReturnStatus)) in TConCheck>
        <M-6 run RoundAmount
           (input-output tCrossCompanyBalance.tdPostingLineBalanceLC (bdUnroundedAmount), 
            input  ? (iiCurrencyId), 
            input  tCrossCompanyBalance.tcCompanyLC (icCurrencyCode), 
            output vcFormatedAmountLC (ocFormatedAmount), 
            output viFcReturnSuper (oiReturnStatus)) in TConCheck>
        <M-46 run RoundAmount
           (input-output tCrossCompanyBalance.tdPostingLineBalanceCC (bdUnroundedAmount), 
            input  ? (iiCurrencyId), 
            input  tCrossCompanyBalance.tcCompanyCC (icCurrencyCode), 
            output vcFormatedAmountCC (ocFormatedAmount), 
            output viFcReturnSuper (oiReturnStatus)) in TConCheck>
        put stream sSumOut unformatted trim(#T-54'Source':255(69134)T-54#)  at 1
                                       Company.CompanyCode to 20
                                       tCrossCompanyBalance.tcGLCode to 32
                                       vcFormatedAmountTC to 52 
                                       tCrossCompanyBalance.tcCurrencyCode to 58
                                       vcFormatedAmountLC to 78 
                                       tCrossCompanyBalance.tcCompanyLC to 83
                                       vcFormatedAmountCC to 103 
                                       tCrossCompanyBalance.tcCompanyCC to 108 skip.
        <M-95 run RoundAmount
           (input-output tCrossCompanyBalance.tdTargetPostingLineBalanceTC (bdUnroundedAmount), 
            input  tCrossCompanyBalance.tiTargetCurrencyID (iiCurrencyId), 
            input  ? (icCurrencyCode), 
            output vcFormatedAmountTC (ocFormatedAmount), 
            output viFcReturnSuper (oiReturnStatus)) in TConCheck>
        <M-85 run RoundAmount
           (input-output tCrossCompanyBalance.tdTargetPostingLineBalanceLC (bdUnroundedAmount), 
            input  ? (iiCurrencyId), 
            input  tCrossCompanyBalance.tcTargetCompanyLC (icCurrencyCode), 
            output vcFormatedAmountLC (ocFormatedAmount), 
            output viFcReturnSuper (oiReturnStatus)) in TConCheck>
        <M-58 run RoundAmount
           (input-output tCrossCompanyBalance.tdTargetPostingLineBalanceCC (bdUnroundedAmount), 
            input  ? (iiCurrencyId), 
            input  tCrossCompanyBalance.tcTargetCompanyCC (icCurrencyCode), 
            output vcFormatedAmountCC (ocFormatedAmount), 
            output viFcReturnSuper (oiReturnStatus)) in TConCheck>
        put stream sSumOut unformatted trim(#T-33'Target':19(1613)T-33#)   at 1
                                       tCrossCompanyBalance.tcTargetCompanyCode to 20
                                       tCrossCompanyBalance.tcTargetGLCode to 32
                                       vcFormatedAmountTC to 52
                                       tCrossCompanyBalance.tcTargeCurrencyCode to 58
                                       vcFormatedAmountLC to 78
                                       tCrossCompanyBalance.tcTargetCompanyLC to 83
                                       vcFormatedAmountCC to 103 
                                       tCrossCompanyBalance.tcTargetCompanyCC to 108 skip.
        put stream sSumOut unformatted ' ' skip.    
    end. /* for each tCrossCompanyBalance */
end.
put stream sSumOut unformatted "____________________________________________________________" skip.
OUTPUT STREAM sSumOut CLOSE. 

if oiReturnStatus = -98
then assign oiReturnStatus = 0.