ATC: How to disable usage of pragmas/pseudocomments for standard tests
I could not find this information in detail on the internet yet, and I think it is quite useful to know, so here is a quick description.
If you are the person responsible for ATC checks, and you want to use an SAP provided check (for example in automatic checks during release of transports), but you want to disable the possibility for the developers to use a pragma or pseudocomment, you can do this quite easily by creating a subclass to the respective SAP test class.
For example, we do NOT want the developers to call obsolete functions. We also do not want to allow the “workaround” of using a pseudo comment or pragma (FM_OLDED/FB_OLDED) that the SAP standard check allows.
This check is part of test class CL_CI_TEST_EXTENDED_CHECK.
So, we create a subclass of that class:
CLASS zcl_ci_test_extended_check DEFINITION PUBLIC INHERITING FROM cl_ci_test_extended_check FINAL CREATE PUBLIC . PUBLIC SECTION. METHODS constructor. PROTECTED SECTION. PRIVATE SECTION. ENDCLASS. CLASS zcl_ci_test_extended_check IMPLEMENTATION. METHOD constructor. super->constructor( ). myname = 'ZCL_CI_TEST_EXTENDED_CHECK' ##NO_TEXT. " necessary in this case because otherwise pragma is still displayed in finding details DATA(parentname) = myname+1. description = description && ' fewer pragmas'(001). LOOP AT scimessages REFERENCE INTO DATA(msg). IF msg->pcom = 'FM_OLDED'. " obsolete function module msg->pcom = c_exceptn_imposibl. ENDIF. IF msg->test = parentname. " necessary to keep the standard SAP priority mapping (CL_CI_TEST_ROOT->INFORM) INSERT VALUE #( BASE msg->* test = myname ) INTO TABLE scimessages. ENDIF. ENDLOOP. DELETE scimessages WHERE test = parentname. ENDMETHOD. ENDCLASS.
In the constructor, we modify the standard table of checks scimessages. We change the field pcom (pseudo comment) for the respective test.
After creating and activating the class (don’t forget to create the text element 001), we need to enable it for ATC/SCI. This is done vie transaction SCI, menu: Code Inspector / Management of / Tests. At the end of the list, you should see your new Z class. You have to tick the checkbox on the left, then save.
Now the new check is available when you create or change check variants.
Update 18.02.2019: Bugfix in code to re-enable standard SAP priority mapping.
Update 26.03.2019: For some test classes, e.g. CL_CI_TEST_CRITICAL_STATEMENTS, the pragmas are ignored during the check – as intended, but in the finding list, the pragmas are still mentioned (because the class passes its own name as a constant as the origin of its findings).
Thanks Edo for sharing the tip.
It's unfortunate that the ability to turn off pseudo comments/pragmas isn't a setting in the system for the very reasons you mentioned for checks from remote systems. There is an option to ignore them when doing scheduled runs, but we want to catch issues before they are moved into our production system and that means at time of release of the request/task. It appears the change you suggest would also stop a developer from requesting an exception. Can you confirm if this enhancement still allows the developer to request a formal exception (for those items configured) in the system and only ignores the pseudo comments/pragmas? Ideally in my situation I would want to allow developers to request exceptions but not hide them using pseudo comments/pragmas for any error (level 1) messages. I appreciate any additional information you can provide.
sorry, I only now noticed your question.
With the Approach suggested above, ATC exemptions are still possible.
We followed the instructions, and we do not see the same result as described. The code in question that has the pseudo comment/pragma to suppress the error is still not being caught. The only difference is when the pseudo comment/pragma is not used and the error is caught, we no longer see the "hint" in the output for the check in question that states "Finding can be suppressed with pseudo comment". We now see the comment "Cannot be hidden using a pragma or pseudo-comment", but these item are still not found when using the pseudo comment/pragma. Was there an additional step that was missed in the original post that is needed to get ATC to not consider the pseudo comment/pragma?
one reason for what you describe, could be that you forgot to Switch from the old check to the new check in your test variant(s). You have to de-select the original test, and select the new one - like in the lower screenshot.
Thank you for your reply. We did switch on the new check, and in fact we had both the standard and new check running at the same time to make comparison easier. We found that the use of the pragma would still hide the error from the check when using the suggested solution. The only difference we saw was that it removed the "hint" that is displayed when you look at the detail from within the ATC output for the error in question. So now it looked like there wasn't a way to hide it, but the change only impacted the message that was displayed on the check detail and did not change the check behavior. This would seem to make sense as the only thing that was altered was the messages table and not the "NO_SUPPRESS" attribute that is used in the SAP logic. I'm suspecting that we are on different versions and that may play into the behavior. I am working with ATC Hub v7.52 SP1. I know SAP has been adding the ability to "turn off" the pragmas when running manually or from a scheduled run, but has yet to implement this for the check when it runs automatically before release of a request/task. I plan to submit a note to SAP on this very subject in the next day or two, and will report back.
I just tested the behavior again our System.
For CL_CI_TEST_EXTENDED_CHECK "FM_OLDED", everything works as desired. There is no "hint" in the finding to use a pragma, and a pragma in the Code does not "solve" the finding.
But for CL_CI_TEST_CRITICAL_STATEMENT (e.g. #EC CI_EDITORCALL), the "hint" is still shown in the finding. Even though the pragma in the coding does not "solve" the finding.
I will open an incident as well.
Thanks for the follow-up. So the behavior seems to be different by the check/message. I was checking against the use of a hard coded break-point in CL_CI_TEST_EXTENDED_CHECK "NO_BREAK". The incident I submitted is still under review by SAP, and last comment indicated it was being discussed with development team.
I wanted to provide an update as SAP was able to guide us on a workaround for our situation. The situation I'm referring is that we are running remote ATC checks through a hub system and we are not using any baseline. Given this, SAP suggested two places where we were able to introduce implicit enhancement points in our hub system to remove the ability to use pragmas/pseudo comments. We are currently at version 7.52 in our ATC hub, so not sure if these changes would apply to lower versions, but want to provide in case anyone else can leverage this logic. The modifications are to two ABAP functions, and in both cases the implicit enhancement was done at the beginning of the object. The changes are simple and straightforward and are as follows:
P_NO_SUPPRESS = ABAP_TRUE.
LOOP AT LCL_HANDLER=>EXEC_SCIRESTPS ASSIGNING FIELD-SYMBOL(<L_EXEC_SCIRESTPS>).
Testing has shown that any of the checks that we have configured that have pragmas or pseudo comments, now can't be hidden, but the exemption process still works as needed. We did not test every pragma/pseudo comment, but did enough to see how some were covered with the change to one of the function modules while others were part of the other change. It appears that SAP has two separate ways of handling this situation currently and goes further to explain the differences that I was seeing with the original post in this blog.
SAP did indicate that they would add this functionality to the list for future enhancements, but made no commitment on timing.
This is really helpful, thank you. I've just enabled it and struggled at first with the step to enable it in SCI. Maybe it would have helped to add this step with a screenshot, too.
see OSS note "3088590 - ATC: Offer default option to handle pseudocomments and pragmas"