2.2 KiB
2.2 KiB
1. Goal
Summarise the harvest of two growing rooms of a mushroom farm. The store keeper calls one function module for the two rooms. The function module reads the harvest records of the two rooms and returns the summary.
2. Open questions
None.
3. Context
- Function group {{P}}FG_MUSH exists in package $TMP.
- Table {{P}}HARVEST exists in package $TMP. It holds the harvest records of all growing rooms. Its fields are room_id, grade, batch_no and weight_kg. One record is the weight of one batch of one grade in one room.
- The function module reads the harvest records of the two rooms from this table.
4. Contract
- Create the function module {{P}}MUSH_HARVEST in function group {{P}}FG_MUSH.
- Interface of {{P}}MUSH_HARVEST: IMPORTING iv_room_a TYPE string IMPORTING iv_room_b TYPE string EXPORTING ev_total_kg TYPE decfloat34 EXPORTING ev_room_count TYPE i EXPORTING ev_top_grade TYPE char1 EXCEPTIONS no_stock
5. Business rules
- A harvest record counts only if all of these conditions are true:
- its room_id is not empty,
- its room_id is equal to iv_room_a or to iv_room_b,
- its grade is 'A', 'B' or 'C',
- its weight_kg is greater than zero.
- A record that does not count is ignored. It does not cause an error.
- ev_total_kg is the sum of the weight_kg of all counting records. If no record counts, ev_total_kg is 0.
- ev_room_count is the number of different room_id values among the counting records. If no record counts, ev_room_count is 0.
- ev_top_grade is the grade with the highest sum of weight_kg among the counting records. If two grades have the same sum, ev_top_grade is the grade that comes first in alphabetical order. If no record counts, ev_top_grade is initial.
- If no record counts, the function module raises the exception NO_STOCK.
- If at least one record counts, the function module does not raise an exception.
6. Constraints
- Release target: ABAP Platform 2025 (SAP_BASIS 816).
- Coding standards: Clean ABAP. Keep the function module below 40 statements.
- Out of scope: do not change table {{P}}HARVEST.
7. Acceptance
- The function module is active and has no syntax error.
- The hidden tests pass.
- Write ABAP Unit tests for the function module in a global test class.