98 lines
4.4 KiB
Markdown
98 lines
4.4 KiB
Markdown
# 1. Goal
|
|
A tour operator checks a holiday booking before it confirms the booking. The
|
|
booking desk calls one check method for each booking. The check method reports
|
|
each problem as a class-based exception. Each exception carries a message and
|
|
the values that caused the problem.
|
|
|
|
# 2. Open questions
|
|
None.
|
|
|
|
# 3. Context
|
|
- Class {{P}}CX_HOLIDAY_ERROR exists in package $TMP. It is active. It is
|
|
abstract and inherits from cx_static_check. It has the public read-only
|
|
attribute mv_message TYPE string and a public constructor with the importing
|
|
parameter iv_message TYPE string. The constructor sets mv_message.
|
|
- The tour operator offers five destinations. The destination code and the
|
|
maximum number of travellers of each destination are:
|
|
ALPS 6, CRETE 4, KYOTO 8, LAPLAND 5, SAFARI 7.
|
|
- The booking desk passes the booking and the current date to the check method.
|
|
- A booking has a destination code, a number of travellers, a number of nights,
|
|
and a departure date.
|
|
|
|
# 4. Contract
|
|
Create these five classes in package $TMP. Do not change {{P}}CX_HOLIDAY_ERROR.
|
|
|
|
1. Class {{P}}HOLIDAY_CHECKER
|
|
- The class is public and final. It has a public constructor without
|
|
parameters.
|
|
- Public type ty_dest_code, type string.
|
|
- Public type ty_booking, a structure with these components:
|
|
dest_code TYPE ty_dest_code, travellers TYPE i, nights TYPE i,
|
|
departure TYPE d.
|
|
- Public method check with this signature:
|
|
IMPORTING is_booking TYPE ty_booking
|
|
iv_today TYPE d
|
|
RAISING {{P}}CX_HOLIDAY_ERROR
|
|
- Do not add other public methods.
|
|
|
|
2. Class {{P}}CX_UNKNOWN_DEST
|
|
- The class is final and inherits from {{P}}CX_HOLIDAY_ERROR.
|
|
- Public read-only attribute mv_dest TYPE string.
|
|
- Public constructor with the importing parameter iv_dest TYPE string.
|
|
- mv_message is 'Destination is not offered'.
|
|
- mv_dest holds the normalized destination code. The value has no leading or
|
|
trailing blanks.
|
|
|
|
3. Class {{P}}CX_BAD_TRAVELLERS
|
|
- The class is final and inherits from {{P}}CX_HOLIDAY_ERROR.
|
|
- Public read-only attributes mv_travellers TYPE i and mv_max TYPE i.
|
|
- Public constructor with the importing parameters iv_travellers TYPE i and
|
|
iv_max TYPE i.
|
|
- mv_message is 'Number of travellers is not allowed'.
|
|
|
|
4. Class {{P}}CX_BAD_NIGHTS
|
|
- The class is final and inherits from {{P}}CX_HOLIDAY_ERROR.
|
|
- Public read-only attribute mv_nights TYPE i.
|
|
- Public constructor with the importing parameter iv_nights TYPE i.
|
|
- mv_message is 'Number of nights is not allowed'.
|
|
|
|
5. Class {{P}}CX_BAD_DEPARTURE
|
|
- The class is final and inherits from {{P}}CX_HOLIDAY_ERROR.
|
|
- Public read-only attributes mv_departure TYPE d and mv_earliest TYPE d.
|
|
- Public constructor with the importing parameters iv_departure TYPE d and
|
|
iv_earliest TYPE d.
|
|
- mv_message is 'Departure date is too early'.
|
|
|
|
# 5. Business rules
|
|
The method check applies these rules in this sequence. The method raises the
|
|
exception of the first rule that fails. If no rule fails, the method returns
|
|
without an exception.
|
|
|
|
1. Normalize the destination code: remove all spaces and convert all letters to
|
|
upper case.
|
|
2. The normalized code must be ALPS, CRETE, KYOTO, LAPLAND, or SAFARI. If it is
|
|
not, raise {{P}}CX_UNKNOWN_DEST. Pass the normalized code in iv_dest.
|
|
3. The number of travellers must be 1 or more. It must not be more than the
|
|
maximum number of travellers of the destination. If a value is not correct,
|
|
raise {{P}}CX_BAD_TRAVELLERS. Pass the number of travellers in iv_travellers
|
|
and the maximum of the destination in iv_max.
|
|
4. The number of nights must be 2 or more. It must not be more than 28. If a
|
|
value is not correct, raise {{P}}CX_BAD_NIGHTS. Pass the number of nights in
|
|
iv_nights.
|
|
5. The departure date must be at least 14 days after iv_today. If it is not,
|
|
raise {{P}}CX_BAD_DEPARTURE. Pass the departure date in iv_departure and the
|
|
earliest possible date (iv_today plus 14 days) in iv_earliest.
|
|
|
|
# 6. Constraints
|
|
- Release target: SAP_BASIS 816 (ABAP Platform 2025).
|
|
- Coding standards: Clean ABAP. Methods below 40 statements. No global
|
|
variables. No comment that restates the code.
|
|
- Out of scope: do not change {{P}}CX_HOLIDAY_ERROR. Do not create a database
|
|
table, a CDS view entity, a function module, or a report. Do not change the
|
|
signature of check.
|
|
|
|
# 7. Acceptance
|
|
- All five classes are active and have no syntax error.
|
|
- The hidden tests pass.
|
|
- Write your own ABAP Unit tests for {{P}}HOLIDAY_CHECKER.
|