Skip to content

Get an error when query to ABAP CDS contains read by association #133

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Kronrir opened this issue Oct 9, 2023 · 5 comments
Closed

Get an error when query to ABAP CDS contains read by association #133

Kronrir opened this issue Oct 9, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@Kronrir
Copy link

Kronrir commented Oct 9, 2023

Hello!
I've used ABAPCleaner for last 3 months and that is super cool tool thank you a lot!
I found one bug when I tried to clean/format piece of code which contains select by association in ABAP CDS view.
Error you can see at the screenshot
image
I can't refactor this command it is usual read by association for me.
Maybe somebody can suggest how to refactor such code, but I think that is a bug.

@Kronrir Kronrir changed the title Get an error when query contains association query Get an error when query to ABAP CDS contains read by association association Oct 9, 2023
@Kronrir Kronrir changed the title Get an error when query to ABAP CDS contains read by association association Get an error when query to ABAP CDS contains read by association Oct 9, 2023
@jmgrassau jmgrassau self-assigned this Oct 10, 2023
@jmgrassau jmgrassau added the enhancement New feature or request label Oct 10, 2023
@jmgrassau
Copy link
Member

Hi Kronrir,

thanks for opening this issue! Actually this error is just about the colon ":" inside the brackets [ ... INNER : WHERE ... ], so "refactoring" would simply mean to remove this colon, getting [ ... INNER WHERE ... ].

With such a colon, you could do things like this:

    CONSTANTS lc_id1 TYPE s_conn_id VALUE '1234'.
    CONSTANTS lc_id2 TYPE s_conn_id VALUE '5678'.

    SELECT \_spfli[ (1) INNER WHERE : 
         connid > @lc_id1 ]-connid AS connid FROM demo_cds_assoc_scarr AS scarr INTO @DATA(result1),  
         connid < @lc_id2 ]-connid AS connid FROM demo_cds_assoc_scarr AS scarr INTO @DATA(result2).
        " do something with result1 and result2
      ENDSELECT.
    ENDSELECT.

So you'd have one opening [, but two closing ], and one SELECT, but two ENDSELECT, and that would be very hard for ABAP cleaner to process (and for humans to read).

However, strictly speaking, in this case, the colon doesn't harm so much, because there is no comma, therefore it is just a "chain with one element" and the opening bracket is only closed once. I shall adjust ABAP cleaner to accept these cases. Nevertheless, I think there is no reason to have this colon here.

Kind regards,
Jörg-Michael

@Kronrir
Copy link
Author

Kronrir commented Oct 10, 2023

Ok, agree with you in this case I reworked query and read data directly from CDS which is associated from root CDS, that was not a problem.
It will be nice if ABAP cleaner can process that colon correctly because sometimes read by association very helpfull.
Thank you.

@jmgrassau
Copy link
Member

Hi Kronir,

I am not sure whether I understand you point: How does removing the chain colon change the way how data is read here? From what I see in the ABAP documentation on attributes in Path Expressions, there is no need to put a colon between INNER and WHERE.

Kind regards,
Jörg-Michael

@Kronrir
Copy link
Author

Kronrir commented Oct 10, 2023

Hi, Jörg-Michael
That is my fault I didn't get your point 🤣
I'm new with this read by association inside query, I took that query from the book about CDS and didn't read help.
And you are absolutely correct that query works correct without colon.
Live and learn.
Thank you again 😃

@jmgrassau
Copy link
Member

Hi Kronrir,

thanks again for bringing this up – in version 1.7.0, which was just released, ABAP cleaner now "tolerates" chain colons inside of parentheses and brackets if no comma is found (i.e. in "chain of one" cases), so your example above wouldn't trigger a "parse error" anymore.

Kind regards,
Jörg-Michael

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants