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

Run Length Encoding - AT #134

Open
aferngas opened this issue Apr 10, 2022 · 4 comments · Fixed by exercism/abap-test-runner#178
Open

Run Length Encoding - AT #134

aferngas opened this issue Apr 10, 2022 · 4 comments · Fixed by exercism/abap-test-runner#178
Assignees

Comments

@aferngas
Copy link

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 larshp self-assigned this Apr 11, 2022
@larshp
Copy link
Member

larshp commented Apr 11, 2022

abaplint/abaplint#2495

@larshp
Copy link
Member

larshp commented Apr 11, 2022

abaplint/transpiler#706 opened, first bug fixed

@larshp larshp changed the title Run Length Encoding - Variable "TEMP4" contains unknown: UNDEFINED not found, lookup (unknown_types) Run Length Encoding - AT Apr 11, 2022
@larshp
Copy link
Member

larshp commented Mar 7, 2023

image

@larshp
Copy link
Member

larshp commented Mar 7, 2023

@aferngas try again

image

@larshp larshp assigned aferngas and unassigned larshp Mar 7, 2023
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

Successfully merging a pull request may close this issue.

3 participants