One Round Trip, Top N
Logistics opens every review meeting with the same slide: the customers we shipped the most to this period. The code behind it walks every customer, then every shipment document of that customer, then every line of that document — the DBA's trace shows a wall of tiny SELECT statements growing with the customer list. The ranking is right; the report is just having O(customers × documents) little conversations with the database instead of one.
Your job: the same ranking, one conversation.
Requirements
Create a codeunit named "Top Shippers" with one public procedure:
procedure TopShippedCustomers(CustomerNoFilter: Text; FromDate: Date; ToDate: Date; TopCount: Integer): List of [Text]Rules:
- Consider every
Customerwhose"No."matchesCustomerNoFilter— an AL filter expression for a Code field. The tests use patterns likeTRYAL-T1-*; the filter is never empty. - A customer's shipped volume comes from the
Sales Shipment Linerecords of their shipment documents: aSales Shipment Headerbelongs to the customer through its"Sell-to Customer No.", and a line belongs to its document through"Document No.". - Only lines of documents whose header
"Posting Date"lies inFromDate..ToDatecount — both boundary dates included. Shipment lines carry a"Posting Date"and a"Sell-to Customer No."of their own — stamps copied at posting time, possibly stale. The tests deliberately seed lines whose stamps contradict their header; the header decides.
Solve it with Pro
You’re reading the opening of the statement. Pro unlocks the whole problem:
- The full statement
- Starter code in the browser editor
- 13 grading tests, run on Business Central 28.5
- 3 hints
- The reference solution
Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.
Already on Pro? Sign in