ABAP Guidelines
ABAP Guidelines
Document Reference : NA
Version : 1.0
Document Status : Final
Author: KPMG
Document History
2
Small ABAP Guidelines
Table of Contents
1 DOCUMENTATION............................................................................................................................................................................4
1.1 MAIN DOCUMENTATION BLOCK............................................................................................................................................4
1.2 PROGRAM FUNCTION HEADER.............................................................................................................................................5
1.3 PROGRAM COMMENTS........................................................................................................................................................5
1.4 OBJECT LEVEL DOCUMENTATION.........................................................................................................................................6
2 NAMING CONVENTIONS FOR THE CUSTOM OBJECTS.........................................................................................................................6
2.1 APPLICATION PROGRAMS....................................................................................................................................................6
2.2 INCLUDE MODULES.............................................................................................................................................................6
2.3 VARIANTS...........................................................................................................................................................................7
2.4 NAMING CONVENTION GUIDELINES FOR THE LOCAL OBJECT(S) IN PROGRAM(S)......................................................................7
2.5 MODULE POOL...................................................................................................................................................................8
2.6 SCREEN NUMBER...............................................................................................................................................................8
2.7 MENUS...............................................................................................................................................................................8
2.8 FUNCTION KEYS.................................................................................................................................................................8
2.9 TITLE BARS.........................................................................................................................................................................9
2.10 PF STATUS........................................................................................................................................................................9
2.11 FUNCTION GROUPS.............................................................................................................................................................9
2.12 FUNCTION MODULE...........................................................................................................................................................10
2.13 SAP SCRIPT.....................................................................................................................................................................10
2.14 SMARTFORMS...................................................................................................................................................................10
2.15 SMARTSTYLE....................................................................................................................................................................11
2.16 MEMORY ID......................................................................................................................................................................11
2.17 STRUCTURE......................................................................................................................................................................11
2.18 TABLE TYPE......................................................................................................................................................................11
2.19 SEARCH HELP..................................................................................................................................................................11
2.20 TRANSPARENT TABLES......................................................................................................................................................12
2.21 DOMAIN............................................................................................................................................................................12
2.22 DATA ELEMENT.................................................................................................................................................................12
2.23 VIEWS..............................................................................................................................................................................12
2.24 LOCK OBJECTS.................................................................................................................................................................12
2.25 TRANSACTION CODES.......................................................................................................................................................13
2.26 AUTHORIZATION GROUPS..................................................................................................................................................13
2.27 BADI’S.............................................................................................................................................................................13
2.28 ENHANCEMENT.................................................................................................................................................................13
2.29 CUSTOMER EXIT...............................................................................................................................................................14
2.30 CLASSES..........................................................................................................................................................................14
2.31 STANDARD TEXTS.............................................................................................................................................................14
3 CODE FORMATTING FOR ABAP PROGRAMMING..............................................................................................................................14
3.1 ONE COMMAND ONE LINE.................................................................................................................................................14
3.2 PRETTY PRINTER..............................................................................................................................................................14
3.3 PROGRAM VARIABLES.......................................................................................................................................................15
3.4 SUBROUTINES...................................................................................................................................................................15
3.5 TEXT SYMBOLS.................................................................................................................................................................15
4 GUIDELINES FOR THE DESCRIPTION OF TRANSPORT REQUEST (TR)................................................................................................16
5 CODING GUIDELINES.....................................................................................................................................................................17
5.1 GENERAL.........................................................................................................................................................................17
5.2 DATABASE........................................................................................................................................................................17
5.3 MODULARIZATION..............................................................................................................................................................17
5.4 DATA PROCESSING...........................................................................................................................................................17
6 MISCELLANEOUS...........................................................................................................................................................................18
6.1 SYST STRUCTURE ACCESS..............................................................................................................................................18
7 APPENDIX.....................................................................................................................................................................................19
7.1 APPENDIX A – COUNTRY CODES.......................................................................................................................................19
7.2 APPENDIX B – MODULE NAMES.........................................................................................................................................19
7.3 APPENDIX C – OBJECT TYPES...........................................................................................................................................19
7.4 APPENDIX D – APPLICATION PROGRAM TYPE.....................................................................................................................20
3
Small ABAP Guidelines
1 Documentation
Documentation is required for all programs or function modules. A program needs to include four types of
documentation:
Main documentation block
Program Function header
Program Comments
Object level documentation
*---------------------------------------------------------------------*
*Mod02:
*---------------------------------------------------------------------*
*Mod03:
*---------------------------------------------------------------------*
4
Small ABAP Guidelines
*Mod04:
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Include for Data declaration
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Include for Selection Screen
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Include for ALV data declaration
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Include for Forms
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Initialization
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* AT selection-screen
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* START-OF-SELECTION
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* END-OF-SELECTION
*---------------------------------------------------------------------*
Note: Place the version number in each line of your correction by adding a comment with the version
number in each line of code. If you are incorporating a large number of new lines of code, then place your
code in following manner:
** Begin of changes <Mod#>
Insertion of code
** End of changes < Mod#>
Whenever you do new changes in old programs follow the new coding standards and no need to follow
the existing standards. Also, no section of the old code should be deleted while making changes in the old
programs. Instead, comment the old code and add the new code using the version number.
5
Small ABAP Guidelines
Ensure that the comments are simple, yet clear and concise making the reader aware of the utility of
the code written.
Ensure that the comments add value for the reader and they are not the copy of the code written.
Ensure that the comments are updated as and when the code gets updated/changed.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6-8 Any meaningful description determined by the developer
9-11 Incremental number starting with ‘001’ and incremented subsequently by 1.
Programs other than executable programs are 12 characters in length and should follow the below
naming convention.
Positio Description
n
1 Z – Must be a literal i.e. Z
2 Must identify the type of program. Please refer to Appendix D
3-4 Country Code. Please refer to Appendix A
5-6 SAP Module for which the program is developed. Please refer to Appendix B
7-9 Any meaningful description determined by the developer
10-12 Incremental number starting with ‘001’ and incremented subsequently by 1.
In addition, the following points should be noted about executable programs:
All executable programs and corresponding includes should be assigned with the relevant
authorization group.
The description for the main program, all includes and transaction code should be same and should
follow the below naming convention;
<Module Name><:><Description specifying the purpose of the program>
6
Small ABAP Guidelines
Positio Description
n
1-11 Main program name for reports
12 Underscore “_”
2.3 Variants
13-20 Freely definable classification, e.g. _SEL, _FORMS, _TOP etc.
The
Positio Description
n
1 Z – Must be a literal i.e. Z
2 Underscore “_”
2.4 3-14
Naming A unique 12 character
Convention Guidelines mnemonic name
for the representing
local object(s)usein
and purpose
program(s)
Any local variable / attribute in the program must follow a proper naming convention which must start
with the prefixes.
Prefix Variable Type
CL_ Classes
CNT_ Counters
P_ Parameter
R_ Range Table
7
Small ABAP Guidelines
S_ Select Option
The above prefixes must be followed by a descriptive meaningful word which will specify the purpose
of the variable/attribute.
Use of the technical names of the variables must be preferred over the business name/description.
E.g. lv_bukrs must be preferred over lv_co_code for the local variable meant for company code.
Use of vague names should be completely avoided. E.g temp1, lv_temp1.
Positio Description
n
1-3 SAP
4 x, must be replaced as given below
5 “Z”
6-16 Transaction Code
The fourth character “x” in the above naming conventions varies depending on the type of module pool
program being created and should be replaced with the appropriate values as given below:
M: Screen
L: Function Module
Include programs inside the module pool should follow the below naming conventions
Positio Description
n
1-16 Program name
17 Underscore “_”
18 Type of include, i.e. F for Forms, O for PBO and I for PAI
19-20 Numeric value starting from 00 to 99
2.6 Screen Number
Screen number is 4 characters in length. The number range for this numeric field is 9000 to 9999.
2.7 Menus
SAP menus are based on a combination of SAP Dynpro and ABAP CUA items. The menus should be of
four characters in length starting with “Z” followed by 3 descriptive characters. For example, ZCUS –
Customer Menu.
Positio Description
n
1 “Z”
2-3 Incremental number starting from 00 to 99
8
Small ABAP Guidelines
Developers are free to use the any function keys in the program. However, there are certain keys used by
SAP which are as follows:
Function Key Assignment
F1 Help
F2 Choose
F3 Back
F4 Possible entries
F9 Select
F13 Cancel
Shift+F1 Print
Shift+F2 Delete
Shift+F5 Open
2.10 PF Status
The PF status can be up to 20 characters in length. The name should always begin with literal “Z”.
Positio Description
n
1 Z – Must be a literal i.e. Z
2 Must identify the type of program. Please refer to Appendix D
3-4 Country Code. Please refer to Appendix A
5-6 SAP Module for which the program is developed. Please refer to Appendix B
7-9 Any meaningful description determined by the developer
9
10-12 Incremental number starting with ‘001’ and incremented subsequently by 1.
Small ABAP Guidelines
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6 Underscore “_”
7-30 Any meaningful description highlighting the purpose of the function module
The
parameters used in the interface of the function module must follow the below prescribed naming
convention.
Position Description Prefix
1-2 Import Parameter I_*
1-2 Export Parameter E_*
1-2 Changing C_*
Note: Tables parameters are obsolete, hence must not be used.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6 Underscore “_”
7-30 Any meaningful description highlighting the purpose of the function module
2.14 Smartforms
Smartform name can be up to 30 characters in length.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6 Underscore “_”
7-30 Any meaningful description highlighting the purpose of the function module
The
interface parameters of the Smartform should follow the same naming conventions as for Function
Modules.
2.15 Smartstyle
Smartstyle name can be up to 30 characters in length.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A 10
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6 Underscore “_”
7-30 Any meaningful description highlighting the purpose of the function module
Small ABAP Guidelines
2.16 Memory ID
The developer may use the SAP Global memory during any development. Given to understand the nature
and sensitivity of the SAP memory IDs, it is necessary for it to be unique across the system. The naming
convention for memory storage ID’s is given below.
Positio Description
n
1 “Z”
2 Underscore “_”
3-10 Calling Object
11 Underscore “_”
12-20 A unique and descriptive name representing use or purpose
2.17
Structure
Structure name should be 12 characters in length.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6-9 Any meaningful description determined by the developer
10-12 Incremental number starting with ‘001’ and incremented subsequently by 1.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6-9 Any meaningful description determined by the developer
10-12 Incremental number starting with ‘001’ and incremented subsequently by 1.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6-9 Any meaningful description determined by the developer
10-12 Incremental number starting with ‘001’ and incremented subsequently by 1.
11
Small ABAP Guidelines
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
2.21 6-9 Any meaningful description determined by the developer
10-12 Incremental number starting with ‘001’ and incremented subsequently by 1.
Domain
As far as possible, all Z fields should refer to standard available domains. In case a standard domain is
not available, domain name can be created using the following naming conventions.
Positio Description
n
2.22 1-2 Z – Must be a literal i.e. Z
3-20 Corresponding SAP standard domain
Data Element
As far as possible, all Z fields should refer to standard available data elements. In case a standard data
element is not available, data element name can be created using the following naming conventions.
Positio Description
n
2.23 1 Z – Must be a literal i.e. Z
2-20 Corresponding SAP standard data element
Views
View name should be 12 characters in length.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6-9 Any meaningful description determined by the developer
10-12 Incremental number starting with ‘001’ and incremented subsequently by 1.
Positio Description
n
1-2 “EZ”
3-4 Country Code. Please refer to Appendix A
5-6 SAP Module for which the program is developed. Please refer to Appendix B
7-10 Any meaningful description determined by the developer
11-13 Incremental number starting with ‘001’ and incremented subsequently by 1.
12
Small ABAP Guidelines
Positio Description
2.26
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6-9 Incremental number starting with ‘0001’ and incremented subsequently by 1.
Authorization Groups
All custom objects should be assigned with the relevant authorization group. The following authorization
groups have already been created in the system per module.
Module Module Code
ZGCO Controlling
ZGFI Financial
ZGMM Materials Management
ZGSD Sales and Distribution
2.27 BADI’s
Any custom BADI implementation name can be up to 20 characters in length.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6 Underscore “_”
7-20 A unique and descriptive name representing use or purpose
2.28 Enhancement
Any custom enhancement implementation name can be up to 30 characters in length.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
2.29 6 Underscore “_”
7-30 A unique and descriptive name representing use or purpose
Customer Exit
The length of the exit can be up to 8 characters in length.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6 Underscore “_”
7-20 A unique and descriptive name representing use or purpose
13
Small ABAP Guidelines
2.30 Classes
The length of the class can be up to 20 characters in length.
Positio Description
n
1 Z – Must be a literal i.e. Z
2-3 Country Code. Please refer to Appendix A
4-5 SAP Module for which the program is developed. Please refer to Appendix B
6 Underscore “_”
7-20 A unique and descriptive name representing use or purpose
2.31
Standard Texts
Standard texts should be 23 characters in length.
Positio Description
n
3 Code1 Formatting
Z – Must be for ABAP
a literal i.e. Z programming
2-3 Must identify the type of program. Please refer to Appendix D
4-5 Country Code. Please refer to Appendix A
6-7 SAP Module for which the program is developed. Please refer to Appendix B
8-11 Must identify the organizational element code such as plant, company code,
sales org etc.
12-20 A unique and descriptive name representing use or purpose, for example,
PLANTADDR, CCODEADDR, SAORGADDR
21-23 Incremental number starting with ‘001’ and incremented subsequently by 1.
ABAP code written in any object will be governed by the following rules.
14
Small ABAP Guidelines
3.4 Subroutines
Any code that is executed more than once in a normal flow of a program, must be placed in a
subroutine. Subroutines make the program readable and easier for maintenance.
The name of the subroutine must be descriptive enough for the reader to understand its purpose.
The variables used inside the subroutine must be locally defined.
Any subroutines that is being used by multiple programs, must be define as a function module.
The developer must document the functionality of the routine (refer Program Function Header
Documentation).
Any parameter which is expected to be changed in the subroutine must be defined as a changing
parameter while the ones which are only referred to inside the subroutine must be defined as using.
The naming convention that must be followed for the parameters of the subroutine is as below.
15
Small ABAP Guidelines
The developer must always adjust the text symbols.(Goto -> Text Elements -> Utilities -> Adjust ->
Text Symbols ).
The first character of the TR description must be “W” in case of workbench request and “C” for
Customizing request.
Next two character must specify the country for which the development/configuration is being done
(refer Appendix A).
The next character must be an underscore acting as a separator.
(WHERE APPLICABLE) The next seven characters must be the ticket number, in case of support
project.
(APPLICABLE INCASE THERE IS A TICKET NUMBER PRECEDED) The next character must be an
underscore acting as a separator.
The next two characters will specify the module for which the development / configuration has being
done (refer Appendix B).
16
Small ABAP Guidelines
5 Coding Guidelines
5.1 General
Any change to the existing code or creation of new object should be with reference to an approved FS
/ CR Only.
Any ABAP code must have the proper documentation blocks(refer to Documentation for details)
The data declarations must be adequately documented.
The data declarations must follow the naming conventions (refer Naming Convention Guidelines for
the local object(s) in program(s)).
Variables defined must be based on the dictionary object.
The scope of the variables must be decided properly. If any variable is needed just during the lifetime
of the subroutine, viability of declaring it as a local variable must be checked.
The reusable variables (or all, at times) must be cleared before they are being used in the context of
the program.
If the code is no longer needed, it must be eliminated (and not just commented).
Text symbols must be used in the program as directed (refer Text Symbols).
Authorization checks must be implemented in the code wherever necessary.
Transparent tables and programs must be assigned to an authorization group in all the cases.
5.2 Database
Enhancement category must be specified for any transparent table.
The client specific tables must have a client (MANDT) field in the key fields.
Any table with a maintenance view, must be provided with a transaction code.
SELECT and READ statements must be followed by a SUBRC check and action must be taken
accordingly in case of failures.
FOR ALL ENTRIES must be preceded by a NOT INITIAL check on the table referred to in the FOR
ALL ENTRIES clause.
Columns in the select query must be explicitly listed instead of a * and they must include the
maximum possible key fields of the table.
SELECT ENDSELECT must be avoided. FOR ALL ENTRIES must be used instead in conjunction
with READ statement.
Use of negative logic in the SELECT query must be avoided.
ORDER BY clause but be avoided in the select query. SORT statement must be used instead.
Standard tables must not be updated directly. BAPIs / Standard Screens must be used.
Array operation must be used instead of single record operation in INSERT/UPDATE/DELETE.
COMMIT and ROLLBACK must not be used in standard exit.
Any custom table being modified, must be locked before modification and released post modification.
5.3 Modularization
There must be no unnecessary duplication of the code. Appropriate modularization units must be
used.
Globally re-usable code must be defined in a well-documented FM/Class Method.
17
Small ABAP Guidelines
6 Miscellaneous
18
Small ABAP Guidelines
7 Appendix
7.1 Appendix A – Country Codes
Country Country Code
G Global
IN India
19
Small ABAP Guidelines
M Module Pools for Screen Contain processing steps for screen modules
Painter Screens
I Includes Contain program code that cannot be run on its own
S Subroutines Contain parts of programs (FORM routines) that can be called
using external PERFORM statements.
F Function Groups Contain function modules
J Interface Pools Contain interfaces
K Class Pools Contain interfaces
ST Standard Text SO10 texts
20