Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chapter 13 Task Traceability

  • Task 1 → LoanRepaymentPerformance.Codeunit.al (CountUnpaidInstallments uses SetRange(Paid, false) before FindSet).
  • Task 2 → LoanRepaymentPerformance.Codeunit.al (SetLoadFields(Paid) added).
  • Task 3 → LoanRepaymentPerformance.Codeunit.al (ExplainBorrowerLookupPlacement documents lookup placement outside loop).
  • Task 4 → LoanRepaymentMgt.Codeunit.al in Chapter 9 keeps trigger-driven insert behavior; optimize writes only after measuring realistic volume, lock behavior, and trigger requirements.

Code

LoanRepaymentPerformance.Codeunit.al

codeunit 50105 "Loan Repayment Performance"
{
    procedure CountUnpaidInstallments(): Integer
    var
        LoanRepaymentSchedule: Record "Loan Repayment Schedule";
        UnpaidCount: Integer;
    begin
        LoanRepaymentSchedule.SetRange(Paid, false);
        LoanRepaymentSchedule.SetLoadFields(Paid);

        if LoanRepaymentSchedule.FindSet() then
            repeat
                UnpaidCount += 1;
            until LoanRepaymentSchedule.Next() = 0;

        exit(UnpaidCount);
    end;

    procedure ExplainBorrowerLookupPlacement(): Text
    begin
        exit('If installments are processed for one loan at a time, load borrower data once before the loop and reuse it inside the loop.');
    end;
}