Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My code runs in ABAP System of on-prem but gives error in Exercism #203

Open
SatheesP opened this issue Sep 24, 2022 · 5 comments
Open

My code runs in ABAP System of on-prem but gives error in Exercism #203

SatheesP opened this issue Sep 24, 2022 · 5 comments
Assignees

Comments

@SatheesP
Copy link

SatheesP commented Sep 24, 2022

Dear Team,

Issue reported
We received the following error when we ran your code:

./zcl_itab_aggregation.clas.abap[37, 5] - Statement does not exist in ABAPopen-abap(or a parser error), "aggregated_data" (parser_error) [E]
abaplint: 1 issue(s) found

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.
    " add solution here
    aggregated_data = VALUE #(
      FOR GROUPS grp OF rec IN initial_numbers
      GROUP BY ( group = rec-group cnt = GROUP SIZE )
      LET res = REDUCE aggregated_data_type( INIT tmp = VALUE aggregated_data_type( min = initial_numbers[ group = grp-group ]-number )
                FOR rec2 IN GROUP grp
                NEXT tmp-sum = tmp-sum + rec2-number
                   tmp-min = COND #( WHEN tmp-min > rec2-number THEN rec2-number ELSE tmp-min )
                   tmp-max = COND #( WHEN tmp-max < rec2-number THEN rec2-number ELSE tmp-max )
                ) IN
                ( group = grp-group
                  count = grp-cnt
                  sum = res-sum
                  min = res-min
                  max = res-max
                  average = res-sum / grp-cnt )
      ).

  ENDMETHOD.

ENDCLASS.
@larshp
Copy link
Member

larshp commented Sep 24, 2022

thanks, this looks like a new bug 👍

@larshp
Copy link
Member

larshp commented Sep 25, 2022

first fix = abaplint/abaplint@f0f948f

@larshp larshp self-assigned this Sep 25, 2022
@larshp
Copy link
Member

larshp commented Sep 27, 2022

bug, syntax and types,
image

@urlmic
Copy link

urlmic commented Sep 27, 2022

Dear Team,

I have a similar solution which runs well on-premise but not in Exercism.

My solution

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.
    aggregated_data = VALUE #(
      FOR GROUPS <group_key> OF <wa> IN initial_numbers
        GROUP BY ( key = <wa>-group count = GROUP SIZE )
        LET group_sum = REDUCE i( INIT sum = 0
                                  FOR m IN GROUP <group_key>
                                  NEXT sum += m-number )
            group_max = REDUCE i( INIT max = 0
                                  FOR m IN GROUP <group_key>
                                  NEXT max = nmax( val1 = max
                                                   val2 = m-number ) )
        IN ( group = <group_key>
             sum = group_sum
             max = group_max
             min = REDUCE i( INIT min = group_max
                             FOR m IN GROUP <group_key>
                             NEXT min = nmin( val1 = min
                                              val2 = m-number ) )
             average = group_sum / <group_key>-count
             count = <group_key>-count ) ).
  ENDMETHOD.

ENDCLASS.

abaplint issues received on Exercism

We received the following error when we ran your code:
./zcl_itab_aggregation.clas.abap[40, 21] - Type "_GROUP_KEY_TYPE" contains unknown: TYPENOTFOUND not found, lookupView (unknown_types) [E]
./zcl_itab_aggregation.clas.abap[45, 6]  - Variable "_GROUP_KEY_TAB" contains unknown: TYPENOTFOUND not found, lookupView (unknown_types) [E]
./zcl_itab_aggregation.clas.abap[46, 6]  - Variable "TEMP2" contains unknown: TYPENOTFOUND not found, lookupView (unknown_types) [E]
./zcl_itab_aggregation.clas.abap[47, 15] - Variable "<WA>" contains unknown: Type error, not a table type initial_numbers-items (unknown_types) [E]
./zcl_itab_aggregation.clas.abap[48, 1]  - Table without header, cannot access fields, initial_numbers- (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[49, 1]  - Statement does not exist in ABAPopen-abap(or a parser error), "READ" (parser_error) [E]
./zcl_itab_aggregation.clas.abap[61, 15] - Variable "<GROUP_KEY>" contains unknown: TYPENOTFOUND not found, lookupView (unknown_types) [E]
./zcl_itab_aggregation.clas.abap[66, 10] - Variable "M" contains unknown: Type error, not a table type <group_key>-items (unknown_types) [E]
./zcl_itab_aggregation.clas.abap[67, 5]  - Loop, not a table type, Type error, field not part of structure initial_numbers-items (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[76, 5]  - Variable name "m" already defined (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[77, 5]  - Loop, not a table type, Type error, field not part of structure initial_numbers-items (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[83, 7]  - Variable name "temp2" already defined (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[84, 7]  - Component "group" not found in structure (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[85, 7]  - Component "sum" not found in structure (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[86, 7]  - Component "max" not found in structure (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[90, 7]  - Variable name "m" already defined (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[91, 7]  - Loop, not a table type, Type error, field not part of structure initial_numbers-items (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[95, 7]  - Component "min" not found in structure (check_syntax) [E]
./zcl_itab_aggregation.clas.abap[96, 7]  - Component "average" not found in structure (check_syntax) [E]
abaplint: 19 issue(s) found```

@larshp
Copy link
Member

larshp commented Sep 28, 2022

another fix = abaplint/abaplint#2706

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants