Files

4.0 KiB

1. Goal

A transportation planner collects the stops of delivery tours. The planner needs one class that stores the stops and reports the load of each tour.

2. Open questions

None.

3. Context

  • The class {{P}}TOUR_PLANNER is new. Create it in package $TMP.
  • A tour ID has 4 characters, for example T001. A stop number is a whole number. A customer number has 10 characters. The weight is in kilograms with 2 decimal places.
  • No other object of this task exists.

4. Contract

  • Create the class {{P}}TOUR_PLANNER in package $TMP.

  • The class is public, final, and has a public constructor without parameters.

  • The class has these public elementary types:

    TYPES ty_status TYPE c LENGTH 10. TYPES ty_tour_id TYPE c LENGTH 4. TYPES ty_customer TYPE c LENGTH 10. TYPES ty_weight TYPE p LENGTH 8 DECIMALS 2.

  • The class has this public constant structure:

    CONSTANTS: BEGIN OF c_status, ok TYPE ty_status VALUE 'OK', invalid TYPE ty_status VALUE 'INVALID', duplicate TYPE ty_status VALUE 'DUPLICATE', END OF c_status.

  • The class has these public structured types:

    TYPES: BEGIN OF ty_item, tour_id TYPE ty_tour_id, stop_no TYPE i, customer TYPE ty_customer, packages TYPE i, weight TYPE ty_weight, END OF ty_item, tt_item TYPE STANDARD TABLE OF ty_item WITH EMPTY KEY,

    BEGIN OF ty_tour, tour_id TYPE ty_tour_id, stops TYPE i, packages TYPE i, weight TYPE ty_weight, END OF ty_tour, tt_tour TYPE STANDARD TABLE OF ty_tour WITH EMPTY KEY.

  • The class has these public methods:

    METHODS add_item IMPORTING iv_tour_id TYPE ty_tour_id iv_stop_no TYPE i iv_customer TYPE ty_customer iv_packages TYPE i iv_weight TYPE ty_weight RETURNING VALUE(rv_status) TYPE ty_status.

    METHODS remove_tour IMPORTING iv_tour_id TYPE ty_tour_id RETURNING VALUE(rv_count) TYPE i.

    METHODS items RETURNING VALUE(rt_item) TYPE tt_item.

    METHODS stops_of_tour IMPORTING iv_tour_id TYPE ty_tour_id RETURNING VALUE(rt_item) TYPE tt_item.

    METHODS find_stop IMPORTING iv_tour_id TYPE ty_tour_id iv_stop_no TYPE i RETURNING VALUE(rs_item) TYPE ty_item.

    METHODS tour_summary RETURNING VALUE(rt_tour) TYPE tt_tour.

  • Do not add other public methods.

5. Business rules

  1. The tour ID and the stop number identify a stop.
  2. ADD_ITEM stores one stop. It returns INVALID and changes no data if one of these conditions is true:
    • IV_TOUR_ID is empty,
    • IV_STOP_NO is smaller than 1,
    • IV_PACKAGES is smaller than 0,
    • IV_WEIGHT is smaller than 0. IV_CUSTOMER can be empty.
  3. ADD_ITEM returns DUPLICATE and changes no data if a stop with the same tour ID and the same stop number is already stored. The stored stop keeps its values.
  4. Otherwise ADD_ITEM stores the stop and returns OK.
  5. ITEMS returns all stored stops, sorted by tour ID ascending and, for the same tour ID, by stop number ascending.
  6. STOPS_OF_TOUR returns the stops of one tour, sorted by stop number ascending. The result is empty if the tour is not known.
  7. FIND_STOP returns the stop with the given tour ID and stop number. If the stop is not known, all components of the result are initial.
  8. TOUR_SUMMARY returns one line for each tour that has at least one stop. A line contains the tour ID, the number of stops, the sum of the packages and the sum of the weight. The result is sorted by tour ID ascending.
  9. REMOVE_TOUR deletes all stops of the tour and returns the number of deleted stops. It returns 0 if the tour is not known.

6. Constraints

  • Release target: 7.58.
  • Coding standards: Clean ABAP. Method length below 40 statements. No global variables. No comment that restates the code.
  • Out of scope: do not change objects that are not part of this task.

7. Acceptance

  • The class is active and has no syntax error.
  • The hidden tests pass.
  • Write your own ABAP Unit tests for the class.