5008

Temporary Means No SQL

Basics
Medium
Pro
table
temporary-record
sql-budget

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 key
  • Quantity — Decimal
  • Amount — 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:

  1. The codeunit keeps one staging buffer of "Import Preview Line" rows that survives across calls on the same codeunit instance — lines added by one AddLine call are still there when LineCount runs later.
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

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.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade