Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 36 ยท Projects and Practice

Project: A Pricing Engine

Build a runnable pricing engine that mimics the SAP condition technique with access sequences, condition records, a pricing procedure, scales and a price analysis log.

In this project you build a compact pricing engine that follows the structure of SAP's condition technique from The Pricing Condition Technique: condition records are found through access sequences, and a pricing procedure applies them in order to produce a net value with a price analysis log that explains each step.

The real SAP pricing is much richer (many condition classes, exclusion groups, requirements in ABAP, rounding rules). This is a stand-in that runs in the browser. All data is invented.

Design

flowchart LR
  O["Order item<br/>customer, material, qty"] --> E["Engine"]
  R["Condition records"] --> E
  A["Access sequences"] --> E
  S["Pricing procedure"] --> E
  E --> N["Net value<br/>+ analysis log"]

The engine is generic: behavior comes only from the four data sets.

We support:

  • condition types with a class (price, discount, surcharge, tax);
  • percentage and amount calculation;
  • scales (quantity tiers) for prices;
  • access sequences (most specific first);
  • procedure steps with a base (the subtotal a percentage applies to);
  • a log line for every step.

Step 1: the data model

JS Step 1: records, access sequences and the procedure

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Step 2: the engine

The engine below repeats the data so that this block runs on its own. Read the code through before running: findScaleValue chooses the highest scale tier not above the quantity, findRecord follows the access sequence, and price walks the procedure keeping every step's amount in stepValue so later steps can use it as a base.

JS Step 2: run the engine

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Look at the two logs. The first customer gets the special price through the combined customer+material access, a customer discount and, because the quantity reaches 50, the material discount. The second customer falls back to the general list price with the 100-piece scale, gets no customer discount (no record) but still gets the material discount for 50 or more pieces, and pays freight and tax.

Step 3: tests

Pricing errors cost real money, so a pricing engine needs tests, just like ABAP Unit tests for real code (see Modularization and Classes in ABAP). These checks use a simplified price function to show the pattern.

JS Step 3: table-driven tests

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Ideas for extension

  1. Validity dates on records (see the lookup in the previous lesson) and a pricingDate on the order.
  2. Exclusion groups: apply only the best of several discounts.
  3. Manual conditions: let the order override a price, and log that a human changed it.
  4. Currency conversion with exchange rates and rounding rules per currency.
  5. Condition supplements: a surcharge attached to a main condition.
  6. Export the log as JSON for auditors.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In the engine, why are access sequences ordered?

    The first access that finds a record wins, so specific keys go first.
  2. 2. What does a scale do?

    A scale holds several values depending on the quantity.
  3. 3. Why does the engine write a log line for every step?

    A price analysis makes each element and its source traceable.
  4. 4. What is the purpose of a subtotal step?

    Percentages such as tax refer to a named subtotal.

Summary

  • A generic engine can be driven purely by data: records, access sequences, condition types and a procedure.
  • Scales, subtotals and bases are small additions with large effect.
  • A log per step makes prices explainable.
  • Tests protect pricing logic from regressions.
  • The same principles apply to SAP's real configuration in the IMG.

Next: Practice Questions