Skip to Content

In general the use of pragmas is a good way to tell

„Yes, I know it’s dirty, but I need it that way“.

It is faster than ATC exemptions but from a quality assurance perspective it’s also a bit scary cause you have less control how often these exemptions are used. Due to that we came up with code inspector test to validate if the developer wrote additional text behind de pragma / pseudo comment.

DATA gv_unused               Type  ##NEEDED .
DATA gv_unused_with_reason   Type  ##NEEDED. “Is used in dynamic assign.

During the development of this test my colleague found out that in our current Netweaver version 740 SP3 pragmas do not show up in code inspector scans.

The Issue is a missing parameter in the command for the source scan in CL_CI_SCAN : CONSTRUCTOR


SCAN ABAP-SOURCE      p_include->lines
          TOKENS          INTO tokens
          STATEMENTS      INTO statements
          LEVELS          INTO levels
          STRUCTURES      INTO structures
          FRAME PROGRAM   FROM p_include->trdir-name
          INCLUDE PROGRAM FROM p_include->trdir-name
          MESSAGE         INTO message
          INCLUDE         INTO include
          LINE            INTO line
          WORD            INTO word
          WITH ANALYSIS
          WITH INCLUDES
WITH COMMENTS

The parameter WITH PRAGMAS  is missing.

Unsing SAP Enhancements you can change the SCAN command and enable pragmas for the tests.

We implemented an implicit enhancement and added the WITH PRAGMAS option controlled by additional Parameters in the Constructor:


method CONSTRUCTOR .
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Klasse CL_CI_SCAN, Methode CONSTRUCTOR, Anfang                                                                                                    A
*$*$-Start: (1)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 1  Z001_ENH_CI_SCAN_CONSTRUCTOR.    "active version
LOG-POINT ID Z000_SAP_CODE_ENHANCEMENT SUBKEY sy-cprog FIELDS 'Z001_ENH_CI_SCAN_CONSTRUCTOR'.
   IF p_with_pragmas = abap_true.
     SCAN ABAP-SOURCE p_include->lines
          TOKENS          INTO tokens
          STATEMENTS      INTO statements
          LEVELS          INTO levels
          STRUCTURES      INTO structures
          FRAME PROGRAM   FROM p_include->trdir-name
          INCLUDE PROGRAM FROM p_include->trdir-name
          MESSAGE         INTO message
          INCLUDE         INTO include
          LINE            INTO line
          WORD            INTO word
          WITH ANALYSIS
          WITH INCLUDES
          WITH COMMENTS
          WITH PRAGMAS '*'.
     subrc = sy-subrc.
     IF p_noaunit = abap_true.
       determine_aunit_lines( ).
     ENDIF.
     RETURN.
   ENDIF.
ENDENHANCEMENT.
*$*$-End:   (1)---------------------------------------------------------------------------------$*$*
     SCAN ABAP-SOURCE      p_include->lines
          TOKENS          INTO tokens
          STATEMENTS      INTO statements
          LEVELS          INTO levels
          STRUCTURES      INTO structures
          FRAME PROGRAM   FROM p_include->trdir-name
          INCLUDE PROGRAM FROM p_include->trdir-name
          MESSAGE         INTO message
          INCLUDE         INTO include
          LINE            INTO line
          WORD            INTO word
          WITH ANALYSIS
          WITH INCLUDES
          WITH COMMENTS.
   subrc = sy-subrc.
   if p_noaunit = 'X'.
     DETERMINE_AUNIT_LINES( ).
   endif.
ENDMETHOD.

This parameter is transferred from the Initialisation of the first test to the CL_CI_SCAN class. The CONSTRUCTOR of CL_CI_SCAN needs be enhanced with an additional parameter:

P_WITH_PRAGMAS     TYPE ABAP_BOOL  DEFAULT ABAP_FALSE

The CONSTRUCTOR is CALLD in Method GET of CL_TEST_SCAN that needs an implicit enhancement at the top too:


ENHANCEMENT 1  Z001_ENH_CI_TEST_SCAN_GET.    "active version
* Enhancement enables the output of pragmas in the code scan to make them searchable.
LOG-POINT ID Z000_SAP_CODE_ENHANCEMENT SUBKEY sy-cprog FIELDS 'Z001_ENH_CI_TEST_SCAN_GET'.
* Code is copied from SAP lines below
   IF ref_include IS INITIAL.
     CHECK super->get( ) = abap_true.
   ENDIF.
   CHECK ref_include->subrc = 0.
   IF ref_scan IS INITIAL.
     cl_ci_scan=>create( EXPORTING p_include      = ref_include
                                   p_noaunit      = no_aunit
                                   p_with_pragmas = with_pragmas  "new attribute of class which is to be set on usage class exmpl: ZCL_001_CI_TEST_PRAGMA_JSTFCTN
                         IMPORTING p_ref          = ref_scan ).
   ENDIF.
ENDENHANCEMENT.

Here is now a class attribute used to control pragmas on/off. This needs to be added to the class:

WITH_PRAGMAS Instance Attribute     Protected Type ABAP_BOOL

This attribute is inherited to the test classes an used in the CONSTRUCTOR of the custom test where we set it to abap_true.

Attention:  If the first test in the SCI variant is a standard test that does not use the enhancement, it will not be called again as the Instance of CL_CI_SCAN is reused by default. Until now we did not test it, but to use the CLEAR method in your own test class could help to enforce to start the source scan again.

Thanks to my colleagues Stefan Gaertner  for the great work.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Lars Hvam

    Hi Timo,

    I was thinking, this could probably also be done by having the custom code inspector check do the SCAN, that way changes to standard code would not be needed, however it would suffer from worse performance(CL_SI_SCAN results are reused, as you mention)

    (0) 

Leave a Reply