Files

73 lines
2.8 KiB
Markdown

# 1. Goal
A car rental company checks the return of a rental car. The return desk calls
the check before it closes the rental contract. The check reports the first
problem that it finds.
# 2. Open questions
None.
# 3. Context
- The table {{P}}VEHICLE is in package $TMP. It is active. The table contains
the master data of the rental vehicles:
- MANDT: client, key.
- VEHICLE_ID: CHAR 10, key. The identifier of the vehicle.
- MAX_DAYS: INT4. The maximum number of rental days for this vehicle.
- The seed class {{P}}SEED_VEHICLE fills the table with example data.
# 4. Contract
- Create the exception class {{P}}CX_RETURN_ERROR in package $TMP.
- The class inherits from CX_STATIC_CHECK.
- The class has the public attribute MV_REASON. MV_REASON has a character
type with length 10.
- MV_REASON has one of these values: NO_DATA, DATE_ORDER, MILEAGE, FUEL,
DAMAGE, UNKNOWN, TOO_LONG.
- Do not add other public methods.
- Create the class {{P}}RETURN_CHECKER in package $TMP.
- The class is public and final. It has a public constructor without
parameters.
- The class has this public type:
TYPES:
BEGIN OF ty_return_data,
rental_id TYPE string,
vehicle_id TYPE string,
start_date TYPE d,
return_date TYPE d,
start_mileage TYPE i,
end_mileage TYPE i,
fuel_percent TYPE i,
damage_code TYPE string,
is_damaged TYPE abap_bool,
END OF ty_return_data.
- The class has this public method:
METHODS check
IMPORTING is_return_data TYPE ty_return_data
RAISING {{P}}CX_RETURN_ERROR.
- Do not add other public methods.
# 5. Business rules
Check the return data. Apply the rules in this sequence. The check reports the
reason of the first rule that fails. If no rule fails, the check does not raise
an exception.
1. NO_DATA: RENTAL_ID or VEHICLE_ID is empty, or START_DATE or RETURN_DATE is
initial.
2. DATE_ORDER: RETURN_DATE is before START_DATE.
3. MILEAGE: END_MILEAGE is smaller than START_MILEAGE.
4. FUEL: FUEL_PERCENT is smaller than 0 or larger than 100.
5. DAMAGE: IS_DAMAGED is 'X' and DAMAGE_CODE is empty.
6. UNKNOWN: VEHICLE_ID is not in the table {{P}}VEHICLE.
7. TOO_LONG: the rental duration is larger than MAX_DAYS of the vehicle.
The rental duration is the number of calendar days from START_DATE to
RETURN_DATE. Both days are included. Example: start date 2024-01-01 and return
date 2024-01-03 give a duration of 3 days.
# 6. Constraints
- Release target: SAP_BASIS 816.
- 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}}VEHICLE and {{P}}SEED_VEHICLE.
# 7. Acceptance
- The classes are active and have no syntax error.
- The hidden tests pass.
- Write your own ABAP Unit tests for {{P}}RETURN_CHECKER.