107 lines
5.1 KiB
Markdown
107 lines
5.1 KiB
Markdown
# 1. Goal
|
|
A logistics program calculates the shipping fee of a parcel. The program must not
|
|
contain the fee rules itself. It uses an interface as the contract. Create this
|
|
interface.
|
|
|
|
# 2. Open questions
|
|
None.
|
|
|
|
# 3. Context
|
|
- Package $TMP, client 001.
|
|
- The interface {{P}}IF_PARCEL_FEE does not exist yet. Create it.
|
|
- A parcel has a weight in grams, a shipping zone, and an express flag. A fee is
|
|
an amount in whole cents.
|
|
- The interface is only a contract. Other programs implement it and calculate the
|
|
fee. The interface declares four methods:
|
|
- check_input: checks the weight and the zone and returns a reason code.
|
|
- base_fee: returns the base fee of a zone.
|
|
- weight_surcharge: returns the surcharge that the weight causes.
|
|
- total_fee: returns the complete fee of a parcel.
|
|
- The meaning of the values: zone '1' is the home zone, zone '2' is the national
|
|
zone, zone '3' is the europe zone. The reason 'OK' means that the input is
|
|
valid, 'WEIGHT' means that the weight is out of range, and 'ZONE' means that the
|
|
zone is unknown. The base fee is 350 cents for zone '1', 620 cents for zone '2',
|
|
and 990 cents for zone '3'. The first 1000 grams are included in the base fee.
|
|
Each started 1000 grams above 1000 grams costs 90 cents. The express option
|
|
costs 750 cents. A call with invalid input returns the fee 0.
|
|
|
|
# 4. Contract
|
|
Create the interface {{P}}IF_PARCEL_FEE in package $TMP. The interface is public.
|
|
It contains exactly the types, the constants, and the methods below. Do not add
|
|
other components.
|
|
|
|
Types:
|
|
- ty_weight_g TYPE i
|
|
- ty_cents TYPE i
|
|
- ty_zone TYPE c LENGTH 1
|
|
- ty_reason TYPE c LENGTH 10
|
|
|
|
Constants:
|
|
- c_zone: components home, national, europe, each TYPE ty_zone
|
|
- c_reason: components ok, weight, zone, each TYPE ty_reason
|
|
- c_limit: components min_weight, max_weight, each TYPE ty_weight_g
|
|
- c_surcharge: components per_step, express, each TYPE ty_cents
|
|
|
|
Methods:
|
|
- check_input
|
|
IMPORTING iv_weight_g TYPE ty_weight_g
|
|
iv_zone TYPE ty_zone
|
|
RETURNING VALUE(rv_reason) TYPE ty_reason
|
|
- base_fee
|
|
IMPORTING iv_zone TYPE ty_zone
|
|
RETURNING VALUE(rv_cents) TYPE ty_cents
|
|
- weight_surcharge
|
|
IMPORTING iv_weight_g TYPE ty_weight_g
|
|
RETURNING VALUE(rv_cents) TYPE ty_cents
|
|
- total_fee
|
|
IMPORTING iv_weight_g TYPE ty_weight_g
|
|
iv_zone TYPE ty_zone
|
|
iv_express TYPE abap_bool
|
|
RETURNING VALUE(rv_cents) TYPE ty_cents
|
|
|
|
# 5. Business rules
|
|
1. The type ty_zone is a character type with length 1. The type ty_reason is a
|
|
character type with length 10. The types ty_weight_g and ty_cents are integer
|
|
types.
|
|
2. The constant structure c_zone has the components home, national, and europe.
|
|
Each component has the type ty_zone. The values are '1', '2', and '3'.
|
|
3. The constant structure c_reason has the components ok, weight, and zone. Each
|
|
component has the type ty_reason. The values are 'OK', 'WEIGHT', and 'ZONE'.
|
|
4. The constant structure c_limit has the components min_weight and max_weight.
|
|
Each component has the type ty_weight_g. The values are 1 and 31500.
|
|
5. The constant structure c_surcharge has the components per_step and express.
|
|
Each component has the type ty_cents. The values are 90 and 750.
|
|
6. The method check_input has the importing parameter iv_weight_g of type
|
|
ty_weight_g, the importing parameter iv_zone of type ty_zone, and the returning
|
|
parameter rv_reason of type ty_reason. It returns c_reason-weight if the weight
|
|
is below c_limit-min_weight or above c_limit-max_weight. Else it returns
|
|
c_reason-zone if the zone is not one of the values of c_zone. Else it returns
|
|
c_reason-ok.
|
|
7. The method base_fee has the importing parameter iv_zone of type ty_zone and
|
|
the returning parameter rv_cents of type ty_cents. It returns 350 for zone '1',
|
|
620 for zone '2', 990 for zone '3', and 0 for every other zone.
|
|
8. The method weight_surcharge has the importing parameter iv_weight_g of type
|
|
ty_weight_g and the returning parameter rv_cents of type ty_cents. It returns 0
|
|
for a weight up to 1000 grams. For every started 1000 grams above 1000 grams it
|
|
returns c_surcharge-per_step cents.
|
|
9. The method total_fee has the importing parameters iv_weight_g of type
|
|
ty_weight_g, iv_zone of type ty_zone, and iv_express of type abap_bool, and the
|
|
returning parameter rv_cents of type ty_cents. It returns 0 if check_input does
|
|
not return c_reason-ok. Else it returns base_fee plus weight_surcharge, and it
|
|
adds c_surcharge-express if iv_express is abap_true.
|
|
|
|
# 6. Constraints
|
|
- Release target: SAP_BASIS 816 (SAP ABAP Platform 2025).
|
|
- Coding standards: Clean ABAP. No global variables. No comment that restates the
|
|
code.
|
|
- Out of scope: no database table, no CDS view, no function module, no report, and
|
|
no application class.
|
|
|
|
# 7. Acceptance
|
|
- The interface {{P}}IF_PARCEL_FEE is active and has no syntax error.
|
|
- The hidden tests pass.
|
|
- Write your own ABAP Unit tests for the interface. An interface has no test
|
|
include, so create one global test class in package $TMP. The test class
|
|
implements the interface and checks the constants, the type lengths, and the
|
|
method signatures. Keep all test code in this one global class.
|