Coding Standards and Clean ABAP

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Two developers can write ABAP that does the same thing and looks nothing alike: one adds prefixes to every variable, the other uses none; one declares everything at the top of a method, the other declares a variable where it is first used. A coding standard is the set of agreed habits that makes a team’s code look and read the same, so the next person can change it without first decoding it. This page explains how names of your own objects are chosen, what SAP’s public Clean ABAP style guide recommends and why, how to silence a harmless warning with a pragma instead of an old pseudo comment, and how to check code against such rules automatically. It is written against Standard ABAP release 8.16 and ABAP for Cloud Development release 9.20 (2608), and against the Clean ABAP guide as it stood on the main branch of its repository on 2026-11-13. Naming in the customer namespace and the Clean ABAP rules apply to ABAP Cloud and to classic Standard ABAP alike, on premise and in the Public Edition; pragmas silence warnings of the syntax check and the extended program check, which exist in both. The abaplint part runs on your own computer and needs no SAP system.

Before you read

Key terms

  • Clean ABAP: SAP’s public style guide that applies the ideas of the book Clean Code to the ABAP language.

  • Customer namespace: the part of the name range that SAP leaves to customers, names that start with Y or Z or sit between slashes of a namespace you have reserved.

  • Hungarian notation: a habit of putting the kind of a variable into its name, such as lv_ for a local variable or it_ for an importing table.

  • Pragma: a marker such as ##NEEDED written after a statement that tells a check tool to hide one named warning for that statement.

  • Pseudo comment: the older way of hiding a warning, a comment such as #EC NEEDED that the check tool reads; it is obsolete.

  • ABAP Formatter: the editor function that re-indents code and changes the case of keywords by the team’s settings (called Pretty Printer in SAP GUI).

  • Static check: a check that reads the source text of a program and reports problems without running it.

Why a team writes its standard down

A standard is not about taste. Code is read far more often than it is written, and a change request nearly always means reading code written by someone else. The Clean ABAP guide states the same idea in its own words: the team rules. It adds that you are free to disagree with any of its advice, as long as you give the advice a fair chance first, and that the guide is a starting point to adapt, not a law. In practice a team picks the points it agrees with, writes them down in one page, and lets tools enforce what a tool can enforce, so that code review is about design and not about indentation.

Three layers cover most standards:

  1. Names, because a good name replaces a comment.

  2. Language style, which of several correct statements to prefer.

  3. Mechanics, such as formatting, warnings you may hide and checks that must pass before a transport leaves.

The next sections go through the layers in this order.

Names of your own objects

Everything you create in a system, a class, a table, a program, a CDS view, lives in one shared repository together with the objects delivered by SAP. To keep the two apart, SAP reserves names. Objects of the customer start with Y or Z, or use a namespace that the customer has reserved and that is written between slashes, such as /ACME/. ADT states this when it creates a package: customer-specific objects use names that start with Y or Z or your own namespace between slashes. Global class names must be unique in the whole system, so a collision with an SAP name is avoided by the prefix alone. The SAP flight demo uses the namespace /DMO/, and the RAP guide says that namespace is only for demos, so never create your own objects in it.

After the Z a team usually adds a short code for the application, then a letter pair or word for the kind of object. The running example of this section follows that pattern: the Expense claims objects start with zexp_ or zcl_exp_, and the CDS layer names such as ZI_ExpClaim and ZC_ExpClaim follow the RAP guide’s prefixes I_ for an interface view and C_ for a consumption (projection) view. One classic book adds that an exception class is named ZCX_ in the customer namespace and CX_ in the SAP namespace. The exact prefix for each object kind is a team decision. What matters is that it is the same everywhere, that it is written down, and that nobody puts customer objects into the SAP name range.

Names inside the code

The Clean ABAP guide gives short rules for the names you give to variables, parameters, methods and classes:

  • Say what it is, not how it is stored. A name should tell the reader the meaning of the thing, customizing_entries for a table of customizing rows, not iso3166tab, which names a table shape and a standard.

  • Use snake_case. ABAP ignores the case of names, so the guide recommends one convention, words joined by underscores, rather than flatcase or UPPERCASE. A method name can have at most 30 characters; when you run out of space, abbreviate the unimportant words, do not remove the underscores.

  • Avoid abbreviations while you have room. The guide’s example is cust, which in SAP applications can mean customizing, customer or custom. If you must abbreviate, use the same abbreviation everywhere.

  • Nouns for classes, verbs for methods. A class is a thing (claim_reader), a method does something (read_claim).

  • Drop the encoding prefixes. The guide encourages you to get rid of all prefixes that encode a kind, lv_, gt_, iv_, rv_ and the like. In its words the reading of result = a + b is not helped by writing rv_result = iv_a + iv_b.

The last rule is the one that most often surprises a reader who learned ABAP from a book, because it undoes a habit that was taught for years. The reason is that a prefix tells you what the compiler already knows, and a method that is short enough to read at a glance shows where each name comes from. A team that works on old code may keep its prefixes until it rewrites a unit. What it must not do is mix both styles inside one method.

An older book and today’s habits

A book written for AS ABAP 7.5 or older, such as the first edition (2016) of Complete ABAP that this page was cross-checked against for coverage, teaches the prefix style as the rule: global variables start with gv_, local variables with lv_, internal tables with it_, and so on, and it says such names are set by a company as part of its coding standards. That description is accurate for a lot of code you will meet, and it is why you must be able to read it. For new code SAP’s own Clean ABAP guide now advises against encoding prefixes. The same book hides a warning of the Code Inspector with a pseudo comment, which later releases replaced by pragmas (below). Read such a book for the meaning of the statements, and apply the current guide for style.

Clean ABAP highlights

Clean ABAP is long. It is split into sections for names, language, constants, variables, tables, strings, Booleans, conditions, classes, methods, error handling, comments, formatting and testing, and each rule has a short explanation, a good example and an anti-pattern. The table lists a selection that a beginner meets on the first day, with the form the guide recommends. The guide marks the bad form as an "anti-pattern" in its examples; this page uses "before" and "after".

Rule of the guide Before After

Prefer inline to up-front declarations

DATA line TYPE i. and later LOOP AT t INTO line.

LOOP AT t INTO DATA(line).

Prefer NEW to CREATE OBJECT

CREATE OBJECT reader EXPORTING number_range = 'X'.

DATA(reader) = NEW reader( 'X' ).

Prefer RETURNING to EXPORTING

METHODS total EXPORTING value TYPE i.

METHODS total RETURNING VALUE(result) TYPE i.

Use XSDBOOL to set Boolean variables

IF and ELSE with abap_true and abap_false

result = xsdbool( total > 1000 ).

Prefer INSERT INTO TABLE to APPEND TO

APPEND line TO table.

INSERT line INTO TABLE table.

Do not chain up-front declarations

DATA: a TYPE i, b TYPE i.

DATA a TYPE i. and DATA b TYPE i. on separate lines

Comment with a quote, not with an asterisk

a comment line that starts with an asterisk

a comment line that starts with a double quote and is indented with the code

Delete code instead of commenting it out

commented-out statements

nothing; the version history keeps the old code

Avoid obsolete language elements

CALL METHOD, unescaped host variables in SELECT

method call in functional form, host variables escaped with @

ABAP Doc only for public APIs

ABAP Doc on every private helper

ABAP Doc on what other teams call

A few of the rules are about design and not about statements. The guide prefers composition to inheritance, prefers final classes unless a class is designed to be inherited from, and wants members PRIVATE unless they must be PROTECTED; the page Interfaces and Inheritance shows the reasons. It wants class-based exceptions rather than return codes, and exceptions for errors, not for regular cases, which the page Exceptions explains. It wants methods that do one thing, are short, and take few IMPORTING parameters, at best fewer than three. It asks you to put test code in local test classes and to name a test method after what is given and what is expected.

Two sentences of the guide set the spirit. Use the ABAP Formatter before you activate an object (Shift+F1 in ADT, SE80 and SE24), with the settings of your team, so nobody spends review time on layout. And explain the why in a comment, not the what, because code already says what it does.

The guide also says what is not decided: the case of keywords. It does not give a clear guidance for upper or lower case, so the team decides and the formatter enforces the decision.

Running a Clean ABAP check on your own computer

You do not need an SAP system to check code against these rules. abaplint is an open source reimplementation of the ABAP parser that reads code serialized in the abapGit file layout, offers integrations such as GitHub Actions and text editors, and covers some of the guide’s anti-patterns. The Clean ABAP guide itself points to it in its section "How to check automatically", next to code pal for ABAP and the SAP tools. The abap-lab of this site already contains abaplint (version 2.120.103). The experiment below adds two small classes to a copy of the lab. Both compute the total of a list of claim amounts and decide whether a total is big. The first is written the way an old book teaches it; the second follows the table above. The lab table is a reduced version of the Expense claims table, so the listings use plain integers instead of the full claim structure.

flowchart LR A[Edit in ADT] --> B[ABAP Formatter] B --> C[abaplint in the editor or in CI] C --> D[Commit] D --> E[ATC check on the SAP system] E --> F[Transport]

The first class, with the habits of an older book. It is a deliberately untidy example, not a model.

CLASS zcl_exp_messy DEFINITION PUBLIC CREATE PUBLIC.
  PUBLIC SECTION.
    TYPES tt_amounts TYPE STANDARD TABLE OF i WITH EMPTY KEY.
    METHODS total_amount
      IMPORTING it_amounts TYPE tt_amounts
      EXPORTING ev_total   TYPE i.
    METHODS is_big_claim
      IMPORTING iv_total      TYPE i
      RETURNING VALUE(rv_big) TYPE abap_bool.
ENDCLASS.

CLASS zcl_exp_messy IMPLEMENTATION.
  METHOD total_amount.
    DATA: lv_sum TYPE i,
          lv_unused TYPE i.
    DATA lv_line TYPE i.
    DATA lt_seen TYPE tt_amounts.
    DATA lv_text TYPE string. "#EC NEEDED
* add up all amounts
    LOOP AT it_amounts INTO lv_line.
      lv_sum = lv_sum + lv_line.
      APPEND lv_line TO lt_seen.
    ENDLOOP.
    ev_total = lv_sum.
  ENDMETHOD.

  METHOD is_big_claim.
    IF iv_total > 1000.
      rv_big = abap_true.
    ELSE.
      rv_big = abap_false.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

The second class does the same with the guide’s habits. It has a test class too, so the claim "the same result" is run and not just stated.

CLASS zcl_exp_clean DEFINITION PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    TYPES amounts TYPE STANDARD TABLE OF i WITH EMPTY KEY.
    METHODS total_amount
      IMPORTING amounts       TYPE amounts
      RETURNING VALUE(result) TYPE i.
    METHODS is_big_claim
      IMPORTING total         TYPE i
      RETURNING VALUE(result) TYPE abap_bool.
ENDCLASS.

CLASS zcl_exp_clean IMPLEMENTATION.
  METHOD total_amount.
    LOOP AT amounts INTO DATA(amount).
      result = result + amount.
    ENDLOOP.
  ENDMETHOD.

  METHOD is_big_claim.
    result = xsdbool( total > 1000 ).
  ENDMETHOD.
ENDCLASS.
CLASS ltc_total DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
  PRIVATE SECTION.
    METHODS sums_amounts FOR TESTING.
    METHODS flags_big_claim FOR TESTING.
ENDCLASS.

CLASS ltc_total IMPLEMENTATION.
  METHOD sums_amounts.
    DATA(cut) = NEW zcl_exp_clean( ).
    cl_abap_unit_assert=>assert_equals(
      act = cut->total_amount( VALUE #( ( 120 ) ( 35 ) ( 80 ) ) )
      exp = 235 ).
  ENDMETHOD.

  METHOD flags_big_claim.
    DATA(cut) = NEW zcl_exp_clean( ).
    cl_abap_unit_assert=>assert_equals(
      act = cut->is_big_claim( 1500 )
      exp = abap_true ).
  ENDMETHOD.
ENDCLASS.

The rules that abaplint runs are chosen in a configuration file. The file used here is the lab’s own abaplint.json with its rules section replaced by the checks that correspond to the table. A configuration without a rules section reports nothing, so every rule you want must be named.

{
  "rules": {
    "parser_error": true,
    "check_syntax": true,
    "unknown_types": true,
    "unused_variables": true,
    "no_prefixes": { "types": "^TY_|^TT_" },
    "prefer_returning_to_exporting": true,
    "prefer_inline": true,
    "prefer_insert_into_table": true,
    "prefer_pragmas": true,
    "use_new": true,
    "prefer_xsdbool": true,
    "use_line_exists": true,
    "keyword_case": { "style": "upper" }
  }
}

The no_prefixes rule has defaults for variables, parameters and constants; the setting above adds TT_ to the prefixes it looks for in type names, because the older class names its table type tt_amounts.

Run in the copy of the lab (npx abaplint abaplint-clean.json) with both classes present, abaplint 2.120.103 printed the following. Real output, shortened by the blank lines:

abaplint 2.120.103
Using config: abaplint-clean.json
ABAP release: v793 (SAP_BASIS 7.93, kernel 793, on-premise 758, cloud 793, CE 2308)
ABAP language version: Normal
Clone: https://github.com/open-abap/open-abap-core
src/zcl_exp_messy.clas.abap[3, 11]  - Avoid hungarian notation (no_prefixes) [E]
src/zcl_exp_messy.clas.abap[6, 17]  - Prefer RETURNING to EXPORTING (prefer_returning_to_exporting) [E]
src/zcl_exp_messy.clas.abap[15, 11] - Variable "lv_unused" not used (unused_variables) [E]
src/zcl_exp_messy.clas.abap[16, 10] - Prefer Inline Declarations, LV_LINE (prefer_inline) [E]
src/zcl_exp_messy.clas.abap[18, 31] - Prefer pragma NEEDED (prefer_pragmas) [E]
src/zcl_exp_messy.clas.abap[22, 7]  - Prefer INSERT INTO TABLE over APPEND (prefer_insert_into_table) [E]
abaplint: 6 issue(s) found, 11 file(s) analyzed

Read the result carefully, because it shows what a tool can and cannot do. All six findings are in the older class and none is in the newer one: with the file zcl_exp_messy moved out of src/, the same command reported 0 issues in 9 files and the lab’s own npm run lint reported 0 as well. The rule names (in brackets) are searchable on the abaplint site. The tool did not report the asterisk comment, the IF and ELSE that set a Boolean, the chained DATA: or the EXPORTING of ev_total as a design problem beyond the one rule; those need a rule you switch on, a code review, or an SAP-side check. use_new, prefer_xsdbool and use_line_exists are enabled and found nothing here, which is correct for these files. abaplint is also not the same as the checks of an SAP system: it does not know released APIs, so a call of a class that ABAP Cloud forbids passes abaplint and fails the ATC check variant for the cloud.

The test class was run with the lab’s npm test (transpiles the sources and runs the ABAP Unit tests with open-abap). The relevant lines of the output:

ZCL_EXP_CLEAN: running ltc_total->sums_amounts
ZCL_EXP_CLEAN: running ltc_total->flags_big_claim
ZCL_GREETER: running ltcl_greeter->greets_by_name

The tests ran with the open-abap runtime, a community transpiler, not an SAP system, so they show that the language subset behaves as expected and not that the classes work in a real system.

Pragmas and pseudo comments

Sometimes a check tool warns about code that is correct. A variable that is only needed because a statement requires a target, a text literal that the check wants in a text element although it is only a technical key: you cannot always rewrite the code to quiet the warning, and a warning list that nobody reads stays long. ABAP lets you hide one named warning for one statement.

A pragma is written ##code, optionally followed by parameters in square brackets, and is not case-sensitive and holds no blanks. It applies to the statement it belongs to, which ends at the next period or comma, and a pragma in front of the colon of a chained statement applies to the whole chain. The Keyword Documentation allows a pragma at the start of a line, after any number of blanks, or at the end of a line followed only by a period, comma or colon, but not after a period, comma or colon. Several pragmas may follow each other, separated by blanks. Pragmas hide two kinds of warning: those of the ABAP compiler’s syntax check and those of the extended program check. An unknown, malformed or wrongly parameterized pragma itself causes a syntax warning, and a pragma at a wrong place for a syntax warning has no effect.

The documentation’s own examples show both kinds. ##SHADOW hides the syntax warning that a method hides a built-in function, and the optional parameter narrows it: ##SHADOW[SUBSTRING] hides the warning about substring only. For the extended program check the documentation shows a variable that is only declared with ##needed and a text literal marked with ##no_text. The long text of the warning names the pragma that hides it.

The earlier way was a pseudo comment, a comment such as #EC NEEDED after the statement, which the extended program check read. The documentation says pragmas replace the pseudo comments that hid warnings of the extended program check, that these pseudo comments are obsolete and should no longer be used, and that the program ABAP_SLIN_PRAGMAS shows which pragma replaces which pseudo comment. In a program that uses pragmas, the statement SET EXTENDED CHECK and the pseudo comment #EC * can no longer be used and produce a warning that cannot be hidden. Clean ABAP says the same in one line: prefer pragmas to pseudo comments, and its pattern is the one below. The table SLIN_DESC also holds the mapping, says the guide.

" pattern
MESSAGE e001(ad) INTO DATA(message) ##NEEDED.

" anti-pattern
MESSAGE e001(ad) INTO DATA(message). "#EC NEEDED

This listing is a text example of the style guide and requires an SAP system to be checked by the SAP tools; not run here. What the lab did run is the abaplint rule prefer_pragmas: in the output above it flagged the pseudo comment of line 18 and asked for the pragma NEEDED, and it accepted ##NEEDED on a declaration in a trial before the final version of the classes was written.

Use a pragma sparingly and with a reason. A pragma hides information for everyone who reads the check result, so hide a warning only after you decided that it is irrelevant for this statement, and prefer to remove the cause when you can. The ATC check list and its exemptions, which are the SAP-side way to accept a finding, are in ABAP Test Cockpit (ATC).

Other tools that check a standard

The Clean ABAP guide lists the tools that find some of its anti-patterns. Each one covers part of the guide.

  • ABAP Formatter changes layout and the case of keywords in the editor (Shift+F1 in ADT). It decides nothing about names.

  • ABAP Test Cockpit, Code Inspector and extended check run on the SAP system. They know the repository, released APIs and the cloud rules, which abaplint does not.

  • code pal for ABAP, an SAP open source project, provides a comprehensive suite of checks for Clean ABAP.

  • ABAP Cleaner is an SAP open source project that differs from the ATC; the ATC page of this section says how.

  • abaplint works without an SAP system on code serialized with abapGit and is used above.

How to introduce a standard in a team

  1. Write down the decisions that the team needs: the prefixes of object names, the case of keywords, the formatter settings and which Clean ABAP rules count as mandatory.

  2. Turn what a tool can check into configuration: the formatter settings, an abaplint configuration and the ATC check variant.

  3. Apply the formatter to new objects before activation, and to an old object in a transport of its own, so the history shows layout and logic changes apart. The guide gives this advice for a large unformatted legacy object.

  4. Review the rest by reading. Rules about design, such as one purpose per method, cannot be checked by a tool.

  5. Revisit the list when the release changes; a rule that existed because of a limitation can disappear.

Summary

  • Customer objects live in the Y or Z range or in a reserved namespace between slashes; the exact object prefixes are the team’s decision.

  • Clean ABAP is SAP’s public style guide. It prefers meaningful names without encoding prefixes, inline declarations, NEW, RETURNING, XSDBOOL, class-based exceptions and short methods, and it says the team decides.

  • Older books teach the lv_ and it_ prefixes; read them, but follow the current guide for new code.

  • A pragma such as ##NEEDED hides one named warning for one statement; pseudo comments are obsolete, and the program ABAP_SLIN_PRAGMAS maps the old to the new.

  • abaplint checks part of the guide on your own computer; the run on this page reported six findings in the untidy class and none in the tidy one. The SAP system’s ATC knows what abaplint cannot.

Try it

To do this by hand, follow the guide Check Code against Clean ABAP Rules: it checks a class against Clean ABAP rules with abaplint and fixes the findings.