Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Peter_Inotai
Active Contributor
44,523

Introduction

I always felt excited when I read about new ABAP related tools. One of the first such tool I fell in love was the Code Inspector. Around in 2001-2002 we were on 46C, and in one for the Code inspector presentation I saw a note about, that there is a down port for 46C with some limitation. I got green light from my manager to import it to our development system and I could play around with this tool ... and fun begun.

I found very useful to perform static checks on the code. From that point I always used Code Inspector instead of the Extended syntax check.

About the Code inspector framework

The Code Inspector is a tool for the static analysis of ABAP programs and other SAP repository objects. It’s available as of basis release 6.10 as part of SAP standard delivery and a down port is available for 46C with some limitations.

Code inspector is a framework, where all the categories and checks are based on ABAP classes. SAP continuously delivers new build-in checks for new tools (e.g.: ABAP Unit) and new objects (e.g.: BSP Applications).

It’s also possible to add customer-built checks within this framework.

Main steps for creating a new check

  • Create new category
  • Create new check
  • Create documentation
  • Activate new category/check

In this example we will build a very simple check for searching string ‘SDN’. This example is based on SAP standard check CL_CI_TEST_FREE_SEARCH.

I believe standard checks are covers most of the customer needs, however new checks can be useful for checking customer specific programming conventions.

The goal of this example is to show how the code inspector checks are built.

Creating a new category

Copy CL_CI_CATEGORY_TEMPLATE to ZCL_CI_CATEGORY_SDN.

Select the package in the popup (e.g.: $TMP)

Change the CONSTRUCTOR method to the following:

Create the text elements and activate your class.

This method sets the attributes of this category in the code inspector check tree.

Creating a new check

Copy CL_CI_TEST_SCAN_TEMPLATE to ZCL_CI_SCAN_SDN.

Select the package in the popup (e.g.: $TMP)

Add the following attributes to the class:

C_MY_NAME  Constant  Private  Type  SEOCLSNAME  'ZCL_CI_SCAN_SDN'

C_PROGRAM  Constant  Private  Type  SCI_ERRC  Code Inspector: ID for Message Code  'PROG'

C_SDN  Constant  Private  Type  CHAR03  Three-digit character field for Idocs  'SDN'

Method constructor sets the attributes of this check in the code inspector check tree.

Method run to search for string SDN and pass the parameters to method INFORM

Method get_message_text is to generate explanation text in the check tree.

Documentation

Via transaction SE61 you can add documentation to the categories/checks.

Create the follwing documentations:

ZCL_CI_CATEGORY_SDN/000       New Category for SDN

ZCL_CI_SCAN_SDN/000     Search for SDN

Activate new categories and checks

Start transaction SCI. Navigate to Goto-> Test Administration in the menu. Set the flag for the new category and check in order to make them available in the framework.

Testing our new check

Create a simple test program containing string ‘SDN’.

Start transaction SCII, where you can test the code without saving the inspection.

In the Object selection block set Single, select Program and enter program name.

In the Check variant block select Temporary Definition and make sure that you flag ‘New Category for SDN’ category and ‘Seach for SDN’ check. Remember, these texts were defined in the constructors.

Press execute and when you got the message ‘The inspection was carried out successfully’ go to the results.

Remarks

·        There are some changes between releases in the mentioned menu path and also in the available techniques.

·        This example was created on a SAP R/3 Enterprise 4.70x200 /WAS 6.20/ system.

·        Although suppress message is possible via method INFORM parameter p_suppress, somehow I couldn’t manage to make it work.

·        If you import the package in 46C, you can expect some extra work during the next upgrade SPAU, however all of these object can be reset to SAP standard

Reference documents

OSS note 543359        Code Inspector for SAP R/3 Release 4.6C

Improving the Quality of Your ABAP Code Using the Code Inspector

Evaluating the Quality of Your ABAP Programs and Other Repository Objects with the Code Inspector

ABAP Troubleshooting

75 Comments
Peter_Inotai
Active Contributor
0 Likes
Source code is available via SAPLink:
http://abap-inotai.googlecode.com/svn/trunk/

Peter
Former Member
0 Likes
Hi Peter,

Yours is one of the few and best help that I could manage to locate on Code Inspector. But I have a few doubts regarding the code in the Run() method. I was unable to understand the purpose of the following statement :
IF ref_scan IS INITIAL.
CHECK get( ) = 'X'.
ENDIF.
What does it aims to do?
Similarly the satements,
CHECK statement_wa-from <= statement_wa-to.
CHECK statement_wa-type NA 'EMPSDR'.
are trying to achieve what?
It would be very helpful in gaining more clarity if you could explain this.
Peter_Inotai
Active Contributor
0 Likes
Hi Shikha,

The code presented here is based on CL_CI_TEST_FREE_SEARCH->RUN.

The best is to put a break-point in method RUN to see what is happening there.

1)
IF ref_scan IS INITIAL.
CHECK get( ) = 'X'.
ENDIF.

If there is no scan is available, so REF_SCAN is initial / which is an istance of CL_CI_SCAN / then it will call the GET( ) method /from CL_CI_TEST_SCAN/ and call the constructor to create an instance for REF_SCAN. If this went fine, the return parameter P_RESULT is set to 'X'.
So, in nutshell it does two steps in one step, create object for REF_SCAN and check if it's went fine.

2)
CHECK statement_wa-from <= statement_wa-to.

This check might be removed, it's just checking if the statement start line is lower or equal to the statement end line. Normally it should be the case.

3)
CHECK statement_wa-type NA 'EMPSDR'.

I can't find this line in my code. However I think it's checking the statement type, which is based on data element STMNT_TYPE, which can be EXEC SQL, INCLUDE, macro, ..., rest.
In CL_CI_TEST_SCAN_NESTED->GET_STMNT_NAME you can find some info about type:
case P_STMNT_TYPE.
when 'D'. p_stmnt_name = 'DO/ENDDO'.
when 'W'. p_stmnt_name = 'WHILE/ENDWHILE'.
when 'L'. p_stmnt_name = 'LOOP/ENDLOOP'.
when 'V'. p_stmnt_name = 'PROVIDE/ENDPROVIDE'.
when 'S'. p_stmnt_name = 'SELECT/ENDSELECT'.
endcase.

Hope it helps.

Best regards,
Peter
Former Member
0 Likes
Hi Peter,

I really thank you for your prompt reply and help. Your answer has realy made the thing clear to me which was essential for moving forward.

You have really got a rich experience in ABAP. Can I benefit from the same by asking you queries in the future (as I am still growing in this field ) and if yes, where shall i write to you?

Regards,
Shikha.
Former Member
0 Likes
Hi Peter,

I really thank you for your prompt reply and help. Your answer has realy made the thing clear to me which was essential for moving forward.

You have really got a rich experience in ABAP. Can I benefit from the same by asking you queries in the future (as I am still growing in this field ) and if yes, where shall i write to you?

Regards,
Shikha.
Peter_Inotai
Active Contributor
0 Likes
Some additional info about statement_wa-type:
In the CONSTRUCTOR of CL_CI_SCAN, the SCAN ABAP-SOURCE statement is used to get the statamenets.
If you check the F1-help, you can see that it's for "This statement is for internal use only. "
However there is some info about the type:

TYPE
Type of statement with the following possible values:

E (Native SQL statement between EXEC SQL and ENDEXEC)
I (INCLUDE prog )
J (INCLUDE prog, prog does not exist, can occur only in connection with the addition WITH INCLUDES )
T ( TYPE-POOLS pool)
V (TYPE-POOLS pool, pool nicht vorhanden)
R (Call a macro from table TRMAC)
D (Call a macro internally defined with DEFINE)
M (Macro definition between DEFINE and END-OF-DEFINITION)
C (COMPUTE statement, sometimes without COMPUTE as first token)
A (Method call in short form)
K (Other ABAP/4 key word)
N (Blank statement)
P (Comment between statements)
S (Comment within statements)
U (Unknown, non-blank statement)

Peter
Former Member
0 Likes
Hi Peter,

I really thank you for your prompt reply and help. Your answer has realy made the thing clear to me which was essential for moving forward.

You have really got a rich experience in ABAP. Can I benefit from the same by asking you queries in the future (as I am still growing in this field ) and if yes, where shall i write to you?

Regards,
Shikha.
Former Member
0 Likes
Hi Peter,

I really thank you for your prompt reply and help. Your answer has realy made the thing clear to me which was essential for moving forward.

You have really got a rich experience in ABAP. Can I benefit from the same by asking you queries in the future (as I am still growing in this field ) and if yes, where shall i write to you?

Regards,
Shikha.
Former Member
0 Likes
Hi Peter,

I really thank you for your prompt reply and help. Your answer has realy made the thing clear to me which was essential for moving forward.

You have really got a rich experience in ABAP. Can I benefit from the same by asking you queries in the future (as I am still growing in this field ) and if yes, where shall i write to you?

Regards,
Shikha.
Former Member
0 Likes
Hi Peter,

I really thank you for your prompt reply and help. Your answer has realy made the thing clear to me which was essential for moving forward.

You have really got a rich experience in ABAP. Can I benefit from the same by asking you queries in the future (as I am still growing in this field ) and if yes, where shall i write to you?

Regards,
Shikha.
Peter_Inotai
Active Contributor
0 Likes
Hi Shikha,

I'm happy that my answer helped you.

To be honest I wouldn't like to share my email because of SPAM reasons. However you can post your Code Inspector questions here, and for other topics I'd suggest to post them in the SDN ABAP forums. I'll check them regularly, when I have some time, which is unfortunately it's not the case recently:(

Best regards,
Peter
Former Member
0 Likes
Ok Peter, although its a loss of mine of not being able to benefit from your knowldge through a direct access but I still respect and understand your issue.

Currently, I am studying a code which has imbibed a lot of code and functionality from 'Code Inspector' and modified it further to make an indigeneous Code Inspector which suits the requirement's purpose. If I am stuck anywhere, I will definitely show up again with another query.

Thanks and Regards,
Shikha
Former Member
0 Likes
Hi Peter,

I like your introduction to creating new SCI checks. Do you know if there is any SAP or publicly available site where additional SCI checks can be made available?

In particular, I was thinking about developing a check which determines SAP4.6C compatibility in a SAP4.7 coding and I wonder whether such a check is already available.

Best regards,
Björn
Peter_Inotai
Active Contributor
0 Likes
Hi Björn,

Thanks for your feedback.

Sorry for the late answer, it seems something wrong with the notification as I didn't get any notification about your comment.

I'm not aware of any site for SCI checks. Any custom made can be shared via SAPlinkm but I didn't see any of them. SAP delivers new checks via new releases or basis support packages.

I don't think there is standard SCI check for 4.6C-4.70 compatibility. I think the best is to run the unicode check report in 46C, however I don't have the report name anymore as we don't have 46C system. I'll check my notes, hopefully I can find it back.

Best regards,
Peter
Peter_Inotai
Active Contributor
0 Likes
The report name is RSUNISCAN, which allows some kind of unicode-simulation checks in 46C. Most of the incompatibilty these releases coming from the Unicode-compatibility.
Peter
PS: It seems there is a new version of this program, which is called RSUNISCAN_FINAL.
Former Member
0 Likes
Hello again,

thanks for the hint with the report.
A colleague of mine is now working on this compatibility check, which will actually run on NetWeaver to check for downwards compatibility. When he's finished, I'll see whether my company releases the code so we can send it to SDN as a contribution (even though there is the remote possiblity that no-one would be interested in such a check 😉 ).

Björn

P.S.: It's really sad that my name doesn't get displayed correctly :,(
Peter_Inotai
Active Contributor
0 Likes
Hi Björn,
Thanks for the info.
It seems unicode compatibility is not only an issue for upgrade from 46C, but for your name 🙂 Maybe if you try to enter with a different encoding it might work.
About the check, I'd be very curious. As it class based, the easiest would be to share it via SAPlink.
Best regards,
Peter
Former Member
0 Likes
Could someone please tell me how we can customise
code inspector (SCI) with the Transport Organizor (SE01). Is it possible to automatically invoke SCI when someone tries to release a transport?
Thanks.
Soyab
Peter_Inotai
Active Contributor
0 Likes
Hi Soyab,
As of release 6.40 SCI is integrated to the Transport organizer.
In lower releases you might use Badi CTS_REQUEST_CHECK method CHECK_BEFORE_RELEASE to trigger a code inspector check.
Best regards,
Peter
Former Member
0 Likes
Peter,
CTS_REQUEST_CHECK is not modifiable. I found another one that we use that is also  a CHECK_BEFORE_RELEASE and I'm trying to do a CALL TRANSACTION on SCI.
In BAdI (ZCL_IM_VSD_TP_CREATION_CHK method
IF_EX_CTS_REQUEST_CHECK~CHECK_BEFORE_RELEASE) I call a function module.
The function module builds the BDC Table and performs a CALL TRANSACTION SCI (code inspector). This call transaction correctly processes screen
0100 to create a new inspection, screen 0200 is correctly populated and
the OKCODE is set to '=RUN' to execute the inspection. However, what
actually happens is that the information is SAVED and the execution is
NOT performed. If I go and execute SCI using the inspection name it
shows it as unexecuted and when I select 'RUN' it executes it and the
inspection results are created. My question is how do I get SCI to work
correctly in background via a call transaction. I have tried the OKCODE
= SAVE and then followed by =RUN it still gives me the same results. In
order for it to work I have to manually execute it in SCI using the
stored inspection.
I debugged the process and the background processing 'exits' after it
encounters the first 'commit work'. In foreground it continues after
the 'commit work'.
Is there a work around?
Any help would be extremely appreciated.
Thanks.
Soyab
Peter_Inotai
Active Contributor
0 Likes
Hi,
>CTS_REQUEST_CHECK is not modifiable.
It's normal, it contains only the definition, you have to do the implementation.

I'd suggest to try transaction SCID, which calls with the default variant. Something like this:
    set parameter id 'SCI_OBJ_TYPE' field 'PROG'.
    set parameter id 'SCI_OBJ_NAME' field l_object_name.
    call transaction 'SCID'.

Best regards,
Peter
Former Member
0 Likes
Hi Peter,
Thanks for your advice.
I have another question.
I'm trying the 'Security checks' -> 'Check SY-SUBRC handling' and checking 'CALL FUNCTION'.
I'm trying to check a program that does:
CALL FUNCTION 'ARCHIVE_SAVE_OBJECT'
      EXPORTING
        archive_handle = handle.

On execution it does NOT flag it as an error/warning that the SY-SUBRC check is missing.
Is this a bug?
However, when I check 'changing DB Access' it correcly flags as an error the following condition is NO SY-SUBRC is checked:
UPDATE ZVBAKX etc etc

Thanks.
Soyab
Peter_Inotai
Active Contributor
0 Likes
Hi Soyab,
I tried the same in our system (SAPKB62061) and got the same result. For me it looks like a bug. Checking SY-SUBRC makes no sense if there is no exception in the Function module, but in this case there is, so there should be an error.
I checked OSS Notes, but couldn't find any relevant one:(
Best regards,
Peter
former_member193209
Discoverer
0 Likes
Hi all,
thanks for this information / new check. I want to create a new check / div by zero. Can you help me ?
Thanks
Dorothée
Peter_Inotai
Active Contributor
0 Likes
Hi Dorothée,
I don't think Code Inspector is the tool for such checks. It's for static checks, and division by zero needs a dynamic check.
Peter
former_member193209
Discoverer
0 Likes
Hi Peter,
You're right...
Thanks for your feedback.
Dorothée
Former Member
0 Likes
Hi Peter.

I have imported the code inspector into 46C.
Is it possible to include the naming conventions check in 46C versions.

Ravi
Peter_Inotai
Active Contributor
0 Likes
Hi Ravi,
I have no access anymore for a 46C system with CI to check this, but I think naming convention check should be available as a standard check. You can check OSS note 543359 for the 46C limitations.
If the standard naming convention check doesn't meet with your requirements, you can just create a new check based on the standard one.
Best regards,
Peter
Former Member
0 Likes
Hi Peter,

In Limitations it is not given. But i imported into 46C, in SCI Transaction i Can not see the Programing naming conventions check. Other checks are coming in SCI Tcode. We can including programming naming conventions check with extra programming.

Ravi

Peter_Inotai
Active Contributor
0 Likes
Hi Ravi,
Maybe you can check in the SCI administration if CL_CI_CATEGORY_CONVENTIONS/CL_CI_TEST_ABAP_NAMING are available and the flag is set for them.
Peter
Former Member
0 Likes
HI Peter,

In SCI Administration the above two classes are not available and some of other classes are available.
1. Is it possible to add above mentioned classes to this(Custom developed).
2. If it is available in SCI administration is it possible to check the check boxes.

Please let me know. This is very crucial to us to develop in 46C.

Thanks in Advance.

Ravi
Peter_Inotai
Active Contributor
0 Likes
Hi Ravi,
You can always active the available classes. See the chapter "Activate new categories and checks" in this blog.
If you need these checks in 46C, maybe it's worth to downport them manually from a higher release. For example you can get them from the Netweaver Sneak Preview for ABAP system, which can be downloaded from SDN and copy/adopt from there.
Best regards,
Peter
Peter_Inotai
Active Contributor
0 Likes
Hi Soyab,
Please check OSS Note 1296076 - Code Inspector: Improved check of SY-SUBRC handling.
Best regards,
Peter
0 Likes
hi peter,
interesting article , do you know some FunctionModule how i can analy de sourcecode with a "check variante" likes the FM "EXTENDED_PROGRAM_CHECK" ?
Peter_Inotai
Active Contributor
0 Likes
Hi Ricardo Alberto,
I'm not sure if I understand your question correctly. Code Inspector works with classes and not Function modules to analyze the source code.
The mentioned FM "EXTENDED_PROGRAM_CHECK" is also encapsulated into class CL_CI_TEST_EXTENDED_CHECK and integrated to the Code inspector framework.
You have to call transaction SCI or SCII to analyze the code, you cannot really call separate FM to get the same result.
Best regards,
Peter
Former Member
0 Likes

Hy,Dominik

Peter_Inotai
Active Contributor
0 Likes
Hi Dominik,
I didn't see this error.
You can give a try to upload them via SAPLink from here and see if it works:
http://abap-inotai.googlecode.com/svn/trunk/
Best regards,
Peter
Former Member
0 Likes
Hy,
sorry, I simple forgot to define a test symbol for English for "My Category"(000).
So you can delete this post.
regards
Dominik
Peter_Inotai
Active Contributor
0 Likes
Hi Dominik,
I cannot delete posts. Anyway it could be useful for others if they have the same problem.
I'm happy that it works.
Best regards
Peter
Former Member
0 Likes
Hi Peter,

Thank You for such a nice article.

Right now, I need to create a check concerned with "Loop at" statement.
I am bit unclear about the statement table, token table etc, which is the most important part I need to understand to write a check.

Is there any document that can explain these things in detail?

Regards,
Raghotham S

Peter_Inotai
Active Contributor
0 Likes
Hi Raghotham S,
I'm not aware of any documentation.
You can always create a test program, where you have the statement, example you want to inspect. Then you can start to build your check-class and debug it, what information is available etc.
It also depends what exactly you want to do on "LOOP AT", but you can have a look the following classes:
CL_CI_TEST_IMUD_NESTED         Changing Database Accesses in Loops
CL_CI_TEST_SCAN_NESTED         Nested Loops
CL_CI_TEST_SELECT_NESTED       SELECTs in Loops
Best regards,
Peter
Former Member
0 Likes
Hi Peter,

Thank You very much for the info.
It was of great help.

I shall debug and find out things 🙂

Regards,
Raghotham S
Former Member
0 Likes

So my question is how can i change the status of the error message. With your tutorial in the result-table of the code inspector all the messages have the type "information" but i want "error" the red one. What parameters should I change that it works.

Peter_Inotai
Active Contributor
0 Likes

Just use for the inform( ) method call

p_kind         = c_error.

Former Member
0 Likes

Thank you very much.

c_error = error

c_note = information

c_warning = warning ???

Peter_Inotai
Active Contributor
0 Likes

Yes, exactly:

Message type (C_NOTE = information, C_WARNING = warning, C_ERROR = error message)

Former Member
0 Likes

HI Peter,

i programmed my frist own check for the SCI. I show the result with the display_as_tree method. But now i have the problem that i cant jump by double click to postion in the scoure code.

Is there a special parameter to set, that this function is usable??? The result tree sad when i double click "The object " does not exist". I think the three cant find the object but why????

Thanks


Peter_Inotai
Active Contributor
0 Likes

Did you pass the p_position, p_line and p_column for the INFORM method? They are required for that.

Try something like this:

  g_include = get_include( ).

  g_line    = get_line_abs( l_tokennr ).

  g_column  = get_column_abs( l_tokennr ).

 

  CALL METHOD inform( p_sub_obj_type = c_type_include

    p_sub_obj_name = g_include

    p_position = g_position

    p_line = g_line

    p_column = g_column

    p_errcnt = g_errcnt

    p_kind = c_error

    p_test = con_my_name

    p_code = '0023' ).

Former Member
0 Likes

Hello Peter,

thanks for your help. It worked awesome. I wrote in the last week 5 exams for the SCI. Now i had another problem. After all my own checks i used the method display as a tree to get the nice SCI overview. So my question is, is it possible to create a onw button on the result display of the display as a tree method. I haven't found any BADI.

Peter_Inotai
Active Contributor
0 Likes

Hi Gero,

I'm happy that you managed it in the end :smile:

Unfortunately I'm not aware of any possibility to add custom button to the tree. I'm afraid since the tree columns are added by the framework and there is possibility to only show documentation and attributes, probable there is no such possibility.

Peter