abap icon indicating copy to clipboard operation
abap copied to clipboard

wrong error: Variable name "i" already defined (check_syntax) [E]

Open Ennowulff opened this issue 2 years ago • 1 comments

The following code leads to the error: Variable name "i" already defined (check_syntax) [E]

CLASS zcl_demo DEFINITION.

  PUBLIC SECTION.
    METHODS test
      IMPORTING
        word1 TYPE string
        word2 TYPE string
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS zcl_demo IMPLEMENTATION.
  METHOD text.

    DATA(word1_table) = VALUE string_table( FOR i = 0 WHILE i < strlen( word1 )
                                        ( substring( val = word1 off = i len = 1 ) ) ).
    DATA(word2_table) = VALUE string_table( FOR i = 0 WHILE i < strlen( word2 )
                                        ( substring( val = word2 off = i len = 1 ) ) ).
  ENDMETHOD.

ENDCLASS.

The second VALUE command uses the same local variable "i" what is accepted by the ABAP compiler. But it leads to the error in exercism.

Ennowulff avatar Feb 15 '23 13:02 Ennowulff

thanks, also see https://github.com/exercism/abap/issues/202

larshp avatar Feb 15 '23 13:02 larshp