project QadFinancials > class BPosting > method AddStandardPosting

Description

add a posting line on any gl account (except control and VAT accounts) to current posting


Parameters


icPostingtcRowidinputcharactertposting.tc_Rowid
icGLCodeinputcharactergl account
icDivisionCodeinputcharacterSub-Account
icCostCentreCodeinputcharactercost centre
icCostCentreTextinputcharacterText
icProjectCodeinputcharacterproject
icProjectTextinputcharacterText
icIntercoBusinessRelationCodeinputcharacterinterco
icCurrencyCodeinputcharactercurrency
idDebitTCinputdecimalDebitTC
idDebitLCinputdecimalDebitLC (use NULL if value should be calculated)
idDebitCCinputdecimalDebitCC (use NULL if value should be calculated)
idDebitPCinputdecimalDebitPC (use NULL if value should be calculated)
idCreditTCinputdecimalCreditTC
idCreditLCinputdecimalCreditLC (use NULL if value should be calculated)
idCreditCCinputdecimalCreditCC (use NULL if value should be calculated)
idCreditPCinputdecimalCreditPC (use NULL if value should be calculated)
idQtyinputdecimalQuantity
icLineTextinputcharacterText
icSafTextinputcharacterText
tDefaultSafsinputtemp-tabledefault saf's
icExchangeRateTypeinputcharacterexchange rate type
idExchangeRateinputdecimal
idExchangeRateScaleinputdecimal
idPostingLineCCRateinputdecimal
idPostingLineCCScaleinputdecimal
oiPostingLineIdoutputintegerPosting Line ID
iiSafStructureIdinputintegerSaf Structure ID : necessary for posting on project, cost centre, .. so that you knows which saf structure you must take, if this is blank, then the first one will be taken
icSafStructureCodeinputcharacterSaf Structure Code : necessary for posting on project, cost centre, .. so that you knows which saf structure you must take, if this is blank, then the first one will be taken
icAllocationKeyinputcharacter
ilLinkedCrCyDaemonReqExistsinputlogical
itExchangeRateDateinputdate
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.AdditionalUpdatesAllCosts
method BAPMatching.AdditionalUpdatesAllCreatePLCirec
method BAPMatching.AdditionalUpdatesAllLinesPLAddPostingLine
method BAPMatching.AdditionalUpdatesAllLinesPLAddPostingLineOpAllocCode
method BBankEntry.AdditionalUpdatesInv
method BBankEntry.AdditionalUpdatesInvCurrDiff
method BBankEntry.AdditionalUpdatesInvDeductions
method BBankEntry.AdditionalUpdatesInvDiscountCurrDiff
method BBankEntry.AdditionalUpdatesInvDiscountCurrDiffTax
method BBankEntry.AdditionalUpdatesInvRounding
method BCDocument.AdditionalUpdatesPostingCrossCy
method BCDocument.AdditionalUpdatesPostingDocCtrl
method BCDocument.AdditionalUpdatesPostingDocCtrl3
method BCDocument.AdditionalUpdatesPostingPrePayment
method BCDocument.AdditionalUpdatesPostingRounding
method BCDocument.AdditionalUpdatesPostingXrefCIDisc
method BCDocument.AdditionalUpdatesPostingXrefCIDiscTax
method BCDocument.AdditionalUpdatesPostingXrefCIInt
method BCDocument.AdditionalUpdatesPostingXrefDI
method BCDocument.AdditionalUpdatesPostingXRefWHT
method BCInvoice.CreateCInvoiceMovementsCrossCy
method BCInvoice.CreateCInvoiceMovementsRoundDiff
method BCInvoice.CreateCInvoiceMovementsRoundDiffCC
method BCInvoice.CreateCIPosting2
method BCInvoice.CreateMFPosting
method BConsolid.AdditionalUpdatesPosting
method BDDocument.AdditionalUpdatesPostingDeduction
method BDDocument.AdditionalUpdatesPostingDocCtrl
method BDDocument.AdditionalUpdatesPostingDocCtrl3
method BDDocument.AdditionalUpdatesPostingPrePayment
method BDDocument.AdditionalUpdatesPostingRounding
method BDDocument.AdditionalUpdatesPostingXrefDIDisc
method BDDocument.AdditionalUpdatesPostingXrefDIDisc2
method BDDocument.AdditionalUpdatesPostingXrefDIInt
method BDInvoice.CreateDInvoiceMovementsCrossCy
method BDInvoice.CreateDInvoiceMovementsRoundDiff
method BDInvoice.CreateDInvoiceMovementsRoundDiffCC
method BDInvoice.CreateDInvoicesDeduction
method BDInvoice.CreateDIPosting
method BDInvoice.CreateDIPostingSales
method BDInvoice.UpdateDeductionDetailPosting
method BExpenseNote.ExpNoteRegisterPosting
method BFixedAssetDepreciation.AdditionalUpdatesPosting
method BFixedAssetDisposal.AdditionalUpdatesPosting
method BFixedAssetRevaluation.AdditionalUpdatesPosting
method BGLOpenItemProcessor.GLOpenItemInitializationPosting
method BPosting.AddPostingLineExchRateGainLoss
method BPosting.CreatePostingsFromImport
method BJournalEntry.CreateReverseEntries
method BOpenItemAdjustment.OIAdjCommitSubCheckPostingBalanceLCCC
method BOpenItemAdjustment.OIAdjCommitSubCInvoiceDiscount
method BOpenItemAdjustment.OIAdjCommitSubDInvoiceDiscount
method BQCrossCyPosting.ApiProcessQCrossCyPosting
method BQCrossCyPosting.ApiProcessQCrossCyPostingForAPM
method BSelfBill.ApiCreateInvPrepayPaymentSubPostERD
method BYearClosing.AdditionalUpdatesPostingCloseOpenBS
method BYearClosing.AdditionalUpdatesPostingCloseOpenPL
method BYearClosing.AdditionalUpdatesPostingTrans


program code (program1/bposting.p)

/* ====================================== */
/* Exception handling and param resetting */
/* ====================================== */
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0
       idExchangeRate      = round(idExchangeRate, 10)
       idExchangeRateScale = round(idExchangeRateScale, 10).

if iiSafStructureId   = ? then assign iiSafStructureId   = 0.
if icSafStructureCode = ? then assign icSafStructureCode = "":U.

/* =============== */
/* Start the block */
/* =============== */
ADDSTANDARDPOSTINGBLOCK : DO :
    
    /* ======================= */
    /* Get the correct posting */
    /* ======================= */
    find tPosting where
         tPosting.tc_Rowid = icPostingtcRowid no-error.
    if not available tPosting
    then do:
        assign vcMessage           = trim(substitute(#T-20'Internal error: posting record not found for row ID &1.':150(3199)T-20#, icPostingtcRowid))
               viLocalReturnStatus = -3.
        <M-18 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-873':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave ADDSTANDARDPOSTINGBLOCK.
    end. /* if not available tPosting */
    if itExchangeRateDate = ? then assign itExchangeRateDate = tPosting.PostingDate.
    /* ====================================================================== */
    /* Call submethod that creates the posting-line                           */
    /* After this call: tqGLForPostingLineCreation and tPostingLine are avail */
    /* ====================================================================== */
    <M-1 run AddPostingSub
       (input  icGLCode (icGLCode), 
        input  icDivisionCode (icDivisionCode), 
        input  icCurrencyCode (icCurrencyCode), 
        input  icIntercoBusinessRelationCode (icBusinessRelationIntercoCode), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then Leave ADDSTANDARDPOSTINGBLOCK.
    if not available tqGLForPostingLineCreation or 
       not available tPostingLine
    then do :
        assign vcMessage           = trim(substitute(#T-27'Internal error. The system cannot find the posting record details for row ID '&1'.':255(69655)T-27#, icPostingtcRowid)) + chr(10) + 
                                     trim(substitute(#T-28'Available &1: &2':255(69656)T-28#,"tPostingLine":U,(if available tPostingLine then trim(#T-29'Yes':5(69658)T-29#) else trim(#T-30'No':5(69659)T-30#)) ))  + chr(10) + 
                                     trim(substitute(#T-31'Available &1: &2':255(69656)T-31#,"tqGLForPostingLineCreation":U,(if available tqGLForPostingLineCreation then trim(#T-32'Yes':5(69660)T-32#) else trim(#T-33'No':5(69661)T-33#)) ))
               viLocalReturnStatus = -3.
        <M-34 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-8233':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave ADDSTANDARDPOSTINGBLOCK.
    end. /*  if not available tqGLForPostingLineCreation or  */
    
    /* ==================================================================== */
    /* Assign the values in tPostingLine. The allocation type will be set   */
    /* based on the first (and second) entry of the AllocationKey parameter */
    /* ==================================================================== */
    assign tPostingLine.PostingLineText           = icLineText
           tPostingLine.PostingLineDebitTC        = idDebitTC
           tPostingLine.PostingLineDebitLC        = idDebitLC
           tPostingLine.PostingLineDebitCC        = idDebitCC
           tPostingLine.PostingLineCreditTC       = idCreditTC
           tPostingLine.PostingLineCreditLC       = idCreditLC
           tPostingLine.PostingLineCreditCC       = idCreditCC
           tPostingLine.PostingLineExchangeRate   = if idExchangeRate = 0 or idExchangeRate = ? then 1 else idExchangeRate
           tPostingLine.PostingLineRateScale      = if idExchangeRateScale = 0 or idExchangeRateScale = ? then 1 else idExchangeRateScale
           tPostingLine.tcAllocationKey           = if tPostingLine.tcGLTypeCode = {&GLTYPECODE-OPEN} then entry(1,icAllocationKey,chr(2)) else ?
           tPostingLine.tcAllocationType          = if tPostingLine.tcAllocationKey = "":U or
                                                       tPostingLine.tcAllocationKey = ?
                                                    then {&ALLOCATIONTYPE-LATER}
                                                    else if num-entries(icAllocationKey,chr(2)) > 1 and 
                                                            entry(2,icAllocationKey,chr(2)) = {&ALLOCATIONTYPE-LINK}
                                                         then {&ALLOCATIONTYPE-LINK}
                                                         else {&ALLOCATIONTYPE-NEW}
           tPostingLine.tlLinkedCrCyDaemonReqExists  = ilLinkedCrCyDaemonReqExists
           oiPostingLineId                        = tPostingLine.PostingLine_ID.

    /* ==================================================== */
    /* Retrieve / Set the Analysis on the GL. This is not   */
    /* allowed for YearClosings as they only go to GL-level */
    /* ==================================================== */
    if tPosting.tcPeriodTypeCode <> {&PERIODTYPECODE-YEARCLOSING}
    then do:
        /*  In some cases, the SAFs against the project should be ignored.  This should be documented in the User Guide, as well as fixed in the code. */                                                         
        /* ======================================== */
        /* Set the CostCentre and its optional SAFs */
        /* ======================================== */      
        if tqGLForPostingLineCreation.tlGLIsCostCentreAccount
        then do:        
            if icCostCentreCode = "":U or 
               icCostCentreCode = ?
            then do:
                if tPosting.PostingParentText <> {&POSTINGPARENTTEXT-APMATCHING} and /* Skip this defaulting in case it concerns an APMatchign-posting */
                   tqGLForPostingLineCreation.tiCostCentreProfile_ID <> 0 and 
                   tqGLForPostingLineCreation.tiCostCentreProfile_ID <> ?    
                then do:
                    <Q-2 run GetCostCentreFromProfile (all) (Read) (Cache)
                       (input tPosting.Company_ID, (CompanyId)
                        input tqGLForPostingLineCreation.tiCostCentreProfile_ID, (CostCentreProfileId)
                        output dataset tqCostCentreFromProfile) in BProfile>
                    find first tqCostCentreFromProfile no-error.
                    if available tqCostCentreFromProfile
                    then do:
                        assign tPostingLine.CostCentre_ID           = tqCostCentreFromProfile.tiCostCentre_ID
                               tPostingLine.tcCostCentreCode        = tqCostCentreFromProfile.tcCostCentreCode
                               tPostingLine.tcCostCentreDescription = tqCostCentreFromProfile.tcCostCentreDescription
                               tPostingLine.PostingLineCostCentreText = icCostCentreText.
                        <M-8 run AddDefaultSaf
                           (input  {&POSTINGSAFPARENTTYPE-COSTCENTRE} (icType), 
                            input  tPostingLine.CostCentre_ID (iiObjectId), 
                            input  iiSafStructureId (iiSafStructureId), 
                            input  icSafStructureCode (icSafStructureCode), 
                            input  tPostingLine.GL_ID (iiGLId), 
                            output viFcReturnSuper (oiReturnStatus)) in BPosting>
                        if viFcReturnSuper <> 0
                        then assign viLocalReturnStatus = viFcReturnSuper.
                        if viFcReturnSuper < 0 
                        then Leave ADDSTANDARDPOSTINGBLOCK.
                    end. /* if available tqCostCentreFromProfile */
                end. /* if (tqGLForPostingLineCreation.tiCostCentreProfile_ID <> 0 and */
            end. /* if icCostCentreCode = "":U or  */
            else do:
                <Q-3 run CostCentrePrim (all) (Read) (Cache)
                   (input tPosting.Company_ID, (CompanyId)
                    input 0, (CostCentreID)
                    input icCostCentreCode, (CostCentreCode)
                    output dataset tqCostCentrePrim) in BCostCentre>
                find first tqCostCentrePrim no-error.
                if available tqCostCentrePrim
                then do:
                    assign tPostingLine.CostCentre_ID             = tqCostCentrePrim.tiCostCentre_ID
                           tPostingLine.tcCostCentreCode          = tqCostCentrePrim.tcCostCentreCode
                           tPostingLine.tcCostCentreDescription   = tqCostCentrePrim.tcCostCentreDescription
                           tPostingLine.PostingLineCostCentreText = icCostCentreText.
                    <M-9 run AddDefaultSaf
                       (input  {&POSTINGSAFPARENTTYPE-COSTCENTRE} (icType), 
                        input  tPostingLine.CostCentre_ID (iiObjectId), 
                        input  iiSafStructureId (iiSafStructureId), 
                        input  icSafStructureCode (icSafStructureCode), 
                        input  tPostingLine.GL_ID (iiGLId), 
                        output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    if viFcReturnSuper <> 0
                    then assign viLocalReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0 
                    then Leave ADDSTANDARDPOSTINGBLOCK.
                end. /* if available tqCostCentrePrim */
            end. /* Not if icCostCentreCode = "":U or  */
        end. /* if tqGLForPostingLineCreation.tlGLIsCostCentreAccount */
        
        /* ======================================== */
        /* Set the Project and its optional SAFs    */
        /* ======================================== */
        if tqGLForPostingLineCreation.tcGLAnalysisLimitation   = {&GLANALYSISLIMITATION-EXCLEACHOTHER} and
           tPostingLine.tcCostCentreCode                      <> "":U
        then assign tPostingLine.tcProjectCode        = "":U
                    tPostingLine.tcProjectDescription = "":U
                    tPostingLine.Project_ID           = 0.        
        else if tqGLForPostingLineCreation.tlGLIsProjectAccount
        then do:
            if icProjectCode = "":U
            or icProjectCode = ?
            then do:
                if tPosting.PostingParentText <> {&POSTINGPARENTTEXT-APMATCHING} and /* Skip this defaulting in case it concerns an APMatchign-posting */
                   tqGLForPostingLineCreation.tiProjectProfile_ID <> 0 and 
                   tqGLForPostingLineCreation.tiProjectProfile_ID <> ? 
                then do:
                    <Q-4 run GetProjectFromProfile (all) (Read) (Cache)
                       (input tPosting.Company_ID, (CompanyId)
                        input tqGLForPostingLineCreation.tiProjectProfile_ID, (ProjectProfileID)
                        output dataset tqProjectFromProfile) in BProfile>
                    find first tqProjectFromProfile no-error.
                    if available tqProjectFromProfile 
                    then do:
                        assign tPostingLine.Project_ID             = tqProjectFromProfile.tiProject_ID
                               tPostingLine.tcProjectCode          = tqProjectFromProfile.tcProjectCode
                               tPostingLine.tcProjectDescription   = tqProjectFromProfile.tcProjectDescription
                               tPostingLine.PostingLineProjectText = icProjectText
                               viProjectCurr                       = tqProjectFromProfile.tiCurrency_ID
                               viProjectRate                       = tqProjectFromProfile.tiExchangeRateType_ID.
                        <M-10 run AddDefaultSaf
                           (input  {&POSTINGSAFPARENTTYPE-PROJECT} (icType), 
                            input  tPostingLine.Project_ID (iiObjectId), 
                            input  iiSafStructureId (iiSafStructureId), 
                            input  icSafStructureCode (icSafStructureCode), 
                            input  tPostingLine.GL_ID (iiGLId), 
                            output viFcReturnSuper (oiReturnStatus)) in BPosting>
                        if viFcReturnSuper <> 0
                        then assign viLocalReturnStatus = viFcReturnSuper.
                        if viFcReturnSuper < 0 
                        then Leave ADDSTANDARDPOSTINGBLOCK.
                    end. /* if available tqProjectFromProfile */
                end. /* if (tqGLForPostingLineCreation.tiProjectProfile_ID <> 0 and  */
            end. /* if icProjectCode = "":U or */
            else do:
                <Q-19 run ProjectByCode (all) (Read) (Cache)
                   (input tPosting.Company_ID, (CompanyId)
                    input icProjectCode, (ProjectCode)
                    output dataset tqProjectByCode) in BProject>
                find first tqProjectByCode no-error.
                if available tqProjectByCode
                then do:
                    assign tPostingLine.Project_ID             = tqProjectByCode.tiProject_ID
                           tPostingLine.tcProjectCode          = tqProjectByCode.tcProjectCode
                           tPostingLine.tcProjectDescription   = tqProjectByCode.tcProjectDescription
                           tPostingLine.PostingLineProjectText = icProjectText
                           viProjectCurr                       = tqProjectByCode.tiCurrency_ID
                           viProjectRate                       = tqProjectByCode.tiExchangeRateType_ID.
                    <M-11 run AddDefaultSaf
                       (input  {&POSTINGSAFPARENTTYPE-PROJECT} (icType), 
                        input  tPostingLine.Project_ID (iiObjectId), 
                        input  iiSafStructureId (iiSafStructureId), 
                        input  icSafStructureCode (icSafStructureCode), 
                        input  tPostingLine.GL_ID (iiGLId), 
                        output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    if viFcReturnSuper <> 0
                    then assign viLocalReturnStatus = viFcReturnSuper.
                    if viFcReturnSuper < 0
                    then Leave ADDSTANDARDPOSTINGBLOCK.
                end. /* if available tqProjectByCode */
            end. /* Not if icProjectCode = "":U or */ 
        end. /* if tqGLForPostingLineCreation.tlGLIsProjectAccount */
        /* ======================= */
        /* Set the Saf-information */
        /* ======================= */
        if tqGLForPostingLineCreation.tlGLIsSafAccount = true
        then do:
            assign tPostingLine.PostingLineSafText = icSafText.
            <M-35 run AddDefaultSaf
               (input  {&POSTINGSAFPARENTTYPE-GL} (icType), 
                input  tPostingLine.GL_ID (iiObjectId), 
                input  iiSafStructureId (iiSafStructureId), 
                input  icSafStructureCode (icSafStructureCode), 
                input  tPostingLine.GL_ID (iiGLId), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            if viFcReturnSuper <> 0
            then assign viLocalReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 
            then Leave ADDSTANDARDPOSTINGBLOCK.
        end. /* if tqGLForPostingLineCreation.tlGLIsSafAccount */
    end. /* end of if tPosting.tcPeriodTypeCode <> {&PERIODTYPECODE-YEARCLOSING} */

    /* ======================== */
    /* Set the Unit information */
    /* ======================== */
    if tqGLForPostingLineCreation.tiUnit_ID <> 0 and 
       tqGLForPostingLineCreation.tiUnit_ID <> ?
    then do:
        <Q-6 run UnitPrim (all) (Read) (Cache)
           (input tqGLForPostingLineCreation.tiUnit_ID, (UnitID)
            input '':U, (UnitCode)
            output dataset tqUnitPrim) in BUnit>
        find first tqUnitPrim no-error.
        if available tqUnitPrim
        then assign tPostingLine.tcUnitCode     = tqUnitPrim.tcUnitCode
                    tPostingLine.PostingLineQTY = idQty.
    end. /* if tqGLForPostingLineCreation.tiUnit_ID <> 0 and  */

    /* ========= */
    /* Assign LC */
    /* ========= */
    if tPostingLine.PostingLineDebitLC  = ? or
       tPostingLine.PostingLineCreditLC = ?
    then do:
        if idExchangeRate = ? or idExchangeRateScale = ?
        then do:
            if tPostingLine.Currency_ID = viCompanyLCId
            then assign tPostingLine.PostingLineDebitLC      = tPostingLine.PostingLineDebitTC
                        tPostingLine.PostingLineCreditLC     = tPostingLine.PostingLineCreditTC
                        tPostingLine.PostingLineExchangeRate = 1
                        tPostingLine.PostingLineRateScale    = 1.
            else do:            
                 <M-39 run GetExchangeRate
                    (input  tPosting.Company_ID (iiCompanyID), 
                     input  tPostingLine.Currency_ID (iiFromCurrencyID), 
                     input  ? (icFromCurrencyCode), 
                     input  ? (iiToCurrencyID), 
                     input  ? (icToCurrencyCode), 
                     input  ? (iiExchangeRateTypeID), 
                     input  icExchangeRateType (icExchangeRateTypeCode), 
                     input  itExchangeRateDate (itValidityDate), 
                     output vdRate (odExchangeRate), 
                     output vdRateScale (odExchangeScaleFactor), 
                     output viFcReturnSuper (oiReturnStatus)) in BPosting>
                if viFcReturnSuper <> 0
                then assign viLocalReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0 
                then Leave ADDSTANDARDPOSTINGBLOCK.
                assign tPostingLine.PostingLineExchangeRate = vdRate
                       tPostingLine.PostingLineRateScale    = vdRateScale.
                if tPostingLine.PostingLineDebitLC = ?
                then assign tPostingLine.PostingLineDebitLC = 
                         <M-21 RoundAmount
                            (input  tPostingLine.PostingLineDebitTC * vdRate * vdRatescale (idUnroundedAmount), 
                             input  viCompanyLCId (iiCurrencyID), 
                             input  vcCompanyLC (icCurrencyCode)) in business>.
                if tPostingLine.PostingLineCreditLC = ?
                then assign tPostingLine.PostingLineCreditLC = 
                         <M-22 RoundAmount
                            (input  tPostingLine.PostingLineCreditTC * vdRate * vdRateScale (idUnroundedAmount), 
                             input  viCompanyLCId (iiCurrencyID), 
                             input  vcCompanyLC (icCurrencyCode)) in business>.
            end. /* if tPostingLine.Currency_ID = viCompanyLCId */
        end.
        else assign tPostingLine.PostingLineDebitLC = 
                       <M-38 RoundAmount
                          (input  tPostingLine.PostingLineDebitTC * idexchangeRate * idExchangeRateScale (idUnroundedAmount), 
                           input  viCompanyLCId (iiCurrencyID), 
                           input  '':U (icCurrencyCode)) in business>
                    tPostingLine.PostingLineCreditLC = 
                       <M-40 RoundAmount
                          (input  tPostingLine.PostingLineCreditTC * idexchangeRate * idExchangeRateScale (idUnroundedAmount), 
                           input  viCompanyLCId (iiCurrencyID), 
                           input  '':U (icCurrencyCode)) in business>.
    end. /* if tPostingLine.PostingLineDebitLC  = ? or */
    else if idExchangeRate <> ? and idExchangeRateScale <> ?
         then assign tPostingLine.PostingLineExchangeRate = idExchangeRate
                     tPostingLine.PostingLineRateScale    = idExchangeRateScale.
         else if tPostingLine.PostingLineDebitTC - tPostingLine.PostingLineCreditTC = 0
              then assign tPostingLine.PostingLineExchangeRate = 0
                          tPostingLine.PostingLineRateScale    = 0.
              else assign tPostingLine.PostingLineExchangeRate = absolute(round((tPostingLine.PostingLineDebitLC - tPostingLine.PostingLineCreditLC) / (tPostingLine.PostingLineDebitTC - tPostingLine.PostingLineCreditTC), 10))
                          tPostingLine.PostingLineRateScale    = 1.

    /* ========= */
    /* Assign CC */
    /* ========= */
    if tPostingLine.PostingLineDebitCC  = ? or
       tPostingLine.PostingLineCreditCC = ?
    then do:               
        if idPostingLineCCRate = ? or idPostingLineCCScale = ?
        then do:           
            if viCompanyCCId = tPostingLine.Currency_ID
            then assign tPostingLine.PostingLineDebitCC  = tPostingLine.PostingLineDebitTC
                        tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineCreditTC
                        tPostingLine.PostingLineCCRate   = 1
                        tPostingLine.PostingLineCCScale  = 1. 
            else if vlDomainIsStatutory = false
                 then assign tPostingLine.PostingLineDebitCC  = tPostingLine.PostingLineDebitLC
                             tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineCreditLC
                             tPostingLine.PostingLineCCRate   = tPostingLine.PostingLineExchangeRate
                             tPostingLine.PostingLineCCScale  = tPostingLine.PostingLineRateScale.
                 else do:
                     <M-62 run GetExchangeRate
                        (input  tPosting.Company_ID (iiCompanyID), 
                         input  tPostingLine.Currency_ID (iiFromCurrencyID), 
                         input  ? (icFromCurrencyCode), 
                         input  viCompanyCCId (iiToCurrencyID), 
                         input  ? (icToCurrencyCode), 
                         input  ? (iiExchangeRateTypeID), 
                         input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
                         input  itExchangeRateDate (itValidityDate), 
                         output vdRate (odExchangeRate), 
                         output vdRateScale (odExchangeScaleFactor), 
                         output viFcReturnSuper (oiReturnStatus)) in BPosting>                        
                     if viFcReturnSuper <> 0
                     then assign viLocalReturnStatus = viFcReturnSuper.
                     if viFcReturnSuper < 0 
                     then Leave ADDSTANDARDPOSTINGBLOCK.
                     assign tPostingLine.PostingLineCCRate  = vdRate
                            tPostingLine.PostingLineCCScale = vdRateScale.
                     if tPostingLine.PostingLineDebitCC = ?
                     then assign tPostingLine.PostingLineDebitCC = 
                            <M-23 RoundAmount
                               (input  tPostingLine.PostingLineDebitTC * vdRate * vdRateScale (idUnroundedAmount), 
                                input  viCompanyCCId (iiCurrencyID), 
                                input  '':U (icCurrencyCode)) in business>.
            
                    if tPostingLine.PostingLineCreditCC = ?
                    then assign tPostingLine.PostingLineCreditCC = 
                            <M-24 RoundAmount
                               (input  tPostingLine.PostingLineCreditTC * vdRate * vdRateScale (idUnroundedAmount), 
                                input  viCompanyCCId (iiCurrencyID), 
                                input  '':U (icCurrencyCode)) in business>.
                 end. /* Not if viCompanyCCId = viCompanyLCId */ 
        end. /* if idPostingLineCCRate = ? or idPostingLineCCScale = ? */ 
        else if vlDomainIsStatutory = false
             then assign tPostingLine.PostingLineDebitCC  = tPostingLine.PostingLineDebitLC
                         tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineCreditLC
                         tPostingLine.PostingLineCCRate   = tPostingLine.PostingLineExchangeRate
                         tPostingLine.PostingLineCCScale  = tPostingLine.PostingLineRateScale.
             else assign tPostingLine.PostingLineCCRate  = idPostingLineCCRate
                         tPostingLine.PostingLineCCScale = idPostingLineCCScale
                         tPostingLine.PostingLineDebitCC = 
                            <M-36 RoundAmount
                               (input  tPostingLine.PostingLineDebitTC * idPostingLineCCRate * idPostingLineCCScale (idUnroundedAmount), 
                                input  viCompanyCCId (iiCurrencyID), 
                                input  '':U (icCurrencyCode)) in business>
                         tPostingLine.PostingLineCreditCC = 
                            <M-37 RoundAmount
                               (input  tPostingLine.PostingLineCreditTC * idPostingLineCCRate * idPostingLineCCScale (idUnroundedAmount), 
                                input  viCompanyCCId (iiCurrencyID), 
                                input  '':U (icCurrencyCode)) in business>.
        
    end. /* if tPostingLine.PostingLineDebitCC  = ? or */
    else if idPostingLineCCRate <> ? and idPostingLineCCScale <> ?
         then assign tPostingLine.PostingLineCCRate  = idPostingLineCCRate
                     tPostingLine.PostingLineCCScale = idPostingLineCCScale.
         else if tPostingLine.PostingLineDebitTC - tPostingLine.PostingLineCreditTC = 0
              then assign tPostingLine.PostingLineCCRate  = 0
                          tPostingLine.PostingLineCCScale = 0.
              else assign tPostingLine.PostingLineCCRate  = absolute(round((tPostingLine.PostingLineDebitCC - tPostingLine.PostingLineCreditCC) / (tPostingLine.PostingLineDebitTC - tPostingLine.PostingLineCreditTC), 10))
                          tPostingLine.PostingLineCCScale = 1.

    /* ====================================== */
    /* Keep query result for descendant class */
    /* ====================================== */
    empty temp-table tqGLForPostingLineCreationCpy.
    create tqGLForPostingLineCreationCpy.
    buffer-copy tqGLForPostingLineCreation to tqGLForPostingLineCreationCpy.
END. /* ADDSTANDARDPOSTINGBLOCK */


/* ================== */
/* Exception handling */
/* ================== */
assign oiReturnStatus = viLocalReturnStatus.