code pal for ABAP > Documentation > Optional Parameters
This check searches for optional parameters in method signatures. It is recommended to avoid optional parameters because they might confuse the consumers of the class about questions like:
- Which parameters are really required?
- Which combination of parameters are valid?
- Which parameters exclude each other?
It also becomes harder to perform any changes in the method since all possible combinations of its parameters must always be considered.
Multiple methods with specific parameters for their respective use cases avoid this confusion by giving clear guidance which parameter combinations are expected.
Create new methods dedicated to their specific use case instead of adding optional parameters to a generic method.
Before the check:
METHODS do_one_or_the_other
IMPORTING
what_i_need TYPE string OPTIONAL
something_else TYPE i OPTIONAL.
After the check:
METHODS do_one_thing IMPORTING what_i_need TYPE string.
METHODS do_another_thing IMPORTING something_else TYPE i.
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:
METHODS do_one_or_the_other
IMPORTING
what_i_need TYPE string OPTIONAL
something_else TYPE i OPTIONAL. "#EC OPTL_PARAM