Creating your own Code Inspector checks

In this recipe, we will see how we can create our own company specific checks and categories and display them with the standard check categories. For simplicity's sake, we will create a check by the name My Check under a new category My Check category. When this check will run, it will search for the token T512T in the program and will display the number of occurrences and the corresponding line numbers.

How to do it...

Follow these steps:

  1. Call the SAP transaction SE24. Enter the class name CL_CI_CATEGORY_TEMPLATE in the class field and click the Copy button. The screenshot appears as follows:
    How to do it...
  2. Open the new class in the Change mode and the CONSTRUCTOR method in the Edit mode. Add the code given in the following screenshot:
    How to do it...
  3. Next, we will create a copy of the CL_CI_TEST_SCAN_TEMPLATE class having the name ZST9_CL_CI_CHECK. In the CONSTRUCTOR method, add the code given in the following screenshot:
    How to do it...
  4. Add the code in the run method of the Check class, which is given in the following screenshot:
    How to do it...
  5. Add the code for the GET_MESSAGE_TEXT method of the class given in the following screenshot:
    How to do it...
  6. Activate the two classes. Make sure all components are also active.
  7. Next we will do the necessary setting for displaying the newly created check and category along with standard checks in transactions SCI and SCII. Follow the menu path from the transaction SCI.
    How to do it...
  8. The two newly created classes will appear in the list that is displayed.
    How to do it...
  9. First, select the category class and click Save. A confirmation dialog box appears. Click Yes.
  10. Repeat the last step for the check class.

How it works...

First we create the category class. We assign the necessary text (My Check Category) to be displayed in the CONSTRUCTOR method. The folder of the category will have this text displayed. Next the check class is defined and the text My Check. The linkage between the check class and the category class is done in the CONSTRUCTOR method of the check class.

The run method is executed when the check is executed. The REF_SCAN object supplied with the TOKENS table within the method is used for checking all the tokens of the program code that is to be included in the inspection. A loop is run on the TOKENS table and if the token t512T is found, the method INFORM is called with the necessary information supplied. We want the information message to be displayed along with the row and column of the token. The P_CODE value 0001 is also supplied, for which an appropriate text message is added in the GET_MESSAGE_TEXT method.

Then, both classes were activated.

Finally, the activation setting will display the new check and the category along with standard categories and checks for transactions SCI and SCII, as shown in the following screenshot:

How it works...

We ran the inspection for a program having two occurrences of the token T512T. The output of the results is shown in the following screenshot:

How it works...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.142.2