exercism / abap

Exercism exercises in ABAP.
https://exercism.org/tracks/abap
MIT License
75 stars 36 forks source link

Matrix: LET variable unkown #151

Open Koch013 opened 2 years ago

Koch013 commented 2 years ago

I receive the following error when running the test for Matrix:

We received the following error when we ran your code:
./zcl_matrix.clas.abap[79, 5] - "lv_start" not found, findTop (check_syntax) [E]
./zcl_matrix.clas.abap[82, 5] - "lv_start" not found, findTop (check_syntax) [E]
abaplint: 2 issue(s) found

Looks like to be the same error as in 148 but this time for VALUE

Here's my code:

CLASS zcl_matrix DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    TYPES integertab TYPE STANDARD TABLE OF i WITH EMPTY KEY.
    METHODS matrix_row
      IMPORTING
        string        TYPE string
        index         TYPE i
      RETURNING
        VALUE(result) TYPE integertab.
    METHODS matrix_column
      IMPORTING
        string        TYPE string
        index         TYPE i
      RETURNING
        VALUE(result) TYPE integertab.
  PROTECTED SECTION.
  PRIVATE SECTION.
    METHODS build_matrix
      IMPORTING
        i_string   TYPE string
      EXPORTING
        ev_columns TYPE i
        ev_rows TYPE i
        et_matrix  TYPE string_table.

ENDCLASS.

CLASS zcl_matrix IMPLEMENTATION.
  METHOD build_matrix.
    DATA(lv_string_wo_nl) = replace( val = i_string sub = `\n` with = ` ` occ = 0 ).
    ev_rows = count( val = i_string sub = `\n` ) + 1.
    ev_columns  = COND i( LET lv_qty_values =
                             count( val = lv_string_wo_nl sub = ` `
                             len = COND i( LET lv_pos_nl = find( val = i_string sub = `\n` ) IN
                                           WHEN lv_pos_nl <= 0 THEN strlen( i_string )
                                           ELSE lv_pos_nl + 1 ) ) IN

                          WHEN lv_qty_values <= 0 THEN 1 ELSE lv_qty_values ) .
    SPLIT lv_string_wo_nl AT ` ` INTO TABLE et_matrix .
  ENDMETHOD.

  METHOD matrix_row.
    build_matrix(
          EXPORTING
            i_string = string
          IMPORTING
            ev_columns = data(lv_columns)
            et_matrix  = data(lt_matrix) ).

    result = VALUE #( LET lv_start = ( index - 1 ) * lv_columns + 1 IN 
                      FOR i = lv_start UNTIL i > lv_start + lv_columns - 1 ( lt_matrix[ i ] ) ).
  ENDMETHOD.

  METHOD matrix_column.
        build_matrix(
          EXPORTING
            i_string = string
          IMPORTING
            ev_rows = data(lv_rows)
            ev_columns = data(lv_colums)
            et_matrix  = data(lt_matrix) ).

        result = VALUE #( FOR i = 0 UNTIL i = lv_rows ( lt_matrix[ index + i * lv_colums ] ) ).
  ENDMETHOD.
ENDCLASS.
larshp commented 2 years ago

thanks 👍

larshp commented 2 years ago

reproduced as

DATA result TYPE STANDARD TABLE OF i WITH DEFAULT KEY.
result = VALUE #(
  LET lv_start = 2 + 2 IN
  FOR i = lv_start UNTIL i > lv_start * 2
  ( lv_start ) ).
larshp commented 2 years ago

https://github.com/abaplint/abaplint/pull/2535/commits/16707cbde94b589d854b36bd7bed65b5e370193c

larshp commented 2 years ago

step by step, day by day

image

larshp commented 2 years ago

one more working, image