exercism / abap

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

Run Length Encoding - AT #134

Open aferngas opened 2 years ago

aferngas commented 2 years ago

Running the tests for the "Run Encoding Length" exercise ends with an error. The output is:

We received the following error when we ran your code: ./zcl_rle.clas.abap[89, 12] - Variable "TEMP4" contains unknown: UNDEFINED not found, lookup (unknown_types) [E] abaplint: 1 issue(s) found

The solution tests fine in a Netweaver 7.4 system.

Here is the code I'm trying:

CLASS zcl_rle DEFINITION FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    METHODS encode IMPORTING input         TYPE string
                   RETURNING VALUE(result) TYPE string.

    METHODS decode IMPORTING input         TYPE string
                   RETURNING VALUE(result) TYPE string.

  PRIVATE SECTION.
    TYPES:
      type_e_letter TYPE c LENGTH 1,
      type_t_letter TYPE STANDARD TABLE OF type_e_letter
                    WITH NON-UNIQUE DEFAULT KEY.

    METHODS:
      _split_in_letters
        IMPORTING
          input            TYPE string
        RETURNING
          VALUE(rt_letter) TYPE type_t_letter.

ENDCLASS.

CLASS zcl_rle IMPLEMENTATION.
  METHOD encode.
    LOOP AT _split_in_letters( input ) ASSIGNING FIELD-SYMBOL(<lv_letter>).
      AT NEW table_line.
        DATA(lv_count) = 0.
      ENDAT.
      lv_count = lv_count + 1.
      AT END OF table_line.
        DATA(lv_encoded) = COND string( WHEN lv_count = 1
                                        THEN |{ <lv_letter> WIDTH = 1 }|
                                        ELSE |{ lv_count }{ <lv_letter> WIDTH = 1 }| ).
        result = result && lv_encoded.
      ENDAT.
    ENDLOOP.
  ENDMETHOD.

  METHOD decode.
    DATA(lv_offset) = 0.
    WHILE lv_offset < strlen( input ).
      DATA(lv_decode) = ||.
      FIND REGEX '(^\d+)(\D)' IN input+lv_offset IGNORING CASE
        MATCH OFFSET DATA(lv_match_offset) MATCH LENGTH DATA(lv_match_length)
        SUBMATCHES DATA(lv_repeat) DATA(lv_letter).
      IF sy-subrc = 0.
        DO CONV i( lv_repeat ) TIMES.
          lv_decode = |{ lv_decode }{ lv_letter }|.
        ENDDO.
        result = |{ result }{ lv_decode }|.
        lv_offset = lv_offset + lv_match_offset + lv_match_length.
        CONTINUE.
      ENDIF.
      result = |{ result }{ input+lv_offset(1) }|.
      lv_offset = lv_offset + 1.
    ENDWHILE.
  ENDMETHOD.

  METHOD _split_in_letters.
    DO strlen( input ) TIMES.
      DATA(lv_offset) = sy-index - 1.
      INSERT CONV #( input+lv_offset(1) ) INTO TABLE rt_letter.
    ENDDO.
  ENDMETHOD.
ENDCLASS.

Could it be that the table type definition is not transpiling correctly?

larshp commented 2 years ago

https://github.com/abaplint/abaplint/pull/2495

larshp commented 2 years ago

https://github.com/abaplint/transpiler/issues/706 opened, first bug fixed

larshp commented 1 year ago

image

larshp commented 1 year ago

@aferngas try again

image