Skip to content

Avoid IS INSTANCE OF and CASE TYPE OF Type Tests ​

WarningClean ABAP & Modern Syntax#EC NO_INSTANCE_OFRemote Enabled

Overview ​

Avoid IS INSTANCE OF / CASE TYPE OF checks.

ATC Finding Message: Avoid runtime type checks via IS INSTANCE OF; use polymorphism

Rationale ​

Checking concrete object types at runtime via IS INSTANCE OF or CASE TYPE OF breaks polymorphism, violates the Open-Closed Principle, and introduces fragile type coupling. Instead of conditional type inspection, introduce polymorphic methods on common interfaces.

Non-Compliant ​

abap
IF io_shape IS INSTANCE OF cl_circle.
  render_circle( ).
ENDIF.

Compliant ​

abap
io_shape->render( ).

Configuration & Thresholds ​

This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:

Parameter NameData TypeDefault ValueDescription & Guidance
CHECK_CASE_TYPEBooleantrueReport CASE TYPE OF type tests in addition to IS INSTANCE OF

Suppression ​

To suppress findings for this rule, append the pseudo-comment to the statement:

abap
" Standard pseudo-comment:
... "#EC NO_INSTANCE_OF

" SAP CI_ prefix format:
... "#EC CI_NO_INSTANCE_OF

Technical Details ​

Released under the MIT License.