Skip to content

Error in group / Aggreation #207

@hendrik77

Description

@hendrik77

Exercism Aggregate error:

CLASS zcl_itab_aggregation DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    TYPES group TYPE c LENGTH 1.
    TYPES: BEGIN OF initial_numbers_type,
             group  TYPE group,
             number TYPE i,
           END OF initial_numbers_type,
           initial_numbers TYPE STANDARD TABLE OF initial_numbers_type WITH EMPTY KEY.

    TYPES: BEGIN OF aggregated_data_type,
             group   TYPE group,
             count   TYPE i,
             sum     TYPE i,
             min     TYPE i,
             max     TYPE i,
             average TYPE f,
           END OF aggregated_data_type,
           aggregated_data TYPE STANDARD TABLE OF aggregated_data_type WITH EMPTY KEY.

    METHODS perform_aggregation
      IMPORTING
        initial_numbers        TYPE initial_numbers
      RETURNING
        VALUE(aggregated_data) TYPE aggregated_data.
  PROTECTED SECTION.
  PRIVATE SECTION.

ENDCLASS.

CLASS zcl_itab_aggregation IMPLEMENTATION.
  METHOD perform_aggregation.
    LOOP AT initial_numbers INTO DATA(g) GROUP BY g-group .
      DATA(group_count) = REDUCE #( INIT i = 0 FOR c IN GROUP g NEXT i += 1 ).
      DATA(group_sum)   = REDUCE #( INIT j = 0 FOR s IN GROUP g NEXT j += s-number ).
      INSERT VALUE #(
        group = g-group
        count = group_count
        sum = group_sum
        min = REDUCE #( INIT min_number = 9999
                        FOR m IN GROUP g
                        NEXT min_number = nmin( val1 = min_number val2 = m-number ) )
        max = REDUCE #( INIT max_number = 0
                        FOR n IN GROUP g
                        NEXT max_number = nmax(  val1 = max_number val2 = n-number ) )
        average = group_sum / group_count
        ) INTO TABLE aggregated_data.
    ENDLOOP.
  ENDMETHOD.

ENDCLASS.

Error from Exercism:
./zcl_itab_aggregation.clas.abap[56, 7] - Statement does not exist in ABAPopen-abap(or a parser error), "DATA" (parser_error) [E] ./zcl_itab_aggregation.clas.abap[57, 7] - Statement does not exist in ABAPopen-abap(or a parser error), "DATA" (parser_error) [E] ./zcl_itab_aggregation.clas.abap[61, 7] - "group_count" not found, findTop (check_syntax) [E] ./zcl_itab_aggregation.clas.abap[62, 7] - "group_sum" not found, findTop (check_syntax) [E] ./zcl_itab_aggregation.clas.abap[66, 12] - Variable "M" contains unknown: Type error, not a table type g-items (unknown_types) [E] ./zcl_itab_aggregation.clas.abap[67, 7] - Component "items" not found in structure (check_syntax) [E] ./zcl_itab_aggregation.clas.abap[75, 12] - Variable "N" contains unknown: Type error, not a table type g-items (unknown_types) [E] ./zcl_itab_aggregation.clas.abap[76, 7] - Component "items" not found in structure (check_syntax) [E] ./zcl_itab_aggregation.clas.abap[81, 7] - "group_sum" not found, findTop (check_syntax) [E] abaplint: 9 issue(s) found

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions