SAP CODE INSPECTOR - Guide
Get Example source ABAP code based on a different SAP table
GUIDELINE 3.8
Code Inspector
ABAP_BACKGROUND
The Code Inspector tool performs a static check of Repository objects regarding performance, security, syntax, and adherence to naming conventions. You can call transaction
You can also call the Code Inspector from the ABAP Workbench to perform a standard set of checks for your current object, for example by choosing
As in the extended program check, the results of the
ABAP_RULE
Perform the standard check variant of the
ABAP_DETAILS
If you are using the
Compared with the messages of the extended program check, it is not always so easy to correct these problems at their source, perhaps because there is no other option for a selection, or because the transparency or robustness of a construct is seen as more important than a small potential loss of performance.
In such cases, the messages can be suppressed using the appropriate pseudo comments. A pseudo comment is a clear indication to the reader of a program that the program author has performed the relevant checks and has explicitly suppressed the message for a good reason. If necessary, pseudo comments can be substantiated by additional normal
Bad example
A standard Code Inspector run for the example class below issues warnings because an internal table is returned by pass by value and an inner join for database tables with activated SAP buffering is used in the
PUBLIC SECTION.
TYPES: BEGIN OF docu_wa,
object TYPE dokil-object,
dokldate TYPE dokhl-dokldate,
dokltime TYPE dokhl-dokltime,
END OF docu_wa,
docu_tab TYPE SORTED TABLE OF docu_wa
WITH NON-UNIQUE KEY object.
METHODS get_docu
IMPORTING VALUE(langu) TYPE sy-langu
EXPORTING VALUE(documents) TYPE docu_tab.
ENDCLASS.
CLASS class IMPLEMENTATION.
METHOD get_docu.
SELECT d~object h~dokldate h~dokltime
FROM dokil AS d
INNER JOIN dokhl AS h
ON h~id = d~id AND
h~object = d~object AND
h~typ = d~typ AND
h~langu = d~langu AND
h~dokversion = d~version
INTO CORRESPONDING FIELDS OF TABLE documents
WHERE d~id = 'SD' AND
d~object LIKE 'AB%' AND
d~typ = 'E' AND
d~langu = langu.
ENDMETHOD.
ENDCLASS.
Good example
The source code below shows the corrected version of the above class, for which the Code Inspector no longer issues any messages.
The pass by value of the internal table is replaced by a pass by reference. For the transfer of the elementary parameter
The inner join of the
PUBLIC SECTION.
TYPES: BEGIN OF docu_wa,
object TYPE dokil-object,
dokldate TYPE dokhl-dokldate,
dokltime TYPE dokhl-dokltime,
END OF docu_wa,
docu_tab TYPE SORTED TABLE OF docu_wa
WITH NON-UNIQUE KEY object.
METHODS get_docu
IMPORTING VALUE(langu) TYPE sy-langu '#EC CI_VALPAR
EXPORTING REFERENCE(documents) TYPE docu_tab.
ENDCLASS.
CLASS class IMPLEMENTATION.
METHOD get_docu.
SELECT d~object h~dokldate h~dokltime '#EC CI_BUFFJOIN
FROM dokil AS d
INNER JOIN dokhl AS h 'Buffering is done
ON h~id = d~id AND 'by application
h~object = d~object AND 'with Shared Objects
h~typ = d~typ AND
h~langu = d~langu AND
h~dokversion = d~version
INTO CORRESPONDING FIELDS OF TABLE documents
WHERE d~id = 'SD' AND
d~object LIKE 'AB%' AND
d~typ = 'E' AND
d~langu = langu.
ENDMETHOD.
ENDCLASS.