Files
2026-10-05 18:02:52 +02:00

2.2 KiB

1. Goal

A pest control company charges a fee for each treatment visit. The dispatcher calls the class {{P}}PEST_FEE for each job before it plans the route. The class is legacy code. Refactor the class in place. The class name and the public interface stay the same. The fee stays the same for each input.

2. Open questions

None.

3. Context

  • The class {{P}}PEST_FEE exists in package $TMP. It is active.
  • The class is public, final, and has a public constructor without parameters.
  • The public interface has the types TY_PEST and TY_FEE and the method CALCULATE_FEE with the importing parameters IV_PEST_TYPE, IV_AREA, IV_URGENT and IV_CONTRACT and the returning parameter RV_FEE.
  • Users report that the class is difficult to read and to maintain. The method is long, the numbers have no name, the same area logic appears twice, and one variable is not used.
  • The legacy implementation contains the business rules. Read it before you change it.

4. Contract

  • Refactor the class {{P}}PEST_FEE in package $TMP.
  • The class name stays the same.
  • The class stays public and final and keeps the public constructor without parameters.
  • The public types TY_PEST and TY_FEE stay the same.
  • The public method CALCULATE_FEE keeps its name, its importing parameters IV_PEST_TYPE, IV_AREA, IV_URGENT, IV_CONTRACT and its returning parameter RV_FEE.
  • Do not add other public methods.
  • Do not change the behavior.

5. Business rules

  • The legacy implementation of {{P}}PEST_FEE defines the business rules.
  • The refactored class must return the same fee as the legacy class for every combination of the input values.
  • The rules are not repeated in this document. Read the legacy code.

6. Constraints

  • Release target: SAP_BASIS 8.16 (ABAP Platform 2025).
  • Coding standards: Clean ABAP. Method length below 40 statements. No number without a name. No deep nesting. No unused variable. No comment that restates the code.
  • Out of scope: do not change the public interface of {{P}}PEST_FEE.

7. Acceptance

  • The class is active and has no syntax error.
  • The hidden tests pass.
  • The class has no ATC finding with priority 1 or 2.
  • Write your own ABAP Unit tests for the class.