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

Matrix: LET variable unkown #151

Open
Koch013 opened this issue May 11, 2022 · 5 comments
Open

Matrix: LET variable unkown #151

Koch013 opened this issue May 11, 2022 · 5 comments

Comments

@Koch013
Copy link

Koch013 commented May 11, 2022

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
Copy link
Member

larshp commented May 11, 2022

thanks 👍

@larshp
Copy link
Member

larshp commented May 11, 2022

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
Copy link
Member

larshp commented May 11, 2022

@larshp
Copy link
Member

larshp commented May 12, 2022

step by step, day by day

image

@larshp
Copy link
Member

larshp commented May 13, 2022

one more working,
image

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

3 participants