Skip to content

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

@Ennowulff

Description

@Ennowulff

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.

Metadata

Metadata

Assignees

No one assigned

    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