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

I think maybe the FIND commmand does not work in excercism #210

Closed
TMNielsenApS opened this issue Sep 28, 2022 · 9 comments
Closed

I think maybe the FIND commmand does not work in excercism #210

TMNielsenApS opened this issue Sep 28, 2022 · 9 comments

Comments

@TMNielsenApS
Copy link

TMNielsenApS commented Sep 28, 2022

I'm trying to solve Atbash Cipher but so far no luck.

I can't debug on xcercism, but I think I can conclude that the problem is that the following find command does not work even though it works fine in my own SAP system.

    FIND cipher_text+lv_idx(1) IN cipher MATCH OFFSET lv_cipher_idx.

I have so far only written code for the decode method and it looks like this:

METHOD decode.    
  DATA: lv_plain_idx  TYPE i VALUE -1,
          lv_cipher_idx TYPE i,
          lv_char(255),
          lv_blank(1) value space.

    DO strlen( cipher_text ) TIMES.
      DATA(lv_idx) = sy-index - 1.
      lv_blank = cipher_text+lv_idx(1).
      if lv_blank = space.
        CONTINUE.
      ELSE.
        FIND cipher_text+lv_idx(1) IN cipher MATCH OFFSET lv_cipher_idx.
        ADD 1 TO lv_plain_idx.
        IF sy-subrc = 0.
          lv_char+lv_plain_idx(1) = plain+lv_cipher_idx(1).
        ELSE.
          lv_char+lv_plain_idx(1) = cipher_text+lv_idx(1).
        ENDIF.
      ENDIF.
    ENDDO.
    plain_text = lv_char.
  ENDMETHOD.

additionally I've added to strings to the private section of the class:

    DATA: plain  TYPE string VALUE 'abcdefghijklmnopqrstuvwxyz',
          cipher TYPE string VALUE 'zyxwvutsrqponmlkjihgfedcba'.

@larshp
Copy link
Member

larshp commented Sep 28, 2022

one tip for debugging, try reproducing via https://transpiler.abaplint.org

image

put the ABAP code in the left editor, and rightmost it the output from WRITE

data cipher_text type c length 10.
data cipher type c length 10.
data lv_cipher_idx type i.
data lv_idx type i.
cipher_text = '1234567890'.
FIND cipher_text+lv_idx(1) IN cipher MATCH OFFSET lv_cipher_idx.
write lv_cipher_idx.

@larshp
Copy link
Member

larshp commented Sep 28, 2022

seems okay,

image

@larshp
Copy link
Member

larshp commented Sep 28, 2022

initializing in data,

image

@larshp
Copy link
Member

larshp commented Sep 28, 2022

try these workarounds:

  • use CONSTANTS if the variables are constant
  • initialize the value of the variable in the constructor

@TMNielsenApS
Copy link
Author

Ok, I will try these workarounds, but I don't get any "some exception raised"

image

@TMNielsenApS
Copy link
Author

Yes - I changed from DATA to CONSTANTS and now my decode method works.

Thanks Lars.

@larshp
Copy link
Member

larshp commented Sep 28, 2022

abaplint/transpiler#891 opened

@TMNielsenApS
Copy link
Author

so, does this mean I can close this issue?

@larshp
Copy link
Member

larshp commented Sep 28, 2022

yea

I've also added it in #202

there are other worse errors to fix first 😅

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

No branches or pull requests

2 participants