What are pragmas and pseudo comments in ABAP?
When using the ABAP Test Cockpit (ATC) for statically and dynamically checking the quality of your ABAP code and related repository objects, some of the warnings and errors identified by the ATC aren’t relevant in your specific scenario. Leaving errors and warnings unaddressed might cause confusion at some future point-in-time when you or another developer needs to change the code. In order to reduce the confusion, ABAP pragmas and pseudo comments can be used to blend out irrelevant warnings and errors. Let us take a detailed look at what pseudo comments and pragmas are and how to use them.
Pseudo comments are program directives that influence check and test procedures. Pseudo comments have mostly become obsolete and have been replaced by pragmas or real additions.ABAP Keyword Documentation
Even though mostly obsolete, the pseudo comments are still relevant for some scenarios in the code inspector.
A pseudo comment looks like this:
METHOD get_sources. SELECT source, textlong INTO TABLE @rt_source FROM tb006 WHERE spras = @sy-langu. "#EC CI_SUBRC ENDMETHOD.
The pseudo comment
"#EC CI_SUBRC is used to hide a message telling us that
sy-subrc should be checked after a
SELECT statement. In the example above the desired behavior is that an empty table should be returned if the
SELECT statement is not successful, so there is no need to check the value of
Sometimes a line of code generates several warnings or errors which you may want to hide. Using pseudo comments, it is only possible to specify one pseudo comment for each program line. When multiple pseudo comments are required, the statement must be divided up to span multiple lines.
Note that the pseudo comment is placed after the ending dot of a statement.
Pragmas are program directives that can be used to hide warnings from various check tools.ABAP Keyword Documentation
Pragmas can be used to hide warnings from the ABAP compiler syntax check as well as from the extended program check.
The use of a pragma looks like this:
MESSAGE e001(ad) INTO DATA(lv_message) ##NEEDED.
##NEEDED tells the check tools that even though the variable
lv_message isn’t used for further processing, the variable is still needed. In this specific scenario, it is needed since we want to be able to perform a where-used search for the message
AD 001 from transaction SE91.
Not that a pragma is placed before the dot or comma ending the statement to which the pragma is applied. If multiple pragmas are needed for the same statement, they can be placed one after the other separated by space. It is also possible to place pragmas in front of a colon (:) of a chained statement. This applies the pragma to the whole chained statement:
DATA ##NEEDED: gt_messages TYPE bapiret2_t, gt_sel_data TYPE ty_sel_data_tt.
Personally I think that this is hard to read, and I’d much rather use the following format:
DATA: gt_messages TYPE bapiret2_t ##NEEDED, gt_sel_data TYPE ty_sel_data_tt ##NEEDED.
Some pragmas can be used with parameters. The example mentioned in the ABAP Keyword Documentation is
##SHADOW, which can be used with an optional parameter. It looks like this:
I’ve never come across this in practice, so I don’t have much experience to share. Feel free to give some input on this by writing a comment on the blog post.
The mapping between obsolete pseudo comments and pragmas
As already mentioned, most pseudo comments are obsolete and have been replaced by pragmas. SAP provides a program which can be run to find the mapping between obsolete pseudo comments and pragmas. The name of the program is
ABAP_SLIN_PRAGMAS. The main table used by the program is
SLIN_DESC, if you prefer looking up the pseudo comments and programs directly in a table viewer like SE16.
As an example, the pseudo comment
"#EC AUTFLD_MIS has been superseded by the pragma
TRPRAGMAT contain all pragmas.
I hope that this brief overview of pragmas and pseudo comments was useful. Please leave a comment if you think that I missed mentioning something crucial. Happy coding!
This blog post first appeared on the Developer Voyage blog at https://www.developervoyage.com/2019/09/03/what-are-pragmas-and-pseudo-comments-in-abap.html
Thanks for your write-up, Johan!
I have a question regarding the placement of pseudo comments where you mention "Note that the pseudo comment is placed after the ending dot of a statement."
Is this version dependent? I'm asking because we just place them in any of the lines of the relevant statement if it spans more than one line and it does work as intended for the ATC-checks by supressing the finding. It just doesn't work - not too surprsingly! - if the pseudo comment is put directly below the affected statement.
My experience is also, that you can place them at the end of ANY line.
The hint with using the table directly instead of ABAP_SLIN_PRAGMAS is good, because that report has a limited feature set (no filtering or excel export on the table).
Thanks for the comment Bärbel!
What I probably should have written is “Note that the pseudo comment is placed after the ending dot of a statement on the same line as the statement, if the statement only spans one line.”
Just like you noted, when you have a statement spanning multiple lines, you can put the pseudo comment at the end of any of the lines of the statement.
Note that Check 82 of abapOpenChecks recommends that you place the pseudo comment after the statement. But if you have several pseudo comments for the same statement, you have no other option than breaking them up into several lines.
Thanks for clarifying, I was confused by that, too! (As splitting the statement would not give m another ending dot, where I could place another pseudo-comment ).
So this works fine:
Great blog! I noticed the change when doing an extended check. #NEEDED seems to be the one I use the most. I do wish they were easier to read. It so nice to be able to look them up in a table. I didn't know about that.
I think ##NO_HANDLER deserves an honorable mention too 🙂
Anyway thanks for the tip regarding the tables
Thanks for the blog.!
I was looking for documentation for each pragmas/pseudo comments, but I didn't find any.
From SLIN_ADMIN, I was able to check documentation for some pragmas but not all.
Wondering if there is any tcode/link where I can documentation for all pragmas.
Thanks for the help
Unfortunately I haven't been able to find a complete documentation of all pragmas / pseudo comments either. Please let me know if you would find it.
I was just wondering about the list of Pragmas myself and I saw that the question was already posted without an answer. Did a bit of digging and to whoever it may concern, we can use the report ABAP_SLIN_PRAGMAS to generate the full list of Pragmas and respective pseudo comment.
Hope it helps someone.
That was exactly the info I was looking for! Thanks!
(but I'll read the rest of the text, as well! 😉 )
But check Johan's additional info in one of the replies:
So, normally, putting the pseudo comment at the end of any line of a multi-line statement should be ok.
However, it seems that things are more complicated. We just upgraded to 7.50 SP16, and I just noticed that the following pseudocomment was not noticed by ATC. It is only noticed when it is put after the dot . in the last line.
How to add pseudo comment when the ATC error is in the RFC structure parameter (Type component &2 used by RFC-Function parameter)?