Step F first pass: 81/92 accepted; budget floor 60 calls; rejected slots moved for regeneration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
This commit is contained in:
Kral
2026-10-03 12:10:52 +02:00
parent d3250acfb8
commit 39769afce8
741 changed files with 40573 additions and 317 deletions

View File

@@ -0,0 +1,108 @@
CLASS {{p}}news_dist_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
TYPES ty_date TYPE d.
TYPES tt_date TYPE RANGE OF ty_date.
TYPES ty_dist TYPE c LENGTH 4.
TYPES tt_dist TYPE RANGE OF ty_dist.
METHODS run
IMPORTING it_date TYPE tt_date OPTIONAL
it_dist TYPE tt_dist OPTIONAL
RETURNING VALUE(rr_data) TYPE REF TO data.
METHODS value_of
IMPORTING ir_data TYPE REF TO data
iv_row TYPE i
iv_col TYPE string
RETURNING VALUE(rv_value) TYPE string.
METHODS lines_of
IMPORTING ir_data TYPE REF TO data
RETURNING VALUE(rv_lines) TYPE i.
METHODS all_agents FOR TESTING.
METHODS sorted_by_rate FOR TESTING.
METHODS sums_and_rate FOR TESTING.
METHODS district_filter FOR TESTING.
METHODS date_filter FOR TESTING.
METHODS zero_copies FOR TESTING.
METHODS no_deliveries FOR TESTING.
METHODS outside_period FOR TESTING.
ENDCLASS.
CLASS {{p}}news_dist_hidden IMPLEMENTATION.
METHOD run.
cl_salv_bs_runtime_info=>set( display = abap_false metadata = abap_false data = abap_true ).
SUBMIT {{p}}news_dist_old WITH s_date IN it_date WITH s_dist IN it_dist AND RETURN.
TRY.
cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = rr_data ).
CATCH cx_salv_bs_sc_runtime_info.
ENDTRY.
cl_salv_bs_runtime_info=>clear_all( ).
ENDMETHOD.
METHOD lines_of.
FIELD-SYMBOLS <lt_data> TYPE STANDARD TABLE.
IF ir_data IS BOUND.
ASSIGN ir_data->* TO <lt_data>.
rv_lines = lines( <lt_data> ).
ENDIF.
ENDMETHOD.
METHOD value_of.
FIELD-SYMBOLS <lt_data> TYPE STANDARD TABLE.
ASSIGN ir_data->* TO <lt_data>.
ASSIGN <lt_data>[ iv_row ] TO FIELD-SYMBOL(<ls_line>).
ASSIGN COMPONENT iv_col OF STRUCTURE <ls_line> TO FIELD-SYMBOL(<lv_value>).
cl_abap_unit_assert=>assert_subrc( exp = 0 msg = |Column { iv_col } missing| ).
rv_value = condense( CONV string( <lv_value> ) ).
ENDMETHOD.
METHOD all_agents.
cl_abap_unit_assert=>assert_equals( exp = 6 act = lines_of( run( ) ) ).
ENDMETHOD.
METHOD sorted_by_rate.
DATA(lr_data) = run( ).
cl_abap_unit_assert=>assert_equals( exp = `A5` act = value_of( ir_data = lr_data iv_row = 1 iv_col = `AGENT` ) ).
cl_abap_unit_assert=>assert_equals( exp = `A6` act = value_of( ir_data = lr_data iv_row = 6 iv_col = `AGENT` ) ).
ENDMETHOD.
METHOD sums_and_rate.
DATA(lr_data) = run( it_date = VALUE #( ( sign = 'I' option = 'BT' low = '20260101' high = '20260131' ) ) ).
cl_abap_unit_assert=>assert_equals( exp = 6 act = lines_of( lr_data ) ).
cl_abap_unit_assert=>assert_equals( exp = `A1` act = value_of( ir_data = lr_data iv_row = 4 iv_col = `AGENT` ) ).
cl_abap_unit_assert=>assert_equals( exp = `200` act = value_of( ir_data = lr_data iv_row = 4 iv_col = `COPIES` ) ).
cl_abap_unit_assert=>assert_equals( exp = `15` act = value_of( ir_data = lr_data iv_row = 4 iv_col = `RETURNED` ) ).
cl_abap_unit_assert=>assert_equals( exp = `7.50` act = value_of( ir_data = lr_data iv_row = 4 iv_col = `RATE` ) ).
ENDMETHOD.
METHOD district_filter.
DATA(lr_data) = run( it_dist = VALUE #( ( sign = 'I' option = 'EQ' low = 'W' ) ) ).
cl_abap_unit_assert=>assert_equals( exp = 2 act = lines_of( lr_data ) ).
cl_abap_unit_assert=>assert_equals( exp = `A5` act = value_of( ir_data = lr_data iv_row = 1 iv_col = `AGENT` ) ).
ENDMETHOD.
METHOD date_filter.
DATA(lr_data) = run( it_date = VALUE #( ( sign = 'I' option = 'GE' low = '20260110' ) ) ).
cl_abap_unit_assert=>assert_equals( exp = 2 act = lines_of( lr_data ) ).
cl_abap_unit_assert=>assert_equals( exp = `A1` act = value_of( ir_data = lr_data iv_row = 1 iv_col = `AGENT` ) ).
cl_abap_unit_assert=>assert_equals( exp = `A3` act = value_of( ir_data = lr_data iv_row = 2 iv_col = `AGENT` ) ).
ENDMETHOD.
METHOD zero_copies.
DATA(lr_data) = run( it_dist = VALUE #( ( sign = 'I' option = 'EQ' low = 'W' ) ) ).
cl_abap_unit_assert=>assert_equals( exp = `A6` act = value_of( ir_data = lr_data iv_row = 2 iv_col = `AGENT` ) ).
cl_abap_unit_assert=>assert_equals( exp = `0` act = value_of( ir_data = lr_data iv_row = 2 iv_col = `COPIES` ) ).
cl_abap_unit_assert=>assert_equals( exp = `0.00` act = value_of( ir_data = lr_data iv_row = 2 iv_col = `RATE` ) ).
ENDMETHOD.
METHOD no_deliveries.
cl_abap_unit_assert=>assert_equals(
exp = 0
act = lines_of( run( it_dist = VALUE #( ( sign = 'I' option = 'EQ' low = 'E' ) ) ) ) ).
ENDMETHOD.
METHOD outside_period.
cl_abap_unit_assert=>assert_equals(
exp = 0
act = lines_of( run( it_date = VALUE #( ( sign = 'I' option = 'BT' low = '20270101' high = '20271231' ) ) ) ) ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,34 @@
{
"task": "E21",
"mutants": [
{
"object": "{{P}}NEWS_DIST_OLD",
"mutant": "SORT: DESCENDING -> ASCENDING",
"status": "killed",
"hidden": "4/8",
"failed_tests": [
"sorted_by_rate",
"sums_and_rate",
"district_filter",
"zero_copies"
]
},
{
"object": "{{P}}NEWS_DIST_OLD",
"mutant": "rate guard: > -> >=",
"status": "killed",
"hidden": "5/8",
"failed_tests": [
"all_agents",
"sorted_by_rate",
"sums_and_rate",
"district_filter",
"zero_copies"
]
}
],
"valid": 2,
"killed": 2,
"kill_rate": 1.0,
"ok": true
}

View File

@@ -0,0 +1,131 @@
REPORT {{p}}news_dist_old.
TYPES ty_rate TYPE p LENGTH 8 DECIMALS 2.
TYPES: BEGIN OF ty_line,
agent TYPE {{p}}agent-agent_id,
name TYPE {{p}}agent-agent_name,
district TYPE {{p}}agent-district,
copies TYPE i,
returned TYPE i,
rate TYPE ty_rate,
END OF ty_line.
TYPES tt_line TYPE STANDARD TABLE OF ty_line WITH EMPTY KEY.
TYPES ty_date TYPE d.
TYPES tt_date TYPE RANGE OF ty_date.
TYPES ty_dist TYPE c LENGTH 4.
TYPES tt_dist TYPE RANGE OF ty_dist.
DATA gv_date TYPE ty_date.
DATA gv_dist TYPE ty_dist.
SELECT-OPTIONS s_date FOR gv_date.
SELECT-OPTIONS s_dist FOR gv_dist.
CLASS lcl_report DEFINITION FINAL.
PUBLIC SECTION.
METHODS select_lines
IMPORTING it_date TYPE tt_date
it_dist TYPE tt_dist
RETURNING VALUE(rt_lines) TYPE tt_line.
METHODS display
CHANGING ct_lines TYPE tt_line.
PRIVATE SECTION.
METHODS add_rate
CHANGING cs_line TYPE ty_line.
ENDCLASS.
CLASS lcl_report IMPLEMENTATION.
METHOD select_lines.
SELECT a~agent_id AS agent,
a~agent_name AS name,
a~district AS district,
SUM( d~del_copies ) AS copies,
SUM( d~ret_copies ) AS returned
FROM {{p}}agent AS a
INNER JOIN {{p}}deliv AS d ON d~agent_id = a~agent_id
WHERE d~del_date IN @it_date
AND a~district IN @it_dist
GROUP BY a~agent_id, a~agent_name, a~district
INTO CORRESPONDING FIELDS OF TABLE @rt_lines.
LOOP AT rt_lines ASSIGNING FIELD-SYMBOL(<ls_line>).
add_rate( CHANGING cs_line = <ls_line> ).
ENDLOOP.
SORT rt_lines BY rate DESCENDING agent ASCENDING.
ENDMETHOD.
METHOD add_rate.
DATA lv_copies TYPE p LENGTH 15 DECIMALS 2.
lv_copies = cs_line-copies.
IF lv_copies > 0.
cs_line-rate = cs_line-returned * 100 / lv_copies.
ELSE.
cs_line-rate = 0.
ENDIF.
ENDMETHOD.
METHOD display.
TRY.
cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_alv)
CHANGING t_table = ct_lines ).
lo_alv->display( ).
CATCH cx_salv_msg INTO DATA(lx_error).
MESSAGE lx_error TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(go_report) = NEW lcl_report( ).
DATA(gt_lines) = go_report->select_lines( it_date = s_date[]
it_dist = s_dist[] ).
go_report->display( CHANGING ct_lines = gt_lines ).
CLASS ltc_report DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
CLASS-DATA go_env TYPE REF TO if_osql_test_environment.
CLASS-METHODS class_setup.
CLASS-METHODS class_teardown.
METHODS sums_per_agent FOR TESTING.
METHODS rate_with_zero_copies FOR TESTING.
ENDCLASS.
CLASS ltc_report IMPLEMENTATION.
METHOD class_setup.
go_env = cl_osql_test_environment=>create(
i_dependency_list = VALUE #( ( '{{P}}AGENT' ) ( '{{P}}DELIV' ) ) ).
DATA lt_agent TYPE STANDARD TABLE OF {{p}}agent WITH EMPTY KEY.
lt_agent = VALUE #( ( agent_id = 'A1' agent_name = 'One' district = 'N' )
( agent_id = 'A2' agent_name = 'Two' district = 'S' ) ).
go_env->insert_test_data( lt_agent ).
DATA lt_deliv TYPE STANDARD TABLE OF {{p}}deliv WITH EMPTY KEY.
lt_deliv = VALUE #( ( deliv_id = 1 agent_id = 'A1' del_date = '20260105' del_copies = 100 ret_copies = 5 )
( deliv_id = 2 agent_id = 'A1' del_date = '20260112' del_copies = 100 ret_copies = 15 )
( deliv_id = 3 agent_id = 'A2' del_date = '20260106' del_copies = 0 ret_copies = 0 ) ).
go_env->insert_test_data( lt_deliv ).
ENDMETHOD.
METHOD class_teardown.
go_env->destroy( ).
ENDMETHOD.
METHOD sums_per_agent.
DATA(lt_lines) = NEW lcl_report( )->select_lines( it_date = VALUE tt_date( )
it_dist = VALUE tt_dist( ) ).
cl_abap_unit_assert=>assert_equals( exp = 2 act = lines( lt_lines ) ).
cl_abap_unit_assert=>assert_equals( exp = 'A1' act = lt_lines[ 1 ]-agent ).
cl_abap_unit_assert=>assert_equals( exp = 200 act = lt_lines[ 1 ]-copies ).
cl_abap_unit_assert=>assert_equals( exp = 20 act = lt_lines[ 1 ]-returned ).
cl_abap_unit_assert=>assert_equals( exp = '10.00' act = |{ lt_lines[ 1 ]-rate }| ).
ENDMETHOD.
METHOD rate_with_zero_copies.
DATA(lt_lines) = NEW lcl_report( )->select_lines( it_date = VALUE tt_date( )
it_dist = VALUE tt_dist( ) ).
cl_abap_unit_assert=>assert_equals( exp = 'A2' act = lt_lines[ 2 ]-agent ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lt_lines[ 2 ]-copies ).
cl_abap_unit_assert=>assert_equals( exp = '0.00' act = |{ lt_lines[ 2 ]-rate }| ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,11 @@
@EndUserText.label : 'Newsagent'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table {{p}}agent {
key client : abap.clnt not null;
key agent_id : abap.char(6) not null;
agent_name : abap.char(40);
district : abap.char(4);
}

View File

@@ -0,0 +1,13 @@
@EndUserText.label : 'News delivery'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table {{p}}deliv {
key client : abap.clnt not null;
key deliv_id : abap.int4 not null;
agent_id : abap.char(6);
del_date : abap.dats;
del_copies : abap.int4;
ret_copies : abap.int4;
}

View File

@@ -0,0 +1,72 @@
REPORT {{p}}news_dist_old.
* Legacy distribution report of the newspaper publisher.
* Shows the delivered copies and the returns of each newsagent.
TYPES ty_rate TYPE p LENGTH 8 DECIMALS 2.
TYPES: BEGIN OF ty_out,
agent TYPE {{p}}agent-agent_id,
name TYPE {{p}}agent-agent_name,
district TYPE {{p}}agent-district,
copies TYPE i,
returned TYPE i,
rate TYPE ty_rate,
END OF ty_out.
DATA: gt_agent TYPE STANDARD TABLE OF {{p}}agent,
gs_agent TYPE {{p}}agent,
gt_deliv TYPE STANDARD TABLE OF {{p}}deliv,
gs_deliv TYPE {{p}}deliv,
gs_out TYPE ty_out,
gt_out TYPE STANDARD TABLE OF ty_out,
gt_list TYPE STANDARD TABLE OF ty_out,
gv_date TYPE d,
gv_dist TYPE c LENGTH 4,
go_alv TYPE REF TO cl_salv_table.
SELECT-OPTIONS s_date FOR gv_date.
SELECT-OPTIONS s_dist FOR gv_dist.
START-OF-SELECTION.
SELECT * FROM {{p}}agent INTO TABLE gt_agent.
LOOP AT gt_agent INTO gs_agent.
SELECT * FROM {{p}}deliv INTO TABLE gt_deliv
WHERE agent_id = gs_agent-agent_id
AND del_date IN s_date.
IF gt_deliv IS NOT INITIAL.
CLEAR gs_out.
gs_out-agent = gs_agent-agent_id.
gs_out-name = gs_agent-agent_name.
gs_out-district = gs_agent-district.
LOOP AT gt_deliv INTO gs_deliv.
gs_out-copies = gs_out-copies + gs_deliv-del_copies.
gs_out-returned = gs_out-returned + gs_deliv-ret_copies.
ENDLOOP.
PERFORM calc_rate USING gs_out-returned gs_out-copies
CHANGING gs_out-rate.
APPEND gs_out TO gt_out.
ENDIF.
ENDLOOP.
LOOP AT gt_out INTO gs_out WHERE district IN s_dist.
APPEND gs_out TO gt_list.
ENDLOOP.
SORT gt_list BY rate DESCENDING agent ASCENDING.
TRY.
cl_salv_table=>factory( IMPORTING r_salv_table = go_alv
CHANGING t_table = gt_list ).
go_alv->display( ).
CATCH cx_salv_msg.
ENDTRY.
FORM calc_rate USING iv_returned TYPE i
iv_copies TYPE i
CHANGING cv_rate TYPE ty_rate.
DATA lv_copies TYPE p LENGTH 15 DECIMALS 2.
lv_copies = iv_copies.
IF lv_copies > 0.
cv_rate = iv_returned * 100 / lv_copies.
ELSE.
CLEAR cv_rate.
ENDIF.
ENDFORM.

View File

@@ -0,0 +1,33 @@
CLASS {{p}}news_seed DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
ENDCLASS.
CLASS {{p}}news_seed IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DELETE FROM {{p}}deliv.
DELETE FROM {{p}}agent.
INSERT {{p}}agent FROM TABLE @( VALUE #(
( agent_id = 'A1' agent_name = 'Corner Shop' district = 'N' )
( agent_id = 'A2' agent_name = 'Station Kiosk' district = 'N' )
( agent_id = 'A3' agent_name = 'City News' district = 'S' )
( agent_id = 'A4' agent_name = 'Harbour Store' district = 'S' )
( agent_id = 'A5' agent_name = 'Airport Shop' district = 'W' )
( agent_id = 'A6' agent_name = 'Closed Kiosk' district = 'W' )
( agent_id = 'A7' agent_name = 'Village Store' district = 'E' ) ) ).
INSERT {{p}}deliv FROM TABLE @( VALUE #(
( deliv_id = 1 agent_id = 'A1' del_date = '20260105' del_copies = 100 ret_copies = 5 )
( deliv_id = 2 agent_id = 'A1' del_date = '20260112' del_copies = 100 ret_copies = 10 )
( deliv_id = 3 agent_id = 'A2' del_date = '20251220' del_copies = 40 ret_copies = 4 )
( deliv_id = 4 agent_id = 'A2' del_date = '20260106' del_copies = 50 ret_copies = 0 )
( deliv_id = 5 agent_id = 'A3' del_date = '20260107' del_copies = 200 ret_copies = 40 )
( deliv_id = 6 agent_id = 'A3' del_date = '20260114' del_copies = 200 ret_copies = 20 )
( deliv_id = 7 agent_id = 'A4' del_date = '20260108' del_copies = 80 ret_copies = 8 )
( deliv_id = 8 agent_id = 'A5' del_date = '20260109' del_copies = 60 ret_copies = 30 )
( deliv_id = 9 agent_id = 'A6' del_date = '20260103' del_copies = 0 ret_copies = 0 ) ) ).
out->write( 'Seed done' ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,52 @@
# 1. Goal
The program {{P}}NEWS_DIST_OLD in package $TMP is the legacy distribution
report of a regional newspaper publisher. It shows, for a period, the copies
that each newsagent received and returned. The report works, but its source
does not meet the current quality standards of the company. Refactor the
source of {{P}}NEWS_DIST_OLD in place. The behavior of the program stays the
same.
# 2. Open questions
None.
# 3. Context
- The executable program {{P}}NEWS_DIST_OLD exists in package $TMP and is
active. Its source is the legacy code that you refactor.
- The tables {{P}}AGENT and {{P}}DELIV exist in package $TMP and contain data.
- Users run the program with the selection screen and read the ALV list.
# 4. Contract
- Object: the executable program {{P}}NEWS_DIST_OLD in package $TMP.
Refactor this program in place. Keep the name. Do not create a new program.
- Selection screen, unchanged:
- Select-option S_DATE for the delivery date.
- Select-option S_DIST for the district.
- The program shows the result with CL_SALV_TABLE, as before.
- The ALV list keeps these column names:
AGENT, NAME, DISTRICT, COPIES, RETURNED, RATE.
# 5. Business rules
The behavior of the program does not change. The legacy source of
{{P}}NEWS_DIST_OLD is the specification of the behavior. Read the source and
keep all of it:
- the filters of the selection screen,
- the set of lines of the list,
- the values of the columns,
- the sort order of the lines.
Do not change the result of the program.
# 6. Constraints
- Release target: 8.16.
- Coding standards: Clean ABAP.
- The refactored program has no database access inside a loop.
- No method of the program has more than 40 statements.
- The program has no ATC finding of priority 1 or 2.
- Write ABAP Unit tests as local test classes in the program.
- Out of scope: do not change the tables {{P}}AGENT and {{P}}DELIV.
Do not change the selection screen names and the ALV column names.
# 7. Acceptance
- {{P}}NEWS_DIST_OLD is active and has no syntax error.
- The result of the program is the same as before the refactoring.
- The hidden tests pass.
- The local test classes pass.

View File

@@ -0,0 +1,73 @@
{
"id": "G0141",
"category": "E",
"object_type": "PROG",
"difficulty": 2,
"release_target": "v816",
"expected_outcome": "implement",
"budget": {
"max_tool_calls": 60,
"max_activations": 15
},
"seed": [
{
"type": "TABL",
"name": "{{P}}AGENT",
"file": "seed/agent.tabl.asabap",
"description": "Newsagents"
},
{
"type": "TABL",
"name": "{{P}}DELIV",
"file": "seed/deliv.tabl.asabap",
"description": "News deliveries"
},
{
"type": "CLAS",
"name": "{{P}}NEWS_SEED",
"file": "seed/news_seed.clas.abap",
"description": "Seed data",
"run": true
},
{
"type": "PROG",
"name": "{{P}}NEWS_DIST_OLD",
"file": "seed/news_dist_old.prog.abap",
"description": "Legacy distribution report"
}
],
"contract": [
{
"type": "PROG",
"name": "{{P}}NEWS_DIST_OLD",
"parameters": [
"s_date",
"s_dist"
]
}
],
"out_of_scope": [
"{{P}}AGENT",
"{{P}}DELIV"
],
"hidden_tests": [
{
"type": "CLAS",
"name": "{{P}}NEWS_DIST_HIDDEN",
"file": "hidden/news_dist_hidden.clas.abap",
"description": "Hidden tests for the distribution report"
}
],
"reference": [
{
"type": "PROG",
"name": "{{P}}NEWS_DIST_OLD",
"file": "reference/news_dist_old.prog.abap",
"description": "Refactored distribution report"
}
],
"craft_checks": [
"db_operation_in_loop",
"method_length"
]
}