ABAP Coding Standards Reference Guide
ABAP Coding Standards Reference Guide
Reference Guide
August 2010
ABAP Coding Standards Reference Guide | 1
INTrODuCTION This document provides a quick reference to ABAP coding standards and expectations for
new SAP™ development. The standards represent a minimum requirement and are
intended to be an adjunct to other commonly accepted best practices in the industry. The
corporate coding rules, which are described in the document, can be monitored using the
HAWKEYE™ Monitor tool.
A key element of the coding standards and application governance methodology is the
application of an automatic code review process using HAWKEYE™. The Hawkeye system
continually scans code, generates real time reports, and delivers alerts to management. In
addition, developers can use the APOD tool. It helps ABAP programmers ensure their
code is consistent with corporate expectations, quickly and eficiently.
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 2
ACCESS CONDITION WITHOuT ALL This rule covers both, SELECTs from database tables and READs from internal tables.
KEYS Single rows in internal tables are accessed with a READ TABLE statement. All READs
access the internal table by numeric index or with an internal table key. For READs with
an incomplete or incorrect key there may be mulitple rows that satisfy the partial criteria.
In this case the READ statement returns the irst matching row. This may not match the
expected result.
Select Single should provide all ields of the Primary Key. The purpose of a select single
is to retrieve a single unique row based on the unique primary key ields(s). Without all
key ields speciied, there may be multiple rows that satisfy the partial key criteria resulting
in any one of the rows being returned. Therefore, the speciic record expected may not
be the one returned.
ACCESSING ABAP MEMOrY Programs should always reference ABAP Memory by a unique ID. Referencing Memory
WITHOuT ID generically can have impact on other applications using ABAP memory i.e. FREE
MEMORY without an ID would wipe out all ABAP memory which could affect other
programs that are counting on data in memory.
ALV LIST VIEWEr Use ABAP List Viewer instead of Classic Lists. WRITE statements and classic report
writing techniques are obsolete and should be replaced with ALV programming using the
SAP List Viewer Object model. Complete ABAP™ OO programming is supported using
SALV that delivers user lexibility for output format, feature rich programming, and end
user capabilities without the need for additional programming. The area of report writing
has gone through several progressions. As a programmer you will encounter all lavours
of report programming as listed below.
• This was then replaced with the Class based ALV using CL_GUI_ALV_GRID
• And now a complete delivery of the ALV object model called SALV.
AMBIGuOuS FIELD NAME Avoid using ield names that are the same as pre-deined SAP TYPES (N, I, F, D, etc) or
operators.
ArITHMETIC OPErATOrS INSTEAD Use operators (+, -, *, /, =) rather than the obsolete words ADD, SUBTRACT, MULTIPLY,
OF WOrDS DIVIDE, MOVE.
ASSIGNMENT HAS NO EFFECT Avoid assigning variables to themselves. There is no effect from this practice.
BrEAK-POINT STATEMENT All break-point statements must be removed prior to production. This could potentially
DETECTED stop production and provide back door access (I.e. debugger) into the code and
conidential data.
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 3
BuFFEr INVALIDATED Tables buffered in the SAP table buffer should be changed as seldom as possible. In
certain cases, local changes of a few records in a table can cause invalidation of the table
in the buffer in other application servers. This will result in entries no longer being current
in the buffer and will therefore have to be imported again from the database. Avoid any
of the following scenarios that will invalidate the buffer:
• UPDATE/DELETE with a WHERE on generically buffered table and generic key not
fully speciied.
• UPDATE/DELETE with a WHERE, and the generic key in the WHERE condition is not
fully speciied, all the generic areas of the buffer are invalidated.
Each change of a completely buffered table invalidates the table in the buffers of the
other application servers of the system. If the parameter "Only 'buffering switched on' " is
set in the check, accesses to tables that allow the option 'buffering' in their technical
properties, but have 'switched off' set, are not checked.
BuFFErED TABLE IN A JOIN Avoid the use of Buffered Tables in a Join. This will cause bypass of the buffer.
BuFFErED TABLE IN SELECT WITH Avoid the use of buffered tables in a sub query to avoid bypassing the buffer.
SuBQuErY
BYTE & CHArACTEr STrINGS Use the variable length statement STRING and XSTRING when declaring character and
byte data variables. It provides better use of memory than ixed length text statements
TYPE C and TYPE X.
CASE VErSuS IF Use the CASE statement rather than IF/ELSEIF/ENDIF construct when there are multiple
= conditions. If there is only one condition, then the IF/ELSE/ENDIF statement is a good
choice.
CASE WHEN FIrST STATEMENT WHEN must be the irst statement after a CASE statement.
CASE WITHOuT WHEN OTHErS Case Statement requires a “When Others” clause. Any condition that is not met will have
a fallout path. In the “When Others”, always provide an action or a generic message so
that the program can announce that an unexpected situation has been encountered.
CATCH - PrOCESSING MISSING Processing section inside the CATCH … ENDCATCH block is empty. Exceptions must
be explicitly handled within the CATCH … ENDCATCH block. Add the required exception
processing between CATCH and ENDCATCH
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 4
CLIENT SPECIFIED LIMITED TO In Multi-Client production systems, regular ABAP application programs should never
SYSTEM TOOLS select data across clients with the CLIENT SPECIFIED option since there’s a risk with
mixing data across clients / companies. Standard SAP always stays within a client for
regular application data and therefore custom code should follow the same rule. The use
of CLIENT SPECIFIED should be limited to system tools.
CLIENT SPECIFIED TABLE FIrST This is a Data Dictionary Requirement that Client Speciied Tables MUST have the irst
FIELD ield of the table deined as CLIENT (MANDT).
CODING BLOCK EMPTY Do not create empty coding blocks inside blocks such as IF...ENDIF, WHILE...ENDWHILE,
SELECT MAX, etc. Empty coding blocks add no value and are considered maintenance
overhead.
COMMON PArT STruCTurE Identically Named Common Parts must have the same structure deinition.
DEFINITION INCONSISTENT
COMPONENT NOT ASSIGNED TO Function Module must be assigned as a component of a CMOD enhancement.
AN ENHANCEMENT
CurrENCY CLAuSE When outputting numbers that are tied to currency, always use the CURRENCY formatting
option. This will set the number of decimals according to the currency of the country.
CuSTOMEr DEFINED MACrOS Operational issues in Macros that cause Program Dumps are dificult to trace. Wrap the
NOT rECOMMENDED reusable code in a method instead.
DANGErOuS HIDE ON A FIELD Avoid using ield symbol with a HIDE statement. If ield symbol is not assigned,
SYMBOL unpredictable results can occur
DATA VArIABLES - uSE OF Do not use implied defaults on data declarations. Be explicit when TYPING your data
DEFAuLTS variable. Always Specify the TYPE and Length
DATA VArIABLES - uSE OF TYPE Use keyword TYPE when declaring data objects rather than LIKE (which is an old
VS LIKE convention). LIKE should only be used when a data declaration refers to an existing data
object deined in your program. LIKE is also commonly used for declaring the line type of
an internal table i.e. LIKE LINE OF.
Note: In OO porgramming, any reference to a dictionary type MUST use the keyword
TYPE. LIKE will fail syntax check.
DATABASE ACCESS INSIDE A LOOP Avoid database accesses inside a loop to minimize performance issues.
DATABASE uPDATE WITHOuT Updates to the database should be encapsulated in V1 or V2 Update function modules.
uPDATE MODuLE This provides full recovery and logging of activity when performing INSERT, UPDATE,
MODIFY and DELETE of Database tables.
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 5
DATABASE uPDATES INSIDE A Replace Updates inside a loop with a single set level process update to the Database
LOOP outside of the loop. This will reduce the trips to the Database and improve performance.
DATE FOrMAT uNSuPPOrTED Do not reference unsupported date formats. The only valid supported date formats are
found in USR01-DATFM
DIrECT uPDATE TO SAP TABLE Under no circumstances should any program directly update SAP delivered tables.
Updating of SAP tables should be performed using pre-delivered API's that perform the
update
DuPLICATE DEFINITION Avoid Duplicate Deinitions for all objects and declarations. It is redundant, causes
Maintenance issues, and possible extraneous processing with unpredictable results.
DuPLICATE WHEN CONDITIONS Never duplicate a WHEN condition. Unexpected program behavior could result with
duplicated WHEN conditions.
DYNAMIC CALLS TO PrOGrAMS Dynamic Calls to programs can lead to production failures if program or object does not
exist. Without proper exception handling, this is a dangerous practice.
DYNAMIC TABLE ACCESS Always Include Exception Handling when accessing Tables Dynamically. Dynamic Calls
can lead to production failures if the call can not be resolved or object does not exist.
Dynamic Table access can be a very a dangerous programming practice if proper
exception handling is not in place.
ESSENTIAL PrINT PArAMETErS Essential Print Parameters are missing. Unexpected results can occur without the
essential print parameters. Essential required print parameters are:
Spool control: Deletion of the spool job after print output (RELEASE)
New spool request, this means do not append to an existing request (NEW_LIST_ID)
Format speciications:
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 6
EXCEPTION HANDLING - uSE Use Class Based Exception Handling Techniques. CATCH … ENDCATCH is obsolete.
CLASS BASED
Errors should be anticipated and handled in all program code. The nature of errors varies
and could be caused by incorrect implementations internal to the program or external
interactions such as input errors or unexpected resource limitations (E.g. iles,
memory).
All runtime errors (E.g. zero divide, conversion errors, …) raise class-based exceptions
and should be captured and handled in program code with the CATCH statement in a
TRY/ENDTRY control block.
EXCEPTION HANDLING GENErIC Generic Messaging after a function call is not recommended. Anytime the PATTERN
MESSAGE AFTEr FuNCTION CALL function in the workbench is used to insert a function, it automatically inserts a generic
message of the form:
This statement assumes that SY variables have been illed with meaningful values by the
function itself. However, often times, this is not the case and the message will be
meaningless.
The generic message should only be used in the case where the function and all nested
functions that are called use the Message...Raising format consistently throughout the
function chain. The Message...Raising format sets the sy-message and other sy variables.
Only then, can you be assured that a generic message statement can be used to present
a proper error message. However, since this situation is most likely not the case, a good
developer will handle the message themselves and not count on the generic format to
provide a meaningful message relevant to the situation.
EXCEPTION HANDLING MISSING ABAP Statements that can potentially cause program dumps require that the correct
Or WrONG EXCEPTION exception for the statement as per the SAP Help must be caught and handled to avoid
dump situations. Ensure that a Try/Endtry is in place to catch the exception.
This check ensures that the CORRECT EXCEPTIONS are handled for the following
statements: REPLACE, COLLECT, SORT, FIND, ASSIGN, CREATE, Dynamic SELECT,
and Dynamic METHOD
EXCEPTION NOT CAuGHT Or The exception is neither caught nor declared in the RAISING clause of the procedure.
DECLArED
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 7
EXCEPTION NOT PrOCESSED There may be cases where SAP delivered functions do not have deined exceptions. It is
still recommended to provide exception handling when Calling the function. This enables
that the code still works without a run-time error in the event that SAP adds an exception
to the Function Module interface. For example the application of an OSS Note is able to
introduce a new execption for the function module. Setting all exceptions to 0 in the CALL
FUNCTION statement is not a good practice because it basically ignores the
exceptions.
The programmer should always check the exception returned from a function. DO NOT
not count on an importing parameter being returned to the calling program as a sign of
successful execution. An assumption holds true that a ield is not set if an exception is
returned, but that could change during a future enhancement of the function.
Exception: Excluded from this rule are system functions that don't return any exceptions,
i.e. function module DEQUEUE. For these system functions that do not have deined
exceptions, it does not make sense to check for SY-SUBRC after the function call.
Recommendation:
==> If a function module has exceptions deined, you have to handle them. An empty IF
statement is not enough
==> If a function module has no exception deined, and the programmer is not
using EXCEPTION OTHERS = 1 you can't check sy-subrc after the function module call
since the sy-subrc will not be set by the function call
EXTErNAL CALLS External calls to subroutines are forbidden. In the case of short dumps, the ability to
debug external calls is restricted and Production support therefore becomes more
dificult.
EXTrACT FILES Extract Files are considered Obsolete. There is no need to use this old style array
processing technique
EXTRACT iles are a convenient way of dealing with internal tables of different structures
that have same or similar keys. The same can be achieved with internal tables. Only one
EXTRACT ile can be used per program.
FIELD IS uNKNOWN Only ields that are deined or in a speciied table can be referenced. Any reference to
ields that do not exist will cause syntax issues.
FIELD NOT A PArAMETEr Or The parameter / select-option in the SUBMIT statement does not exist on the selection
SELECT OPTION srceen of the called program. Verify that the parameters and select options match
between the SUBMIT statement and the called program selection screen
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 8
FIELD SYMBOL NOT ASSIGNED A ield symbol was deined but not assigned. If the ield symbol is not used, then it should
be removed.
FILE OPErATIONS - LOGICAL FILE Use the logical ile concept instead of hard coded physical ile names. The function FILE_
NAMES GET_NAME must be used to translate the logical ile name to the physical path and ile
name.
Logical ilenames are mapped to physical ilenames using transaction FILE. Dynamic
parameters are available to i.e. client, instance, etc. to ensure ile names meet ile naming
conventions and the programs that use the iles work across all system boundaries.
FuNCTION GrOuP INCONSISTENT All components of a Function Group must pass internal consistency check. If the
consistency check error occurs, it is possible that some internal objects have been
corrupted. This can result in the function module not being stored in the database table
TFDIR or possibly stored under a different name.
FuNCTION MODuLE OBSOLETE Using Obsolete Function Modules should be avoided. It will cause upgrade issues as
they are not forward compatible or supported by SAP™.
FuNCTIONS WITHOuT When Calling a function, always include the exceptions clause. There is no value in
EXCEPTIONS checking sy-subrc if the exceptions clause is not part of the CALL Function statement.
Don't add an empty IF SY-SUBRC = 0 ... ENDIF block or a CHECK SY-SUBRC = 0 after
a function call without exceptions. A function should be deined with exceptions unless it
is a special purpose function such as update task, asynchronous, RFC, etc.
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 9
HArD CODING When the same text literal is used repeatedly in an arithmetic or logical expression,
deine the value as a Constant instead of a text literal and name the constant descriptively.
This check determines if their is hard coding contained in the following statements:
SELECT, DELETE, SORT, LOOP, WHEN, IF, READ.
Corporate processes change. So do the business values used in daily operations. For
example, it is very common to experience changes to business conig items such as
document types, org level deinitions, cost centers, company codes, plants, etc. Therefore
it is highly recommended to avoid ‘Hard Coding’ of any business values required in your
program.
Where possible, use existing SAP tables to provide business values to the program and
use a SELECT statement to retrieve those values into an internal table. If an SAP table
is not available with the required values, then it is advised to build a custom Z* table to
contain the required business values. There are signiicant beneits to this approach
when it comes to maintenance. When a business value changes, then maintenance is
performed on the custom table (once) rather than all instances of programs that use the
business values. Customer deined business type tables should try to use data elements
that are already used in like ields in other SAP tables.
If the above approach is not followed and it is decided to hard code business values in
the program then at minimum, the hard coded value should be deined as a constant and
named descriptively.
HYPHEN DETECTED Avoid the use of the hyphen in a declared variable name. It is normally used as a
dereferencing operator.
IGNOrED EXCEPTIONS CLAuSE The EXCEPTIONS clause is ignored for asynchronous update function modules. Clean
up the function by removing the superluous Exceptions.
ILLEGAL NuMBEr CONVErSION Non numeric ields should not be converted into numbers. This could result in a run time
error with a program dump.
INCOMPATIBLE uSING/CHANGING The actual parameter category must match the formal parameter category. This means
that if a parameter is passed as a USING, it shoud be received as a USING.
INCOMPLETE ACCESS TO Avoid Indirect Index Access to an Internal Table. All INSERT statements need to be either
INTErNAL TABLE placed within a LOOP or use a speciic row INDEX. Duplicate records for an unique
internal table index will cause a program dump. For all internal table operations make
sure the system is clearly able to identify the internal table row where the change, delete
or insert needs to occur.
INCOMPLETE Or MISSING WHErE Use a WHERE condition with appropriate indexes where possible.
CONDITION
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 10
INCOrrECT MESSAGE WITH ields must match placeholders deined for the MESSAGE statement.
PArAMETErS
INCOrrECT uSE OF FOr ALL When using the addition FOR ALL ENTRIES in ITAB, the driver table ITAB and table
ENTrIES ields must have the same type and length.
INEFFICIENT COPY (LArGE DATA Avoid poor performing assignment of large amounts of data. This is especially critical in
OBJECT) the case of deep structures or large data elements.
INTErNAL TABLES - DELETE DELETE ADJACENT DUPLICATES should always be explicit by using the COMPARING
ADJACENT COMPArING clause, even if there is only one ield in the ITAB.
INTErNAL TABLES - LOOP AND Use LOOP AT ITAB and assign to a ield symbol. This technique improves performance
ASSIGN on medium and large ITABs.
INTErNAL TABLES - MODIFY IN When using LOOP AT … ASSIGNING, MODIFY and UPDATE statements are redundant.
LOOP ASSIGN The Assigning is a pointer. Any changes to the row become explicit on the row being
processed so there is no need to issue the update or Modify commands.
INTErNAL TABLES - NESTED Nested Loops can cause ineficient processing when programmed incorrectly. Use
LOOPS parallel cursor technique for nested loops with standard tables. It is the most eficient
means of processing Nested Loops. The performance gains are signiicant.
INTErNAL TABLES - SINGLE rEAD DO NOT LOOP an itab to retrieve a speciic record when a single READ will do the job.
INTErNAL TABLES Use the TRANSPORTING clause with READ and MODIFY wherever possible to transport
- TrANSPOrTING only the ields necessary.
INTErNAL TABLES SOrT BY FOR BREAK LEVEL processing with the AT command inside a LOOP at ITAB, sort by the
BrEAK LEVEL FIELDS break level ields before entering the LOOP.
INTErNAL TABLES SOrTING When sorting internal tables, always be explicit by using "SORT BY key1 … keyn", never
just "SORT" on its own.
INTErNAL TABLES WITH HEADEr Avoid any syntax that results in obsolete tables with headers such as OCCURS 0 or With
Header Line or Perform Tables.
INTErNAL TABLES WITH HEADEr Do not use TABLES statement when passing internal tables to FORMS. This will result
IN FOrM in an internal table with Header being created local to the form. ITABS with header are
obsolete.
INTErruPT COMMANDS RETURN Statement should be used to exit a procedure (FORM, FMOD, METHOD).
EXIT should not be used.
If a conditional statement (i.e LOOP, IF, etc. ) is in the procedure, the programmer can
code either EXIT or RETURN depending on the desired exit scenario i.e. is the intent to
leave the conditional block or to exit the procedure
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 11
INVALID PrOGrAM TYPE FOr Include program type attribute must be correctly set to indicate it is an Include
INCLuDE
INVALID SLIN PSEuDOCOMMENT Use valid PSEUDOCOMMENTS as deined by SAP when marking code for inspection
bypass.
IS ASSIGNED IS ASSIGNED check should be issued prior to a ield symbol assignment in the Read
TABLE statement. If the ield symbol is referenced and has not yet been assigned, a
short dump will occur.
ITAB MODIFY INDEX IN LOOP Avoid LOOP at ITAB and then modifying by index in the loop. This can lead to unpredictable
results and performance costs.
Avoid inserting new lines while looping over an internal table. Instead, add new lines
inside the LOOP using the APPEND statement to add the new line at the end of the
internal table.
ITAB OVErWrITE IN LOOP During LOOP Processing of an internal table, do not delete or overwrite the table that is
being Looped.
KEY NOT SPECIFIED IN A Use keys in tables to avoid bypassing the buffered table. In the case of Generically
BuFFErED TABLE Buffered Key Area, specify all keys that are part of the generic buffered area as deined
in the technical setting of the table.
LIST PrOCESSING EVENTS List Processing Event Blocks are obsolete. All report programming should be performed
using the ALV object model. Therefore, any list processing events that are traditionally
used for controlling lists in classic programming are considered obsolete. This would
include Top-of-Page, End-of-Page, New-Page, at pf . Selection screen events are still
used to support selection screens.
LOGICAL OPErATOrS INSTEAD OF Use operators ( >=, <=, =, <>, >, <) rather than the obsolete words GE, LE, EQ, NE, GT,
WOrDS LT
LOOP IN SELECT/ENDSELECT Avoid LOOP/ENDLOOP blocks within SELECT...ENDSELECT statements. They are
very performance expensive.
MAINTAIN TEXT ELEMENTS TEXT Element is not deined in text pool in the original language.
MESSAGE TruNCATED Message parameter should not exceed ield length speciication. SAP only provides a
maximum length of 50 characters for any message parameter (SYST-MSGV1-MSGV4).
Please make sure that all ields and texts that are passed into a message variable are no
longer than 50 characters
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 12
METHODS FOr MODuLArIZATION For Modularization and re-usability, always use methods as your irst choice over FORMS
(subroutines) and function Modules. In OO context, FORM...ENDFORM is considered
obsolete.
MISSING CrITICAL PrOGrAM Critical Program Elements are missing and therefore the program can not compile. (This
ELEMENT includes sub objects such as screens, tables, Includes, forms, parameters, etc.). All
referenced components must exist.
MISSING MANDATOrY PArAMETEr All mandatory parameters must be speciied when calling a function.
IN FuNCTION CALL
NATIVE SQL Avoid using native SQL to ensure database independence and avoid incompatibilities
between different database tables.
NESTED LOOP Nested loops can cause performance issues. This applies to any form of Nested Loop i.e.
WHILE or DO inside of a Loop or a LOOP inside of WHILE or DO. In the case of a Loop
within a Loop, explore the possibility of using a Parallel cursor technique where checks
are in place to ensure that the inner loop record exists using READ and uses EXIT to exit
inner loop when keys are different. With large tables, the performance gains are
signiicant.
NO rEAD ACCESS TO FIELD Validate that the FIELDS are used in the program. It is posible that it is referenced
indirectly such as parameter passing to a procdure. If the ield is not used anywhere,
remove unreferenced ields from the program.
NO WHErE CONDITION IN A LArGE Where statements should always include index ields for performance reasons, especially
TABLE for LARGE tables.
OBJECT uNrEFErENCED Or Remove all program elements that are unused or unreferenced.
uNuSED
OFFSETS AND SuBSCrIPTING Avoid code that uses speciic offsets for the purpose of subscripting into parts of a
structure. Offset coding is problematic when coding in a UNICODE environment since
characters are not represented by a single byte and can therefore lead to incorrect data
sub stringing. Offset coding is also very problematic when dealing with dates where
users are able to change their date format.
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 13
ON CHANGE OF IN LOOPS Avoid using ON CHANGE OF statement for Break level processing. Unpredictable results
can occur with ON CHANGE OF because it is speciic to a single ield whereas the AT...
ENDAT triggers a break when any change occurs in the ield speciied or ields left of the
speciied ield.
OPEN DATASET with ENCODING The ENCODING option determines the character representation of the content of the ile.
At minimum, you must specify the encoding option DEFAULT or UTF-8.
When Opening a Dataset for Output in Text Mode, the ile should be Opened with the
Encoding Option UTF-8 and With Byte Order Mark(BOM). This will create a proper
Unicode non platform dependant ile with a BOM, consisting of 3 bytes at the beginning
of the ile that identifes the ile as UTF-8
When opening a Unicode File (UTF-8) for Input, specify the addition SKIPPING BYTE-
ORDER MARK so that the BOM is skipped and NOT considered part of the ile content.
The ile pointer will be set immediately after the 3 byte BOM
OPEN DATASET with MESSAGE Authorization and permission access at the OS level is one of the most frequent causes
of an OPEN statement failing. Always Use the Message clause on the OPEN statement
to trap operating system errors. This approach traps the Operating System error and
therefore goes beyond the standard subrc checking. Subrc only tells if the operation was
successful but does not give the speicic reason why the operation failed. The Message
Clause reports speciic application server errors such as permissions, ile existence,
etc.
OVEr rIDE VIOLATIONS Used to bypass detected rule violations due to technical reasons
PArAMETEr PASSING BY As a general rule, PASS BY REFERENCE should be used where possible for performance
rEFErENCE reasons. This test examines whether it is possible to improve the performance of a
parameter transfer for a method, form, function module, or event. However, there are
programmatic reasons for using by VALUE. i.e. in the case of a RETURNING parameters,
it is always by VALUE. Speciically, the test checks for the following situations:
• The type of the VALUE parameter contains tables whose row type in turn contains
internal tables.
• The type of the VALUE parameter contains tables with different row types.
• The parameter type is a lat ield with a length > 100 bytes/characters.
• The type of the VALUE input parameter is a lat ield with a length <= the parameter
PArAMETEr PASSING IN FOrMS Deine USING parameters by VALUE. Deine CHANGING and Internal Tables by
REFERENCE.
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 14
PArAMETEr uNTYPED All parameters must be typed to enable static type checks. If a type cannot be declared,
use the type ANY.
PArAMETErS - uSING DOES NOT USING parameters must match CHANGING parameters.
MATCH CHANGING
POSSIBLE LOSS OF DB CurSOr The database cursor may be lost as a result of certain call sequences that contain
COMMIT. For example, a Commit work or PERFORM inside a SELECT…ENDSELECT
is problematic.
POSSIBLE SEQuENTIAL ACCESS Avoid sequential access on internal tables. On large tables, this can be costly. A sequential
ON AN INTErNAL TABLE access will happen if internal tables have incomplete keys or in the case of standard
tables, Binary Search clause is missing. For internal tables avoid using the obsolete
version of READ TABLE ... WITH KEY. Instead specify an appropriate UNIQUE or NON-
UNIQUE INDEX as part of the internal type deinition and use READ TABLE ... WITH
TABLE KEY. Note: The addition BINARY SEARCH is still required to avoid sequential
reads when using STANDARD tables.
This rule also applies to change or delete access in internal tables, e.g. deleting data in
an internal table with a WHERE condition results in a full scan of the internal standard
table. A better solution is to deine the table as a SORTED table with a nonunique (or
unique) key. In the DELETE statement use the WHERE condition in combination with
WITH TABLE KEY and the key ields. Now the access will be able to leverage the sort
sequence.
PrIMArY KEY FIELDS NOT FuLLY Always specify the ields of a primary key in a single record buffered table.
SPECIFIED
PrOBLEM WITH INDEX ACCESS TO When using Non-Numeric Index Value to delete rows from an internal table, use the
INTErNAL TABLE format 'DELETE ITAB FROM work areas'
rAISE FOr EXCEPTION MISSING An EXCEPTION that is part of the exception group never gets raised. This exception
should be removed from the exception group if it is never used.
rAISE ONLY IN FuNCTION GrOuPS RAISE statements should only be used in FUNCTION groups.
SECONDArY INDEX IN A CLIENT Secondary indexes for CLIENT SPECIFIC tables should have client as the irst ield of
SPECIFIC TABLE WITHOuT CLIENT the secondary index.
FIELD
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 15
SELECT FOr ALL ENTrIES When using "Select... For all Entries" the following rules MUST be followed:
• The WHERE clause must include INDEX ields to make use of index scan.
• If index ields are not available as part of the WHERE clause, then it is better not to use
FOR ALL ENTRIES. The better option would be a SELECT…WHERE into an ITAB.
Any further iltering can be done using ABAP Memory
SELECT INTO COrrESPONDING Avoid the use of SELECT ... INTO CORRESPONDING especially for tables with a large
number of ields. The CORRESPONDING clause results in DB overhead. The
corresponding target ields are not know until runtime and therefore need to be rebuilt at
execution. The has a negative effect on performance.
Instead, Specify the individual ields required and deine the work area to correspond to
the ields being selected.
SELECT SINGLE EXPECTED FOr Use SELECT SINGLE with full key when accessing Single Record Buffered Table or
SINGLE rECOrD BuFFErED buffer will be bypassed.
TABLE
SELECT WITH A SuBSEQuENT Avoid the use of CHECK statements after a SELECT. Instead use a WHERE statement
CHECK to ilter the data.
SELECT WITH AGGrEGATE Use aggregate functions with caution in a buffered table. Aggregate functions will cause
FuNCTION ON BuFFErED TABLE the buffer to be bypassed which leads to increased processing to retrieve data from DB
instead of buffer.
SELECTION SCrEEN FIELDS The purpose of a selection screen is to provide the user with lexible options to enter
values that will inluence the outcome of the program execution. Create variants, where
possible, and have the user community use the variant to set screen default values.
Exceptions to this rule are non-business technical related parameters i.e. Logical File
Names, etc.
SELECTION TEXT NOT MAINTAINED Be sure to maintain the Selection text for all selection ields and parameters. In multilingual
systems the DDIC reference lag should be set wherever possible to leverage existing
SAP translations from Data Dictionary ==> Reduces translation efforts
SELECTION TEXT WITHOuT Selection Texts that are deined but not used or referenced on a selection screen should
SELECTION FIELD be removed from the text element list.
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 16
SINGLE PErIOD LINE Eliminate lines of code that contain a single period.
• Be sure that table is sorted by same key that is used in the READ WITH KEY statement
(or data will be missed)
STATEMENT uNrEACHABLE Unreachable statements have been detected. i.e. after Jump statement such as RAISE:
EXIT. Ensure that all statements can be reached.
STruCTurES OBSOLETE Use type statement to build local structures. Structure statement is obsolete.
SYSTEM CALL Never make calls directly to System Functions for production programs. System Calls
and functions are reserved exclusively for SAP™ use.
SYSTEM FIELDS FLAGGED Never Use obsolete system ields. Check Dictionary structure SYST. The data element
OBSOLETE description indicates which ields are lagged as obsolete.
SYSTEM FIELDS PASSING & Never update system ields or pass system ields to Procedures (FORMS, METHODS,
uPDATING Function Calls). There are some syst ields that are exempt: SY-LSIND,
SY-SuBrC NOT HANDLED Always Check Return Code SY-SUBRC after critical operations – SQL, ITAB Operations,
Function Calls, etc.
TEXT ELEMENT IN POOL NOT uSED TEXT ELEMENT from text pool in program is not used.
TEXT ELEMENT INCONSISTENT Text Element is deined differently in the program and the text pool
TEXT ELEMENT MISSING Char. strings without text elements cannot be translated in a multi-lingual environment.
TEXT LITErAL SHOuLD BE It is more eficient to use numeric literals directly. Text literal must be converted to a
NuMErIC numeric literal.
TrANSPOrTING NO FIELDS It does not make sense to use TRANSPORTING NO FIELDS if the ields need to be
referenced
uNCOMPILABLE CODE Use the Code Inspector to eliminate all SYNTAX errors, including syntax warnings.
uNDEFINED INTO FIELD Into LISTS must be of the form (f1...fn) with all ields deined.
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 17
uNDESIrABLE LANGuAGE A number of ABAP statements are no longer compatible with the latest SAP technologies.
ELEMENTS These statements still work in a SAP GUI transaction environment but have been replaced
by newer much more eficient and lexible solutions. Programming syntax that is
considered problematic are as follows:
• ABAP list processing statements like WRITE, FORMAT, SKIP, NEW-LINE etc. in
programs should instead using ABAP List Viewer classes for list display functions.
• The use of CALL TRANSACTION USING to submit a BDC. This technology relies on
screen layouts. If a screen layout changes, the code stops working. This makes the
code highly unreliable during the application of Support Packs, Enhancement Packs
and Upgrades. Therefore programs need to use BAPIs to submit business functions.
• Programs need to avoid using position operations in sequential iles. If necessary iles
should be processed sequentially instead of controlling the read position (SET
DATASET, GET DATASET, TRUNCATE DATASET).
• Database SELECTs need to avoid retrieving a single line for Update. This operation
includes an implicit database lock quickly leading to bottenecks and deadlocks. Instead
use ENQUEUE functions to lock an object in SAP, read it and subsequently update it.
• Avoid using SELECT .. BYPASSING BUFFER.. since this access avoids using the
database cache causing performance issues and inconsistencies.
• Avoid using native SQL to ensure database independence and avoid incompatibilities
between different database tables.
uNICODE FLAG NOT SET All programs in a Unicode system must have the UNICODE lag set ON. If the lag is not
set in a Unicode system the program dumps with a syntax error. The Unicode lag can
only be set once the program passes the Unicode syntax check (transaction UCCHECK).
In a non-Unicode system the lag does not have to be set, but as of ERP 6.0 SAP only
supports single code page non-Unicode ERP system. Any multi code page system has
to be Unicode. Therefore it's generally better to always turn this lag on
uNIT CLAuSE When outputting numbers that are tied to units of measure, always use the UNIT
formatting option. This will set the number of decimals according to the unit of measure
being output.
uPDATING and PASSING GLOBAL Avoid the declaration of global variables as much as possible. Avoid passsing Globals to
FIELDS Subroutines and Methods.
Avoid setting global variables in too many places. A preferred approach to setting globals
is to use dedicated recognized methods that follows best practice naming convention
such as SET_*
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved
ABAP Coding Standards Reference Guide | 18
uSEr SPECIFIC CONTrOL Avoid using references to speciic USERS or USERIDs for any reason.
VALuE ASSIGNMENT EXCEEDS VALUE speciications must not exceed the length of the deined ield or type.
LENGTH
VArIABLE NAME INCOrrECT Variable names should not begin with %_*. Preix %_* is reserved for internal names.
www.codeExcellence.com
Tel: (403) 875-0809
[email protected]
[email protected]
Headquarters in Calgary, Alberta, Canada
CONFIDENTIAL
ABAP Coding Standards - Reference Guide. Vers. 2.0
Copyright © 2010. CodeExcellence Inc. All Rights Reserved