You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[code pal for ABAP](../../README.md) > [Documentation](../check_documentation.md) > [Optional Parameters](optional-parameters.md)
4
2
5
3
## Optional Parameters
6
4
7
5
### What is the Intent of the Check?
8
6
9
-
Avoid usage of `OPTIONAL` parameters because they confuse callers:
7
+
This check searches for OPTIONAL parameter in method signatures. It is recommended to avoid the usage of `OPTIONAL` parameters because they might confuse the consumers of the class:
10
8
11
-
* Which ones are really required?
12
-
* Which combinations are valid?
13
-
* Which ones exclude each other?
9
+
* Which parameters are really required?
10
+
* Which combination of parameters are valid?
11
+
* Which parameters exclude each other?
14
12
15
13
Multiple methods with specific parameters for the use case avoid this confusion by giving clear guidance which parameter combinations are valid and expected.
16
14
17
15
### How to solve the issue?
18
16
19
-
Splitting methods instead of adding `OPTIONAL` parameters.
20
-
21
-
### What to do in case of exception?
22
-
23
-
You can suppress Code Inspector findings generated by this check using the pseudo comment `"#EC OPTL_PARAM`.
24
-
The pseudo comment has to be placed after the method declaration.
25
-
26
-
```abap
27
-
METHODS do_one_or_the_other
28
-
IMPORTING
29
-
what_i_need TYPE string OPTIONAL
30
-
something_else TYPE i OPTIONAL. "#EC OPTL_PARAM
31
-
```
17
+
Splitting methods (creating new ones) instead of adding `OPTIONAL` parameters.
32
18
33
19
### Example
34
20
@@ -48,6 +34,17 @@ After the check:
48
34
METHODS do_another_thing IMPORTING something_else TYPE i.
49
35
```
50
36
37
+
### What to do in case of exception?
38
+
39
+
In exceptional cases, you can suppress this finding by using the pseudo comment `"#EC OPTL_PARAM` which should to be placed after the method declaration:
40
+
41
+
```abap
42
+
METHODS do_one_or_the_other
43
+
IMPORTING
44
+
what_i_need TYPE string OPTIONAL
45
+
something_else TYPE i OPTIONAL. "#EC OPTL_PARAM
46
+
```
47
+
51
48
### Further Readings & Knowledge
52
49
53
50
*[ABAP Styleguides on Clean Code](https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md#split-methods-instead-of-adding-optional-parameters)
0 commit comments