Files

2 lines
2.9 KiB
Markdown

Please create the class {{P}}STOCK_AGE in package $TMP. The class is public and final, and it has a public constructor without parameters. The class implements {{P}}IF_STOCK_AGE. Do not add other public methods. The interface {{P}}IF_STOCK_AGE exists in package $TMP and is active. The interface defines the types ty_material, ty_batch_id, ty_bucket, ty_quantity, ty_batch, tt_batch, ty_age_row, tt_age_row, ty_total, and tt_total. ty_material is character with length 10. ty_batch_id is character with length 10. ty_bucket is character with length 2. ty_quantity is packed number with length 13 and 3 decimals. ty_batch is a structure with components material, batch, quantity, and gr_date. tt_batch is a table of ty_batch. ty_age_row is a structure with components material, bucket, quantity, and batch_count. tt_age_row is a table of ty_age_row. ty_total is a structure with components material, quantity, and batch_count. tt_total is a table of ty_total. The interface defines the constant structure C_BUCKET with components D0_30 = '01', D31_60 = '02', D61_90 = '03', and D91_PLUS = '04'. The interface defines method analyze with importing it_batch type tt_batch and iv_key_date type dats, returning rt_age type tt_age_row. The interface defines method total_by_material with importing it_batch type tt_batch and iv_key_date type dats, returning rt_total type tt_total. Both methods use the same validity rules and the same age buckets. A row of IT_BATCH is valid when its goods receipt date is not initial and is not after IV_KEY_DATE. A row that is not valid is ignored. It must not change any result. The age of a batch is the number of days between its goods receipt date and IV_KEY_DATE. The bucket of a batch is 01 (C_BUCKET-D0_30) for age 0 to 30 days, 02 (C_BUCKET-D31_60) for age 31 to 60 days, 03 (C_BUCKET-D61_90) for age 61 to 90 days, and 04 (C_BUCKET-D91_PLUS) for age more than 90 days. In method ANALYZE, group the valid rows by material and bucket. For each group, sum the quantity and count the valid rows. Return one row per group. Sort the result by material ascending and then by bucket ascending. A group is in the result as soon as one valid row belongs to it, also when the summed quantity is zero. If no valid row exists, return an empty table. In method TOTAL_BY_MATERIAL, group the valid rows by material only. For each group, sum the quantity and count the valid rows. Return one row per material. Sort the result by material ascending. If no valid row exists, return an empty table. The quantity of a batch can be negative. Add the quantities as they are. The release target is SAP_BASIS 8.16 (ABAP Platform 2025). Follow Clean ABAP. Keep method length below 40 statements. Do not use global variables. Do not write comments that restate the code. Pass large parameters by reference. Do not change {{P}}IF_STOCK_AGE. The class is active and has no syntax error. The hidden tests pass. Write your own ABAP Unit tests for the class.