Code: Alles auswählen.
REPORT.
PARAMETERS: p_lines TYPE i OBLIGATORY DEFAULT 1000,
p_seed TYPE i.
CLASS lcl_test DEFINITION FINAL.
PUBLIC SECTION.
TYPES: BEGIN OF mts_data,
distance TYPE s_distance,
distid TYPE s_distid,
END OF mts_data,
mtt_data TYPE STANDARD TABLE OF mts_data WITH EMPTY KEY.
CLASS-METHODS:
create_testdata IMPORTING iv_lines TYPE i
iv_seed TYPE i,
solution RETURNING VALUE(rv_distance) TYPE f.
CLASS-DATA:
mt_testdata TYPE mtt_data.
ENDCLASS.
END-OF-SELECTION.
lcl_test=>create_testdata( iv_lines = p_lines
iv_seed = p_seed ).
WRITE:/ p_lines, p_seed, lcl_test=>solution( ) DECIMALS 4 EXPONENT 0.
CLASS lcl_test IMPLEMENTATION.
METHOD solution.
* Bitte hier austoben
* Längen summieren
rv_distance = 42. " Sehr mutige Annahme die leider manchmal falsch ist
ENDMETHOD.
METHOD create_testdata.
DATA: lo_rnd1 TYPE REF TO cl_abap_random_int,
lo_rnd2 TYPE REF TO cl_abap_random_int,
ls_testdata LIKE LINE OF mt_testdata.
lo_rnd1 = cl_abap_random_int=>create( seed = iv_seed
min = 1
max = 10 ).
lo_rnd2 = cl_abap_random_int=>create( seed = iv_seed
min = 1
max = 7 ).
DO iv_lines TIMES.
ls_testdata-distance = lo_rnd1->get_next( ).
CASE lo_rnd2->get_next( ).
WHEN 1. ls_testdata-distid = 'CM'.
WHEN 2. ls_testdata-distid = 'DM'.
WHEN 3. ls_testdata-distid = 'FT'.
WHEN 4. ls_testdata-distid = 'IN'.
WHEN 5. ls_testdata-distid = 'KM'.
WHEN 6. ls_testdata-distid = 'M'.
WHEN 7. ls_testdata-distid = 'MI'.
WHEN OTHERS.
ASSERT 1 = 0." ls_testdata-distid = 'IN'.
ENDCASE.
APPEND ls_testdata TO mt_testdata.
ENDDO.
ENDMETHOD.
ENDCLASS.
Code: Alles auswählen.
rv_distance = REDUCE #( INIT re TYPE f
FOR wa IN mt_testdata
NEXT re = re + ( wa-distance * SWITCH f( wa-distid WHEN 'CM' THEN '0.01'
WHEN 'DM' THEN '0.1'
WHEN 'FT' THEN '0.3048'
WHEN 'IN' THEN '0.0254'
WHEN 'KM' THEN 1000
WHEN 'M' THEN 1
WHEN 'MI' THEN '1609.344' ) ) ).
Code: Alles auswählen.
SELECT msehi AS m, zaehl AS z, nennr AS n
INTO TABLE @DATA(t)
FROM t006.
rv_distance = REDUCE #(
INIT e TYPE f
FOR w IN mt_testdata
NEXT e = e + w-distance * t[ m = w-distid ]-z / t[ m = w-distid ]-n ).
Code: Alles auswählen.
DATA o TYPE s_distance.
LOOP AT mt_testdata ASSIGNING FIELD-SYMBOL(<t>).
CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
EXPORTING
input = <t>-distance
unit_in = <t>-distid
unit_out = 'M'
IMPORTING
output = o.
ADD o TO rv_distance.
ENDLOOP.
Code: Alles auswählen.
SELECT SUM( division( itab~distance * t006~zaehl ,t006~nennr ,11 ) )
FROM @mt_testdata AS itab JOIN t006 ON itab~distid = t006~msehi
INTO @rv_distance.
Code: Alles auswählen.
DATA o TYPE s_distance.
LOOP AT mt_testdata ASSIGNING FIELD-SYMBOL(<t>)
GROUP BY ( distid = <t>-distid ) ASSIGNING FIELD-SYMBOL(<g>).
CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
EXPORTING
input = 1
unit_in = <g>-distid
unit_out = 'M'
IMPORTING
output = o.
LOOP AT GROUP <g> ASSIGNING FIELD-SYMBOL(<m>)
rv_distance = rv_distance + <m>-distance * o.
ENDLOOP.
ENDLOOP.