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

" TODO: variable is assigned but never used (ABAP cleaner) after checking whether a database entry exists #38

Closed
JanisBur opened this issue May 30, 2023 · 5 comments
Assignees
Labels
documentation Improvements or additions to documentation no defect

Comments

@JanisBur
Copy link

Sometimes I just want check, whether a database entry exists using the sy-subrc variable. I am forced to select the data into some table/structure, because a "SELECT" without "INTO" is not possible.

`" TODO: variable is assigned but never used (ABAP cleaner)
SELECT SINGLE * FROM pa0000 INTO @DaTa(ls_dummy) WHERE begda <= @sy-datum
AND endda >= @sy-datum.

IF sy-subrc = 0.
" further processing
ENDIF.`

Would it be possible to switch the message "TODO: variable is assigned but never used (ABAP cleaner)" off in such cases?

@jmgrassau
Copy link
Member

Hi JanisBur,

I think the best way to suppress this would be to add a ##NEEDED pragma at the end of the line of @DATA(ls_dummy). With this, ABAP cleaner will not add such a TODO comment (in fact, it will even automatically remove the existing one). Without ##NEEDED, the Extended Check (transaction SLIN) would also create a Field Attributes warning:

image

Kind regards,
Jörg-Michael

@ConjuringCoffee
Copy link
Contributor

This wasn't clear to me. I really like how it even automatically removes its own comment. How about adding examples to the rule to demonstrate the use of ##NEEDED?

@fabianlupa
Copy link

@JanisBur For the existence check I usually do this instead:

SELECT COUNT(*)
  FROM pa0000
  WHERE begda <= @sy-datum
    AND endda >= @sy-datum.
IF sy-dbcnt >= 1.
  " further processing
ENDIF.

Or even this:

SELECT SINGLE @abap_true
  FROM pa0000
  WHERE begda <= @sy-datum
    AND endda >= @sy-datum
  INTO @DATA(exists).
IF exists = abap_true.
  " further processing
ENDIF.

Do note using COUNT bypasses the table buffer implicitly compared to the other solutions.

@jmgrassau
Copy link
Member

Hi @ConjuringCoffee,

How about adding examples to the rule to demonstrate the use of ##NEEDED?

Actually there is already a tiny, inconspicuous line in the "Delete unused variables" examples …

image

… but happy to add some more comment there to explain it! Anyway you could often continue the "no defect" label with "… but apparently not intuitive and documented well enough" :-)

So reopening this to make sure I don't forget it.

Kind regards,
Jörg-Michael

@jmgrassau jmgrassau reopened this May 30, 2023
@jmgrassau jmgrassau added the documentation Improvements or additions to documentation label May 30, 2023
@jmgrassau jmgrassau self-assigned this May 30, 2023
@jmgrassau
Copy link
Member

Hi JanisBur and @ConjuringCoffee,

in version 1.3.0, the example of the "Delete unused variables" rule is now enhanced to make the effect of the ##NEEDED pragma a bit more visible:

image

Kind regards,
Jörg-Michael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation no defect
Projects
None yet
Development

No branches or pull requests

4 participants