Skip to content

Commit fbdc02f

Browse files
Update scope-of-variable.md
1 parent 62287fa commit fbdc02f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/checks/scope-of-variable.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ If a variable is declared in a statement, it should be used/referred to inside t
88
### How does the check work?
99
It searches for `DATA` and `FIELD-SYMBOLS` declaration inside of `IF`, `ELSEIF`, `ELSE`, `DO`, `CASE/WHEN`, `LOOP`, and `WHILE` statements, and for its usage/reference outside this statement.
1010

11+
ABAP lacks of proper scope handling. If a variable is declared in a IF-Block, it should only be used/refered inside this IF-block (not outside). The same applies for LOOP, DO, WHILE or any block structure. In otehr words, it is not allowed the usage of a variable outside the block/scope where it was declared. Thus, it is still possible to make usage of dynamic declarations inside of blocks with a single statement:
12+
13+
```abap
14+
IF cond = ABAP_TRUE.
15+
DATA(MYDATA) = MY_METHOD().
16+
ENDIF.
17+
mydata = ABAP_TRUE. "no longer accepted
18+
```
19+
1120
### How to solve the issue?
1221
Relocate the declaration.
1322

0 commit comments

Comments
 (0)