Snapshot: new training tasks (balanced generation), docs
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
108
tasks_gen/train/G1941/reference/compost_sum.prog.abap
Normal file
108
tasks_gen/train/G1941/reference/compost_sum.prog.abap
Normal file
@@ -0,0 +1,108 @@
|
||||
REPORT {{p}}compost_sum.
|
||||
|
||||
DATA gv_round TYPE {{p}}gwaste-round_id.
|
||||
|
||||
PARAMETERS p_from TYPE d OBLIGATORY.
|
||||
SELECT-OPTIONS s_round FOR gv_round.
|
||||
|
||||
CLASS lcl_report DEFINITION FINAL.
|
||||
PUBLIC SECTION.
|
||||
TYPES:
|
||||
BEGIN OF ty_line,
|
||||
round_id TYPE {{p}}gwaste-round_id,
|
||||
total_kg TYPE {{p}}gwaste-weight_kg,
|
||||
deliveries TYPE i,
|
||||
heavy TYPE i,
|
||||
END OF ty_line,
|
||||
tt_line TYPE STANDARD TABLE OF ty_line WITH EMPTY KEY,
|
||||
tt_round TYPE RANGE OF {{p}}gwaste-round_id.
|
||||
CONSTANTS c_heavy_kg TYPE {{p}}gwaste-weight_kg VALUE '1000.00'.
|
||||
METHODS select_totals
|
||||
IMPORTING iv_from TYPE d
|
||||
it_round TYPE tt_round
|
||||
RETURNING VALUE(rt_lines) TYPE tt_line.
|
||||
METHODS display
|
||||
CHANGING ct_lines TYPE tt_line.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS lcl_report IMPLEMENTATION.
|
||||
METHOD select_totals.
|
||||
SELECT round_id, weight_kg
|
||||
FROM {{p}}gwaste
|
||||
WHERE deliv_date >= @iv_from
|
||||
AND round_id IN @it_round
|
||||
INTO TABLE @DATA(lt_deliveries).
|
||||
|
||||
DATA lt_work TYPE SORTED TABLE OF ty_line WITH UNIQUE KEY round_id.
|
||||
LOOP AT lt_deliveries INTO DATA(ls_delivery).
|
||||
READ TABLE lt_work WITH TABLE KEY round_id = ls_delivery-round_id
|
||||
ASSIGNING FIELD-SYMBOL(<ls_line>).
|
||||
IF sy-subrc <> 0.
|
||||
INSERT VALUE #( round_id = ls_delivery-round_id ) INTO TABLE lt_work ASSIGNING <ls_line>.
|
||||
ENDIF.
|
||||
<ls_line>-total_kg += ls_delivery-weight_kg.
|
||||
<ls_line>-deliveries += 1.
|
||||
IF ls_delivery-weight_kg >= c_heavy_kg.
|
||||
<ls_line>-heavy += 1.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
|
||||
rt_lines = lt_work.
|
||||
SORT rt_lines BY total_kg DESCENDING.
|
||||
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_totals( iv_from = p_from it_round = s_round[] ).
|
||||
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 totals_per_round FOR TESTING.
|
||||
METHODS heavy_and_sorted FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS ltc_report IMPLEMENTATION.
|
||||
METHOD class_setup.
|
||||
go_env = cl_osql_test_environment=>create( i_dependency_list = VALUE #( ( '{{P}}GWASTE' ) ) ).
|
||||
DATA lt_waste TYPE STANDARD TABLE OF {{p}}gwaste WITH EMPTY KEY.
|
||||
lt_waste = VALUE #(
|
||||
( delivery_id = 1 round_id = 'A' waste_type = 'GRAS' deliv_date = '20260101' weight_kg = '1200.00' )
|
||||
( delivery_id = 2 round_id = 'A' waste_type = 'HEDG' deliv_date = '20260102' weight_kg = '500.00' )
|
||||
( delivery_id = 3 round_id = 'B' waste_type = 'BRAN' deliv_date = '20260101' weight_kg = '900.00' ) ).
|
||||
go_env->insert_test_data( lt_waste ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD class_teardown.
|
||||
go_env->destroy( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD totals_per_round.
|
||||
DATA(lt_lines) = NEW lcl_report( )->select_totals( iv_from = '20260101' it_round = VALUE #( ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = lines( lt_lines ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'A' act = lt_lines[ 1 ]-round_id ).
|
||||
DATA(lv_total) = lt_lines[ 1 ]-total_kg.
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV {{p}}gwaste-weight_kg( 1700 ) act = lv_total ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD heavy_and_sorted.
|
||||
DATA(lt_lines) = NEW lcl_report( )->select_totals( iv_from = '20260101' it_round = VALUE #( ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lt_lines[ 1 ]-heavy ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 0 act = lt_lines[ 2 ]-heavy ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lt_lines[ 2 ]-deliveries ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
Reference in New Issue
Block a user