Avoid Hardcoding System & Tenant Environment Checks (sy-sysid, sy-mandt)
Overview
Avoid reading environment system fields (sy-sysid, etc.).
ATC Finding Message:
Avoid reading environment system fields (sy-sysid, sy-uname, etc.)
Rationale
Branching business logic on hardcoded SAP System IDs (sy-sysid = 'PRD'), client numbers (sy-mandt = '100'), or server hostnames makes ABAP code fragile, untestable in sandbox environments, and incompatible with cloud transports. In multi-tenant ABAP Cloud systems (BTP), hardcoding client numbers breaks tenant isolation and violates SAP Clean Core guidelines.
Best Practice: Encapsulate environment configurations in feature toggles, custom configuration tables, or standard SAP BPF/BTP environment services.
Non-Compliant
" Anti-pattern: Hardcoded environment and client checks
IF sy-sysid = 'PRD' AND sy-mandt = '100'.
send_live_bank_order( is_payment ).
ELSEIF sy-sysid = 'DEV'.
mock_bank_response( ).
ENDIF.Compliant
" Clean ABAP: Feature toggle or environment service configuration
IF mo_env_service->is_live_payment_active( ) = abap_true.
send_live_bank_order( is_payment ).
ELSE.
mock_bank_response( ).
ENDIF.Configuration & Thresholds
This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:
| Parameter Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
CHECK_SYSID | Boolean | true | Detect hardcoded checks against sy-sysid |
CHECK_MANDT | Boolean | true | Detect hardcoded client number comparisons against sy-mandt |
CHECK_HOST | Boolean | true | Detect hardcoded server hostnames (sy-host) |
CHECK_DBSYS | Boolean | true | Detect database system checks (sy-dbsys) |
CHECK_OPSYS | Boolean | true | Detect operating system checks (sy-opsys) |
CHECK_UNAME | Boolean | true | Detect hardcoded user names (sy-uname) in conditional branches |
ONLY_CONDITIONAL | Boolean | false | Only flag occurrences when used inside conditional comparisons (IF, CASE) |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
" Standard pseudo-comment:
... "#EC NO_HARDCODED_ENV
" SAP CI_ prefix format:
... "#EC CI_NO_HARDCODED_ENVRelated Rules
- Avoid Raising System Exceptions Directly (CX_SY_*) —
#EC NO_RAISE_CX_SY - Avoid Kernel and Native Database Calls (SYSTEM-CALL, EXEC SQL) —
#EC NO_KERNEL_CALL - Handle System and Communication Failures in Remote Function Calls (RFC) —
#EC NO_RFC_ERR
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_HARDCODED_ENV - Implementation File: zcl_skylint_no_hardcoded_env.clas.abap