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

3.5 KiB

1. Goal

Plan the cost of a production job in a metal workshop. The workshop office checks a job before it accepts the job and calculates the planned cost of the job. The office needs one clear reason for each job that it rejects.

2. Open questions

None.

3. Context

  • A job order has a job ID, a calculation mode, work hours, a part count, a material group, a due date and a material value.
  • The words HOURS, MODE, ORDER, DATE, COUNT, GROUP and VALUE are reserved words in ABAP SQL. Do not use them as names of fields, types, variables or constants. Use the names of the contract.
  • The office passes the job data to the class. No database table is necessary.

4. Contract

Both classes are in package $TMP.

4.1 Class {{P}}CX_JOB_ERROR

  • The class is public, final, and inherits from CX_STATIC_CHECK.
  • Public type TY_REASON, character 12.
  • Public constant structure C_REASON with these components and values: NO_JOB_ID, BAD_MODE, BAD_HOURS, BAD_COUNT, BAD_GROUP, BAD_DATE, BAD_VALUE.
  • Public method CONSTRUCTOR, IMPORTING iv_reason TYPE ty_reason.
  • Public method GET_REASON, RETURNING VALUE(rv_reason) TYPE ty_reason.
  • Public method GET_MESSAGE, RETURNING VALUE(rv_message) TYPE string.
  • Do not add other public components.

4.2 Class {{P}}JOB_PLANNER

  • The class is public, final, and has a public constructor without parameters.
  • Public type TY_JOB with these components:
    • job_id TYPE c LENGTH 10
    • calc_mode TYPE c LENGTH 1
    • work_hours TYPE p LENGTH 5 DECIMALS 2
    • part_count TYPE i
    • mat_group TYPE c LENGTH 4
    • due_date TYPE d
    • net_value TYPE p LENGTH 11 DECIMALS 2
  • Public type TY_COST, packed number, length 11, 2 decimals.
  • Public method VALIDATE, IMPORTING is_job TYPE ty_job, RAISING {{P}}CX_JOB_ERROR.
  • Public method CALCULATE_COST, IMPORTING is_job TYPE ty_job, RETURNING VALUE(rv_cost) TYPE ty_cost, RAISING {{P}}CX_JOB_ERROR.
  • Do not add other public methods.

5. Business rules

5.1 Validation

VALIDATE checks the job in this sequence. It raises {{P}}CX_JOB_ERROR with the reason of the first rule that fails. A rule after the first failing rule is not checked.

  1. job_id must not be empty. Reason NO_JOB_ID.
  2. calc_mode must be S, E or P. Reason BAD_MODE.
  3. work_hours must be greater than 0 and not greater than 100. Reason BAD_HOURS.
  4. part_count must be greater than 0. Reason BAD_COUNT.
  5. mat_group must be ST, AL, PL or WD. Reason BAD_GROUP.
  6. due_date must not be empty. Reason BAD_DATE.
  7. net_value must not be negative. Reason BAD_VALUE.

5.2 Cost

CALCULATE_COST applies all rules of 5.1 first and raises the same exception. Then it calculates the cost: cost = work_hours * hour rate + part_count * part rate + net_value Hour rate: S 60.00, E 90.00, P 75.00. Part rate: ST 12.50, AL 8.00, PL 3.50, WD 5.00.

5.3 Messages

GET_MESSAGE returns the message text of the reason:

  • NO_JOB_ID: The job ID is missing.
  • BAD_MODE: The calculation mode is not valid.
  • BAD_HOURS: The work hours are not valid.
  • BAD_COUNT: The part count is not valid.
  • BAD_GROUP: The material group is not valid.
  • BAD_DATE: The due date is not valid.
  • BAD_VALUE: The material value is not valid.

6. Constraints

  • Release target: 7.58.
  • Coding standards: Clean ABAP. Method length below 40 statements. No global variables. Pass structures by reference. No comment that restates the code.
  • Out of scope: no database table, no report, no ALV list, no CDS view.

7. Acceptance

  • Both classes are active and have no syntax error.
  • The hidden tests pass.
  • Write your own ABAP Unit tests for {{P}}JOB_PLANNER.