Temporary Means No SQL
The purchasing team imports supplier order proposals from a spreadsheet and wants a preview before anything is committed: how many distinct items, how much of each, what the grand total is. The first version of the preview "worked" — until the DBA asked why a read-only preview screen was one of the top writers in the database, and why the Import Preview Line table held thousands of leftover rows from previews nobody ever confirmed. A preview must leave no trace: it should live in memory and die with the session.
Your job is a staging routine that builds, aggregates and reads the whole preview without the database ever noticing.
Requirements
Create a table named "Import Preview Line" (the starter already contains it) with exactly these fields:
"Item Code"—Code[20], the primary keyQuantity—DecimalAmount—Decimal
Create a codeunit named "Import Preview" with six public procedures:
procedure AddLine(ItemCode: Code[20]; Quantity: Decimal; Amount: Decimal)
procedure LineCount(): Integer
procedure TotalAmount(): Decimal
procedure QuantityOf(ItemCode: Code[20]): Decimal
procedure GetPreview(var TempPreviewLine: Record "Import Preview Line" temporary)
procedure ClearPreview()Rules:
- The codeunit keeps one staging buffer of
"Import Preview Line"rows that survives across calls on the same codeunit instance — lines added by oneAddLinecall are still there whenLineCountruns later.
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
- 12 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