2.6 KiB
2.6 KiB
1. Goal
A sawmill plans the cutting of logs. The sawmill receives the log lists of two forest districts. A planning program calls one service that combines the two lists into one list of logs that are ready for cutting. The program also needs the number of logs and the total length for each district.
2. Open questions
None.
3. Context
- The class {{P}}LOG_MERGER does not exist. Create it in package $TMP.
- A log has a log number, a district, a length in centimetres and a diameter in centimetres.
- A log number identifies a log. The same log number can occur more than once in one list and in both lists.
- The caller gives the log lists. The class does not read a database table.
4. Contract
- Create the class {{P}}LOG_MERGER in package $TMP.
- The class is public and final. It has a public constructor without parameters.
- Public types of the class:
- TY_LOG_NO: character, length 10.
- TY_DISTRICT: character, length 4.
- TY_LOG: structure with the components LOG_NO (TY_LOG_NO), DISTRICT (TY_DISTRICT), LENGTH_CM (integer) and DIAMETER_CM (integer).
- TT_LOG: standard table of TY_LOG with an empty key.
- TY_DISTRICT_STAT: structure with the components DISTRICT (TY_DISTRICT), LOG_QTY (integer) and TOTAL_LENGTH_CM (integer).
- TT_DISTRICT_STAT: standard table of TY_DISTRICT_STAT with an empty key.
- Public methods:
- COMBINE, importing IT_FIRST (TT_LOG) and IT_SECOND (TT_LOG), returning RT_RESULT (TT_LOG).
- COUNT_BY_DISTRICT, importing IT_LOG (TT_LOG), returning RT_STAT (TT_DISTRICT_STAT).
- Do not add other public methods.
5. Business rules
COMBINE:
- Build a merged list. Read IT_FIRST first and IT_SECOND second. Add a log to the merged list only if its log number is not yet in the merged list. Ignore every later log with the same log number.
- Remove every log from the merged list with LENGTH_CM below 200 or with DIAMETER_CM below 20.
- Sort the result by LOG_NO in ascending order.
- The result has no two logs with the same log number.
COUNT_BY_DISTRICT:
- The result has one row for each district that occurs in IT_LOG.
- LOG_QTY is the number of logs of the district.
- TOTAL_LENGTH_CM is the sum of LENGTH_CM of the logs of the district.
- Sort the result by DISTRICT in ascending order.
- An empty input gives an empty result.
6. Constraints
- Release target: ABAP Platform 2025 (SAP_BASIS 816).
- Coding standards: Clean ABAP. Methods below 40 statements. No global variables. No comment that restates the code.
- Out of scope: 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.