SAP ABAP Pragmas in 7.02 EhP2, replacing SLIN Pseudo Comments

By | February 20, 2013 | Concepts | 5,542 | 5

Going forward Pseudo Comments are getting replaced by Pragmas which are introduced since ABAP release 7.0 EhP2. So, What are Pragmas? Lets check it out.

What are Pragmas?

Pragmas are program directives which would use to hide warnings and errors from Compilers and Extended Program checks. Program directive are statements which don’t affect the flow of the execution of the program but it provides a direction to Compiler what to do when specific error or warning situation occurs.

Pragmas are introduced in release 7.02 EhP2. For time being, Pragmas will replace the Pseudo comments for

  • Compiler warnings
  • Extended Program errors and warnings

Pseudo comments for suppressing errors and warnings for Code Inspector would be still effective. Means, you would still need to use Pseudo comments to overpass those warnings and errors coming from the Code Inspector.

How to use Pragmas?

To use Pragmas is quite different from what you do with Pseudo comment. Since Pseudo comment is actually a half line Comment, you put the Pseudo comments after end of the statement ‘.’ Or ‘,’. Like this:

Pseudo Comments to hide SLIN errors/warnings

 
REPORT ztest_np_pseudo_comments.
*&---------------------------------------------------------------------*
*& Purpose : Psuedo comments usage to hide SLIN Errors / warnings
*& Author  : Naimesh Patel
*& URL     : http://zevolving.com/?p=1831
*&---------------------------------------------------------------------*
*
* In SLIN, This would produce a warning that its not read anywhere
DATA text TYPE string. 	                                    "#EC NEEDED
*
* IN SLIN, This would produce error in character string
text  = 'Hello Zevolving using Pseudo Comments'.            "#EC NOTEXT
 

Since Pragmas are part of the statement, it has to be added before end of the statement. It can’t occur after end of the statement, otherwise, system would generate an error. Something like this:

Pragmas to hide errors of SLIN

 
*&---------------------------------------------------------------------*
*& Purpose : Pragmas usage on hiding the errors / warning
*& Author  : Naimesh Patel
*& URL     : http://zevolving.com/?p=1831
*&---------------------------------------------------------------------*
REPORT ztest_np_pragmas.
*
* Hidden using pragmas instead of the pseudo code. 
*   Also notice that pragmas are part of the statement, end of statement 
*   is after the pragmas.
DATA text TYPE string  	    ##needed.
data text_new type string   ##needed.
 
text  = 'Hello Zevolving using Pragmas'           ##no_text.
text  = 'Hello Zevolving using Pseudo Comments'.            "#EC NOTEXT
 

Another small difference is, Pseudo comments gets formatting properly to the end of the line when we use Pretty Printer. Pragmas stay at exactly that position, even when pretty printer is used as they are part of the statement.

When you do the Extended Program check for this demo program with selecting both Character String and Also display hidden messages (Pseudo comments), you would notice the messages like this. I guess, SAP still have to update this option with Display hidden messages (Pragmas & Pseudo Comments).

Result of Pragmas Usage to hide Character String error:

Pragmas Usage to hide Character String

Result of Pragmas Usage to hide Unused variables warning:

Result of Pragmas Usage to hide Unused variables

As you can see in the screenshot, message also points out which Pragmas can be used as an alternative to Pseudo comments to hide that error or warning.

We can also specify Parameter to the Pramas using []. But I still have to figure that out.

Program ABAP_SLIN_PRAGMAS

So how would you know which Pseudo comment is replaced by which Pragma? When run the program ABAP_SLIN_PRAGMAS, you see the list of Pseudo comments and its replacement Pragmas. The info is coming from the table SLIN_DESC. Table SLIN_DESC contains all the Pseudo code which can be used to suppress various errors and warnings from the Extended Program Check (SLIN). The texts are maintained in German only so, we need to ask our friends from Germany to translate it for us ;)

The table does exist in the earlier releases. In earlier releases, you would also notice that there are many SLIN checks which can be hidden using Asterisk (*). So, there are many entries in table where PSEUDO_COM = ‘*’ in earlier release. But with introduction of Pragma, all the entries which can be just hidden using pseudo comment “#EC * are now replaced with specific Pragma as well as specific Pseudo comments.

Conclusion

Pseudo comment will eventually replaced every where with different ways either by Pragmas or by Using additional Keywords like in ABAP Unit. ABAP Unit, would be next new adventure.

Have you used Pragmas yet? What do you think about this? Please let me know your thoughts.

More Concepts Explained

Check out other explanation for new Concepts and make yourself aware of them:

Like It? Share!!

Don't miss an Update

Naimesh Patel{245 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 245 articles.

Load comments

5 Comments

  • Hi Naimesh,

    While enhancing our automatic code review and rework tool (a.k.a smartDevelop ) we found below observations, thought, with your permission, i would take an opportunity to add as a comment to your post.

    The prgama’s are treated as PART of the ABAP code line and are not comments ( Unlike the Pseudo Comments ). i.e pragma is mentioned before the ‘.’ ,the abaps end of statement indicator.

    In addition to the sample program given by SAP, ABAP_SLIN_PRAGMAS, there is an addon table TRPRAGMA, where we have additional pragmas which form an extension to the compilers list.

    There is only a “warning” message shown if a developer uses a non existent pragma by any chance.

    A non existent just-like-that pragma

     
    ##Just-like-that Data: w_data TYPE   bseg .
     

    Pragmas can be parameterised with [ ] addition, And here Pragma parts can not be separated by space ( See the example program “Demo_read_table_using_key” ).

    If there are multiple pragmas to be applied in a single code statement , then the code should be spread into multiple lines, and respective pragma has to be mentioned besides each ‘sensitive’ token of the statement.

     
    " The below line would give an error : 
    Data: w_data3 like ##Just-like-that  bseg  ##Just-like-that.
    *
    "So it has to be broken into 2 lines
    Data: w_data3 TYPE  ##Just-like-that
                  bseg  ##Just-like-that.
     

    Pragmas can hide WARNINGS and some specific errors also. Below is an example :

    Parameterised Pragmas and Hiding a syntax error with Pragma

     
     itab TYPE STANDARD TABLE
                         OF i
                         WITH NON-UNIQUE    KEY primary_key
                           COMPONENTS table_line
                         WITH UNIQUE SORTED KEY sorted_key
                           COMPONENTS table_line
                         WITH UNIQUE HASHED KEY hashed_key
                           COMPONENTS table_line
                         ##tabkey[hashed_key][sorted_key].
     

    Some of the frequently used pragmas :

    ##FM_SUBRC_OK ( During exception handling of Function Modules )
    ##CALLED ( In case of dynamically called MODULE or SUBROUTINE definition)
    ##NEEDED (In case of a un used data declaration )
    ##too_many_itab_fields ( When the database table structure is a subset of the internal table)
    ##catch_all ( In case of Generalised class exception CX_ROOT is used with CATCH )
    ##no_text ( HardCoded texts)
    ##no_handler ( In case the CATCH statement doesnt pass the object reference into a declared object )

    Regards
    Kesari Katakam

  • Steve Oldner

    We have used pseudo comments in custom programs since 7.0 and it is part of the ‘boiler plate’ ALV we use to create new ones. I haven’t seem pragmas yet.

    Thanks to both of you!!

  • Steve Oldner

    I keep getting the “Welcome, you seem new here” toolbar. I follow you on Twitter and am subscribed to the blog.

  • Hello Kesari,

    Thank you very much providing your real-time learning. Much appreciated. I now know how we can use the parameters to the Pragma to control the error or warning suppression.

    Regards,
    Naimesh Patel

  • Hello Steve,

    Yes, pseudo comments are used widely to suppress many errors/warnings from SLIN execution. I’m sure you would start using pragma whenever it would be available to your system ;)

    RE Welcome.. new toolbar, I use Google Analytics to determine if the reader is new vs returning. I bet you are returning and participating reader. I guess the logic of Google Analytics doesn’t work as expected. I would try to fix it. Thanks for bringing to my notice.

    Regards,
    Naimesh Patel

Comments on this Post are now closed. If you have something important to share, you can always contact me.