ABAP Programming Standards and Guidelines
ABAP Programming Standards and Guidelines
Project SAP@RRAB
Document ID ACC-ABAP Programming Standards and Guidelines-20100119 V1.0
Version History
Ver. Ver. Date Changed Change Description Filename
No. By
1.0 19-Jan-10 Initial Draft ACC-ABAP Programming Standards
and Guidelines-20100119 V1.0
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January 2010 2/1/2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0
UPDATED : 1 February 2010
20100119
Table of Contents
2
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
All ABAP/4 dictionary objects created must follow the standards set forth in Appendix 3 -
Naming Standards.
Codes re-use: Before creating a new SAP object, check to ensure that there is not an
existing object that can perform the same task. If one exists, use that one instead of
creating a new one.
Anytime you create a function module that performs a common operation, contact the rest
of the team so that they can use the function module that you‟ve written if necessary.
Attributes for each new ABAP must be set in accordance with the values given in the
Program Attributes section of this document.
Never hard-code values in your programs. If literal values for logical expressions are
required, then declare parameters or working storage constants in the data declaration
section of your program. In this manner, the literal can be easily maintained going forward.
Code one ABAP statement per line. This allows for easier deleting, commenting, and
debugging.
Separate different logical parts of source code with blank lines when applicable. This helps
others view the overall program flow.
Use comments to explain the purpose and/or characteristics of the program subdivisions
and major components. The comments must be meaningful for each construct in isolation
and explain the function of the construct within the entire program. If we don‟t do this, the
code won‟t be maintainable. For further information, refer to the Coding Comments section
of this document.
Use local variables within a form but they must use the naming standards described in the
Internal Data Names section of this document.
Each program should contain a documentation header box at the start of each program.
This should include: Program name, description, author, date of creation, tables, files,
logical data bases and description of each change including the author and date changed.
When creating a program you can copy an existing ABAP template into your own code.
Select the option Insert Statement in the Edit menu option or press CTRL + E. Then, click
on Other Patterns and choose Z_PROGRAM_HEADER. Please refer to Appendix 1 for
details on the Header template.
Programs should indent via pretty printer command and be modularized to ensure clarity.
After every database call, file opening, reading and closing the system variable SY-SUBRC
must be checked.
3
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
Interface programs should be designed so that runtime failures will allow a restart/recovery
that does not result in data loss or corruption. It is desirable to archive the input file for
some time period to allow re-run if necessary. Production interfaces should limit the size of
the BDC batches to prevent deteriorating response time for on-line users.
Audit trail logs should be created to provide information on errors and functional activities.
Define all types together, e.g., all data variables declarations should be grouped together,
all parameters together, etc.
Year 2000 compliance – All programs must be able to accommodate the millennium
rollover. There should be no hard coded date manipulation in any program that is moved to
the production environment. When creating date variable in the program always reference
to the date system variable (SY-DATUM) or to a DDIC date table field.
Whenever possible use logical file names when reading or writing to a non-SAP file. When
developing interfaces, it is advisable to create new logical file names that conform to the
COMPANY standard.
Be aware that the “WS_” function modules (e.g. WS_UPLOAD) cannot run in background.
For control purposes, the AUTHORITY-CHECK statement must be used to check user‟s
authorization on the object.
When processing long sessions notifying the Basis team to arrange suitable time.
Title The title should be a short, concise description of the ABAP. This is the title
that appears in the header of a report when you execute it (unless you
override this feature via Text Elements or the NO STANDARD-PAGE
HEADING command).
Type
„1‟ for online programs running online or in batch
„I‟ for include programs
4
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
Status
„T‟ for test programs
„K‟ for self-developed production programs
„P‟ for SAP standard production programs (not used for new development)
„S‟ for System programs (not used for new development)
Application
SAP Application. Look up at the options via key „PF4‟. This field has to be
consistent to SAP Module used to build up the program name (please refer
to the Appendix 3 - Naming Standards).
Logical Database
Assign the logical database, if necessary. Press PF18 to help choose the
appropriate database.
From Application
To be used in conjunction with the logical database field. The tables
retrieved to access the particular logical database depend on this entry.
Selection Screen If there are more than one selection screen to choose from, you can specify
one here.
Authorization Group Used to restrict access to users without a matching authorization group in
their profile.
5
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
Note: Before creating programs and assigning them to requests, read the Appendix 6 CTS
Procedures on the BSIP Change Request Management and Transport Procedure (Documentum
Basis & Infrastructure Guides System Policy Guide (SPG) Change Request Management
and Transport Procedure).
Program Title: The program title. This field should correspond with the program description
field on the Program Attributes screen.
Development
Request #: The development request number assigned by the Status Tracking Tool (STT)
system. This is the link between the ABAP program and the development
request.
Includes:
Key in any include that will be used in the program.
Calls:
Here, type any function modules or subroutines (internal or external) that you‟ll
be using in your program.
Change History:
Request #: When making modifications to a program that has been completed, include a
request number here.
6
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
YVBAK = VBAK.
REPORT
*PROGRAM HEADING
TABLES
DATA
LITERAL
FIELDS
COUNTERS
FLAGS/SWITCHES
INTERNAL TABLES
FIELD-GROUPS
RANGES
SELECTION-OPTIONS
PARAMETERS
7
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
Example:
*-------------------------------------------------------
* INTERNAL TABLES
*-------------------------------------------------------
DATA: WC_COUNTER TYPE I.
...
*-------------------------------------------------------
* SELECTION-OPTIONS
*-------------------------------------------------------
SELECT-OPTIONS: MATNR FOR MARA-MATNR.
...
2.6 Forms
FORMs are subroutines that allow a developer to define a process once in a program and call that
routine from different places within the program or, in certain cases, from other programs. Use
FORMs to modularize your program to facilitate maintainability. Each FORM should perform only
one operation. Also, don‟t use a FORM whose only function is to call another FORM.
When creating a form utilize functionality supported by the ABAP Development Workbench by
forward navigation. Double-click on the name of the subroutine in the PERFORM statement.
*&-----------------------------------------------------*
*& Form F_<name>
*&-----------------------------------------------------*
* F_<name>
*------------------------------------------------------*
* --> p1 F_<name>
* <-- p2 F_<name>
*------------------------------------------------------*
F_<name>: The name of the FORM. The name should be descriptive. For example, if the
FORM reads table LFA1, the name of the FORM should be
F_READ_TABLE_LFA1.
Description: A brief description of the FORM‟s operations.
2.7 Includes
Use Includes for modularizing large report programs or to create report sections that can be
shared by several report programs. Adhere to the naming conventions for ABAPs when creating
includes (Appendix 3-Naming Standards). When you declare the Include in your program,
comment it like this:
8
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
9
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
2.10 Parameters
When declaring parameters, make the prefix as “PA_” The rest of the parameter name is a short
description of the parameter‟s use and/or contents. Beware that parameter names can be up to 8
characters long. Also, create a meaningful label for the parameters in the Text Elements section in
your program. Declare parameters like this:
2.12 Ranges
While declaring Ranges, make the prefix as “RA_”. Declare your ranges like this:
If you know exactly the number of entries your internal table will contain use OCCURS n (where n
is the number of records). It does not make sense to specify n if you do not know the exact
number. In this case leave it to the system the task of allocating memory blocks by specifying
OCCURS 0 (zero). This procedure will avoid excessive memory requirement helping the overall
performance of the program specially when handling large number of internal table‟s entries.
10
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
2.15 Types
While declaring Types, make the first 3 characters “TY_.” Declare types like this:
There is really no field-group standards except for the global variable standards mentioned above.
You must also use HEADER and DETAIL to sort. Here‟s an example of field-group usage:
Comment data and variables individually by line using the in-line comment indication (“).
Here‟s an example:
11
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
DATA:
WG_WRITE_FILE (1) TYPE C, “„Write file‟ flag
WC_LOOP_CNTR LIKE SY-INDEX, “Step loop counter
WL_NAME (5) TYPE C VALUE „Vista‟ “company name
Do not insert full comment lines in the middle of control events (e.g. IF, CASE) to maintain
program readability. Instead, in-line comment should be used.
In the “Event Processing” section of your code, separate your comments from the code so
that they can be read easily. Refer to the following example:
When making comment lines and boxes (and if you‟re using the Command Editor Mode),
use the ABAP command line command “IC” so that you don‟t have to type each individual
hyphen or asterisk. For example, typing “IC **1” inserts a dashed box on the top line of the
line editor. You can also type the command “N” in the editor line where you want to include
the box.
Typing “N” in the editor line the following comment box will be created:
*-------------------------------------------------------
*
*
*
*-------------------------------------------------------
Typing “IC *-*” in the command line inserts a lower-level comment line:
*------------------------------------------------------*
Comment complex and/or large coding structures by inserting a blocked off comment
section preceding the structure. Here‟s a simple example:
*-------------------------------------------------------
* The following construct performs a SELECT from table
* LFA1 and checks for a return code. If there‟s a
* Return code, the program writes a message to the
* Screen.
*-------------------------------------------------------SELECT * FROM LFA1
WHERE LIFNR = „12345‟.
ENDSELECT
IF SY-SUBRC NE 0.
WRITE: / „The SELECT was unsuccessful.‟
ENDIF
12
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
When calling online messages, write a comment that includes the message‟s contents.
When using the option Insert Statement (command line IC) for message, SAP automatically
inserts a comment describing the message. For example:
IF SY-SUBRC NE 0.
* This message says „The input file does not exist.‟
MESSAGE E001 (Z1)
ENDIF
Statements with multiple objects should be indented and aligned for clarity.
To comment FORMs, refer to the Internal Data Names section of this document.
Documentation
Whenever developing a program, always use the Documentation feature. It‟s imperative that
you use this feature to document your programs because business requirements often change
and the specification may not be available to update. To access the program documentation
screen, select the Documentation radio button on the ABAP/4 Editor: Initial Screen. Include the
following components on the documentation screen:
Note: The ABAP program is not considered finished until it is properly documented. The QA
review has to make sure that the program documentation is done before it can be
released for the functional test.
Text Elements
The use of Text Elements on your program is mandatory. Use text elements every time you
create:
Headers for output lists,
Selection text that appears on the selection screen,
Text symbols which can be used in ABAP statements (E.g. WRITE) instead of literal.
The use of text elements has important advantages:
Text Elements are stored outside the program in language dependent text pools. Programs
automatically use the text element of the user‟s logon language.
13
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
In order to properly use this feature you should maintain your standard report headings in the
ABAP List Heading function.
Additional 6 heading lines could also be specified amongst many other advanced features.
Here is an example:
Initialization
…
…
Start-of-selection
…
…
Example of output
14
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
Here are the fields printed by the header function from left to right:
First Line
Report title or program List header
Company Logo
Second Line
Run Date
Run Time
User Id
3 Online Programming
3.1 Overview
Refer to this section when creating online programs or modifying existing ones. Examples of online
programs are as follows:
Screens that allow the user to maintain specific edit parameters for document entry.
Screens that allow updates to Company specific transparent tables.
New menu options or push-buttons on existing screens.
New transactions for custom systems
When developing new user interfaces for the R/3 system it is extremely important that the user
interface is consistent with the SAP ergonomics. With the applications becoming more and more
complex, the appearance of the system to the user is becoming even more important. The more we
follow SAP ergonomics less is the user effort to learn how to use these new applications. The
intention behind ergonomics is a user-centered approach. The user should not notice when
changing from a SAP application to a new one (developed by you). The transition must be as
smooth as possible resulting in increased efficiency.
SAP has developed an interesting and useful transaction which developers can reference. The
transaction demonstrates how screens have to be built adhering to standard SAP. Pushbuttons,
check-boxes, field alignment, dialog boxes, header and detail screen and several other screen
elements are shown with respective rules to help you understand SAP ergonomics concept. The
transaction name is BIBS.
The Quality Assurance for a screen is going to check the new development against standards
defined by BIBS transaction. Therefore, a new user interface (screen) cannot be considered
completed until it is in accordance to the ergonomics dictated by SAP.
15
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
When you use the Repository Browser in the ABAP/4 Development Workbench, the system
automatically generates the include programs that contain your screen processing logic
(PBO/PAI modules). In this manner, your program is modular. Also, from the Workbench,
you can access all online programming tools (e.g., screen painter, menu painter,
transaction code maintenance, and the ABAP/4 editor).
Put all global data declarations in the “TOP” include that the ABAP Workbench proposes for
you when you create your program. Refer to the Module Pool section in the Appendix 3-
Naming Standards for more details.
Use SAP‟s standard PF keys where applicable. To see a list of SAP‟s standard PF keys,
refer to the PF Keys section in Appendix 3-Naming Standards.
When creating online messages, try to use the standard message classes within message
repository (e.g., V1 for Sales). Otherwise, create your own according to the Appendix 3-
Naming Standards.
When laying out your screen in Screen Painter, name the OK code “OK_CODE.”
When writing text on your screens in Screen Painter, connect each word with an
underscore. Otherwise, each word will be a separate text field.
Give your title-bars and CUA status‟s the same names as the screens to which they are
assigned.
Remember that if you want fields on your screen to have Possible Entries (PF4)
functionality, they must have a foreign key relationship with another field in a check table.
When using fields from the DDIC or from the program use the feature to copy field
templates instead of creating the fields on the screen (from the full screen editor chose Go
to Dict. /Program fields). This saves time and it is less prone to errors.
4 Enhancements / User-Exit
To begin with, enhancements are not an ordinary type of development because it requires deep
knowledge of the application and solid understanding of the ABAP environment. Therefore, when
dealing with user-exits the developer has to, more than ever, stick to standards. For more details
on the procedures to approve and develop enhancements please refer to the Development Life
Cycle document. It explains in details the approval procedures involved on an enhancement
development.
16
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
To help customers more easily add exits to the core system, SAP has created placeholders within
the standard code. These “place holders” are called user-exits. A great number of user-exits are
grouped in, what SAP calls enhancements. There are four basic types of customer exits within an
enhancement. Each of these exits is a hook where you can “hang” your own add-on. Menu Exit,
Screen Exit, Function Module Exit and Keyword Exit are types of exits contained in the
enhancement.
Another type of exit is the Program Exit. These exits are placed in specific module pools but their
content is empty. Because these exits are not supported by the enhancement concept detailed
documentation is needed. Some of these exits are very generic about what you can do. The
consequence of this flexibility is that some exits might be used to solve more than one business
requirement. Therefore, it is advisable that comments are used to document the code. You can
copy an existing template into your own code. Select the option Insert Statement in the Edit menu
option or press CTRL + E. Then, click on Other Patterns and choose Z_USER_EXIT_TEMPLATE.
This template includes all the fields that should be documented when creating a user-exit. Please
find on the Appendix 2, the user exit template that has to be used.
Development ID: The Status Tracking Tool (STT) ID number assign to the development request.
Dev. short Desc: The short description given in the STT database.
Request #: The SAP transport request which exit was assigned to.
Description: A brief description of the functionality to be performed in the user exit with
input and output fields.
Here are some guidelines that must be complied with when working with user exits:
1) DO NOT experiment in Development & Quality. If you are just trying or experimenting (proof of
concept), make an effort to work as much as possible in the sandbox system (e.g. Sandbox
system) or whatever designated sand box system.
2) Only develop in Development & Quality when 100% sure. If no test is possible in the sandbox
or if you completed your testing in that system, then and only then, go to one of the
development boxes.
3) Make sure the User Exit is the correct one. Choose your enhancement carefully. If the User Exit
you desire is not available in one of the standard enhancements (transaction SMOD), choose it
carefully by making sure the transaction processing passes through that code.
4) While developing make your code only executable under your own User ID including a CHECK
statement. When ready to start coding make sure you put the following condition before your
17
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
ABAP code: CHECK SY-UNAME = ‘<your user id>’. This is to guarantee that your code will
only be executed when you are running the transaction/user exit. The User Exit won‟t be
available for the rest of the users.
5) Be careful when the User Exit is being used already. If the same User Exit is being used by
other person, DRF or project is twice as careful. There are two situations that apply here: (A)
the user exit has been released / transported and therefore there is no CHECK statement
against the developer‟s user id anymore. In this case, just include the CHECK described in item
4. (B) The user exit you are about to change is currently being developed/tested and, therefore,
it already contains another developer ID‟s check. In this case, just add your ID on the same
check.
6) DO NOT activate projects with syntax errors. If you are working with project/enhancement
always make sure that there are no syntax errors before activating it. Even if it is for a brief
moment, these syntax errors might annoy several people across several modules.
7) Demand a check by the Design Team. Because of the nature of User Exits, make sure you get
an approval for your work with the design team members involved. Ask them to check all the
transactions that might have been affected by that user exit you‟ve worked on. They might not
know them all but they will have a pretty good idea.
8) Remove the CHECK statement when clear. After Design Team approval of the solution, make
sure you remove your CHECK statement. It will be very embarrassing to learn your check was
transported to Production and only yourself can see the result of your master-piece ABAP code.
9) When your situation does not really fit under this discussion or if the user exit you are working
on is too complex with pieces of ABAP code that must be executed in certain situations but not
in others. For example, there might be cases when the use of IF SY-UNAME = „<your user id>‟
will be more appropriate than CHECK. The idea behind is that you isolate your code until you
are completely sure of the effects in the whole system/project.
When building a form using SAP script, use the LETTER page format. If you use another format,
like INCH12, there could be some problems with text wrapping.
Please refer to the Appendix 3 - Naming Standards when naming SAP script layout sets and
Smartform programs.
18
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
6 Function Modules
Never create a new function module if one already exists that will perform the required task. Always
use the function builder to search for existing function modules. Remember that someone might
have thought about doing what you want to do.
All function modules must have their EXPORT, IMPORT, TABLES and EXCEPTION parameters
documented. The function module itself also needs to be documented using the “Documentation”
on the function builder.
Important: when creating function modules are sensitive to the number of functions within a
function group. Whenever a function module is called the entire function group is loaded in
memory. If necessary, create a new function group. Keep similar function modules within the same
group. For instance, function group “Z_EMAIL” contains modules “Z_SEND_EMAIL”,
“Z_RECEIVE_EMAIL”, etc.
Depending on the change you want to perform in the standard table/structure, a full conversion
of all tables affected is required (with deletion of indexes and tables and consequent re-build of
these objects with the new structure). This is a dangerous procedure and some attention is
required. If the change you are performing in a standard table involves:
19
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
A full adjustment of the SAP table (and its dependent structures) has to be performed in the
database level. In this case, you have to instruct SCC/PS to perform the activation after hours
when nobody is logged into the system. If this is not followed data might be corrupted and
sessions might be crashed with short dumps. Ultimately, the restore of back-ups with
consequent system downtime might occur.
If the full key is available when performing SELECT statements, use SELECT SINGLE. In
this manner, you are only extracting the database record that you‟ll be using instead of
performing unnecessary data retrieval. Also, the SELECT SINGLE performs better than a
straight SELECT.
When use SELECT, always specify your conditions in the WHERE clause instead of
checking yourself with CHECK statements. The database system can then use an index (if
possible) and the network load is considerably less. Also, the order of fields in the “WHERE”
should follow the order of fields in the DDIC table.
e.g.:
SELECT * FROM BKPF
WHERE BUKRS = „0800‟.
ENDSELECT
Not.
SELECT * FROM BKPF.
CHECK BKPF-BUKRS = „0800‟.
ENDSELECT
It is always faster to use SELECT … INTO TABLE than APPEND. However, if the table
used in the INTO TABLE version does not have exactly the same layout of the table being
read use INTO CORRESPONDING FIELDS…. .
If you have a large internal table in your program, it is a good practice to keep it sorted if
single lines are read at random during runtime. You can fill the table so that it is pre-sorted
by the primary key. This keeps single access fast. However, if you always loop through all
lines the table, sorting that table is not really necessary. For more details, refer to help of
commands SELECT … ORDER BY and SORT.
Must use ENQUEUE and DEQUEUE logical locks for database table modifications.
Whenever possible, use column updates instead of single-row updates to update your
database tables instead of selecting each record and updating. Network load is
considerably less. UPDATE dbtab WHERE is faster than SELECT WHERE … UPDATE.
When programming database updates, the use of Logical Unit of Work (LUW) concept is
mandatory. By doing so, you guarantee the database consistency. Updates within the same
LUW are either fully executed or not at all (rollback). If an error within the LUW database
occurs the initial status is reestablished to what t used to be before the LUW. For more
information on this topic please refer to the Programming Database Updates in the R/3
library.
You should use Logical Databases, whenever possible. There are several advantages to
using Logical Databases including performance and ease of use. However, a program can
20
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
run faster with SELECTs depending on the order you want to retrieve data out of the
Logical database structure and the level your checks are performed at. Developers should
carefully choose one of the two techniques or even a mix between LDB and SELECTS.
This is especially true when reading large tables like BSEG and MSEG.
Do not use GET command if you are not reading an entire logical database sequentially. In
this case, a SELECT would enable the user to retrieve the information much faster.
When checking a field against several possible values, you can use either the nested IF or
the CASE statement. The CASE statement is better for two reasons. It is easier to read
and after about five nested IF‟s, the performance of the CASE statement is much better.
When coding IF statements, nest the testing conditions so that the outer conditions are
those that are most frequently true. For logical expressions with AND, place the most likely
false part first.
Use the EXIT command to leave a loop structure as soon as a specified condition is met.
This reduces needless loop processing.
Use the ON CHANGE OF command instead of developing code to compare current and
previous values of a data field within SELECT/ENDSELECT processing or GET events.
Use the CHECK command instead of an IF statement whenever possible. This reduces
processing time and improves readability.
If you need the COLLECT semantics, DO use COLLECT. The logic used by the COLLECT
statement is independent of the number of entries and it does not need to maintain a table
index.
When sorting internal tables, specify the fields to be sorted.
To find out how many entries are in an internal table, use the DESCRIBE command.
When you no longer need an internal table in your program, use the FREE command to
delete the table completely out of memory. In this manner, system resources will be freed
up to more efficiently process the rest of your program.
21
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
For effective modularization, code your program so that PERFORM statements are within
an IF statement. By doing this, you won‟t call the subroutine unless the IF tests fails. For
instance, example “A” is better than example “B.”
A. IF FIELD1 NE 0.
PERFORM SUB1.
ENDIF
FORM SUB1.
...
ENDFORM
B. PERFORM SUB1.
FORM SUB1.
IF FIELD1 NE 0.
...
ENDIF
ENDFORM
Avoid leaving “dead code” in your ABAP. Remove defined fields that are never referenced
and code that can never be logically executed. To see if a declared field is used anywhere
in your program, double-click on it.
Use the ABAP/4 Runtime Analysis feature to ensure that your program is running as
efficiently as possible.
When you‟re indenting nested statements (by 2 spaces), use the Pretty Printer function,
which indents all nested statements in your code by 2 spaces. To invoke the Pretty Printer
function, type “PP” on the command line and press ENTER or, choose it from the menu.
The SAP system provides a large number of function modules to support standard Dialog
Boxes. Several functions are available for different type of dialogs. For details please refer
to the Extended Applications Function Library in the R/3 Library.
We recommend that you work with local data as often as possible. The usage of local data
increases the readability of the source code.
22
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
Whenever possible use the “Extended Program Check” feature from within the ABAP editor
(Program Check Extended Program check). The extended program check makes
static checks that are too laborious for the normal syntax check. When you choose "Perform
check", the checks selected in the "Checks" group box are carried out. If you choose
"Perform std. check", the system reports those errors that are particularly critical.
Runtime Analysis – Upon completion of your transaction/report you should analyze your
coding utilizing the Runtime Analysis. This tool checks the performance of your code
created within the ABAP workbench. The Runtime Analysis tool creates lists that reveal
expensive statements, summarize table accesses, and show the hierarchy of a program‟s
flow. These are some of the problems that can be detected using this tool:
Use the SQL Trace tool when you want to check the program‟s database accesses. Improper
written SQL statements have a great impact on application performance. By using this tool you
can analyze potential problems and make the necessary correction.
23
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
8 Appendix 1
*------------------------------------------------------------------------------*
* Program Name : <Program Name> *
* Title : <Report Title> *
* Development class : Z<XY> *
* Transaction Name : <Transaction Name> *
*------------------------------------------------------------------------------*
* Description : <Report Title> *
*------------------------------------------------------------------------------*
* Change Log *
*----------- *
* *
* TR Number Date Author Description *
* --------- ---- ------ ----------- *
* <TR Number> 12-12-2005 <Author Name> <TR Description> *
* *
*------------------------------------------------------------------------------*
9 Appendix 2
24
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
10 Appendix 3
ACC Program Naming Standards
Report / Program Naming Standards: Z<DEV ID>_<Report Description>
25
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
11 Appendix 4
Naming conventions in Reports, Enhancements & Forms
26
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
The following naming convention has been conceived for use within the SAP namespace:
If you do not observe the naming conventions for object types (classes and interfaces), conflicts will
occur when the system creates persistent classes, since it will be unable to generate the necessary
co-classes.
Naming Convention
The naming convention has been kept as general as possible to avoid adversely influencing the
naming of objects.
General Remarks
When you choose names for development objects, you should:
Use English names
Use glossary terms when possible
27
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
CL_<class name>
Class in the class library The class name should be made up of singular nouns.
CL_COMPANY_CODE,
CL_GENERAL_LEDGER_ACCOUNT
IF_<interface name>
IF_STATUS_MANAGEMANT, IF_CHECKER
Local classes in
LCL_<class name>
programs
LCL_TREE_MANAGEMENT
Local interfaces in
LIF_<interface name>
programs
The sane naming convention applies to interfaces as to
classes.
LIF_PRINTER
28
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
<method name>
GET_STATUS, CREATE_ORDER,
DETERMINE_PRICE
<event name>
BUTTON_PUSHED,
COMPANY_CODE_CHANGED,
BUSINESS_PARTNER_PRINTED
TY_<type name>
Local type definitions within a
class (recommendation)
TY_INTERNAL_TYPE, TY_TREE_LIST
<variable name>
CO_<constant name>
Data definitions (constants)
(recommendation) CO_MAX_LINE, CO_DEFAULT_STATUS,
CO_DEFAULT_WIDTH, CO_MAX_ROWS
29
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
GET_STATUS, SET_USE_COUNT
ON_<event name>
ON_BUTTON_PUSHED,
ON_BUSINESS_PARTNER_PRINTED
AS_<new type>
Methods that perform type
conversions
AS_STRING, AS_ISOCODE
IS_<adjective>
CHECK_<objective>
Check methods
CHECK_AUTHORIZATION,
CHECK_PROCESS_DATE
30
SAP@RRAB
Programming Standards and Guidelines
ACC - ABAP Programming Standards and Guidelines - V 1.0
20100119
Created By: Thangeswaran T.K Created : 19 January
2/1/2010
2010
Document : ACC - ABAP Programming Standards and Guidelines - V 1.0 20100119 UPDATED : 1 FEBRUARY 2010
RESULT RE_<result>
12 Appendix 5
For exceptions
The following table contains a series of possible exception names that can also be used generically
(for example, NOT_FOUND could also be used as DATE_NOT_FOUND)
EXCEPTION Meaning
EXISTING A new object that you want to create already exists in the database.
13 Appendix 6
Change and Transport System Standards
32