Code Inspector User Manual Version 2 January 2002 Table of Contents INTRODUCING THE CODE INSPECTOR ............................................................................ 2 CALLING THE CODE INSPECTOR............................................................................................ 2 RESULTS OF THE INSPECTION............................................................................................... 3 CHECKING SEVERAL OF YOUR OBJECTS ................................................................................ 5 CREATING AN OBJECT SET .............................................................................................. 5 SELECTING AN OBJECT SET ................................................................................................. 6 CREATING A CHECK VARIANT.......................................................................................... 8 CREATING AN INSPECTION............................................................................................... 9 ANONYMOUS INSPECTION .................................................................................................... 9 CREATING A NAMED INSPECTION ........................................................................................ 10 STATUS OF EXECUTION AND STATISTICS OF A NAMED INSPECTION ........................................ 11 APPENDIX.......................................................................................................................... 13 FURTHER POSSIBILITIES TO SELECT AN OBJECT SET ............................................................ 13 DECLARING EXCEPTIONS ................................................................................................... 13 ADMINISTRATION OF CHECKS.............................................................................................. 13 RESTRICTIONS IN CUSTOMER SYSTEMS ............................................................................... 13 LIMITATIONS OF THE CODE INSPECTOR ............................................................................... 14 SWITCH TO MODAL F4 HELP ............................................................................................... 14 COMMENTS AND FEEDBACK ............................................................................................... 14 1 Introducing the Code Inspector Tool for checking static ABAP coding and DDIC objects (generally: TADIR objects) Aspects of checks are: Performance, Security, Reliability, and Statistical Information Checks are performed on single objects or Object Sets (programs, function modules, classes, interfaces, DDIC-objects). One or several single checks make up a Check Variant A Check Variant and one object/Object Set can be combined to an Inspection With the Code Inspector you can perform checks of different categories on single objects as well as on a set of objects. A simple check of one object can be done with almost no preparation (see Calling the Code Inspector or Anonymous Inspection). For more elaborate checks on several objects you might first need to create an Object Set with your objects, then a Check Variant with your special check, and at last a Named Inspection combing the two. Calling the Code Inspector The easiest way to call the Code Inspector for a single object is from ABAP workbench (SE80), ABAP editor (SE38), function builder (SE37), or the class builder (SE24) with Object Check Code Inspector where ‘Object’ stands for ‘Program’, ‘Function module’ or ‘Class’ (see figure 1). The respective single objects (program, function module, or class) are then checked with a Default Check Variant of the Code Inspector. Fig.1: Calling the Code Inspector for a class from SE24 (class builder) 2 Results of the Inspection When the Inspection run is finished, you get the results of the Inspection, which are ordered hierarchically. The system only displays the checks that were applied in the Inspection. Fig.2: Results of an Inspection Hierarchy: List of checks Check category: Performance, security, syntax, search, general Single check Type of result message: Error (red), Warning (yellow), Information (green) Message code of sub-check (with Web AS 6.20) Message Each message contains: the source code position (or name of the TADIR object) a short explanatory text 3 To attain the inspected object double-click the message text. For further explanation click the information icon in front of the message. Fig.3: Information for a sub-check of ‘SELECT Statements that Bypass the Table Buffer’ An information text is available for many of the checks, providing an explanation of the problem and further links within the Code Inspector online documentation. There is also given a pseudo-comment. When this pseudo-comment is inserted into the coding, future Inspections will not show this message. When started from the Workbench, with Web AS 6.20 you get two additional buttons on the result screen (figure 2): With the left button Create Default Check Variant you can create your local Default Check Variant. Your objects will be checked from then on with this local Default Check Variant. You can change or delete your Default variant any time from the result screen or within transaction SCI. With the button Code Inspector you get to transaction SCI. 4 Checking several of your objects If you want to check not only a single object, but rather a number of objects, for example all objects of a package or a SAP component, use transaction SCI to Create an Object Set which contains your objects, Create a new Check Variant which contains the checks you want to execute on your objects (or use a Default Check Variant), Create an Inspection and run it. Creating an Object Set To create an Object Set call transaction SCI, enter a suitable name for your new Object Set and click Create. Fig.4: Create a new Object Set Each Object Set has a version number that the system assigns automatically. This version number can help you to administrate Object Sets with slightly varying properties. 5 Using F4 Help, you get a list of Object Sets. There are ‘local’ and ‘global’ Object Sets. While local Object Sets are only visible for one user (‘Person Responsible’), global Object Sets can be viewed by everyone. Depending on your SAPGui settings, you will have to click on the local/global icon to switch between the two settings, even if you choose an element (Inspection, Object Set, or Check Variant) with F4 Help. See how to let F4 Help switch automatically to the local/global icon. With transaction SCI you can of course also display, change, delete and copy Object Sets. Selecting an Object Set To select an Object Set with your objects, choose TabStrip Select Object Set (figure 5). In the upper part (Object Assignment) you can select objects according to their assignment. This can be one of the following: Application Component (Web AS 6.20) Software Component Package Original system Person responsible In the lower part (Object Selection) you can select the objects. TabStrip Classes, Func. Groups... allows you to select specific classes, interfaces, function groups, programs or reports, DDIC types (data element, structure/table, view, physical pool/cluster, table type), and type-pools. Using Free Obj. Choice you can select any TADIR object type (for example ‚TABL’ for tables). The TabStrip Programs allows for a very general program selection and should only be used by expert users. Be sure that for your selected object type already exists a check ! To save your selection and to create an object list, choose Save. You can immediately control your object list with Display Objects. If you are not satisfied with your selection, you can always change the input and save the Object Set again. If you set the flag ‘Selections Only’, your selection criteria will be saved, but no object list will be generated. This can be done later by clicking on the Create Object List button. If you use an Object Set without object list in an Inspection run, an up-to-date object list will be generated in this moment. Proceeding this way, no outdated state of your object selection will be checked. 6 In figure 5, user HOLMES selected an Object Set which contains the classes and interfaces of package S_CODE_INSPECTOR. You can assign a description to every Object Set. With Web AS 6.20 a default description is generated containing the name and version number of the Object Set. You can also determine a deletion date. Note that the default value lies 50 days ahead. This means as standard your Object Set will be deleted after 50 days if it is not included into an Inspection not yet executed. Fig. 5: Selecting an Object Set with all classes / interfaces belonging to package ‘S_CODE_INSPECTOR’ See also: Further possibilities to select an Object Set 7 Creating a Check Variant Check Variants are also created, displayed, changed, deleted and copied with transaction SCI. To create a Check Variant, enter a suitable name and click Create. You obtain a tree containing all check categories with their respective single checks. Add single checks to your Check Variant just by clicking the tree. Note Some checks have attributes. These attributes can be set by clicking on the arrow in front of the check name. Attributes on the Pop-Up screen are selected by choosing Execute. Some checks (for example the search functions) will not be executed, if none of their attributes are set. With Web AS 6.20 it is not possible to save Check Variants with missing attributes. For more information on a check, choose the Information button. Fig. 6: Create a new Check Variant. Select single checks and maintain their attributes There is always a global Check Variant with name DEFAULT which is applied to the objects that are inspected from SE24, SE37, SE38, or SE80. If you create a local DEFAULT, it will override the global DEFAULT Check Variant. 8 Creating an Inspection An Inspection consists of an single object or an Object Set, and a Check Variant. In the Inspection run, the checks of the Check Variant inspect the objects. Finally you get the Results of the Inspection. Inspections can be Anonymous or Named: An Anonymous Inspection is not stored persistently, it can only handle Object Sets with less than 50 objects and is executed on the local server. A Named Inspection is stored persistently together with it’s results. It can handle Object Sets containing any number of objects and is executed on the local server or alternatively by a server group. You can create suitable server groups with transaction SM59 RFC Groups. A Named Inspection can be scheduled in an background job. Anonymous Inspection In transaction SCI in the Inspection area click on Create without giving a name. You can then combine an Object Set or a single object with an existing Check Variant (Predefined) or one picked spontaneously from the tree of checks (Temporary Definition). When you click the Execute button, the Inspection will be executed immediately on the local server. Fig.7: Anonymous Inspection with single object and temporarily defined Check Variant 9 When the Inspection run is finished, you can access the results by choosing Results. Note: All results of an Anonymous Inspection will be lost when you leave the screen Inspection. Clicking the Repeat button enables you to change the input parameters for an Anonymous Inspection. The results of the old Inspection are lost, but you do not need to call the transaction SCI again and repeat all of your inputs to start a new Anonymous Inspection. Creating a Named Inspection In transaction SCI type in a name for your Inspection and click Create. You can then combine an Object Set, a single object, or objects from a request with an existing Check Variant. There are two possibilities to execute the Named Inspection: on the local server or by a Server Group. When choosing Execute, the Inspection run will be started immediately on the local server in one task. Fig.8: A Named Inspection can be executed by a server group (Execute...). You can start the Inspection immediately or you can schedule it in a background job. 10 If you choose Execute... you get to the ‘Execution Options’ Pop-Up screen where you can select a server group. Make sure that the group contains only active servers that have sufficient free resources. With the button Maintain Server Group (or, alternatively, with SM59 RFC Groups) you get directly into the server group maintenance. We recommend you to run the Inspection on a Server Group when the Object Set is large (more than 50 objects). The Inspection will then be performed parallel in up to 12 tasks on all servers of the server group (if they have free resources). The load will be split up into packages of 10 to 50 objects. You can start a Named Inspection immediately or you can schedule it in a background job. Status of execution and statistics of a Named Inspection A Named Inspection can be in different states which are signalled by the status icon in front of it‘s name: An Inspection can be interrupted due to server shutdown, lack of resources, faulty checks, or other reasons. An broken Inspection can be (re-)started just as an Inspection not yet executed, and the Code Inspector then tries to check the remaining objects. In some cases it may not be possible for the Code Inspector to check all objects, so the Inspection will remain in the broken state. Therefore it is possible to get the results also for broken Inspections. Especially in the case of a broken Inspection, you will be interested in the execution statistics of the Inspection to get an hint about what went wrong. From the Inspection screen you get to the statistics with the Statistics button. 11 The statistics inform you about start and end time/date of execution, cumulated runtime, number of servers, tasks, and objects, execution state of the objects and errors. Fig.8: Statistics of execution of a Named Inspection Under Object Statistics you find a summary of the execution states for the checked objects. Objects can have one of the following states: Not to be checked: object belongs to Object Set, but the Inspection executed has no appropriate check for the object Not yet checked: object has not been checked because the Inspection was interrupted Checked w/o message: object was checked, but there was no message Checked with message: object was checked and there is at least one message Lead to an error: an error occurred while checking the object 12 Appendix Further possibilities to select an Object Set Additionally to selecting Object Sets from the scratch you have more options, such as: Edit Object Set: Objects Sets can be united or intersected with others and filtered according their attributes ‚Object Type‘, ‚Object Name‘, ‚Package‘ and ‚Responsible‘ Object Set from Result: objects that triggered messages can be input for building a new Object Set. Again filtering according to the attributes ‚Object Type‘, ‚Object Name‘, ‚Package‘ and ‚Responsible‘ is possible. Additionally, with Web AS 6.20, filtering according to one single check and it’s message codes, and message type (‘Error’, ‘Warning’, or ‘Information’) is possible. Some checks may have objects as message parameters (for example database tables used in programs) that can be extracted into a new Object Set when activating the Flag ‚Object Set from Parameters’ . Object Set from Request: Object Sets can also be extracted from requests/tasks and filtered according the attributes ‚Object Type‘, ‚Object Name‘, ‚Package‘ and ‚Responsible‘. Only main objects (with TADIR program-ID ‘R3TR’) will be put into the new Object Set. Declaring Exceptions You can declare exceptions by the use of pseudo-comments in your coding. You will find the appropriate comments in the online documentation of many of the checks. Exceptions for DDIC objects can be declared in table SCIEXCEPT, but in the moment this is not supported by the Code Inspector transaction SCI. Administration of checks In transaction SCI choose from the menu GoTo Test Administration. On this screen you can activate or deactivate single checks and check categories. Changes executed herein will modify the displayed Check Variant tree. When you create a global Check Variant, you have the possibility to declare it as ‘Transportable’, which means that it can be transported and reused through the entire transport landscape. Some global Check Variants (‘DEFAULT’ and ‘CHECKMAN‘) can only be changed with special authorisation. If you want the Code Inspector to check your objects from workbench with your own Check Variant, create your local ‘DEFAULT’. This will override the global one. Restrictions in customer systems In customer systems only objects developed at the customer site can be put into an Object Set and checked in an Inspection. However, it is possible to check a single SAP object within the first 7 days after it has been modified. 13 Limitations of the Code Inspector The Code Inspector currently has the following limitations which you have to bear in mind when you use the tool: Code analysis only for static source code WHERE clause of a SELECT statement can only be parsed correctly when formulated in disjunctive normal form (which is the recommended form anyway) DB-Views and ABAP JOINs can not be handled ‚hidden‘ LOOPs in called modules can not be detected Switch to modal F4 Help How to let F4 Help switch automatically to the local/global icon (Switch to Dialog/modal Display of F4 Help) From the menu choose Help Settings... On TabStrip F4 Help under ‘User-specific settings’ choose ‘System defaults’ for Settings and under ‘System defaults’ choose ‘Dialog’. Answer Pop-Up screen ‘Deactivate ActiveX search help support ?’ with ‘Yes’. Code Inspector for release 4.6C Code Inspector has been ported down to release 4.6C/4.6D and can be downloaded from sapservX by interested parties. Important limitations of the 4.6C/4.6D version of Code Inspector are: Only English and German language versions available Since we started downport of the Code Inspector before end of Web AS 6.20 development, only English and German language versions are available No integration into workbench It is not possible to check single objects from workbench (SE24, SE37, SE38, or SE80) with the DEFAULT check variant Pseudo-comments are not working Pseudo-comments to hide messages from Code Inspector will not work on release 4.6C/4.6D Comments and Feedback Both are highly appreciated, (Randolf.Eilenberger@sap.com). please send them to Randolf Eilenberger 14