Stage 2 summary at 50 accepted trajectories
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
172
tasks_gen/train/G1102/reference/farm_shop_old.prog.abap
Normal file
172
tasks_gen/train/G1102/reference/farm_shop_old.prog.abap
Normal file
@@ -0,0 +1,172 @@
|
||||
REPORT {{p}}farm_shop_old.
|
||||
|
||||
DATA gv_grp_code TYPE {{p}}goods-grp_code.
|
||||
|
||||
PARAMETERS p_day TYPE d OBLIGATORY.
|
||||
SELECT-OPTIONS s_grp FOR gv_grp_code.
|
||||
|
||||
CLASS lcl_shop_report DEFINITION FINAL.
|
||||
PUBLIC SECTION.
|
||||
TYPES:
|
||||
BEGIN OF ty_line,
|
||||
grp_code TYPE {{p}}goods-grp_code,
|
||||
sales TYPE i,
|
||||
turnover TYPE {{p}}goods-unit_price,
|
||||
pct_share TYPE p LENGTH 5 DECIMALS 1,
|
||||
END OF ty_line,
|
||||
tt_line TYPE STANDARD TABLE OF ty_line WITH EMPTY KEY.
|
||||
TYPES tt_grp_range TYPE RANGE OF {{p}}goods-grp_code.
|
||||
|
||||
METHODS get_totals
|
||||
IMPORTING iv_day TYPE d
|
||||
it_grp TYPE tt_grp_range
|
||||
RETURNING VALUE(rt_lines) TYPE tt_line.
|
||||
|
||||
METHODS display
|
||||
CHANGING ct_lines TYPE tt_line.
|
||||
|
||||
PRIVATE SECTION.
|
||||
METHODS set_shares
|
||||
CHANGING ct_lines TYPE tt_line.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS lcl_shop_report IMPLEMENTATION.
|
||||
METHOD get_totals.
|
||||
TYPES:
|
||||
BEGIN OF ty_row,
|
||||
grp_code TYPE {{p}}goods-grp_code,
|
||||
qty TYPE {{p}}gdsale-qty,
|
||||
unit_price TYPE {{p}}goods-unit_price,
|
||||
END OF ty_row.
|
||||
DATA lt_rows TYPE STANDARD TABLE OF ty_row WITH EMPTY KEY.
|
||||
|
||||
SELECT g~grp_code, s~qty, g~unit_price
|
||||
FROM {{p}}gdsale AS s
|
||||
INNER JOIN {{p}}goods AS g ON g~goods_id = s~goods_id
|
||||
WHERE s~sale_state = 'P'
|
||||
AND s~sale_day = @iv_day
|
||||
AND g~grp_code IN @it_grp
|
||||
INTO TABLE @lt_rows.
|
||||
|
||||
DATA lt_totals TYPE HASHED TABLE OF ty_line WITH UNIQUE KEY grp_code.
|
||||
|
||||
LOOP AT lt_rows INTO DATA(ls_row).
|
||||
ASSIGN lt_totals[ grp_code = ls_row-grp_code ] TO FIELD-SYMBOL(<ls_total>).
|
||||
IF sy-subrc <> 0.
|
||||
INSERT VALUE #( grp_code = ls_row-grp_code ) INTO TABLE lt_totals ASSIGNING <ls_total>.
|
||||
ENDIF.
|
||||
<ls_total>-sales = <ls_total>-sales + 1.
|
||||
<ls_total>-turnover = <ls_total>-turnover + ls_row-qty * ls_row-unit_price.
|
||||
ENDLOOP.
|
||||
|
||||
rt_lines = CORRESPONDING #( lt_totals ).
|
||||
set_shares( CHANGING ct_lines = rt_lines ).
|
||||
SORT rt_lines BY turnover DESCENDING.
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD set_shares.
|
||||
DATA lv_total TYPE {{p}}goods-unit_price.
|
||||
LOOP AT ct_lines INTO DATA(ls_line).
|
||||
lv_total = lv_total + ls_line-turnover.
|
||||
ENDLOOP.
|
||||
IF lv_total = 0.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
LOOP AT ct_lines ASSIGNING FIELD-SYMBOL(<ls_line>).
|
||||
<ls_line>-pct_share = <ls_line>-turnover * 100 / lv_total.
|
||||
ENDLOOP.
|
||||
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(lo_report) = NEW lcl_shop_report( ).
|
||||
DATA(lt_lines) = lo_report->get_totals( iv_day = p_day it_grp = s_grp[] ).
|
||||
lo_report->display( CHANGING ct_lines = lt_lines ).
|
||||
|
||||
CLASS ltc_shop_report DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
PRIVATE SECTION.
|
||||
TYPES ty_share TYPE p LENGTH 5 DECIMALS 1.
|
||||
|
||||
CLASS-DATA go_env TYPE REF TO if_osql_test_environment.
|
||||
CLASS-METHODS class_setup.
|
||||
CLASS-METHODS class_teardown.
|
||||
METHODS totals_per_group FOR TESTING.
|
||||
METHODS sorted_by_turnover FOR TESTING.
|
||||
METHODS share_of_total FOR TESTING.
|
||||
METHODS cancelled_ignored FOR TESTING.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS ltc_shop_report IMPLEMENTATION.
|
||||
METHOD class_setup.
|
||||
go_env = cl_osql_test_environment=>create(
|
||||
i_dependency_list = VALUE #( ( '{{P}}GOODS' ) ( '{{P}}GDSALE' ) ) ).
|
||||
|
||||
DATA lt_goods TYPE STANDARD TABLE OF {{p}}goods WITH EMPTY KEY.
|
||||
lt_goods = VALUE #( ( goods_id = 'G001' grp_code = 'VEG' unit_price = '2.50' )
|
||||
( goods_id = 'G002' grp_code = 'VEG' unit_price = '3.00' )
|
||||
( goods_id = 'G003' grp_code = 'FRU' unit_price = '4.00' )
|
||||
( goods_id = 'G004' grp_code = 'DAI' unit_price = '5.00' )
|
||||
( goods_id = 'G005' grp_code = 'DAI' unit_price = '1.50' ) ).
|
||||
go_env->insert_test_data( lt_goods ).
|
||||
|
||||
DATA lt_sale TYPE STANDARD TABLE OF {{p}}gdsale WITH EMPTY KEY.
|
||||
lt_sale = VALUE #( ( sale_id = 1 goods_id = 'G001' sale_day = '20260314' qty = 4 sale_state = 'P' )
|
||||
( sale_id = 2 goods_id = 'G002' sale_day = '20260314' qty = 2 sale_state = 'P' )
|
||||
( sale_id = 3 goods_id = 'G003' sale_day = '20260314' qty = 3 sale_state = 'P' )
|
||||
( sale_id = 4 goods_id = 'G004' sale_day = '20260314' qty = 2 sale_state = 'P' )
|
||||
( sale_id = 5 goods_id = 'G005' sale_day = '20260314' qty = 2 sale_state = 'P' )
|
||||
( sale_id = 6 goods_id = 'G001' sale_day = '20260314' qty = 5 sale_state = 'C' ) ).
|
||||
go_env->insert_test_data( lt_sale ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD class_teardown.
|
||||
go_env->destroy( ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD totals_per_group.
|
||||
DATA(lt_lines) = NEW lcl_shop_report( )->get_totals(
|
||||
iv_day = '20260314' it_grp = VALUE #( ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 3 act = lines( lt_lines ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'VEG' act = lt_lines[ 1 ]-grp_code ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = lt_lines[ 1 ]-sales ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV {{p}}goods-unit_price( 16 )
|
||||
act = lt_lines[ 1 ]-turnover ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD sorted_by_turnover.
|
||||
DATA(lt_lines) = NEW lcl_shop_report( )->get_totals(
|
||||
iv_day = '20260314' it_grp = VALUE #( ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'VEG' act = lt_lines[ 1 ]-grp_code ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'DAI' act = lt_lines[ 2 ]-grp_code ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 'FRU' act = lt_lines[ 3 ]-grp_code ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD share_of_total.
|
||||
DATA(lt_lines) = NEW lcl_shop_report( )->get_totals(
|
||||
iv_day = '20260314' it_grp = VALUE #( ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV ty_share( '39.0' )
|
||||
act = lt_lines[ 1 ]-pct_share ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV ty_share( '31.7' )
|
||||
act = lt_lines[ 2 ]-pct_share ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD cancelled_ignored.
|
||||
DATA(lt_lines) = NEW lcl_shop_report( )->get_totals(
|
||||
iv_day = '20260314' it_grp = VALUE #( ( sign = 'I' option = 'EQ' low = 'VEG' ) ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( lt_lines ) ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = 2 act = lt_lines[ 1 ]-sales ).
|
||||
cl_abap_unit_assert=>assert_equals( exp = CONV {{p}}goods-unit_price( 16 )
|
||||
act = lt_lines[ 1 ]-turnover ).
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
Reference in New Issue
Block a user