$npx -y skills add likweitan/abap-skills --skill clean-abapCheck ABAP code for compliance with Clean ABAP principles. Use this skill when users ask to check, validate, review, or analyze ABAP code for clean code compliance, code quality, best practices, or adherence to Clean ABAP guidelines. Triggers include requests like "check this ABA
| 1 | # Clean ABAP |
| 2 | |
| 3 | This skill provides comprehensive checking of ABAP code against Clean ABAP principles, based on the Clean ABAP style guide which adapts Robert C. Martin's Clean Code for ABAP. |
| 4 | |
| 5 | ## How to Use This Skill |
| 6 | |
| 7 | When checking ABAP code for Clean ABAP compliance: |
| 8 | |
| 9 | 1. **Read the code** provided by the user |
| 10 | 2. **Categorize issues** by Clean ABAP sections (Names, Language, Constants, Variables, Tables, Strings, Booleans, Conditions, Ifs, Classes, Methods, Error Handling, Comments, Formatting, Testing) |
| 11 | 3. **Identify violations** with specific line references when available |
| 12 | 4. **Provide actionable recommendations** with code examples showing both the problem and the clean solution |
| 13 | 5. **Prioritize issues** by impact (critical, major, minor) |
| 14 | |
| 15 | ## Check Categories |
| 16 | |
| 17 | ### 1. Names |
| 18 | |
| 19 | **Key Principles:** |
| 20 | |
| 21 | - Use descriptive names that convey content and meaning |
| 22 | - Prefer solution domain and problem domain terms |
| 23 | - Use pronounceable names |
| 24 | - Use snake_case consistently |
| 25 | - Avoid abbreviations unless necessary |
| 26 | - Use nouns for classes, verbs for methods |
| 27 | - Avoid noise words like "data", "info", "object" |
| 28 | - Pick one word per concept |
| 29 | - Avoid encodings (Hungarian notation, prefixes like iv*, rv*, lt\_) |
| 30 | - Avoid obscuring built-in functions |
| 31 | |
| 32 | **Check for:** |
| 33 | |
| 34 | - Non-descriptive variable/method/class names (e.g., `data1`, `temp`, `x`) |
| 35 | - Inconsistent abbreviations across the code |
| 36 | - Mixed naming conventions (not snake_case) |
| 37 | - Noise words in names |
| 38 | - Hungarian notation or unnecessary prefixes (iv*, ev*, rv*, lt*, ls\_) |
| 39 | - Method names that obscure ABAP built-in functions |
| 40 | |
| 41 | ### 2. Language |
| 42 | |
| 43 | **Key Principles:** |
| 44 | |
| 45 | - Prefer object orientation to procedural programming |
| 46 | - Prefer functional to procedural language constructs |
| 47 | - Avoid obsolete language elements |
| 48 | - Use design patterns wisely |
| 49 | |
| 50 | **Check for:** |
| 51 | |
| 52 | - Use of obsolete statements (unescaped host variables in SELECT, etc.) |
| 53 | - Procedural code that should be object-oriented |
| 54 | - Use of old-style MOVE instead of assignment |
| 55 | - TRANSLATE instead of to_upper()/to_lower() |
| 56 | - CREATE OBJECT instead of NEW |
| 57 | - Old-style READ TABLE instead of table expressions |
| 58 | |
| 59 | ### 3. Constants |
| 60 | |
| 61 | **Key Principles:** |
| 62 | |
| 63 | - Use constants instead of magic numbers |
| 64 | - Constants need descriptive names |
| 65 | - Prefer ENUM to constants interfaces |
| 66 | - Group related constants |
| 67 | |
| 68 | **Check for:** |
| 69 | |
| 70 | - Magic numbers or string literals in code |
| 71 | - Constants with non-descriptive names (c_01, c_x, etc.) |
| 72 | - Ungrouped constants that should be in BEGIN OF/END OF blocks |
| 73 | |
| 74 | ### 4. Variables |
| 75 | |
| 76 | **Key Principles:** |
| 77 | |
| 78 | - Prefer inline to up-front declarations |
| 79 | - Don't use variables outside their declaration block |
| 80 | - Don't chain up-front declarations |
| 81 | - Don't use field symbols for dynamic data access (modern ABAP) |
| 82 | - Choose the right loop targets (field symbols vs references vs values) |
| 83 | |
| 84 | **Check for:** |
| 85 | |
| 86 | - Up-front DATA declarations when inline would be clearer |
| 87 | - Variables used outside their declaration block scope |
| 88 | - Chained DATA declarations |
| 89 | - Unnecessary field symbols with ASSIGN |
| 90 | |
| 91 | ### 5. Tables |
| 92 | |
| 93 | **Key Principles:** |
| 94 | |
| 95 | - Use the right table type (STANDARD, SORTED, HASHED) |
| 96 | - Avoid DEFAULT KEY |
| 97 | - Prefer INSERT INTO TABLE to APPEND TO |
| 98 | - Prefer LINE_EXISTS to READ TABLE or LOOP AT |
| 99 | - Prefer READ TABLE to LOOP AT |
| 100 | - Prefer LOOP AT WHERE to nested IF |
| 101 | - Avoid unnecessary table reads |
| 102 | |
| 103 | **Check for:** |
| 104 | |
| 105 | - Tables with DEFAULT KEY |
| 106 | - APPEND TO when INSERT INTO TABLE is more appropriate |
| 107 | - READ TABLE ... TRANSPORTING NO FIELDS when LINE_EXISTS would be clearer |
| 108 | - LOOP AT ... EXIT when READ TABLE is intended |
| 109 | - Nested IF inside LOOP AT when WHERE clause would work |
| 110 | - Double reads (checking existence then reading again) |
| 111 | |
| 112 | ### 6. Strings |
| 113 | |
| 114 | **Key Principles:** |
| 115 | |
| 116 | - Use ` (backticks) to define string literals |
| 117 | - Use | (pipes) to assemble text |
| 118 | |
| 119 | **Check for:** |
| 120 | |
| 121 | - Single quotes for string literals |
| 122 | - String concatenation with && instead of string templates |
| 123 | |
| 124 | ### 7. Booleans |
| 125 | |
| 126 | **Key Principles:** |
| 127 | |
| 128 | - Use ABAP_BOOL for boolean types |
| 129 | - Use ABAP_TRUE and ABAP_FALSE for comparisons |
| 130 | - Use XSDBOOL to set boolean variables |
| 131 | - Consider if booleans are the right choice (vs enumerations) |
| 132 | |
| 133 | **Check for:** |
| 134 | |
| 135 | - Use of CHAR1 or other types instead of ABAP_BOOL |
| 136 | - Comparisons with 'X' and ' ' instead of ABAP_TRUE/ABAP_FALSE |
| 137 | - IF-THEN-ELSE to set boolean instead of XSDBOOL |
| 138 | - Boolean parameters that should be split methods |
| 139 | |
| 140 | ### 8. Conditions |
| 141 | |
| 142 | **Key Principles:** |
| 143 | |
| 144 | - Try to make conditions positive |
| 145 | - Prefer IS NOT to NOT IS |
| 146 | - Consider predicative method calls for boolean methods |
| 147 | - Consider decomposing/extracting complex conditions |
| 148 | |
| 149 | **Check for:** |
| 150 | |
| 151 | - Negative conditions that could be positive |
| 152 | - NOT IS i |