Files

3.0 KiB

1. Goal

A courier company dispatches deliveries. Each delivery belongs to a district. The dispatcher needs one service that groups the deliveries per district, and one service that merges two district plans. A planning program calls both services.

2. Open questions

None.

3. Context

  • The class {{P}}DISPATCH_PLANNER does not exist. Create it in package $TMP.
  • A delivery has an ID, a district code, a number of parcels, a weight and an urgency. A small urgency value means a high urgency.
  • A district plan has one line per district.
  • The planning program reads the deliveries of one day and calls PLAN.
  • A second depot sends its own plan. The dispatcher calls MERGE with the plan of the first depot and the plan of the second depot.

4. Contract

  • Create the class {{P}}DISPATCH_PLANNER in package $TMP.
  • The class is public and final. It has a public constructor without parameters.
  • The class has the public methods PLAN and MERGE. It has no other public method.
  • Public types of the class:
    • TY_DELIVERY with the components DELIVERY_ID (character 10), DISTRICT (character 4), PARCELS (integer), WEIGHT (packed number, length 8, 2 decimals) and URGENCY (integer).
    • TT_DELIVERY: a standard table of TY_DELIVERY with an empty key.
    • TY_DISTRICT with the components DISTRICT (character 4), DELIVERIES (integer), PARCELS (integer), WEIGHT (packed number, length 8, 2 decimals) and TOP_URGENCY (integer).
    • TT_DISTRICT: a standard table of TY_DISTRICT with an empty key.
  • Method PLAN: IMPORTING it_delivery TYPE tt_delivery RETURNING VALUE(rt_district) TYPE tt_district.
  • Method MERGE: IMPORTING it_left TYPE tt_district it_right TYPE tt_district RETURNING VALUE(rt_merged) TYPE tt_district.

5. Business rules

Method PLAN:

  1. Ignore each delivery whose PARCELS value is zero or negative.
  2. Group the other deliveries by DISTRICT. Compare the district codes exactly.
  3. Each district has exactly one line in the result:
    • DELIVERIES: the number of deliveries of the district.
    • PARCELS: the sum of the parcels of the deliveries of the district.
    • WEIGHT: the sum of the weights of the deliveries of the district.
    • TOP_URGENCY: the smallest urgency of the deliveries of the district.
  4. Sort the result by DISTRICT in ascending order.
  5. If no delivery remains, the result is empty.

Method MERGE: 6. A district that occurs in both plans has exactly one line in the result:

  • DELIVERIES, PARCELS and WEIGHT: the sum of the two values.
  • TOP_URGENCY: the smaller of the two values.
  1. A district that occurs in only one plan keeps its values.
  2. Sort the result by DISTRICT in ascending order.
  3. If both plans are empty, the result is empty.

6. Constraints

  • Release target: 8.16.
  • Coding standards: Clean ABAP. Method length below 40 statements. No global variables. No comment that restates the code.
  • Out of scope: no other global object in package $TMP.

7. Acceptance

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