What is the worst work needs to be done after Coding and apart from Documentation?
Answer is Reviewing your code. IT is the most difficult task to do as a developer and also as a Code Reviewer and specially this work is become more difficult when A girl is coming to you for Reviewing her code!!!!
Every company has its own coding standard which is not covered by SAP’s standard code inspector
As an example:
- Hard coding
- Auth group should be maintain in your program attributes
-
Program should be Unicode checked,
Every time you need to manually do this. But now after reading this article you can be able to make code inspector to check this.
This Article covers the Enhancement of Code inspector to give an error for the hard coding.
Step 1.
Go to Transaction code Se24 and Create class ZCL_CI_TEST_HARDCODE
And give a superclass as CL_CI_TEST_SCAN .
We have created a class just because CODE INSPECTOR is based on OOP Concept
AS you have specified the super class it will show you all the methods of superclass CL_CI_TEST_SCAN.
Code inspector CALLs the RUN method of each class to complete one check. Here we want to check for HARDCODE in our program . So the code will be written In side the RUN method. We need to re-define this method.(Dobuble click on that RUN method).You can use the below code:
method RUN.
data : lt_temp_tokens type STOKESX_TAB,
tokens_wa1 type stokesx,
lv_string type string,
lv_include type program,
lv_level type i.
data : lv_abvlin type i.
data : lt_temp_tok type stokesx_TAB.
if ref_scan is initial.
Check get( ) = 'X'.
endif.
lt_temp_tokens[] = ref_scan->tokens[].
lt_temp_tok[] = lt_temp_tokens[].
loop at ref_scan->tokens into token_wa where type = 'S'.
If token_wa-len3 = 0.
LV_ABVLIN = sy-tabix - 1.
read table lt_temp_tok index LV_ABVLIN into tokens_wa1.
if tokens_wa1-str eq 'FUNCTION'
or tokens_wa1-str eq 'DEFAULT'
or tokens_wa1-str eq 'VALUE'.
else.
loop at lt_temp_tokens into tokens_wa1 where row = token_wa-row.
CONCATENATE lv_string tokens_wa1-str into lv_string SEPARATED BY space.
endloop.
loop at ref_scan->statements into statement_wa where
from <= token_wa-row and to >= token_wa-row.
lv_level = statement_wa-level.
endloop.
lv_include = get_include( p_level = lv_level ).
inform(
* p_sub_obj_type = c_type_include
p_sub_obj_name = lv_include
p_kind = c_error
p_test = 'ZCL_CI_TEST_HARDCODE'
p_line = token_wa-row
p_column = token_wa-col
p_code = '0001'
p_param_1 = lv_string ).
clear lv_string.
endif.
endif.
endloop.
endmethod.
Step 3.
Define a CONSTRUCTOR method. Put the below code inside the CONSTRUCTOR.
Note: use the screen shot to see the types of the CONSTRUCTOR. This Code is use just to initialize the description and the category where you want to display it in your list of checks.
Like Code inspector have various category
- Performance check
- General check
- Syntax check
Here we have uses the SEARCH category.
method CONSTRUCTOR.
*CALL METHOD SUPER->CONSTRUCTOR
SUPER->CONSTRUCTOR( ).
DESCRIPTION = ‘Search Hardcode’. “required
CATEGORY = ‘CL_CI_CATEGORY_SEARCH’. “required
VERSION = ‘000’. “required
endmethod.
Step 4.
Open Transaction Code SCI (Sap Code inspector).
Just See the beauty of it . Nothing needs to be done go to next step.
Step 5
Follow the menu path GOto à manament of à Tests
Step6.
You can see the list of classes which are related to Code inspector.
Find out your class & select it .if you are not able to find it out make sure that your Class is active.
Step7.
Now create a new check variant. Give the name as ZTEST_HARDCODE and just click on the Create button option.
Step8
You can see the new check option in your SEARCH category as Search Hardcode (Stress on your mind As this you have specify in your Constructor method).For testing perpose we are just interested to check the HARDCODE functionality. So just check that Entry.
Step8.
Now Create a new inspection with name ZTEST_HARDCODE (You can give any name).