3.1 KiB
3.1 KiB
1. Goal
A zoo keeps a feed store. Two suppliers send their feed deliveries. The store manager needs one consolidated stock list per feed type, the quantity of one feed type, and the feed type with the highest quantity. A store program calls the class for each delivery round.
2. Open questions
None.
3. Context
- Interface {{P}}IF_FEED_STOCK exists in package $TMP. It is active.
- The interface has these types:
- TY_FEED_TYPE (CHAR 8), TY_UNIT (CHAR 3), TY_QUANTITY (packed, 3 decimals).
- TY_DELIVERY with the fields FEED_TYPE, UNIT and QUANTITY.
- TT_DELIVERY: a table of TY_DELIVERY.
- TY_STOCK with the fields FEED_TYPE, UNIT, QUANTITY and DELIVERIES (integer).
- TT_STOCK: a table of TY_STOCK.
- The interface has three methods:
- CONSOLIDATE with the importing parameters IT_SUPPLIER_A and IT_SUPPLIER_B (both TT_DELIVERY) and the returning parameter RT_STOCK (TT_STOCK).
- QUANTITY_OF with the importing parameters IT_STOCK (TT_STOCK) and IV_FEED_TYPE (TY_FEED_TYPE) and the returning parameter RV_QUANTITY (TY_QUANTITY).
- TOP_FEED with the importing parameter IT_STOCK (TT_STOCK) and the returning parameter RV_FEED_TYPE (TY_FEED_TYPE).
4. Contract
- Create the class {{P}}FEED_STOCK in package $TMP.
- The class is public, final, and has a public constructor without parameters.
- The class implements {{P}}IF_FEED_STOCK.
- Do not add other public methods.
5. Business rules
5.1 Input
- A delivery row has the fields FEED_TYPE, UNIT and QUANTITY.
- The caller passes two delivery lists: supplier A and supplier B. Each list can hold any number of rows, including none.
5.2 CONSOLIDATE
- Count a row only when its feed type is not empty and its quantity is not zero. Ignore every other row.
- Read the counted rows of supplier A first, in the given order, then the counted rows of supplier B, in the given order.
- Group the counted rows by feed type. The result has one row per feed type.
- The quantity of a result row is the sum of the quantities of the counted rows of this feed type. A negative quantity reduces the sum.
- The unit of a result row is the unit of the first counted row of this feed type.
- The deliveries of a result row is the number of counted rows of this feed type.
- Remove a result row whose quantity is zero.
- Sort the result rows by feed type in ascending order.
- Return an empty list when no result row remains.
5.3 QUANTITY_OF
- Return the quantity of the result row with the given feed type.
- Return zero when the list has no row with this feed type.
5.4 TOP_FEED
- Return the feed type with the highest quantity in the list.
- When more than one feed type has the same highest quantity, return the feed type that comes first in ascending order.
- Return an empty feed type when the list 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: do not change {{P}}IF_FEED_STOCK.
7. Acceptance
- The class is active and has no syntax error.
- The hidden tests pass.
- Write your own ABAP Unit tests for the class.