EDFE Corporate SAP - ABAP Developer Handbook v1.0
EDFE Corporate SAP - ABAP Developer Handbook v1.0
HANDBOOK
Approval
Reviewers
Name Role
Andre Muecke Business Applications Manager - SAP
Ken Saggers SAP Support, Senior Technical Analyst
Giampaolo Lupi Transition Manager - SAP
Satyan Ghumatkar SAP Technical Consultant
1 INTRODUCTION 7
1.1 Purpose 7
1.2 Scope 7
6 PROGRAMMING STANDARDS 46
6.1 General Rules 46
6.2 Documentation 46
6.2.1 General Documentation 46
6.2.2 Documentation on Data and Program Flow 5150
6.2.3 Documenting Form Routines 5352
6.2.4 Documentation in ABAP Objects 5453
9 APPENDIX 9087
9.1 New Standards 9087
9.1.1 Shared Objects 9087
9.1.2 Exception Handling 9187
9.1.3 Switch Framework 9187
9.1.4 New BADI’s 9188
9.1.5 Developing Persistence 9188
1.1 Purpose
The purpose of this handbook is to set-outdefine the standards and guidelines for custom ABAP
development common that is that is to be adoptedvalid in both operational (Application Management)
and project related environments. The use of Aa single universal set of standard and guidelines
supports a standardised consistent approach to software development. The benefits of such an approach
are:the build phase (development & unit test) of the delivery model.
Whilst this handbook is being issued to the Projects, it may not cover all types of development as the
document is currently being created.
1.2 Scope
Standards and guidelines address the quality aspect of custom code created during the build phase
(development & unit test) of the development lifecycle. The definition of custom code in the ABAP
environment covers Enhancements, Modifications, and standalone custom applications.
The creation of new functionality and adaptations to existing functionality are subject to these standards
and guidelines albeit existing functionality is not expected to be adjusted in retrospect to conform.
To develop SAP solutions different techniques and programming languages are at a developer’s
disposal. Architectural standards set-out which techniques and programming languages are permissible
in the SAP development environment. The setting of architectural standards is not the focus of this
document. However, a section on this subject has been included to provide a context.
This document has been written for a SAP NetWeaver 7.0 system release.
1.5.2 Don’ts
When developing new Webdynpro’s, ABAP should be utilised and not Java
Start Realization without sign-off of the Functional Specification
Write complex code unless it is really required.
Release the development request without proper testing.
Update the backend database directly.
Forget to capture the exceptions of all function and method calls.
Use own naming convention and patterns.
Do not declare class static variables as public, because write access is possible
from outside then.
Better: Declare as “private” and provide (public) get-method for reading access.
Then only reading access is possible from outside the class.
3.1 Overview
A naming convention specifies the set of rules used to identify development objects. SAP plays a role
in the setting of the rules insofar it enforces its own recommendations. (See the following the section
called Customer Name Space ID). In the ABAP environment the non-reserved aspect of a custom
repository object name (and the names of any custom internal components) are arbitrary. The overall
responsibility for the enforcement of the naming conventions lies with the individual developers.
What is prescribed in the following sections ensures: (1) a distinction between SAP standard code,
partner code, and customer code and (2) meaningful names for custom developed objects that promote
ease-of-identification.
As part of the delivery process Code Inspector (Transaction code “SCI”) will be used to check whether
programs adhere to naming conventions or not.
Name space identification is the means SAP uses to segment development objects in the repository.
SAP has reserved name ranges for customer objects and SAP objects. SAP reserves the “Z” and “Y”
repository name spaces for its customers that ensure that objects created in this space are preserved
from patching and upgrades. Other name spaces are reserved for SAP’s own developments and that of
it partners. EFDE Corporate SAP adopts the policy of naming test-related objects in the “Y” name
space and Production-related objects in the “Z” namespace. The customer name space identifier always
occupies the first character in the name of a custom development.
Beware that SAP does deliver a few system objects with names that fall within the customer name
space. These objects are listed in table TDKZ.
The process area/application ID identifies the relevant business domain for custom development. It is
represented by a two character code which logically groups related development objects together.
Creation of custom data dictionary objects (DDIC) should be kept to minimum to maintain a low cost
of ownership. New DDIC objects should be created when a requirement exists that cannot be met by a
standard DDIC object.
The following general points are to be kept in mind during definition of new data dictionary (DDIC)
object:
Check whether a suitable DDIC object exists before creating a new one.
Ensure that Client (MANDT) is utilised when creating a new table
Foreign keys referencing SAP table primary keys are highly recommended.
Table maintenance facility (ZSM31) should be implemented by exception for custom tables
that require restricted manual access.
Documentation at the data element level should make use of the long text facility to make on-
line help effective.
If appropriate, for master data or transactional tables, the user names of the persons who
created and/or changed data, the date of creation/change should also be stored along with the
reason for change.
Technical settings should be maintained on all custom tables created (Consult the BASIS team
for assistance with the technical settings).
A DDIC table name may be specified up to 16 characters. The first character should be the standard ‘Z’
for custom objects. The 2ndand 3rd characters should contain the Process Area. The remaining
characters are open.
Format: A BB C DDDDDDDDDDDD
Open (description)
Separator “_”
Process
Area
Customer
space
identifier -
‘Z’
Example: ZHR_REGION
3.2.2 Structures
A structure is defined like a table, but it does not store records in the database – it is typically used as a
reference data definition to ensure consistency between programmes. Structures can be shared by
multiple ABAP programs.
Format: AA BB C DDDDDDDDDDDDDDDDDDDDDD
DDD
Open (Description)
Separator “_”
Process
Area
Customer
space
identifier -
‘ZS’
A DDIC table name may be specified up to 16 characters. The first two characters of the view must be
specified as ‘ZV’. The 3rd and 4th characters specify the Process Area. The other characters can be
arbitrarily assigned. For clarity purposes, the main table name can be used.
Format: AA BB C DDDDDDDDDDD
Open. Should incorporate the
main table name and be unique
Separator “_”
Process Area
Customer
space
identifier -
‘ZV’
Example: ZVHR_REGION
3.2.5 Domains
A domain is a central object for describing the attributes of a business object. A domain describes the
value set for a field. This set of values is defined by specifying the format attributes, such as external
format, length and type.
A DDIC data domain may be specified up to 30 characters. SAP does create domains that begin with a
‘Z’, so custom domains should begin with the first two characters ‘ZZ’. The remaining characters can
be arbitrarily assigned but should be a meaningful name.
Format: AA BBBBBBBBBBBBBBBBBBBBBBBBBBBB
Open (Description)
Customer space
identifier -
‘ZZ’
A DDIC data element may be specified up to 30 characters. The first two characters must be ‘ZZ’ and
the remaining characters can be arbitrarily assigned.
Format: AA BBBBBBBBBBBBBBBBBBBBBBBBBB
BB
Open
Customer space
identifier -
‘ZZ’
Lock objects control simultaneous access to a particular table/entry by two update users – i.e. ensure
two users are prevented from updating the same data object simultaneously. Locks are set and released
by calling a function module. When a lock object is activated, the system automatically generates the
function modules to be included in an ABAP program.
A DDIC lock object may be specified up to 16 characters. Lock object names should start with the
prefix ‘EZ’ followed by the process area. The remaining characters are open to the developer.
However, the table name should be used if it is less than seven characters.
Format: AA BB C DDDDDDDDDDD
Customer
space
identifier -
‘EZ’
Example: EZHR_REGION
A DDIC Search Help may be specified up to 30 characters. The first two characters must be ‘ZH’
followed by the process area. For clarity purposes, the main table/ view name should be used if
possible.
Format: AA BB C DDDDDDDDDDDDDDDDDDDDDDDDD
Open
Separator
“_”
Process
Area
Customer
space
identifier -
‘ZH’
Example: ZHFI_T001
Matchcode objects are obsolete and have been replaced first by the technology of the help views and
later by search help.
Customer
space
identifier
-
‘ZTT’
Example: ZTTFI_REGUH
Format: A BB CC
Freely assignable characters – Use number
assignment
Process
Area
Customer
space
identifier
-
‘Z’
Example:ZQM01
The following program IDs are used to describe the type of program:
Format: A BB C D E F G
Description
from
Functional
Specification
Separator
“_”
WRICEF
Ref #/
CR Ref #/
IR Ref # -
Length of
this sub-
segment
will vary
Separator
“_”
Program
Type
Identifier
App./
Process
Area
‘Z’
ABAP WebDynpro’s should be named using the standard convention, plus a reference to the
functional specification/task number and then a descriptive part. For Example
‘ZFIW_CNN0127_CFP_Report’
Module pools should be named using the standard convention, plus a reference to the
functional specification/task number and then a descriptive part. For example
'SAPMZHR1_EHL00001_EXT.
Transactions should be named in line with the report/program. For example a transaction for
the module pool above would be 'ZHRP01'.
Use descriptive names and hyphenate it with “_” underscore. Use the following prefixes:
New Type definitions should be named starting with ‘T_’.
Global variables should be named starting with ‘G_’.
Global constants should be named starting with ‘GC_’.
Global internal tables should be named starting with ‘GT_’.
Global structures should be named starting with ‘GS_’.
Global range tables should be named starting with ‘GR_’.
Local variables should be named starting with ‘L_’.
Local constants should be named starting with ‘LC_’.
Local internal tables should be named starting with ‘LT_’.
Local structures should be named starting with ‘LS_’.
Local range tables should be named starting with ‘LR_’.
Subroutine parameters should be prefixed with a ‘P’
Field Symbols should be named starting with ‘<FS>.
Selection-screen Parameters should be named starting with ‘P_’.
Select-Options should be named starting with ‘S_’.
An explicit type should always be assigned to the formal parameters of a subroutine to improve
performance.
Where possible, use the Parameter ID associated with a data object to enable automatic population.
This will also aid with the passing of data between programs and transactions.
The use of the MOVE-CORRESPONDING statement, though convenient, should be used with care. In
some cases the use of explicit MOVE statements can aid clarity.
Numeric Value
Process
Area
Constant
‘SAPxZ’
Example: SAPMZPS01_PROC_CHQ
Module pools should be named using the standard convention detailed above, plus a descriptive part.
Example: ‘SAPMZPS01_Project_Systems’.
Remarks: It is mandatory to use the ‘ABAP Workbench’ to construct module pools. The SAP
Workbench is designed to enforce standard naming conventions.
The identification of a screen painter dynpro consists of an ABAP program name and a four digit
dynpro number. The number range reserved for customised dynpros should be between 9000 - 9999.
The initial screen number for a given transaction should be 9000 and additional screens numbers
increment by 10.
ABAP Module
Pool
Format: AAAAAAAA
Open
Example
STANDARD
Format: AAAAAAAAAAAAAAAAAAAA
Open
Example
INITIAL
A transaction code can not be more than 20 characters. The naming convention for transactions created
by Remote Development developers requires the first character be a ‘Z’. The Process Area is placed in
the next three characters. The remaining two characters are open to the developer.
Format: A BB CCCCCCCCCCCCCCCCCCC
Example
ZHR01
Format: AA BB C DDDDDDDDDDD
Example: Z_FI_CREDITNOTE
The SAP Form name can be up to 30 characters long and must begin with ‘Z_’. This will differentiate
custom forms from standard SAP forms. The next two characters of the name will contain the
application/process area (i.e. FI or HR). The remaining characters should contain a meaningful
description and incorporate that SAP standard form name where it makes sense.
Format: AA BB C DDDDDDDDDDDDDDDDDDDDDDDD
D
Open (Description) – incorporate original
form name if copied from SAP
Separator
“_”
Applicat
ion/
Process
Area
Consta
nt ‘Z_’
Example: Z_FI_CREDITNOTE
The IDOC Message Type can be up to 30 characters long (although compatibility with SAP systems
prior to Release 4.0 requires a name of 6 characters or less). The name must begin with ‘Z’ to
differentiate custom Idocs from standard Idocs. The next two characters of the name will contain the
application/process area. The outstanding characters should contain a meaningful description.
Format A BB C DDDDDDDDDDDDDDDDDDDDDDDDD
: D
Open (Description) – Message type name
Separator
“_”
Application/
Process Area
‘Z
’
Example: ZMM_METREAD
The IDOC basic type can be up to 30 characters long (although compatibility with SAP systems prior to
Release 4.0 requires a name of 8 characters or less). The name must begin with ‘Z’ to differentiate
custom Idocs from standard Idocs. The next two characters of the name will contain the
application/process area. The remaining characters should contain a meaningful description that
includes version release number. E.G. ‘01’.
Format: A BB C DDDDDDDDDDDDDDDDDDDDDDD
DDD
Open (Description) – Idoc name
Separator “_”
Application /
Process Area
‘Z’
Example: ZMM_METREAD01
The name of the IDOC Segment type can be up to 27 characters long (although compatibility with SAP
systems prior to Release 4.0 requires a name of 7 characters or less). The name must begin with ‘Z’ to
differentiate custom Idoc segments from standard Idoc segments. The next six characters (or more) of
the name will contain a meaningful description.
Format: A BB C DDDDDDDDDDDDDDDDDDDDD
SAP ABAP Developer Handbook Page 28 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
DD
Open (Description) – Idoc segment
name
Separator “_”
Application /
Process Area
‘Z’
Example: ZMM_METREAD
The function module used to process incoming IDocs with message type
"ZMM_METREAD" could be "Z_IDOC_INPUT_ ZMMI_METREAD".
The logical system name will contain 10 characters. The first three characters specify the system id and
the next four will contain the constant ‘CLNT’ to represent the client number. The last three will
contain the client number.
The model view technical name will contain 10 characters. The first character specifies a customer
object. The next two characters specify the process area followed by a free text description.
Format: A BB CCCCCCC
Open (Description) – Model view
name
Application/
Process Area
Constant ‘Z’
A prefix number needs to be assigned per client / SAP System to allow the differentiation and
verification. This is set automatically but needs to be checked when the system is delivered.
BOR objects:
BOR object can contain 8 characters long which start with the constant ‘Z’. If a subtype is created, it
should be prefixed by Z to allow easy identification to super type (i.e. EMMACASE – ZEMMACASE)
all subsequent method and events created should be prefixed by z.
Packages/Development classes group together development objects (e.g. programs, tables, function
modules) which can be corrected and migrated together along a transport path. A
Package/Development class can, for example, consist of a transaction or a group of related transactions
along with programs, DDIC objects, menu painters, screen painters, lock objects, message classes,
match codes, etc.
If a developer believes that a unit of work is significant and deserves its own Package/Development
class, then an additional Package/Development class may be required. The developer should request an
additional Package/Development class from the SAP Custom Development Team Lead.
No objects should be defined under the $TMP development class – prototyping should
only occur in the Sandbox environment.
The area menu follows the same naming conventions as transaction codes.
SAP ABAP Developer Handbook Page 30 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
Format: A BB CCC
Open (any
alphanumeric
identifier)
Process
Area
Constant ‘Z’
Example
ZHR001
3.4.7 Messages
Messages are used in ABAP programs to send information to the user. There are six different types of
messages: information, warning, error, abend, exit and success.
A message consists of a 4 character message class and a 3 digit number. The first character of the
message class should be a constant ‘Z’ and the next three characters will contain the Process Area. The
message number is open to any number between 000 and 999.
According to the naming conventions, only one message class can exist for each Process Area. When a
developer needs to create new message numbers, they need to request a number range within a specific
class from the development team lead.
Format: A BB CCC
Message Number between 000 - 999
Process Area
Constant ‘Z’
Example
Message Id ‘ZCO’ Type ‘E’ Number ‘001’.
Due to the strategic importance of logical databases and the potential impact on system performance,
careful consideration should be made before creating any new logical databases. Consequently, only
the DBA will be able to create logical databases.
Logical database names consist of six characters. The first character must begin with a constant ‘Z’.
The next three characters will contain the process area. The last two characters will represent the series
of logical database created in that process area eg 01, 02.
Format: A BB CC
Numbers
(00 - 99)
Process
Area
SAP ABAP Developer Handbook Page 31 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
Constant
‘Z’
Example: ZPS01
Frequency: D - Daily
W - Weekly
M - Monthly
Q - Quarterly
R - On Request
Sequenti
ally
assigned
number
Requester’s
SAP Logon
& ‘_’
Critical/
Non-
Critical &
‘_’
Frequency
Flag
Live/Test
Run Flag
Program
Name &
‘_‘
Example ZMOPARI001_PMC_DS_001
Format: AAAAAAAAA B CC
Sequential number
matching last 2
digits of dataset
serial number (for
interfaces).
<or> Open (for
non-interfaces
Underscore “_”
<or> Open (for
non-interfaces)
Name of main
program that
created the session
Example: ZPRPI001_01
Datasets
It is important that SAP-specific dataset naming conventions be adhered since external systems will be
interfacing with SAP. Please note that the following naming convention will be confirmed and
amended accordingly after the details of interface control mechanism have been confirmed.
The file structure for all sap related datasets will be:
/INTERFACES
/<Process Area>
/IN /OUT
Underscore (_)
Process
Area
Constant
‘ZZ_’
Example: ZZ_PRP_LAYOUTSET
3.8.1 Project
Project ID is the highest level of the conversion object repository however individual objects needs to
be transported independently. Hence a new project will be created for each object.
i.e FUSION – FOR Fusion Project
SAPSUPPORT – For SAP Support Team
3.8.2 Subproject
This should equate to the Process Area as defined in Section 3.1
3.8.3 Object
Object ID is used to identify the conversion objects created under each Subproject, Ensure that it is
named in such a way that a user can easily understand what the LSMW has been created for.
Example:
SAP ABAP Developer Handbook Page 35 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
IT0001 – Organisation Assignment
FBD2 – Change re-occurring Payments
Notes:
Always use the ‘V’ in the prefix for definition of variables to avoid misunderstanding. In
normal ABAP GS_<variable_name> represents a global structure.
Avoid using verbs at the start of names for variables in a class (CLASS-DATA, DATA),
because they will conflict with method names.
Protected data definitions start with an ‘S’ in accordance to the ‘super’ statement for the access
from a subclass to these data.
The parameters are seen from the point of view of the method that implements them:
Type Value
EXISTING An object that you want to create exists on the database already.
FAILED The method was not able to carry out its task, due to the current
environment situation. This exception is intended in particular for
situations where the environment is temporarily in a constellation that
makes it impossible to carry out task of the method.
..._FAILED A sub-function of the method could not be carried out, due to the current
environment situation. (OPEN_FAILED, CLOSE_FAILED,
SELECTION_FAILED, AUTHORIZATION_FAILED)
INVALID The specified object data is incorrect. (For example, company code not
available) ( as opposed to NOT_QUALIFIED)
INTERNAL_ERROR The last resort. Use this EXCEPTION when all else fails and the error
can not be narrowed down any further.
Path: TBC
Use the activatable checkpoints tool (transaction SAAB) to maintain checkpoint groups, their
respective activation variants, and the corresponding activation settings.
Checkpoints are used for test and control purposes. An ABAP program can contain the following types
of checkpoints:
Breakpoints
Logpoints
Assertions
To open the tips and tricks, on the initial screen, choose Tips & Tricks.
The Coverage Analyzer is a tool for software testing and quality assurance.
You use it to monitor the system-wide execution of ABAP programs on statement level. The Coverage
Analyzer counts the number of executions and runtime errors for processing blocks and statements
separated according to periods, test groups, and functional areas. You can use it to:
Determine the test coverage (even for single test runs)
Find areas of a program not covered by tests and to create additional ones in order to increase
the test coverage
Determine unused code
6 PROGRAMMING STANDARDS
This section contains a list ofthe ABAP coding standards, as well as some efficiencycoding standards.
The purpose of these standards is is toto:
Encourage Promote a consistent set of practices among programmersdevelopers: . That means
Pdevelopers on the same project and developers on different projectsrograms coded by different
people should follow the same set of standard cocoding conventions.
Emphasise the importance of program Provide internal documentation and style to the overall
standard.: Programs should be documented and styled to the extent that another programmer
developer couldcan follow the logic of the code.
Improve readability: Programs should follow a format that makes the code easy to readpick up the
code and immediately start to understand it.
Write programs for people first, Computers second. This means an emphasis on code readability.
Readability has a positive effect on all these aspects of a program:
Comprehensibility
Reviewability
Debugging
Modifiability (for the original author and other editors)
Development time – a consequence of all the above factors
Quality - a consequence of all the above factors
ABAP programs that update master and/or transactional data MUST ALWAYS use SAP transaction
codes (where transaction codes are available) by utilizing BDC or ‘call transaction’ utilities. The only
exception to this would be the use of a BAPI or "direct input" program or Class Methods provided by
SAP. These methods ensure that logical units of work, rollback, locking operations and edits are
performed.
SAP-supplied tables MUST NEVER be updated directly by custom programs – always use standard
Function Modules/BAPI’s. ABAP programs MUST NEVER be used to update configuration tables.
Internal and external documentation (design documents etc) must exist for a program. Because internal
documentation is bundled with the source code it is important that it remains reflective of the code
through-out its life.
The purpose of comments should be to say things about the code that the code cannot say about its
self. Good comments don’t repeat the code or explain it. Goods comments summarise the code and
clarify its intent. Comments should be written to explain at a higher level of abstraction than the
code what the developer has attempted to achieve. The following description of comment
classifications clarifies the distinctions between helpful and unhelpful comments:
Repeat of the code. A repetitious comment restates what the code does in different words.
These types of comments provide the reader with more to read without providing any
additional information.
Explanation of the code. Explanatory comments are used to explain complicated units of
code. Whilst these comments maybe useful it is because the code causes is not clear. If
the code is so complicated that is needs explanation, a better approach would be to
improve the code.
Intent Comments. Explains the purpose of the code. These types of comments operate
more at the level of the problem than the solution. That is, they explain “why” more than
the “how”.
Dead Code should be removed from the program, i.e. the fields which are never referenced and
code which can never logically executed.
Internal online documentation (Documentation sub-object of a program) must be maintained for all
ABAP reports. This provides reference information for both developers and end-users.
The ABAP editor has a PP (Pretty Printer) command to indent specific lines of code by 2 positions
and add subroutine comments.
SAP ABAP Developer Handbook Page 43 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
Menu path: program/pretty printer in ABAP Editor.
Skipped lines and indention should be used to promote clarity between sections of code as well as
between file definitions and declarations.
For ease of reading code, concatenate repetitive commands with a colon as provided by SAP. All
TYPEs, TOs, VALUEs, DEFAULTs, table names, and comments should be aligned among themselves
throughout the code, For example.
INCLUDE programs should be used for Data Declarations, PBO Dynpro modules, PAI Dynpro
modules, Subroutines, and Individual Event Processing.
Use subroutines and FORM paragraphs whenever possible to improve readability and logic flow. If a
block of code is executed more than once, it should be placed in a subroutine at the bottom of the code.
FORM paragraphs should be placed after all non-subroutine code, after the END-OF-
SELECTION event. FORM paragraphs should generally be positioned in the order in which
they are called within the program.
Every logical division within the program should have descriptive comments immediately prior to
the actual code.
Each program type (Programs/Function Modules/BAPI’s/Enhancement types) shhould have a
header comments box or report headerlock that contains an initial creation section and a revision
section.
When a “REPORT” statement is used, insert the header comments before the “REPORT”
statement and is shown below:
o
*&---------------------------------------------------------------------*
*& Program Name : ZSKELTP01 *
*& Title : Basic ABAP List Report *
*& Module Name : Process Area *
*& Sub-Module : - *
*& Author : Waller (Change Author Name) *
*& Create Date : 15/08/2011 *
*& Logical DB : None *
*& Program Type : Report/Interface *
*& SIR/ CR No. : WRICEF Reference/CR/IR No *
*& SAP Release : ECC6.0 *
*& Description : This is a program template for Basic ABAP List *
*& Report. *
*&---------------------------------------------------------------------*
*& REVISION LOG *
*& *
*& LOG# DATE AUTHOR DESCRIPTION *
*& ---- ---- ------ ----------- *
*& 0000 15/08/11 J Waller Initial Implementation *
*& Correction No. : N/A *
*& Transport Request : DEVK900169 *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& REVISION LOG *
*& *
*& LOG# DATE AUTHOR DESCRIPTION *
*& ---- ---- ------ ----------- *
*& 0001 16/08/11 J Waller Why it is being changed *
*& Correction No. : N/A *
*& Transport Request : DEVK900169 *
*&---------------------------------------------------------------------*
REPORT Z….
When modifying existing custom code delete all redundant code. That is, - don’t comment-out code and
mark with the change reference. Version Management will be utilised to identify changes. This will aid
readability of the code.
When a custom ABAP is modified, the information must be appended to the original Program
Specification. It must also contain the Change Tracking number that was raised in relation to the
required changes.
This header should also be utilised when creating Function Modules/BAPI’s/BADI’s.
When modifying existing non SAP Standard code, delete all redundant code. Version Management will
be utilised to identify changes. This will aid readability of the code.
When a standard SAP ABAP code is modified, add the following line at the top of the code:
The tracking number must also be placed next to the changed code.
Examples:
Short code Addition
Before After
20 ….code…. 20 ….code….
30 ….code…. 25 ….new code …. “ 441+
30 ….code….
Short code Deletion
Before After
20 ….code…. 20 ….code….
30 ….code…. 30 *….code…. “ 442-
Short code Modification
Before After
20 ….code…. 20 ….code….
SAP ABAP Developer Handbook Page 46 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
30 ….code…. 30 *….code…. “ 443-
35 ….new code …. “ 443+
Long code Addition
Before After
20 ….code…. 20 ….code….
30 ….code…. 21 * { 444++
22 ….new code….
23 ….new code….
24 ….new code….
25 ….new code….
26 * } 444++
30 ….code….
Strict adhererence to these formats will allow easy reversal of any modifications. It is critical that these
are followed.
Every logical section within the program should have descriptive comments immediately prior to the
actual code. End of line comments should be minimised.
Comment all subroutines with their purpose. Comments should explain the business reasons for the
code in a particular section and what the code in that section is accomplishing. Comments should not
explain individual ABAP commands. Allow the ABAP editor to generate the comment box, by coding
the "PERFORM <form>" statement and double-clicking on the <form>. Be sure to document the input
and output parameters for the specific form in the comment box.
Dead Code should be removed from the program, i.e. the fields which are never referenced and code
which can never logically executed.
*----------------------------------------------------------------------*
* Data declaration (<- Main function block)
*----------------------------------------------------------------------*
* data for storing formulas for analysis (<- Description of the data)
data: gt_work type yt_log_formulas,
gt_formula_listing type cfftb occurs 0.
* global variables for buffering receiving market (<- Description of the data)
* and step level during navigation
data: g_rcv like tkesk_lk01-eeinheit,
g_co_step type rkesk_konsstufe.
IF sy-subrc = 2.
STOP.
ENDIF.
START-OF-SELECTION.
* set flag for consolidation in function group KESK_02 (<- Intermediate commentary)
CALL FUNCTION 'RKE_SK_CONS_LOG'
EXPORTING
i_action = 'K'.
...
Allow the ABAP editor to generate the comments box. Construct the "PERFORM <form>"
statement and double-clicking on the <form>.
*&---------------------------------------------------------------------*
*& Form Form name
*&---------------------------------------------------------------------*
* Function description/flow
*----------------------------------------------------------------------*
* -->I+_Import-Parameter Description
* <->X+_Changing-Parameter Description
* <--E+_Export-Parameter Description
*----------------------------------------------------------------------*
form ….
Example:
*&---------------------------------------------------------------------*
*& Form fc_tr_objects_append
*&---------------------------------------------------------------------*
* Append field cat. objects for transport interface
*----------------------------------------------------------------------*
* --> PV_OBJNAME name of object
* --> PV_TABKEY key of entry for object
* --> PV_OBJFUNC object function
* <->PT_E071 table with objects
* <->PT_E071K table with keys
* <-- PV_SUBRC returncode (= 0 if successful)
*----------------------------------------------------------------------*
Layout and formatting are features of a programming style. The use of these features aid the reduction
in a program’s complexity by highlighting the logical organisation of the code making it easier to read
and understand. Good layout can be achieved by using the following:
One statement per line. Although the ABAP intepretator does allow more than one statement per
line use of this style is to be avioded.
Indentation. Use indentation to show the logical structure of code. As a rule statements should be
indented under the statement to which they are logically sub-ordinate.
o The PRETTY PRINTER command uniformly indents each nested command structure by
2 positions. Use the convert Keyword to Upper Case option.
Alignment. Align elements that belong together. Alignment of code reinforces the idea that a group
of statements belong together. All TYPEs, TOs, VALUEs, DEFAULTs, table names, and
comments should be aligned among themselves throughout the code, For example.
Modularise code. Dividing code into partitions is a technique to improve the readability of the
overall logic structure.
Use Data Dictionary names (short, medium, long) for field text on screens where applicable;
Always define the field with a Format = OK as OK_CODE. This field is used to validate the
OK Event;
Screen and program field names should generally be identical;
Define all global data in the main program (TOP) module instead of the PBO/PAI;
To handle a lock entry failure, invoke an error message (type E) to prevent any further
progress but leaving the user on the current screen. The user can then take an alternative action
or continue to try to lock the object. To minimize the impact on users, limit retries;
When activating buttons or boxes, activate the associated text as well. This enables the user to
click on either the button/box or the text;
Do not use AT PFnn in programs. Instead use the function name so that any method of
invoking the function will have the same effect as the use of the PF-Key.
Database tables can be stored locally on each application server. Performance time may be improved
because reading from the buffer avoids directly accessing the database. Within SAP, only POOLED
and TRANSPARENT tables allow buffering.
Considerations:
Only buffer a table that has read-only accesses made against it and is referenced frequently.
Only buffer tables that are modifiable, if write access occurs infrequently. Changes to buffered
tables get automatically logged in the database and are transferred to the application servers at
regular intervals. If buffered tables are modified frequently, the additional processing needed
may cancel any performance gains attained by buffering.
Native SQL commands always bypass the buffer and access the database directly. If native SQL was to
update a buffered table directly, the buffer status is not changed; this could result in inconsistencies
between data in the buffer and the database.
The order of preference for the development of ALV grid reports is to use the ALV object
model primarily. Where a developer is unfamiliar with the object oriented nature of this ALV
model then it may be allowable to use the List Viewer Class (LVC) functions to implement
and ABAP list views. The older style SLIS ALV reports should not be used unless it is to
maintain compatibility with an existing development.
Classes using the latest ALV object models may be found using wildcard searches on classes
and functions using the SALV* or *SALV* parameters. Example and demo programs exist
that may be used as a reference. These are available within transactions SE80 and SE38.
Field catalogues for ALV reports are to be generated from dictionary based structures using
ALV field catalogue merge function modules. Manual fields may be added when a suitable
structure does not exist and less than 5 fields are required. Reference dictionary structures are
used to provide long text help, correct field formatting and column headings. Refer to
function LVC_FIELDCATALOG_MERGE
Column headings must not be hard coded. The column headings may be created using text
elements in instances where fields are added manually to the field catalogue.
Reference fields in ALV field catalogues should point to structure / fieldname combinations
wherever possible. (i.e. do not use direct reference of data types such as CHAR).
Fields not intended for display or field catalogue selection are to have the technical value set to
TRUE (X) to ensure they are not displayed.
SAP ABAP Developer Handbook Page 53 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
ALV field catalogue maintenance authority should default to own user maintenance by default
unless other specified by the technical script. Default Global layouts may be created in the
development client and transported to other clients if required.
ALV layouts should also include the grouping and sorting internal tables passed to the
functions as a default to allow the groups and sorting to be retained.
ALV fields that are editable or require F4 lookup help should not have hotspot (hyperlink)
function enabled as this will override the Enter or F4 functionality in the field.
Standard ALV functions such as Excel export should be retained unless the Specification
specifically excludes the requirement.
Generally ALV performance is good however in certain situations degradation may occur if too many
round trips caused by statements that flush data between the front
end (PC) and backend systems (SAP). Therefore any design that uses large datasets must consider the
performance over a wide area network (WAN) and not just the local network.
Web Dynpro ABAP is the SAP standard UI technology for developing Web applications in the ABAP
environment. It consists of a runtime environment and a graphical development environment with
special Web Dynpro tools that are integrated in the ABAP Workbench (SE80). Web Dynpro offers the
following advantages:
The use of declarative and graphical tools significantly reduces the implementation effort
Web Dynpro supports a structured design process
Strict separation between layout and business data
Reuse and better maintainability by using components
The layout and navigation is easily changed using the Web Dynpro tools
Stateful applications are supported – that is, if the page is changed and the required data
remains intact so that you can access it at any time throughout the entire application context.
Note that stateless applications are not possible.
Automatic data transport using data binding
Automatic input check
User interface accessibility is supported
Full integration in the reliable ABAP development environment
UI objects are created using drag and drop of UI elements which fastens overall development
time.
supports both JAVA and ABAP development
While designing the UI layout, it should follow any one of the pattern which is shown below.
A form pane shall not have a white background color. With all SAP-branded background colors, the
white input fields appear slightly highlighted and the blueish disabled or read-only fields are down
SAP ABAP Developer Handbook Page 55 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
lighted. This guides the user to the editable parts of the screen. A form pane can only have max 2
“columns” of label-field combinations.
There should be no hard-coding of date formats in the programs, the date format of the users’ default
information (SU50) should be used to output any date. When creating a BDC session the ABAP should
use the user default date format when formatting the record for the screen. We can’t make assumptions
about the date format of the user executing the program.
There will be no hard-coding of currency output formats in our programs. The decimal notation of the
users’ default information (SU50) should be used to output any currency value.
SAP currently does not support multiple time zones, so the time used in the system is the time that the
database server is set to. The system field SY-TZONE indicates the time difference in seconds to GMT
time.
Basic event such as START-OF-SELECTION, END-OF-SELECTION should be included in the
program to improve the readability of the program.
For each field, include a comment (after the field) describing the use or purpose of the field.
INCLUDES are created for data declarations and any data structures that will be used in more than one
ABAP program.
Global variables are minimized by declaring local variables or by passing parameters while creating
internal subroutines.
Specify the type of field-symbols and formal parameters in source code, the ABAP compiler can better
optimize the code.
I2 = <F>. I2 = <FS_I>.
I3 = <F>. I3 = <FS_I>.
I4 = <F>. I4 = <FS_I>.
Use Data Dictionary names (short, medium, long) for field text on screens where applicable. Always
define the field with a Format = OK as OK_CODE. This field is used to validate the OK Event.
Screen and program field names should generally be identical. Define all global data in the main
program (TOP) module instead of the PBO/PAI.
To handle a lock entry failure, invoke an error message (type E) to prevent any further progress but
leaving the user on the current screen. The user can then take an alternative action or continue to try to
lock the object. To minimize the impact on users, limit retries.
While activating buttons or boxes, activate the associated text as well. This enables the user to click on
either the button/box or the text.
Do not use AT PFnn in programs. Instead use the function name so that any method of invoking the
function will have the same effect as the use of the PF-Key.
Example:
AT SELECTION-SCREEN.
CALL FUNCTION 'FILE_GET_NAME'
EXPORTING
LOGICAL_FILENAME = P_LDSNME
IMPORTING
FILE_NAME = G_PDSNAME
EXCEPTIONS
FILE_NOT_FOUND = 01.
IF SY-SUBRC <> 0.
*-------No physical filename can be determined for &
MESSAGE E016(MG)WITH P_LDSNME.
ENDIF.
START-OF-SELECTION.
IF SY-SUBRC <> 0.
* Insert error processing here.
ENDIF.
6.6.6 Message
Messages are included at appropriate places to indicate illegal operation like no authorization, no data
found, etc. Although consistency with SAP-supplied messages is highly encouraged, do not use SAP-
A program should test the system return code field (SY-SUBRC) after any statements that could
potentially change its value unless the outcome of the statement is not important for subsequent
processing.
The return code should always be checked after any database table read/update statements or READ
statements.
For egE.G: SELECT * FROM TABNA.
…DO Processing
ENDSELECT.
IF SY-SUBRC = 0.
WRITE: / ‘ ‘
ENDIF.
CHECK, EXIT, REJECT, STOP is used to suspend processing or skip unnecessary processing.
CASE statements are clearer for legibility and slightly faster than IF-constructions. After about five
nested Ifs the performance of the CASE is more efficient.
WHILE is used instead of a DO+EXIT-construction, because WHILE is easier to understand and faster
to execute.
Do While
I1 = 0. I1 = 0.
DO. WHILE C1A = SPACE.
IF C1A NE SPACE. EXIT. ENDIF. ADD 1 TO I1.
ADD 1 TO I1. IF I1 GT 10. C1A = 'X'. ENDIF.
IF I1 GT 10. C1A = 'X'. ENDIF. ENDWHILE.
ENDDO.
Runtime Measure(in microsec): 5 Runtime Measure(in microsec): 3
Notes: The runtimes depicted in this manual are just sample measurement, they are measured on multi-
processor environment, and they are, however, not runtime measurement benchmarks.
Case Perform i Of …
* (I1 = 5 in this test) * (I1 = 5 in this test)
CASE I1. PERFORM I1 OF
WHEN 1. PERFORM PV1. PV1
WHEN 2. PERFORM PV2. PV2
WHEN 3. PERFORM PV3. PV3
WHEN 4. PERFORM PV4. PV4
WHEN 5. PERFORM PV5. PV5
WHEN 6. PERFORM PV6. PV6
WHEN 7. PERFORM PV7. PV7
WHEN 8. PERFORM PV8. PV8.
Runtime Measure(in microsec): 5 Runtime Measure(in microsec): 2
LOOP …. WHERE is faster than LOOP/CHECK because LOOP …. WHERE evaluates the specific
condition internally.
Loop/Check Loop/Where
LOOP AT ITAB. LOOP AT ITAB WHERE NAME1 = KVAL.
CHECK ITAB-NAME1 = KVAL. ……….
ENDLOOP. ENDLOOP.
Avoid the use of this statement. The expressed use of “MOVE” is recommended.
The way construction of SQL statements are construction within an ABAP program will have an affect
ons its overall runtime performance. The developer’s role should be to build programs that access the
database in the most efficient manner. Awareness of the following rules during the design phase will
aid the decision-making process:
Minimise the number of transfers between the databases and application server.
Minimise the amount of data to be transferred between the databases and application server.
Minimise the workload of the database.
Aim to retrieve only the database table columns required. That is, limit the usage of the Select All fields
(Select *) statement to scenarios which dictate the need to transfer all the table’s columns from the
database to the program. The number of columns retrieved may be restricted in two ways:
Specification of a field list within the SELECT clause; or
Use of a DDIC table view projection. (A DDIC view has the added advantage of being
reusable).
SELECT statement that specifies all fields SELECT statement with a field list
specified
SELECT * FROM DD01L SELECT DOMNAME FROM DD01L
WHERE DOMNAME LIKE 'CHAR%' INTO DD01L-DOMNAME
AND AS4LOCAL = 'A'. WHERE DOMNAME LIKE 'CHAR%'
ENDSELECT. AND AS4LOCAL = 'A'.
ENDSELECT.
Runtime Measure(in microsec): 42,880 Runtime Measure(in microsec): 11,402
Use a select list with aggregate functions instead of checking and computing, when try to find the
maximum, minimum, sum and average value or the count of a database column, thus network load is
considerably less.
Aim to minimise the number of database table rows retrieved. The specification of the WHERE-clause
avoids the need to retrieve each row of a database table to determine whether it is valid or not for
further processing.
A justification to omit the WHERE-clause is when the entire contents of the database table are required.
The once-only read of a reference value table would fit this criterion.
A WHERE-clause should be formulated to employ a database table index. Each SAP database table has
a primary key (UNIQUE index) and maybe one or more secondary keys defined that supports efficient
searches of its content. Avoid the use of unsupported SELECT statements that result in expensive
searches.
When the primary key can be fully qualified make use of the SELECT SINGLE option instead of
SELECT-ENDSELECT. SELECT SINGLE requires one communication with the database system
whereas SELECT-ENDSELECT needs two.
In the scenario where the available primary or secondary keys defined for a table cannot be fully
qualified then consider the following options:
Evaluate the source of data being used and identify whether an alternative table exists (that
contains the desired data) that can be accessed more efficiently. For example, an unsupported
read on a large (CLUSTER) table like BSEG should be replaced with a read on one of the
accounting secondary indexed tables (BSAD, BSID, BSIS, BSAS, BSAK, BSIK).
Create a new secondary index for the target table in the DDIC.
Make use of the “UP TO N ROWS” option in the FROM-clause to restrict the number of table
rows returned.
Index utilisation is part of the “Minimize the Amount of Data Transferred” objective. To ensure that the
actual table search is optimal developers heed the following factors:
Satisfy as much of the chosen index definition as possible. The database optimiser can still
make use of an index even though the query does not make use of all of the columns specified
in its definition. In this case the sequence of the columns in the index is important as a column
can only be used if all of the columns preceding it in the index’s definition have also been
specified as part of the condition.
Phrase each condition within the query to be positive where possible. Use of negative
operators such as “Not Equal” or “Not Exist” or “Not Like” disables the database optimizer
from using a table index.
The use of equality (EQ) checks and conjunctions (AND) are the most efficient expressions.
“OR” expressions may prevent the database optimiser making use of the full index. This
means that the index columns involved in the “OR” expression may not be included in the
index search. An exception to this are “OR” expressions at the outside of conditions.
SAP ABAP Developer Handbook Page 63 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
6.7.2.1.3 INTO Clause
Use the “INTO TABLE” OR “APPENDING TABLE” options rather than Append each record one at a
time.
It is recommended that the use of the ORDER BY clausestatement should be used in SELECT if we use
the is restricted to when the primary indexkey is fully qualified. else sorting is effective by Otherwise,
readingstore the data intoin an internal table and use the ABAP SORT statement in the program.
Whenever possible, uUse array operations instead of single-row operations to modify your database
tables. The frequent communication between the application program and database system produces
considerable overhead.
Whenever possible, uUse column-specified table updates instead of single-rowentire row updates. to
update your database tables. Network load can then be considerably less.
Avoid the use of nested select statements. Instead use one of the following options:
Table join statement,
DDIC view,
Sub-query select statement
“For All Entries” statement.
o Ensure that the internal table contains at least one entry; and
o Sort internal table by the fields to be used in the WHERE-clause.
Aim to read a given set of data once. Repeated reads of the same data increases the number of database
accesses and increases the load on the database. An example of a repeated read is SELECT before an
UPDATE.
Table buffering on the application server for accessing frequently used, read-only tables, network load
can be considerably less. However, in case of retrieving latest data in multi-user environment, you may
need to bypass the buffer.
For a buffered table do not to use any Open SQL statements that bypass the buffer. The SELECT
statement will bypass the table buffer when any of the following options are used:
The use of a logical database is an option supplied by SAP to limit the database workload. A logical
database executes authorization checking for data access, but even if you just access one table, you will
still need to access all the tables above the current hierarchy level in logical database, which creates
data access inefficiency.
Internal table access can be done more efficiently with the right use of the table type. See
documentation on ABAP keyword TABKIND for the different table types:
any
index
standard
sorted
hashed
Apart from performance advantages that can be obtained, the different table types can have a different
syntax for table operations. Please refer to the online help for more details.
Especially with large amounts of data, internal table access can take a lot of time if the wrong table type
is used.
When loading data into Internal table, INTO TABLE OR APPENDING TABLE is used instead of a
SELECT/APPEND combination.
Use one-step approach READ/INSERT, If the amount of data is small (< 20 entries), or if users need
read-access to the internal table while it is being filled, however, if the data amount is larger and you
need read-access only to the completely-filled table, the two-step algorithm APPEND/SORT or three-
step approach APPEND/SORT/DELETE DUPLICATE (for tables without duplicates) is preferable.
COLLECT is used instead of READBINARY/INSERT If number of entries greater than 1000. READ
BINARY runs in O(log2 (n)) time, and the internal table's index must be adjusted with each INSERT,
however, COLLECT uses a hash algorithm and is therefore independent of the number of entries and
does not need to maintain a table index. If the amount of data is small, the READ/INSERT approach
isn't bad, but for large amounts of data (> 1000), COLLECT is much faster.
Use BINARY SEARCH instead of linear search when internal table has more than 20 entries. If TAB
has n entries, linear search runs in O(n) time, whereas binary search takes only O(log2 (n)). And also
when reading a single record in an internal table, the READ TABLE WITH KEY is not a direct READ.
Therefore, SORT the table and use READ TABLE WITH KEY BINARY SEARCH.
READ TABLE TAB WITH KEY K = 'X'. READ TABLE TAB WITH KEY K = 'X'
BINARY SEARCH.
Runtime Measure(in microsec): 875 Runtime Measure(in microsec): 11
Specify the key fields for read access explicitly, use READ TABLE WITH KEY k = ‘X’ instead of
READ TABLE WITH KEY. Otherwise, the key fields have to be computed dynamically by the run
time system.
Access via implicit default key Access via key specified explicitly
* Table TAB is filled with 30 entries of 500 bytes * Table TAB is filled with 30 entries of 500 bytes
each each
* The READ ends with SY-SUBRC=4 * The READ ends with SY-SUBRC=4
LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified
condition internally. The performance can be further enhanced if LOOP ... WHERE is combined with
FROM i1 and/or TO i2, if possible.
Internal tables can be compared, copied in logical expressions just like other data objects. Two internal
tables are equal if
- They have the same number of lines and
- Each pair of corresponding lines is equal.
Pedestrian way to compare internal tables Let the kernel to do the work …
* Tables TAB1 & TAB2 are each filled with 100 * Tables TAB1 & TAB2 are each filled with 100
entries entries
SAP ABAP Developer Handbook Page 69 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
* of 100 Bytes each. * of 100 Bytes each.
IF TAB_DIFFERENT = SPACE.
" ...
ENDIF.
Runtime Measure(in microsec): 741 Runtime Measure(in microsec): 152
Specify the sort fields on the sort statement, not leave the fields as default, the more restrictively you
specify the sort key, the faster the program will run.
Sort internal table with default sort key Sort with sort key specified explicitly
* Table TAB is filled with 100 entries of 500 bytes * Table TAB is filled with 100 entries of 500
each bytes each
Use parallel cursor instead of join two tables or nested loop. If TAB1 has n1 entries and TAB2 has n2
entries, the time needed for joining TAB1 and TAB2 with the straightforward algorithm is O( n1 *
log2( n2 ) ), nested loop is O( n1 * n2 ), whereas the parallel cursor approach takes only O( n1 + n2 )
time.
Native join: loop tab1, read tab2 with key More sophisticated: use parallel cursor
* Table TAB1 is filled with 1000 entries of 100 * Table TAB1 is filled with 1000 entries of 100
bytes each bytes each
* Table TAB2 is filled with 300 entries of 100 * Table TAB2 is filled with 300 entries of 100
bytes each bytes each
* Table TAB2 is assumed to be sorted by K in * Tables TAB1 & TAB2 to be sorted by K
ascending ascending
* order
I2 = 1.
LOOP AT TAB1. LOOP AT TAB1.
READ TABLE TAB2 WITH KEY READ TABLE TAB2 INDEX I2.
K = TAB1-K BINARY SEARCH. IF SY-SUBRC <> 0. EXIT. ENDIF.
IF SY-SUBRC = 0. IF TAB2-K = TAB1-K.
" ... " ...
ENDIF. ADD 1 TO I2.
ENDLOOP. ENDIF.
ENDLOOP.
Runtime Measure(in microsec): 16,723 Runtime Measure(in microsec): 6,228
Straight forward nested loop More sophisticated loop: parallel cursor
* Table TAB1 is filled with 100 entries of 100 * TAB1 is filled with 100 entries of 100 bytes
SAP ABAP Developer Handbook Page 70 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
bytes each each
* Table TAB2 is filled with 10 * 100 = 1000 * TAB2 is filled with 10 * 100 = 1000 entries of
entries of 100 bytes each
* 100 bytes each * TAB1 & TAB2 assumed to be sorted by K in
ascending order
LOOP AT TAB1. I2 = 1.
LOOP AT TAB2 WHERE K = TAB1-K. LOOP AT TAB1.
“… LOOP AT TAB2 FROM I2.
ENDLOOP. IF TAB2-K <> TAB1-K.
ENDLOOP. I2 = SY-TABIX.
EXIT.
ENDIF.
“…
ENDLOOP.
ENDLOOP.
Runtime Measure(in microsec): 180,472 Runtime Measure(in microsec): 8,839
Use the MODIFY variant “MODIFY itab ... TRANSPORTING f1 f2 ...” for single line, and
“MODIFY itab ... TRANSPORTING f1 f2 ...” WHERE condition for a set of line, to accelerate the
updating of internal table. The longer the table line is, the larger the speed-up is. The effect increases
for tables with complex structured line types.
Use APPEND LINES OF itab1 TO itab2 and INSERT LINES OF itab1 INTO itab2 INDEX idx instead
of APPEND and INSERT. And thus the task of appending and insert a table to another table can be
transferred to the kernel.
Use DELETE ADJACENT DUPLICATES / DELETE itab FROM ... TO ... / DELETE itab [FROM ...]
[TO ...] WHERE ... instead of DELETE, to transfer the task of deleting entries to the kernel.
Use “DELETE itab WHERE ...” instead of “LOOP AT itab WHERE ... DELETE itab. ENDLOOP.”
increases with the number of entries the internal table contains and the number of lines to be deleted.
If the data is processed only once, use a SELECT-ENDSELECT loop instead of collecting data in
an internal table with SELECT ….INTO TABLE because the Internal table handling takes up much
more space.
Internal tables can be copied by move just like any other data object.
Use the special operators CO, CA, CS, instead of programming the operations yourself. If ABAP
statements are executed per character on long strings, CPU consumption can rise substantially.
Some function modules for string manipulation have become obsolete and should be replaced by ABAP
statements or functions:
STRING_CONCATENATE... -> CONCATENATE,
STRING_SPLIT... -> SPLIT,
STRING_LENGTH -> strlen(),
STRING_CENTER -> WRITE...TO...CENTERED,
STRING_MOVE_RIGHT -> WRITE...TO...RIGHT-JUSTIFIED,
Use the CONCATENATE / SPLIT statement instead of programming a string concatenation of your
own.
"Mrs. Jane Miller from New York City" I "Mrs. Jane Miller from New York City" i
Use of SEARCH and MOVE with Offset Use of the SPLIT statement
"CMA contains '(410)-45174-66354312' and shall "CMA contains '(410)-45174-66354312' and shall
"be split into AREA_CODE, "be splitted into AREA_CODE,
" TEL_NO1, " TEL_NO1,
" TEL_NO2. " TEL_NO2.
SEARCH CMA FOR '-'.
MOVE CMA(SY-FDPOS) TO AREA_CODE.
I1 = SY-FDPOS + 2. SPLIT CMA AT '-' INTO AREA_CODE
SEARCH CMA FOR '-' STARTING AT I1. TEL_NO1
I1 = I1 - 1. TEL_NO2.
MOVE CMA+I1(SY-FDPOS) TO TEL_NO1.
I1 = I1 + SY-FDPOS + 1.
MOVE CMA+I1 TO TEL_NO2.
Runtime Measure(in microsec): 27 Runtime Measure(in microsec): 4
If you want to delete the leading spaces in a string, use the ABAP statement SHIFT...LEFT
DELETING LEADING.... Other constructions (with CN and SHIFT...BY SY-FDPOS PLACES, with
CONDENSE if possible, with CN and ASSIGN CLA+SY-FDPOS (LEN) ...) are not as fast. In any
case, avoid using SHIFT inside a WHILE-loop!
Use the STRLEN( ) function to restrict the DO loop to the relevant part of the field, e.g. when
determining a check-sum.
I1 = STRLEN( CLA ).
DO 64 TIMES VARYING STR FROM CLA DO I1 TIMES VARYING STR FROM CLA
NEXT CLA+1. NEXT CLA+1.
CHECK STR NE SPACE. CHECK STR NE SPACE.
ADD STR-LINE TO CHECK_SUM. ADD STR-LINE TO CHECK_SUM.
ENDDO. ENDDO.
Use "CLEAR f WITH val" whenever you want to initialize a field with a value different from the field's
type-specific initial value.
6.8.2 BAPI’s
It is difficult to formalize the contents and functional scope of a BAPI. Every BAPI has a different
functional content, even those that perform similar functions, for example, the standardized BAPIs. The
differences are mainly due to the different characteristics of SAP business object types and their
contents.
Minimize interface complexity. Supply the BAPI with the minimum of data and group the data from a
business perspective. Structure your BAPI in the most efficient way. BAPIs must not invoke COMMIT
WORK commands. In the case of exceptions: If the BAPI contains a COMMIT WORK command; this
must be documented.
CALL TRANSACTION
SUBMIT REPORT
SUBMIT REPORT AND RETURN
INCLUDE structures must not be used in BAPI structures. Database changes can only be made through
updates. The global memory must not be used to transfer values. Due to transparency it is strongly
recommended not to use Set and Get. If required every BAPI must be able to carry out its own
SAP ABAP Developer Handbook Page 75 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
authorization checks. Values relevant for Customizing are not allowed to be changed. Language-
dependent values cannot be used as interface parameters.
BAPIs must not produce any screen output. This means that lists, queries and dialog boxes must not be
returned to the calling program. This is true for the BAPI itself and for any function module that may be
indirectly called by the BAPI.
BAPIs must not cause program terminations, they can only return a message (type A: termination
message) in the return parameter. Messages of type E (error) and A (termination) cannot be output in
the program.
Standardized parameters must be implemented consistently. Each BAPI must have a return parameter
for returning messages to the calling application. All quantity and amount fields must be assigned
quantity unit fields. All currency amount fields must be assigned currency IDs. All key fields in
GetDetail() and GetList() BAPIs must be displayed as text fields. Whenever possible, F4 input help for
fields in BAPI parameters must be made available
Except for:
You must always use a period for the decimal point. Currency amounts with decimal points must be
formatted with a decimal point in the interface. For example, the value "10.12" must be formatted as
"10.12" and not as "1012".
If the BAPI to be implemented is a standardized BAPI, use the generic names, for example,
GetList, GetDetail. You should particularly note the difference between reading and writing
methods and between simple and multiple methods.
The individual components of a BAPI name are separated by the use of upper and lower case.
Example: GetList
Underscores ("_") are not allowed in BAPI names.
Each BAPI has a return parameter that is either an export parameter or an export table.
Customers can enhance BAPIs, each BAPI must have an ExtensionIn and an ExtensionOut
parameter.
Obligatory parameters should be checked to see if they can become optional in the future. This
is important to avoid possible incompatible changes to the interface and to guarantee the
stability of the interface.
If standardized parameters are used, you have to use the names specified for standardized
parameters.
BAPI parameter names should be as meaningful as possible.
The components of a parameter name in the BOR are separated by upper and lower case letters
to make them easier to read. Example : FlightList.
Values that belong to each other semantically should be grouped together in one structured
parameter, instead of using several scalar parameters.
SAP ABAP Developer Handbook Page 76 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
For ISO-relevant fields (country, language, unit of measure, currency), additional fields for
ISO codes are provided.
Unit of measure fields must accompany all quantity fields and currency identifiers must
accompany currency amount fields
6.8.3 IDOC’s
Below are some of the design guidelines and formatting rules for creating new segments and IDOC
types,
Do not re-invent the wheel. Before you create a new segment, check whether your
requirements can be met by an existing segment.
Group your data in a meaningful manner. Business data is contained in segment fields. Data
which belongs together from a logical point of view should be combined to form a segment.
Segments which belong together from a logical point of view should be combined to form a
segment group. For example, the materials in a purchase order could be contained in one
segment. Together with other segments (information about the partner, taxes and terms of
payment), this segment can then form part of the "Items" segment group.
Create universal segments. You can use segments which you have already created in other
IDoc types. Check whether a segment can be used for different messages. An example of a
universal segment is one which contains general address data.
Create clearly arranged segments and segment groups. Position the required fields as close as
possible to the start of the segment. Two segments which always occur together should be
combined in one segment. Consider whether the use of qualifiers can be avoided. Qualifiers
indicate how a segment is used and are difficult to document and interpret. Qualifiers are not
usually defined on a cross-application basis, with the result that these segments are not
universal.
Don’t waste space. The maximum length of all the fields in a segment is 1000 characters. The
larger the segment, the better the ratio of useful data to administration data. A certain amount
of space should be reserved in segments to allow for additional fields in the future.
Document your segments. Use the documentation options provided by the segment editor. You
can store an additional data element for each field to provide information about how the field
is used in the application. You can also document a segment to explain the attributes and
structure of the entire segment. When documenting segments, remember that the segment
fields are used in both inbound and outbound processing.
Remember that conversion to EDI standards may be necessary.
The segment fields may only contain alphanumeric data. You can make sure that this is the
case by using data elements which contain characters in the segment fields.
No distinction is made between upper case and lower case letters.
The fields are maintained in such a way that the values are left-justified.
The standard date representation (without qualifiers) is YYYYMMDD. February 28, 1996 is
therefore represented as 19960228.
The standard time representation (without qualifiers) is HHMMSS. 8.35pm is therefore
represented as 203500.
Values with a fixed decimal point are represented with a decimal point only - there is no
thousand delimiters. Negative values are indicated by a minus sign after the value. The number
-2,097,152.64 is represented as 2097152.64-.
Floating point numbers are represented with a decimal point - there is no thousand delimiters.
Negative values are indicated via a minus sign after the value and the exponent is always
specified. The number -23.4 is represented as -2.34E+01.
The following rules may be useful if your IDocs are to be converted to other EDI standards (EDIFACT,
ANSI X12):
If possible, segment fields in the IDoc should be represented directly by EDI data elements.
Avoid splitting or combining fields or other changes which could lead to problems with
automatic conversion.
SAP ABAP Developer Handbook Page 77 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
The field length should be equal to the maximum length of the SAP application or relevant
EDI standard (depending on which is longer), so that all the existing information can always
be transferred.
The required segment fields in the EDI standard must be present in the IDoc segment, to
ensure that the IDocs can be converted correctly.
During the design phase, the enhancements that are needed are going to be decided, at the least at a
higher level. During the development of code phase, developer finds out some more areas where the
The enhancement options that exist in the standard must be checked first before a formal proposal for
modification is requested. The enhancement decision can be made based on the following order,:
The Enhancement concept provides a Fframework to provides a technology for enhanceding core
source code units without modifying Modificationthem. The basic mechanism is to offer the so-called
enhancement options in development objects. These enhancement options function like “hooks” where
you can attach the enhancements.
There are different kinds of technologies that provide enhancement Enhancement options:
Source code enhancements – enhancement points are positions in the source code where you
can attach source code plug-ins which enhance the source code at these positions. While a
source code plug-in at an enhancement point is processed in addition to the original code, the
code of an enhancement section is substituted by the respective source code plug-in. Program-
bound enhancement implementations in a multiple-use include can only be displayed when the
related main programs are generated. The programs, function groups, classes, and so on can be
generated within the respective editors. Alternatively, transaction SGEN can be used to
perform a mass generation in a system.
Function group enhancements – you can enhance the interface of a function module by
additional parameters using function group enhancements.
Class enhancements – you can add additional methods, optional parameters, pre- and post-
methods to existing methods.
BAdIs – object-oriented enhancement options. The BAdI defines an interface that can be
implemented by classes that are transport objects of their own. The new BAdI is fully
integrated into the Enhancement Framework. Within the Enhancement Framework, a BAdI is
an enhancement option or an anchor point for an object plug-in.
Web Dynpro Enhancements
Enhancements in the Switch Framework
If you are developing an application which can be used more frequently and by used large number of
users, add enhancement into your custom built program.
It helps user to add something at later stage without modifying the custom code.
There are two ways to implement the same,
Enhancement spots are used to manage explicit enhancement options. Enhancement spots carry
information about the positions at which enhancement options were created. The enhancement spot is a
similar concept to a ‘SAP Enhancement’ and the enhancement options corresponds to a user exit within
a ‘SAP Enhancement’.
You create an explicit enhancement option when processing a Repository object with the relevant tool
by creating an enhancement spot element definition at a point where this is possible. This enhancement
option can then be called at different points using enhancement spot element calls. The enhancement
spot element definition and the corresponding enhancement spot element calls make up the definition of
an enhancement option. For example, when editing an ABAP program with the ABAP Editor, you can
define explicit enhancement options in the form of the ENHANCEMENT-POINT statement, which
also represents the element definition and element call.
Where enhancement spots exist in SAP these should be used to provide custom modifications.
Transaction SE18 can be used to view Enhancement Spots.
Standard tables may be enhanced using theThe Append technique permits the enhancement of a
transparent table or structure APPEND Structures. This allows you to enhance tables without making
any in a modification-free manners and it is not overwritten the next time the table object is transported
from the standard systemwhich is protected from SAP updates. An Append structure can only be
assigned to exactly one table or structure albeit a table or structure can have many Append statements.
Append Structures follow the naming pattern as Z* or Y*. Underscores ‘_’ are not allowed in
the name at 2nd &3rd character.
The fields in the append structure must also reside in the customer namespace. That is, - a field
name should begin with ZZ or YY.
SAP may make available one or more pre-define append structures names available for use at
the time of creation. This structure can be added to the standard table as an appended structure.
Customer Append structures are not permissible for Pool tables and Cluster tables.
SAP ABAP Developer Handbook Page 80 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
6.9.2.1.2 Customer/Customizing Include
Some SAP standard tables contain a reserved part for enhancements occupied by a special structure
called a Customer or Customizing Include. These special structures can be identified in the DDIC with
the prefix “CI_”. Like the Append technique a customer’s changes are protected from SAP updates.
The fields in the Customer/Customizing Include must reside in the customer namespace. That
is, - a field name should begin with ZZ or YY.
A Customer/Customizing Include may be reused in multiple tables or structures. If APPEND
structure is already added, we may add a customer include. There are customer includes that
include structures with the prefix “CI_”. These enhancements cannot be lost when upgrading.
If a table or structure of the standard system is enhanced with customer fields using a
customizing include, these customer fields are automatically inserted in the new delivered
table or structure definition during an upgrade.
The terms “Customer Include” and “Customizing Include” are used synonymously.
6.9.2.1.3 Views
Note:
1. An APPEND structure can only ever be added to one table, because it contains a reference to this
table.
2. APPEND structures cannot be added to pool tables or cluster tables, such as table BSEG.
3. If there are views (projection views, help views, and maintenance views) of tables that have been
enhanced using APPENDs or INCLUDEs, these views usually need to be enhanced accordingly and
regenerated if you want the new fields to appear in them.
4. When tables are enhanced using APPENDs or INCLUDEs the number of fields in the corresponding
physical database tables increases. There is usually an upper limit to the number of fields that are
permitted. Be aware of that limit.
The Modification Assistant is a tool that makes it easier to reconcile Modified objects with their
respected upgrade versions. The Modification Assistant is integrated into the ABAP Development
Workbench and logs all changes that are made to standard objects.
The use of Modification Assistant is compulsory within EDF Energy. An exception is this rule is when
a change is made to a custom object that is foreign to that system. This change will be recorded in a
change request with a task typed as a repair. EDF Energy operates two transport routes (one for
Production and another for Projects) custom development objects imported from the Projects route into
the Production route will be identified as copies because they are not original to the Production route.
7 SAP NOTES
8 QUALITY ASSURANCE
This section focuses on aspects of quality assurance. Development efforts that include quality
assurance activities produce better deliverables than those that do not. Two techniques used
to improve quality are unit testing and technical reviews.
A good Unit Test plan is always helpful in putting together the conditions and various inputs that the
individual objects have to be tested with. The following template can be used to write this test plan.
During the actual testing, it serves as a check list. It is also important to collect the results in the form of
Remarks/Comments in this document to ensure completeness.
The template for creating a unit test plan for each object to be tested is linked below.
Find attached the Code Review checklist and Design review checklist which should be completed by
the Reviewer during the Code Review Phase.
9 SAP NOTES
10 APPENDIX
ABAP features a class-based exception concept. It is similar to the corresponding concept in Java, but
offers the user more flexibility in a number of aspects. When you write new code, you should only use
the new class-based exceptions for error handling.
ABAP http://help.sap.com/saphelp_nwpi71/helpdata/en/
43/55509bf8a75f6be10000000a1553f6/frameset.htm
Function Library http://help.sap.com/saphelp_nwpi71/helpdata/en/2a/
f9ff44493111d182b70000e829fbfe/frameset.htm
SDN - ABAP https://www.sdn.sap.com/irj/sdn/abap
The objective is to ensure that a consistent approach is adopted across the Orchard Programme which is
robust, flexible and consistent across all Orchard SAP systems and environments.
10.5.3 Summary
Interface files will be delivered to and retrieved from a consistent location on all SAP systems
Logical file names / file paths will be used within custom developments rather than hard
coding or the use of input parameters.
Mapping of logical file names / file paths to physical file names / file paths will be done using
the SAP Standard Transaction “FILE”.
Manual retrieval of Interface Files or Background Scheduled Reports will use a standard
approach.
It does not apply where idocs or ALE are used as the means of passing data
Note: Although specifically intended for SAP systems the same physical directories could be used
on non SAP systems if required.
The directory structures will have the following physical location formats:
Where:
/interfaces/ is a mounted file system on the appropriate NFS server
(Development, Test, Production).
<SYSID> is the SAP system identifier e.g. SD1 for the Retail IS-U
Development system
<INTERFACE_NAME> is the name of the interface e.g. “thamescard”
For example the following screen shot (from EDF Energy Corporate SAP system) shows the mapping
of the Logical File Name “Z_BACS” to the physical location
“/interfaces/<SYSID>/bacs/”
SAP ABAP Developer Handbook Page 86 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
Custom developments must not contain hardcoded physical locations, but must use Logical Names as
described in the next section.
Note: The FILE transaction can be used to map a logical name to a fully qualified physical file name
or to all or part of the physical path as proposed in this document.
Using the previous example if l_fname = “Z_BACS” the function module would return
“/interfaces/SD1/bacs/” in the SD1 system.
For inbound files “inbound/<FILE_NAME>” would have to be appended to the returned physical
location in order to generate the fully qualified filename for the required inbound file. Similarly for
outbound files “outbound/<FILE_NAME>” would have to be appended to the returned physical
location in order generate the fully qualified filename for the required outbound file.
Note: <FILE_NAME> should normally follow the convention specified in section 3.6.1 of the
Orchard SAP ABAP Developer Handbook.
Note: Where a custom development is used to process only a single file type then the appropriate
Logical File Name should be hardcoded into the development as a parameter (so that it can
easily be amended if required)
If a custom development can be used to process more than one file type then it is suggested
that the Logical File Name be included as an input parameter so that for a particular variant the
program will process the appropriate files.
If an inbound file has not been processed successfully it may be moved from the
“/interfaces/<SYSID>/<INTERFACE_NAME>/inbound/” directory to an error sub-directory -
“/interfaces/<SYSID>/<INTERFACE_NAME>/inbound/error” - depending on the functional
requirements for error processing.
Note: A UNIX script will be run on a regular basis to deleted old files form the
/interfaces/<SYSID>/<INTERFACE_NAME>/inbound/processed directories as part of routine system
housekeeping.
Step 1. On the report selection screen, if a file download option is selected, the user should be
asked to provide a unique identifier which will be used as part of the file name e.g.
“MPAN20080106”
Step 2. The users id “SY_USERID” is used as a prefix to the identifier in step 1 to create the
full filename. Thus if the logged on user’s ID is “white1p” then the created file name
is “white1p_MPAN20080106.csv”
Step 3. The physical file path is obtained as described earlier in this document using the
Logical File Name “Z_MANUAL_DOWNLOAD”. E.g. in system SD1 the return
physical file path might be “/interfaces/SD1/manualdownloads/”.
Step 4. The outbound file would be created with the name from step 2 in the physical
directory from step 3. I.e.
“/interfaces/SD1/manualdownloads/ white1p_MPAN20080106.csv”
To retrieve the file manually the user would be allowed to run transaction Z_REPORT_DOWNLOAD
which would run a custom program1 which would allow the user to browse the physical directory
corresponding to the Logical File Name “Z_MANUAL_DOWNLOAD” and a select file beginning
with their own user Id (SY-USERID). The selected file will then be downloaded to the file on their PC
the user has specified in the download program selection screen
For manual file downloads other than reports then a refinement of this approach may be adopted.
1
possibly based on existing EDF Energy program ZFILETRANSFER
SAP ABAP Developer Handbook Page 88 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
EMAIL is the email address that you wish to send this report to
o RECIPIENT_KEY. This is the name of the PROGRAMM that you want to get the
recipient list for.
o DOC_TYPE. This is the type of document that you are sending. This is optional
INT Text
XLS Excel format. NB you will need to add Tab delimiters ‘09’ and for
Carriage return ‘OD’.
DOC MS Word document
Tables
o MAIN_TEXT – This is a table that has a record length of up to 255 characters length.
The data stored in this table will be placed in the main body of the email.
o ATTACHMENT_DATA – this is a table that has a record length of up to 255
characters length. Any data that is held in this table will be sent to email as a Text
File. Any data written into this file will need to be formatted.
Exceptions
o TOO_MANY_RECEIVERS
o DOCUMENT_NOT_SENT
o NO_RECIPIENTS_FOUND
Coding Logic
o Create the subject line
The OBJ_Name field is defaulted to EMAIL
The Obj_DESCR is filled with the data held in the subject line
o Create the Main text – this is populated from the contents of Table MAIN_TEXT.
o Create the Attachment – this is populated from the contents of table
ATTACHMENT_DATA
o Build the Recipient list
Check to see if the table passed in the field RECIPIENTS exists in DD0L. If
it doesn’t, output an error message to state that no recipients have been
found.
Using RECIPIENT_KEY read that table held in RECIPIENTS and extract
the Recipients email addresses. IF there are no recipient email addresses
output an error message to state that no recipients have been found.
o Pass the parameters to Function Module SO_NEW_DOCUMENT_ATT_SEND_API1
If the return code doesn’t equal 0. Output an error message stating that the
Document has not been sent. (This could be due to the fact that the RFC
connection for Outlook has not been configured)
Domain 30 Y* Z*
Printer macro - Y* Z* 9*
Dynpro 4 9000-9999
If the screen does not belong
to a module pool in the
customer name range.
Package 30 Y* Z*
Enhancement 8 Y* Z*
Enhancement project 8 *
Function Builder
Function module 30 Y_* Z_*
Function group 26 Y* Z*
26 XZ*
User exit function module
26 *
User exit function module (customer-
specific)
IDOC development
Segment Type 27 Z1*
Segment Name 30 Z2*
30 Y* Z*
Basis IDOC type
30 *
Enhancement type
30 *
Logical message
Logical database 20 Y* Z*
Menu 20 Y* Z* +*
Module pool
Module pool for dialog 30 SAPDY* SAPDZ*
INCLUDES 30 DY* DZ*
30 SAPMY* SAPMZ*
Module pool for screens
30 MY* MZ*
INCLUDES
30 MP9*
Module pool for info types 30 MP9*
INCLUDES 30 SAPFY* SAPFZ*
Module pool for subroutines 30 FY* FZ*
30 SAPUY* SAPUZ*
INCLUDES
30 UY* UZ*
Module pool for update programs
INCLUDES
Message
Message ID 20 Y* Z*
Message number 3 900-999
Report Writer
Report 8 1. First character not numeric
Report group 4 1. First character not numeric
3 1. First character not numeric
Library
7 1. First character not numeric
SAP ABAP Developer Handbook Page 95 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
Standard layout
Standard task 8 9*
Standard role 8 9*
Search help 30 Y* Z*
SYSLOG message ID 2 Y* Z*
Table
Pooled tables and cluster tables 10 Y* Z* T9* P9* PA9* PB9*
PS9* PT9* HRT9* HRP9*
HRI9*
YY* ZZ* (in the append
Transparent tables 16 structure, if possible)
If included using the append
structure: YY* ZZ*
16
Table field
Transaction code 20 Y* Z* +*
Types in the ABAP Dictionary (Underscore allowed)
Data element 30 Y* Z*
Structure 30 Y* Z*
30 Y* Z*
Table type
EDM
Data model 10 Y* Z*
Entity 10 Y* Z*
View
Database view, projection view, 16 Y* Z*
maintenance view 16 H_Y* H_Z*
SAP ABAP Developer Handbook Page 96 of 97 Version: 0.1
Status: Draft
Confidential 20/01/2024 06 September 2011
Help view
View cluster 16 Y* Z*
View maintenance data
View content - reserved in TRESC
Table contents - reserved in TRESC