ABAP Keyword Documentation → ABAP - Reference → ABAP Syntax → Program directives
Pragmas
Pragmas are program directives that can be used to hide warnings from various check tools. The following are supported:
- Warnings from the ABAP Compiler syntax check
- Warnings from the extended program check
Other versions: 7.31 | 7.40 | 7.54
Notes
- You can determine whether a pragma exists for a warning from the system check using the long text of the message (which in this case always exists). The description of a message for the enhanced program check is also listed by the pragma, which can be used to hide it.
- Do not use statement
SET EXTENDED CHECK
and the pseudo comment #EC * in programs that use pragmas to deactivate warnings. This causes an extended program check warning that cannot be deactivated.
Syntax
A pragma is structured as follows:
##code[par][par]... ,
is not case-sensitive and does not contain spaces. The pragma code (code) specifies the effect; parameters (par) may further limit the effect.
Note
Pragmas replace the previously common pseudo comments to hide warnings from the enhanced program check. Pseudo comments are now obsolete and should no longer be used. The program ABAP_SLIN_PRAGMAS shows which pragmas are to be used instead of the obsolete pseudo comments.
Examples
An example of a pragma for syntax check warnings is:
##SHADOW
This pragma can be used to hide a syntax warning in a method definition that warns of the shadowing of a predefined function. The pragma has an optional parameter in which the name of the function can be specified as well.
##SHADOW[SUBSTRING]
An example of pragmas for hiding warnings from the enhanced program check is provided below.
DATA TEXT TYPE STRING ##needed.
text = 'Hello Pragmas' ##no_text.
Parameterization and the Effect of Pragmas
A message is affected by a pragma if all the parameters specified match
the concrete parameters. The concrete parameters can also be found in the
long text of the message. Compulsory parameters are underlined in the long
text and must not be omitted. Some parameters are optional. Optional parameters can be omitted by using
an empty pair of brackets []
in the appropriate position or by completely omitting an end part.
Example
In the example a warning for "SUBSTRING" is hidden using
##SHADOW
##SHADOW[SUBSTRING]
##SHADOW[]
but not using SHADOW[FIND]
.
Positioning in ABAP Source Code
A pragma applies for the current statement, that is, for the statement that ends at the next
".
" or ",
". Pragmas in front of the ":
" of a chained statement apply to the whole chained statement. Pragmas that occur when calling a
macro apply to all statements of the macro.
Pragmas must only occur at certain positions in the source code for reasons of readability:
- at the start of a line, after any number of spaces
- at the end of a line, at the most followed by "
.
", ",
", or ":
".
- but not after "
.
", ",
", or ":
".
Multiple pragmas may be entered one after another (separated by spaces) at permitted positions.
Unknown, formally incorrect, or incorrectly parameterized pragmas lead to a syntax warning.
Examples
In some examples for key accesses to internal tables (read, delete), syntax warnings are hidden by the relevant pragma. The pragmas were found in the long text of the syntax warnings (selection of the i button).