Files

2.2 KiB

1. Goal

A winter service clears snow from the roads of its clients. The dispatcher calls the class {{P}}SNOW_FEE for each snow clearing job. The class is in package $TMP and is active. The code is legacy code: one long method, deep nesting and hardcoded numbers. Refactor the class in place. The class name, the public types and the public method stay the same. The behavior stays the same.

2. Open questions

None.

3. Context

  • The class {{P}}SNOW_FEE is in package $TMP. It is active.
  • The dispatcher calls the method CALCULATE for each job.
  • The dispatcher gives the area of the site in square metres, the priority of the job and the distance to the site in kilometres.
  • The class is legacy code. No user reports an error. This is a refactoring task: the result of the method must not change.

4. Contract

  • The class {{P}}SNOW_FEE stays in package $TMP. Do not rename it.
  • The class is public and final. It has a public constructor without parameters.
  • The public section keeps these types:
    • TY_AREA (TYPE i)
    • TY_PRIORITY (TYPE c LENGTH 1)
    • TY_DISTANCE (TYPE i)
    • TY_FEE (TYPE p LENGTH 9 DECIMALS 2)
  • The public section keeps one method: CALCULATE IMPORTING iv_area TYPE ty_area iv_priority TYPE ty_priority iv_distance TYPE ty_distance RETURNING VALUE(rv_fee) TYPE ty_fee.
  • Do not add other public methods. Do not change the signature.

5. Business rules

  • The behavior of the class must stay exactly the same. The current implementation is the only source of the rules.
  • Read the legacy code before you change it. Keep every threshold, every surcharge, every minimum and every special case.
  • The hidden tests call the public method with the same input as the legacy code and compare the result.

6. Constraints

  • Release target: ABAP Platform 2025 (SAP_BASIS 816).
  • Coding standards: Clean ABAP. Each method below 40 statements. No deep nesting. Use constants for the numbers. No comment that restates the code.
  • Out of scope: do not change the public interface; do not create other objects.

7. Acceptance

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