question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule feedback: reorder definitions to the top of routine

See original GitHub issue

I have an issue with this check existing at all. It violates the good practice of using the most restrictive visibility.

Example:

method test.
DATA: 
  some_flag type abap_bool,
  some_string type string.

some_flag = abap_false.

"
"imagine 15 lines of code here 
"

some_string = 'value'.

" some more code here
endmethod.

By placing the declaration at the top, I’m making the string visible to the part of the method I’m not using it in. I’d rather do

method test.
DATA:  some_flag type abap_bool.

some_flag = abap_false.

"
"imagine 15 lines of code here 
"
DATA:  some_string type string.
some_string = 'value'.

" some more code here
endmethod.

If I don’t intend to use the string in the first half of the method, I shouldn’t need to declare it at the beginning - then I’m protected against accidental usage and I’m making my reasoning about the usage explicit to future maintainers.

This is precisely why inline data declarations are good (they have their own scoping issues, but that is another matter), but these might not be available on your release.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
FreHucommented, Jun 5, 2020

as close to the first use as possible - not entirely.

LOOP AT table INTO DATA(x).
  variable = x-blah.
ENDLOOP.
variable = 123.

should declare like this

DATA(variable) = 0.
LOOP AT table INTO DATA(x).
  variable = x-blah.
ENDLOOP.
variable = 123.

not

LOOP AT table INTO DATA(x).
  DATA(variable) = 0.
  variable = x-blah.
ENDLOOP.
variable = 123.

so it should be as close as possible without breaking the code or violating the sane block scoping rules in other languages

0reactions
larshpcommented, Jun 6, 2020

ABAP is a dangerous place, anyhow, I’m having a go at it https://github.com/abaplint/abaplint/pull/933

Read more comments on GitHub >

github_iconTop Results From Across the Web

Definitions in top of routine - abapOpenChecks
Check that DATA and other definitions are in top of routine(FORM/METHOD). Traditionally variables are declared at top of modularization block.
Read more >
A Guide to the Rulemaking Process - Federal Register
For information on using the federal eRulemaking portal to submit comments, go to the. Regulations.gov “Help” pages on submitting a comment. Before the...
Read more >
Ground Rules for Teams: Definition and Examples | Indeed.com
Ground rules are standards set by a team to help them function in the future. In order to work effectively, the team should...
Read more >
PDCA Cycle - What is the Plan-Do-Check-Act Cycle? - ASQ
The Plan–Do–Check–Act cycle is a four-step model for carrying out change. Learn more about the PDCA cycle and how to implement the model...
Read more >
Part 2 - Definitions of Words and Terms | Acquisition.GOV
Change order means a written order, signed by the contracting officer, directing the contractor to make a change that the Changes clause ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found