project QadFinancials > class BDInvoice > method CreateDInvoicesValidate

Description

Validations for creation of debtor invoices


Parameters


tDIOpenBalanceinput-outputtemp-tabletemp-table used for the creation of Debtor-Opening-Balances
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.CreateDInvoices


program code (program3/bdinvoice.p)

/* check if there is one record available */
find first tDIOpenBalance where 
           tDIOpenBalance.tcDebtorCode <> "":U 
           no-error.
if not available tDIOpenBalance
then do:
    assign vcMessage      = (#T-17'No input record found. You must define for which fields the value must default.':255(1236)T-17#)
           oiReturnStatus = -1.
    <M-1 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-688':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
    return.
end.

assign vcPOSTINGTYPES ={&POSTINGTYPES}.

for each tDIOpenBalance where 
         tDIOpenBalance.tcDebtorCode <> "":U :

    /* Ensure the company-ID is set correctly */
    if tDIOpenBalance.tiCompanyId = 0 or 
       tDIOpenBalance.tiCompanyId = ? 
    then assign tDIOpenBalance.tiCompanyId = viCompanyId.
    else if tDIOpenBalance.tiCompanyId <> viCompanyId
         then do :
            assign vcMessage      = trim(substitute(#T-73'The entity-ID of the invoice (&1) must match the entity-ID of the current-entity (&2)':255(97993011)T-73#, tDIOpenBalance.tiCompanyId , viCompanyId))
                   oiReturnStatus = -1.
            <M-48 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-245272':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            return.
         end. /* if tDIOpenBalance.tiCompanyId <> viCompanyId */
    
    /* replace unknown values */
     if tDIOpenBalance.tcAction = ? then assign tDIOpenBalance.tcAction = "":U.
     if tDIOpenBalance.tcBankNumber = ? then assign tDIOpenBalance.tcBankNumber = "":U.
     if tDIOpenBalance.tcCCCurrencyCode = ? then assign tDIOpenBalance.tcCCCurrencyCode = "":U.
     if tDIOpenBalance.tcDebtorCode = ? then assign tDIOpenBalance.tcDebtorCode = "":U.
     if tDIOpenBalance.tcReasonCode = ? then assign tDIOpenBalance.tcReasonCode = "":U.
     if tDIOpenBalance.tcDivisionCode = ? then assign tDIOpenBalance.tcDivisionCode = "":U.
     if tDIOpenBalance.tdExchangeRateTCLC = ? then assign tDIOpenBalance.tdExchangeRateTCLC = 0.
     if tDIOpenBalance.tdExchangeRateScale = ? then assign tDIOpenBalance.tdExchangeRateScale = 1.
     if tDIOpenBalance.tdInvoiceAmountLC = ? then assign tDIOpenBalance.tdInvoiceAmountLC = 0.
     if tDIOpenBalance.tdInvoiceAmountTC = ? then assign tDIOpenBalance.tdInvoiceAmountTC = 0.
     if tDIOpenBalance.tdInvoiceAmountCC = ? then assign tDIOpenBalance.tdInvoiceAmountCC = 0.
     if tDIOpenBalance.tcInvoiceDescription = ? then assign tDIOpenBalance.tcInvoiceDescription = "":U.
     if tDIOpenBalance.tcInvoiceReference = ? then assign tDIOpenBalance.tcInvoiceReference = "":U.
     if tDIOpenBalance.tcInvoiceTSMNumber = ? then assign tDIOpenBalance.tcInvoiceTSMNumber = "":U.
     if tDIOpenBalance.tcInvoiceType = ? then assign tDIOpenBalance.tcInvoiceType = "":U.
     if tDIOpenBalance.tiInvoiceVoucher = ? then assign tDIOpenBalance.tiInvoiceVoucher = 0.
     if tDIOpenBalance.tcJournalCode = ? then assign tDIOpenBalance.tcJournalCode = "":U.
     if tDIOpenBalance.tcLCCurrencyCode = ? then assign tDIOpenBalance.tcLCCurrencyCode = "":U.
     if tDIOpenBalance.tcNormalPaymentConditionCode = ? then assign tDIOpenBalance.tcNormalPaymentConditionCode = "":U.
     if tDIOpenBalance.tcPaymentMeans = ? then assign tDIOpenBalance.tcPaymentMeans = "":U.
     if tDIOpenBalance.tiPeriodPeriod = ? then assign tDIOpenBalance.tiPeriodPeriod = 0.
     if tDIOpenBalance.tiPeriodYear = ? then assign tDIOpenBalance.tiPeriodYear = 0.
     if tDIOpenBalance.tcPostingText = ? then assign tDIOpenBalance.tcPostingText = "":U.
     if tDIOpenBalance.tcPostingType = ? then assign tDIOpenBalance.tcPostingType = "":U.
     if tDIOpenBalance.tcTCCurrencyCode = ? then assign tDIOpenBalance.tcTCCurrencyCode = "":U.
     if tDIOpenBalance.tcTransferAccountCostCentreCode = ? then assign tDIOpenBalance.tcTransferAccountCostCentreCode = "":U.
     if tDIOpenBalance.tcTransferAccountDivisionCode = ? then assign tDIOpenBalance.tcTransferAccountDivisionCode = "":U.
     if tDIOpenBalance.tcTransferAccountGLCode = ? then assign tDIOpenBalance.tcTransferAccountGLCode = "":U.
     if tDIOpenBalance.tcTransferAccountProjectCode = ? then assign tDIOpenBalance.tcTransferAccountProjectCode = "":U.

    /* don't do a thing when it is not save */
    if tDIOpenBalance.tcAction <> {&DAEMONACTION-SAVE}
    then do:
        assign vcMessage      = trim(substitute(#T-18'Action must be '&1'.':255(1237)T-18#, {&DAEMONACTION-SAVE-TR}))
               oiReturnStatus = -1.
        <M-10 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-708':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        return.
    end.

    /* ****************** */
    /* Check Invoice Type */
    /* ****************** */
    if tDIOpenBalance.tcInvoiceType <> {&INVOICETYPE-INVOICE} and
       tDIOpenBalance.tcInvoiceType <> {&INVOICETYPE-FINANCECHARGE} and
       tDIOpenBalance.tcInvoiceType <> {&INVOICETYPE-CREDITNOTE} and
       tDIOpenBalance.tcInvoiceType <> {&INVOICETYPE-ADJUSTMENT} and
       tDIOpenBalance.tcInvoiceType <> {&INVOICETYPE-PREPAYMENT} and
       tDIOpenBalance.tcInvoiceType <> {&INVOICETYPE-INVOICECORRECTION} and
       tDIOpenBalance.tcInvoiceType <> {&INVOICETYPE-DEDUCTION} and
       tDIOpenBalance.tcInvoiceType <> {&INVOICETYPE-CREDITNOTECORRECTION} 
    then do:
        assign vcMessage      = trim(substitute(#T-19'The invoice type must be &1, &2, &3, &4, &5, &6, &7 or &8':255(33401036)T-19#, {&INVOICETYPE-INVOICE-TR},{&INVOICETYPE-FINANCECHARGE-TR},{&INVOICETYPE-CREDITNOTE-TR},{&INVOICETYPE-ADJUSTMENT-TR},{&INVOICETYPE-PREPAYMENT-TR}, {&INVOICETYPE-INVOICECORRECTION-TR}, {&INVOICETYPE-CREDITNOTECORRECTION-TR},{&INVOICETYPE-DEDUCTION-TR}))
               oiReturnStatus = -1.
        <M-3 run SetMessage (input  vcMessage (icMessage),
                 input  '':U (icArguments),
                 input  'tDIOpenBalance.tcInvoiceType':U (icFieldName),
                 input  tDIOpenBalance.tcInvoiceType (icFieldValue),
                 input  'E':U (icType),
                 input  3 (iiSeverity),
                 input  '':U (icRowid),
                 input  'QADFIN-689':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        return.
    end. /* Invoice Type */

    /* ========================== */
    /* check mandatory parameters */
    /* ========================== */
    if (tDIOpenBalance.tiPeriodYear = 0 and tDIOpenBalance.tiPeriodPeriod = 0) or
       (tDIOpenBalance.tcJournalCode = "":U)
    then do:
        assign vcMessage      = trim(#T-20'You must enter the GL period and daybook.':150(1064)T-20#)
               oiReturnStatus = -1.
        <M-4 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-690':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        return.
    end. /* check mandatory parameters */
    
    /* ========================== */
    /* check Debtor Code          */
    /* ========================== */    
    if tDIOpenBalance.tcDebtorCode = "":U
    then do:
        assign vcMessage      = trim(#T-21'You must specify a customer.':150(49407)T-21#)
               oiReturnStatus = -1.
        <M-5 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-691':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        return.
    end.
    else do:
        <Q-2 assign vlFcQueryRecordsAvailable = DebtorPrim (NoCache)
           (input tDIOpenBalance.tiCompanyId, (CompanyId)
            input tDIOpenBalance.tcDebtorCode, (DebtorCode)
            input ?, (Debtor_ID)) in BDebtor>

        if not vlFcQueryRecordsAvailable
        then do:
             assign vcMessage      = (#T-22'The specified customer is not defined in the system.':150(327)T-22#)
                    oiReturnStatus = -1.
            <M-6 run SetMessage (input  vcMessage (icMessage),
                 input  '':U (icArguments),
                 input  'tDIOpenBalance.tcDebtorCode':U (icFieldName),
                 input  tDIOpenBalance.tcDebtorCode (icFieldValue),
                 input  'E':U (icType),
                 input  3 (iiSeverity),
                 input  '':U (icRowid),
                 input  'QADFIN-692':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            return.
        end.
    end. /* check Debtor Code */
    
    /* ========================= */
    /* posting date is mandatory */
    /* ========================= */
    if tDIOpenBalance.ttPostingDate = ?
    then do:
        assign vcMessage      = trim(#T-23'You must enter the posting date.':150(1068)T-23#)
               oiReturnStatus = -1.
        <M-7 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-693':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        return.
    end. /* posting date is mandatory */
    
    /* ========================= */
    /* posting type is mandatory */
    /* ========================= */    
    if tDIOpenBalance.tcPostingType  = "":U
    then do:
        assign vcMessage      = trim(#T-24'You must enter the posting type.':150(1070)T-24#)
               oiReturnStatus = -1.
        <M-8 run SetMessage (input  vcMessage (icMessage),
                 input  '':U (icArguments),
                 input  tDIOpenBalance.tcPostingType (icFieldName),
                 input  tDIOpenBalance.tcPostingType (icFieldValue),
                 input  'E':U (icType),
                 input  3 (iiSeverity),
                 input  '':U (icRowid),
                 input  'QADFIN-694':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        return.
    end.
    else do:
        assign vlFound = false.
        
        do viCounter = num-entries(vcPOSTINGTYPES,chr(2)) to 2 by -1 :
             if tDIOpenBalance.tcPostingType = entry(viCounter,vcPOSTINGTYPES,chr(2)) 
             then do:
                 assign vlFound = true.
                 leave.
             end.
        end.
    
        if not vlFound
        then do:
            assign vcMessage      = trim(substitute(#T-25'The posting type must be &1 or &2.':150(1071)T-25#,{&POSTINGTYPE-DEBIT-TR},{&POSTINGTYPE-CREDIT-TR}))
                   oiReturnStatus = -1.
            <M-9 run SetMessage (input  vcMessage (icMessage),
                 input  '':U (icArguments),
                 input  tDIOpenBalance.tcPostingType (icFieldName),
                 input  tDIOpenBalance.tcPostingType (icFieldValue),
                 input  'E':U (icType),
                 input  3 (iiSeverity),
                 input  '':U (icRowid),
                 input  'QADFIN-695':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            return.
        end.
    end. /* posting date is mandatory */

    /* Debtor Invoice should be Debit, Debtor CreditNotes should be Credit */
    if ((tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-INVOICE} or tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-FINANCECHARGE} or tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-INVOICECORRECTION}) and tDIOpenBalance.tcPostingType <> {&POSTINGTYPE-DEBIT}) or
       ((tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-CREDITNOTE} or tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}) and tDIOpenBalance.tcPostingType <> {&POSTINGTYPE-CREDIT})
    then do :
            assign vcMessage      = trim(substitute(#T-26'Posting type '&1' is not valid for invoice type '&2'.':150(1239)T-26#,tDIOpenBalance.tcPostingType,tDIOpenBalance.tcInvoiceType))
                   oiReturnStatus = -1.
            <M-11 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-1643':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            return.
    end.
    
    /* Get The JournalType */
    <Q-12 run JournalByJournalLayerType (all) (Read) (Cache)
       (input ?, (JournalId)
        input tDIOpenBalance.tcJournalCode, (JournalCode)
        input viCompanyId, (CompanyId)
        input ?, (LayerTypeCode)
        output dataset tqJournalByJournalLayerType) in BJournal>

    find first tqJournalByJournalLayerType no-error.
    if not available tqJournalByJournalLayerType
    then do:
        assign vcMessage      = trim(#T-27'The daybook specified is not defined in the system.':150(1240)T-27#)
               oiReturnStatus = -1.
          <M-13 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-1644':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            return.
    end.
    else do :
        /* Check the Invoice Type with the Journal Type */ /*TO-DO*/
        if (tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-INVOICE} and (tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-DEBTORINVOICE} and tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-SELFBILLINVOICE}))    or
           (tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-FINANCECHARGE} and tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-DEBTORFINANCECHARGE}) or
           (tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-INVOICECORRECTION} and tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-DEBTORINVOICECORRECT}) or
           (tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-CREDITNOTE} and tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-DEBTORCREDITNOTE} ) or
           (tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} and tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-DEBTORCREDITNOTECORRECT}) or
           (tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-ADJUSTMENT} and tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-DEBTORADJUSTMENT} ) or
           (tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-DEDUCTION} and tqJournalByJournalLayerType.tcJournalTypeCode <> {&JOURNALTYPE-DEDUCTION} )
        then do :
            assign vcMessage      = trim(substitute(#T-28'Daybook &1 is not valid for invoice type &2.':150(1241)T-28#,tDIOpenBalance.tcJournalCode,tDIOpenBalance.tcInvoiceType))
                   oiReturnStatus = -1.
          <M-14 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-1645':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            return.
        end.

        if (tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or
            tDIOpenBalance.tcInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}) and
            tqJournalByJournalLayerType.tlJournalTypeIsCorrection = false
        then do:
            assign vcMessage      = trim(substitute(#T-30'The daybook (&1) must be a correction daybook.':150(13969)T-30#,tDIOpenBalance.tcJournalCode))
                   oiReturnStatus = -1.
            <M-31 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-3283':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            return.
        end.
    end.

    /* check reason code */
    if tDIOpenBalance.tcReasonCode <> "":U
    then do:
        <Q-15 run ReasonPrim (all) (Read) (Cache)
           (input ?, (ReasonId)
            input tDIOpenBalance.tcReasonCode, (ReasonCode)
            output dataset tqReasonPrim) in BReason>

        find first tqReasonPrim no-error.
        if not available tqReasonPrim
        then do:
            assign vcMessage      = trim(#T-29'The invoice status code specified is not defined in the system.':150(1242)T-29#)
                   oiReturnStatus = -1.
            <M-16 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-2966':U (icFcMsgNumber),
                 input  '' (icFcExplanation),
                 input  '' (icFcIdentification),
                 input  '' (icFcContext),
                 output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            return.
        end.
    end.

    /* === Set the CC-amounts and / or CC-exchange-rate/scale in case they were left empty === */
    if tDIOpenBalance.tdInvoiceAmountCC = 0 or 
       tDIOpenBalance.tdInvoiceAmountCC = ?
    then do :
        /* Set the CC-amount = LC-amount and set the CC-Rate/Scale = LC-Rate/Scale */
        if viCompanyCCId = viCompanyLCId
        then assign tDIOpenBalance.tdInvoiceAmountCC     = tDIOpenBalance.tdInvoiceAmountLC
                    tDIOpenBalance.tdExchangeRateTCCC    = tDIOpenBalance.tdExchangeRateTCLC 
                    tDIOpenBalance.tdCCExchangeRateScale = tDIOpenBalance.tdExchangeRateScale.
        else 
        if tDIOpenBalance.tdInvoiceAmountTC <> 0 and 
           tDIOpenBalance.tdInvoiceAmountTC <> ?
        then do :
            /* Retrieve the TCCC-Rate/Scale when empty */
            if (tDIOpenBalance.tdExchangeRateTCCC = 0 or  
                tDIOpenBalance.tdExchangeRateTCCC = ?) and 
               (tDIOpenBalance.tdCCExchangeRateScale = 0 or
                tDIOpenBalance.tdCCExchangeRateScale = ?)
            then do :
                /* Fill in the SC-amount and the TCCC-Rate/Scale based upon the TC-amount and Rate/Scale we retrieve */
                <M-34 run GetExchangeRate
                   (input  viCompanyId (iiCompanyID), 
                    input  ? (iiFromCurrencyID), 
                    input  tDIOpenBalance.tcTCCurrencyCode (icFromCurrencyCode), 
                    input  viCompanyCCId (iiToCurrencyID), 
                    input  ? (icToCurrencyCode), 
                    input  ? (iiExchangeRateTypeID), 
                    input  {&EXCHANGERATETYPE-STATUTORY} (icExchangeRateTypeCode), 
                    input  tDIOpenBalance.ttPostingDate (itValidityDate), 
                    output tDIOpenBalance.tdExchangeRateTCCC (odExchangeRate), 
                    output tDIOpenBalance.tdCCExchangeRateScale (odExchangeScaleFactor), 
                    output viFcReturnSuper (oiReturnStatus)) in BDInvoice>

                if viFcReturnSuper < 0 or 
                   (viFcReturnSuper > 0 and oiReturnStatus = 0)
                then assign oiReturnStatus = viFcReturnSuper.    
                if viFcReturnSuper < 0
                then Return.

            end. /* if (tDIOpenBalance.tdExchangeRateTCCC = 0 or */

            /* Fill in the SC-amount based upon the TC-amount and the TCCC-Rate/Scale */
            assign tDIOpenBalance.tdInvoiceAmountCC = <M-95 RoundAmount
                                                         (input  tDIOpenBalance.tdInvoiceAmountTC * tDIOpenBalance.tdExchangeRateTCCC * tDIOpenBalance.tdCCExchangeRateScale (idUnroundedAmount), 
                                                          input  viCompanyCCId (iiCurrencyID), 
                                                          input  ? (icCurrencyCode)) in BDInvoice>.

        end. /* if tDIOpenBalance.tdInvoiceAmountTC <> 0 and  */
    end. /* if tDIOpenBalance.tdInvoiceAmountCC = 0 or */

    /* Fill in the TCCC-Rate/Scale based upon the TC-amount and the SC-amount  */
    if tDIOpenBalance.tdInvoiceAmountCC <> 0 and 
       tDIOpenBalance.tdInvoiceAmountCC <> ? and
       tDIOpenBalance.tdInvoiceAmountTC <> 0 and 
       tDIOpenBalance.tdInvoiceAmountTC <> ? and 
       (tDIOpenBalance.tdExchangeRateTCCC = 0    or  tDIOpenBalance.tdExchangeRateTCCC = ?) and 
       (tDIOpenBalance.tdCCExchangeRateScale = 0 or tDIOpenBalance.tdCCExchangeRateScale = ?)        
    then  assign tDIOpenBalance.tdExchangeRateTCCC    = tDIOpenBalance.tdInvoiceAmountCC / tDIOpenBalance.tdInvoiceAmountTC
                 tDIOpenBalance.tdCCExchangeRateScale = 1. 

end. /* for each tDIOpenBalance where  */