Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
74 lines
3.3 KiB
Markdown
74 lines
3.3 KiB
Markdown
# 1. Goal
|
|
A ship chandler supplies provisions to vessels. The ordering program of the
|
|
chandler calls one service for each provisioning order. The service checks the
|
|
lines of the order and calculates the net value of the order. The service
|
|
reports each violation as a class-based exception with one reason code.
|
|
|
|
# 2. Open questions
|
|
None.
|
|
|
|
# 3. Context
|
|
- The exception class {{P}}CX_PROV_ERROR exists in package $TMP. It is active.
|
|
- The class inherits from CX_STATIC_CHECK. It has the type TY_REASON (CHAR 20),
|
|
the read-only attribute REASON, and a constructor with the importing
|
|
parameter IV_REASON of type TY_REASON.
|
|
- The ordering program catches the exception and shows the reason code.
|
|
|
|
# 4. Contract
|
|
- Create the class {{P}}PROVISION_CALC in package $TMP.
|
|
- The class is public and final. It has a public constructor without parameters.
|
|
- Public types of the class:
|
|
- TY_MATERIAL (CHAR 18), TY_QUANTITY (packed, length 13, 3 decimals),
|
|
TY_PRICE (packed, length 11, 2 decimals), TY_AMOUNT (packed, length 13,
|
|
2 decimals), TY_REASON (CHAR 20).
|
|
- TY_LINE with the components MATERIAL, QUANTITY and PRICE.
|
|
- TT_LINES, a standard table of TY_LINE with an empty key.
|
|
- Public constants of the class:
|
|
- C_MAX_LINES (type I) with the value 999.
|
|
- C_VALUE_LIMIT (type TY_AMOUNT) with the value 100000.00.
|
|
- C_EMPTY_ORDER, C_TOO_MANY_LINES, C_MATERIAL_MISSING, C_QUANTITY_INVALID,
|
|
C_PRICE_NEGATIVE, C_DUPLICATE_MATERIAL and C_LIMIT_EXCEEDED, all of type
|
|
TY_REASON, with the values EMPTY_ORDER, TOO_MANY_LINES, MATERIAL_MISSING,
|
|
QUANTITY_INVALID, PRICE_NEGATIVE, DUPLICATE_MATERIAL and LIMIT_EXCEEDED.
|
|
- Public methods of the class:
|
|
- CHECK_ORDER, importing IT_LINES of type TT_LINES, raising
|
|
{{P}}CX_PROV_ERROR.
|
|
- CALCULATE_VALUE, importing IT_LINES of type TT_LINES, returning RV_VALUE
|
|
of type TY_AMOUNT, raising {{P}}CX_PROV_ERROR.
|
|
- Do not add other public methods.
|
|
|
|
# 5. Business rules
|
|
The value of a line is the quantity multiplied by the price. The net value of
|
|
the order is the sum of the exact line values. Round only the net value, and
|
|
only once, to 2 decimals. Half values round away from zero.
|
|
|
|
CHECK_ORDER applies these rules in this sequence. It raises {{P}}CX_PROV_ERROR
|
|
with the reason of the first rule that fails.
|
|
1. If the order has no line, the reason is C_EMPTY_ORDER.
|
|
2. If the order has more than C_MAX_LINES lines, the reason is
|
|
C_TOO_MANY_LINES.
|
|
3. Check the lines in the given order. For each line apply these rules in this
|
|
sequence:
|
|
a. If the material is empty or contains only spaces, the reason is
|
|
C_MATERIAL_MISSING.
|
|
b. If the quantity is not greater than zero, the reason is
|
|
C_QUANTITY_INVALID.
|
|
c. If the price is less than zero, the reason is C_PRICE_NEGATIVE.
|
|
d. If the material occurs in an earlier line, the reason is
|
|
C_DUPLICATE_MATERIAL.
|
|
4. If the net value of the order is greater than C_VALUE_LIMIT, the reason is
|
|
C_LIMIT_EXCEEDED.
|
|
|
|
CALCULATE_VALUE applies the same checks and returns the net value.
|
|
|
|
# 6. Constraints
|
|
- Release target: SAP_BASIS 8.16.
|
|
- Coding standards: Clean ABAP. Method length below 40 statements. No global
|
|
variables. No comment that restates the code.
|
|
- Out of scope: do not change {{P}}CX_PROV_ERROR.
|
|
|
|
# 7. Acceptance
|
|
- The class is active and has no syntax error.
|
|
- The hidden tests pass.
|
|
- Write your own ABAP Unit tests for the class.
|