transpiler icon indicating copy to clipboard operation
transpiler copied to clipboard

Error with FIND IN TABLE, line

Open mbtools opened this issue 3 years ago • 8 comments
trafficstars

Find in string works, but find in table gives error

TYPES: BEGIN OF ty_submatch,
              offset TYPE i,
              length TYPE i,
            END OF ty_submatch.
TYPES: BEGIN OF ty_match,
              line       TYPE i,
              offset     TYPE i,
              length     TYPE i,
              submatches TYPE STANDARD TABLE OF ty_submatch WITH DEFAULT KEY,
            END OF ty_match.
DATA lt_matches TYPE STANDARD TABLE OF ty_match WITH DEFAULT KEY.
DATA lt_words TYPE TABLE OF string.

APPEND 'hello' TO lt_words.
APPEND 'bar' TO lt_words.
APPEND 'world' TO lt_words.

FIND REGEX |bar| IN TABLE lt_words RESULTS lt_matches.

An error was thrown: TypeError: i.get is not a function

mbtools avatar Feb 17 '22 17:02 mbtools

@mbtools try again, latest version

larshp avatar Mar 29 '22 17:03 larshp

👍

mbtools avatar Mar 29 '22 23:03 mbtools

No more error, but line in the result tab is not filled correctly.

TYPES: BEGIN OF ty_submatch,
              offset TYPE i,
              length TYPE i,
            END OF ty_submatch.
TYPES: BEGIN OF ty_match,
              line       TYPE i,
              offset     TYPE i,
              length     TYPE i,
              submatches TYPE STANDARD TABLE OF ty_submatch WITH DEFAULT KEY,
            END OF ty_match.
DATA ls_submatch TYPE ty_submatch.
DATA ls_match TYPE ty_match.
DATA lt_matches TYPE STANDARD TABLE OF ty_match WITH DEFAULT KEY.
DATA lt_words TYPE TABLE OF string.

APPEND 'hello' TO lt_words.
APPEND '__bar__' TO lt_words.
APPEND 'world' TO lt_words.

FIND REGEX |(bar)| IN TABLE lt_words RESULTS lt_matches.

LOOP AT lt_matches INTO ls_match.
  WRITE:
    / ls_match-line, 
    / ls_match-offset, 
    / ls_match-length,
    / lines( ls_match-submatches ).
  LOOP AT ls_match-submatches INTO ls_submatch.
    WRITE: /,
      / ls_submatch-offset, 
      / ls_submatch-length.
  ENDLOOP.
ENDLOOP.

Output:

0 " should be 2
2 " ok
3 " ok
1 " ok

2 " ok
3 " ok

mbtools avatar Mar 29 '22 23:03 mbtools

just saw the todo https://github.com/abaplint/transpiler/blob/ea99f67c97a24f105cac8537e4dab88064bcde7e/packages/runtime/src/statements/find.ts#L113

mbtools avatar Mar 29 '22 23:03 mbtools

heh 👍

larshp avatar Mar 30 '22 05:03 larshp

https://github.com/abaplint/transpiler/pull/686/commits/c7557e2854bb52fcbfa0e5a10e454f640766e742

larshp avatar Apr 01 '22 10:04 larshp

@mbtools try again

larshp avatar Apr 09 '22 07:04 larshp

now line is filled properly but submatches table is empty instead of one record with offset 2 and lenght 3

mbtools avatar Apr 21 '22 14:04 mbtools