You are on page 1of 344

ABAP Programming (BC-ABA) 1

ABAP Programming (BC-ABA)


This documentation describes the programming of application programs on the SAP NetWeaer
Application Serer ABAP!
ABAP applications are "ritten in the ABAP programming language# and run "ithin the application
la$er of the SAP NetWeaer Application Serer ABAP!
ABAP programs communicate "ith the database management s$stem of the central relational
database (%&B'S) and "ith the presentation la$er! A SAP-specific graphical user interface (SAP
()*) for users logged on to a SAP S$stem and Web bro"sers for Web-based applications are
aailable to $ou as presentation la$ers!
Contents
The documentation is diided into the follo"ing sections+
*ntroduction to ABAP
This contains the basics of ABAP application programming! This information is essential for an
understanding of ABAP programming! ,ollo"ing an oerie" of the NetWeaer Application Serer
ABAP# it introduces the essential features of ABAP programs and the ABAP programming
language! ,inall$# it gies a short introduction to ho" $ou can create ABAP programs in the ABAP
Wor-bench!
ABAP Programming .anguage
This section describes the statements in the ABAP programming language! Beginning "ith simple
statements for data declarations# data processing# and program flo" control# it progresses to
topics such as "or-ing "ith internal tables and e/tracts# e/plaining "hich ABAP statements can
be used for "hich purposes!
0/ecuting ABAP Program )nits
This section e/plains ho" ABAP programs are e/ecuted on the application serer! *t sho"s ho"
$ou can start ABAP programs# the conditions under "hich $ou must start them# and the different
-inds of program e/ecution!
ABAP 1b2ects
This is an introduction to ABAP 1b2ects# the ob2ect-oriented e/tension of ABAP! 1b2ects#
classes# and interfaces are introduced as the fundamental elements of ABAP 1b2ects! *t is sho"n
ho" $ou can define classes $ourself or b$ using interfaces or inheritance! This section also coers
the handling of methods and eents as components of classes!
Appendi/
The appendi/ contains a s$stematic summar$ of important components of ABAP programs and a
list of all s$stem fields!
Introduction to ABAP
The NetWeaer Application Serer ABAP
The Components of ABAP Application Programs
Creating and Changing ABAP Programs
SAP NetWeaver Application Server ABAP
The follo"ing sections e/plain "hat NetWeaer Application Serer ABAP (NetWeaer AS ABAP
or SAP NW AS ABAP# for short) is! 3ou can also find information on "or- processes# "hich are
components of ABAP application serers!
1erie" of NetWeaer AS ABAP
ABAP Application Serer
Wor- Processes

Overview of NetWeaver AS ABAP
The follo"ing sections describe three different ie"s of NetWeaer AS ABAP!
ogical !iew
The difference bet"een the logical ie" and a hard"are- or soft"are-oriented ie" of
NetWeaer AS ABAP is that not all of the components sho"n can be assigned to a particular
ABAP Programming (BC-ABA) 4
hard"are or soft"are unit! The follo"ing illustration represents this logical ie" in form of a
bloc- diagram!

The follo"ing is a list of the tas-s of the three logical components in NetWeaer AS ABAP!
"ernel # Administration Services
The -ernel and administration serices component is a runtime enironment for all ABAP
applications that is $ardware-# operating s%stem- and data&ase-independent! The ABAP runtime
enironment is "ritten principall$ in C and C55! 6o"eer# some lo"-leel parts are also "ritten in
ABAP itself! The tas-s of the -ernel and administration serices component are as follo"s+
' (unning applications
All ABAP applications run on soft"are processors (irtual machines) "ithin this component!
7 )ser and process administration
NetWeaer AS ABAP is a multi-user enironment# and each user can run seeral independent
ABAP applications! *n short# this component is responsible for the tas-s that usuall$ belong to an
operating s$stem! )sers log onto the NW AS and run ABAP applications "ithin it! *n this "a$#
the$ do not come into contact "ith the actual operating s$stem of the host! NetWeaer AS ABAP
is the onl$ user of the host operating s$stem!
' )ata&ase access
0ach NetWeaer AS ABAP is lin-ed to a database s$stem# consisting of a database management
s$stem (&B'S) and the database itself! The ABAP applications do not communicate directl$ "ith
the database! *nstead# the$ use administration serices!
' Communication
ABAP applications can communicate both "ith other SAP S$stems and "ith e/ternal s$stems! *t
is also possible to access ABAP applications from e/ternal s$stems using a BAP* interface! The
serices re8uired for communication are all part of the -ernel and administration serices
component!
' Control and administration of NetWeaver AS ABAP
The component contains programs that allo" $ou to monitor and control the NW AS "hile it is
running# and to change its runtime parameters!
ABAP Wor*&enc$
The ABAP Wor-bench component is a full$-fledged development environment for applications in
the ABAP language! With it# $ou can create# edit# test# and organi9e these application programs!
*t is full$ integrated in NetWeaer AS ABAP and# li-e other ABAP applications# is itself "ritten
in ABAP!
ABAP Programming (BC-ABA) :
Presentation Components
The presentation components are responsible for the interaction bet"een the ABAP applications
and the user (input and output) and for des*top component integration (such as "ord processing
and spreadsheets) into the NW AS!
Software-Oriented !iew
The follo"ing illustration represents the soft"are-oriented ie" of an SAP S$stem! *n an ABAP-
based SAP S$stem# NetWeaer AS ABAP comprises all SAP ()* components and the ABAP
application serers!


An SAP S$stem is a multi-tier client;serer s$stem! The indiidual soft"are components are
arranged in tiers and function# depending on their position# as a client for the components belo"
them or a serer for the components aboe them! The classic configuration of an SAP S$stem
contains the follo"ing soft"are la$ers+
)ata&ase a%er
The database la$er# "hich is accessed b$ NetWeaer AS# consists of a central database s$stem
"hich in turn is made up of the database management s$stem (&B'S) and the database itself!
The database does not onl$ contain the master data and transaction data from $our ABAP
application programs< all data for NetWeaer AS ABAP is stored there! ,or e/ample# the
database contains the control and Customi9ing data that determines ho" NetWeaer AS runs and
the ABAP application programs themseles! The components (program te/ts# screen definitions#
menus# function modules# and so on) are stored in a special part of the database -no"n as the
%epositor$# and are therefore also referred to as %epositor$ ob2ects! 3ou "or- "ith them in the
ABAP Wor-bench!
Application a%er
The soft"are components of the application la$er of NetWeaer AS ABAP consist of one or more
ABAP application serers and a message serer! 0ach application serer contains a set of serices
used to run the NW AS! Theoreticall$# $ou onl$ need one application serer to run a NW AS! *n
practice# the serices are distributed across more than one application serer! This means that
not all application serers "ill proide the full range of serices! The message serer is
responsible for communication bet"een the application serers! *t passes re8uests from one
application serer to another "ithin a NW AS! *t also contains information about application
serer groups and the current load balancing "ithin them! *t uses this information to choose an
appropriate serer "hen a user logs onto the s$stem!
Presentation a%er
This la$er is the interface bet"een the SAP S$stem and its users! )sing its soft"are components
referred to as SAP ()* ((raphical )ser *nterface) this la$er proides an intuitie graphical
interface for entering and displa$ing data! The presentation la$er sends the user=s input to the
ABAP Programming (BC-ABA) >
application serer# and receies data for displa$ from it! While a SAP ()* component is running#
it remains lin-ed to a user=s terminal session in NetWeaer AS ABAP!
This soft"are-oriented ie" can be e/panded to include further la$ers# such as an *nternet
Transaction Serer (*TS)!
Software-Oriented !iew and +ardware !iew
The soft"are-oriented ie" has nothing to do "ith the hard"are configuration of the s$stem!
There are man$ different hard"are configuration possibilities for both la$ers and components!
When distributing the la$ers# for e/ample# $ou can hae all la$ers on a single host# or# at the
other e/treme# $ou could hae at least one host for each la$er! When dealing "ith components#
the distribution of the database components depends on the database s$stem $ou are using! The
application la$er and presentation la$er components can be distributed across an$ number of
hosts! *t is also possible to install more than one ABAP application serer on a single host! A
common configuration is to run the database s$stem and a single ABAP application serer
(containing special database serices) on one host# and to run each further application serer on
its o"n host! The presentation la$er components usuall$ run on the des-top computers of the
users!
Advantages of t$e ,ulti--ier Arc$itecture
The distribution of the SAP S$stem oer three la$ers means that the s$stem load is also
distributed! This leads to better s$stem performance! Another benefit is the high scalabilit$
achieed due to the fact that $ou can distribute the soft"are components of an SAP S$stem
among different hard"are units irtuall$ "ithout an$ restrictions! This is particularl$ aluable in
the application la$er# "here $ou can easil$ adapt NetWeaer AS ABAP to meet increasing demand
b$ installing further ABAP application serers!
The architecture of the SAP S$stem allo"s $ou to install the application la$er and the database
la$er on separate hosts and let them communicate using the net"or-! This considerabl$ reduces
the load placed on the database s$stem "hich contains the central data storage for NetWeaer
AS ABAP and therefore needs to fulfill high demands "hile the s$stem is running!
.i-e"ise# the separation of the presentation and the application la$er reduces the load placed on
the ABAP application serers b$ isolating user entr$ processing and data output formatting from
actual program e/ecution! *t is important to note that the SAP ()* and the ABAP application
serer are set up in a "a$ that reduces the moement of data bet"een the t"o la$ers to the
smallest possible degree! As a result# the components of the presentation la$er can een be used
on hosts that hae slo" connections to application serers a long "a$ a"a$!
.ser-Oriented !iew
The follo"ing illustration represents a SAP ()* user ie" of the SAP S$stem+
,or the user# the isible components of the SAP S$stem are those that appear as a "indo" on the
screen! These "indo"s are created b$ the presentation la$er of NetWeaer AS ABAP!
Before the user logs onto the SAP S$stem# he or she must start a SAP ()* utilit$ called SAP
.ogon# "hich is installed at the front end! *n SAP .ogon# the user chooses one of the aailable
SAP S$stems! The program then connects to the message serer of NetWeaer AS ABAP in the
SAP S$stem selected and obtains the address of a suitable (most lightl$-used) ABAP application
serer! *t then starts a SAP ()*# connected to that application serer! The SAP .ogon program
is then no longer re8uired for this connection!
SAP ()* starts the logon screen! 1nce the user has successfull$ logged on# it displa$s the initial
screen of the SAP S$stem in a "indo" on the screen! Within SAP ()*# each "indo" is
represented as a session! After logging on# the user can open up to fie further sessions wit$in
ABAP Programming (BC-ABA) ?
the single SAP ()*! These behae almost li-e independent SAP applications! The different
sessions allo" $ou to run different applications in parallel# independentl$ of one another!
Within a session# the user can run applications that themseles call further "indo"s (such as
dialog bo/es and graphic "indo"s)! These "indo"s are not independent - the$ belong to the
session from "hich the$ "ere called! These "indo"s can be either modal (the original "indo" is
not read$ for input) or amodal (both "indo"s are read$ for input and interact "ith each other)!
The user can open other SAP ()*s# using SAP .ogon# to log onto the same s$stem or another SAP
S$stem! The indiidual SAP ()*s and corresponding terminal sessions of a user are totall$
independent! This means that $ou can hae SAP ()*s representing the presentation la$ers of
seeral SAP S$stems open on $our des-top computer!
ABAP Application Server
ABAP application serers are important soft"are components of NetWeaer AS ABAP since all
ABAP progrums run on these serers! The follo"ing sections describe the structure and functions
of these application serers in more detail!
Structure of an ABAP Application Server
All ABAP application serers including the message serer represent the application la$er of the
multi-tier architecture of an ABAP-based SAP S$stem! These application serers e/ecute ABAP
applications and communicate "ith the presentation components# the database# and also "ith each
other# using the message serer!
The follo"ing diagram sho"s the structure of an ABAP application serer+

*n addition to seeral "or- processes "hose number and t$pe are determined at the startup of
NetWeaer AS ABAP# each ABAP application serer contains a dispatcher# a gate"a$ and the
shared memor$! The tas-s of these components are briefl$ described in the follo"ing+
Wor* Processes
Wor- processes are components that are able to e/ecute an application (that is# one dialog step
each)! 0ach "or- process is lin-ed to a memor$ area containing the conte/t of the application
being run! The conte/t contains the current data for the application program! This needs to be
aailable in each dialog step!
)ispatc$er
The dispatcher is the lin- bet"een the "or- processes and the users logged onto the ABAP
application serer (that is# the SAP ()*s of theseusers)! *ts tas- is to receie re8uests for
dialog steps from the SAP ()* and direct them to a free "or- process! *n the same "a$# it
directs screen output resulting from the dialog step bac- to the appropriate user!
/atewa%
ABAP Programming (BC-ABA) @
This is the interface for the communication protocols of NetWeaer AS ABAP (%,C# CP*;C)! *t
can communicate "ith other ABAP application serers of the same NW AS# "ith other SAP
S$stems# or "ith e/ternal non-SAP s$stems!
S$ared ,emor%
All of the "or- processes on an ABAP application serer use a common main memor$ area called
shared memor$ to sae conte/ts or to buffer constant data locall$!
The resources that all "or- processes use (such as programs and table contents) are contained in
shared memor$! 'emor$ management in the NetWeaer AS ABAP ensures that the "or-
processes al"a$s address the correct conte/t# that is the data releant to the current state of
the program that is running! A mapping process pro2ects the re8uired conte/t for a dialog step
from shared memor$ into the address of the releant "or- process! This reduces the actual
cop$ing to a minimum!
Advantages of t$is -%pe of Arc$itecture
The structure of the ABAP application serers described here supports the performance and
scalabilit$ of NetWeaer AS ABAP! The fi/ed number of "or- processes and dispatching of
dialog steps leads to optimal memor$ use# since it means that certain components and the memor$
areas of a "or- process are application-independent and reusable! The fact that the indiidual
"or- processes "or- independentl$ ma-es them suitable for a multi-processor architecture!
.ocal buffering of data in the shared memor$ of the ABAP application serer reduces the number
of database reads re8uired! This reduces access times for ABAP application programs
considerabl$! ,or optimal use of the buffer# $ou can concentrate indiidual applications (financial
accounting# logistics# human resources) into separate ABAP application serer groups!
)ata&ase Connection
When $ou start up a NetWeaer AS ABAP# each ABAP application serer registers its "or-
processes "ith the database la$er# and receies a single dedicated channel for each! While the
NW AS is running# each "or- process is a user (client) of the database s$stem (serer)! 3ou
cannot change the "or- process registration "hile the s$stem is running! Neither can $ou reassign
a database channel from one "or- process to another! ,or this reason# a "or- process can onl$
ma-e database changes "ithin a single database logical unit of "or- (.)W)# that is an inseparable
se8uence of database operations!
Wor* Processes
Wor- processes e/ecute the indiidual dialog steps of ABAP application programs! The$ are
components of ABAP application serers! The ne/t t"o sections describe firstl$ the structure of
a "or- process# and secondl$ the different t$pes of "or- process in NetWeaer AS ABAP!
Structure of a Wor* Process
The follo"ing diagram sho"s the components of a "or- process+
Screen Processor
*n ABAP application programming# there is a difference bet"een user interaction and processing
logic! ,rom a programming point of ie"# user interaction is controlled b$ screens! As "ell as the
actual input mas-# a screen also consists of flo" logic# "hich controls a large part of the user
interaction! NetWeaer AS ABAP contains a special language for programming screen flo" logic!
The screen processor e/ecutes the screen flow logic! Aia the dispatcher# it ta-es oer the
ABAP Programming (BC-ABA) B
responsibilit$ for communication bet"een the "or- process and the SAPgui# calls modules in the
flo" logic# and ensures that the field contents are transferred from the screen to the flo" logic!
ABAP Processor
The actual processing logic of an application program is "ritten in ABAP - SAP=s o"n programming
language! The ABAP processor e/ecutes the processing logic of the application program# and
communicates "ith the database interface! The screen processor tells the ABAP processor "hich
module of the screen flow logic should be processed ne/t! The follo"ing screen illustrates the
interaction bet"een the screen and the ABAP processors "hen an application program is running!
)ata&ase Interface
The database interface proides the follo"ing serices+
7 0stablishing and terminating connections bet"een the "or- process and the database!
7 Access to database tables
7 Access to %epositor$ ob2ects (ABAP programs# screens and so on)
7 Access to catalog information (ABAP &ictionar$)
7 Controlling transactions (commit and rollbac- handling)
7 Table buffer administration on the ABAP application serer!

The follo"ing diagram sho"s the indiidual components of the database interface+

The diagram sho"s that there are t"o different "a$s of accessing databases+ 1pen SC. and
Natie SC.!
1pen SC. statements are a subset of Standard SC. that is full$ integrated in ABAP! The$ allo"
$ou to access data irrespectie of the database s$stem that $our installation is using! 1pen SC.
consists of the &ata 'anipulation .anguage (&'.) part of Standard SC.< in other "ords# it
ABAP Programming (BC-ABA) D
allo"s $ou to read (S0.0CT) and change (*NS0%T# )P&AT0# &0.0T0) data! The tas-s of the
&ata &efinition .anguage (&&.) and &ata Control .anguage (&C.) parts of Standard SC. are
performed in NetWeaer AS ABAP b$ the ABAP &ictionar$ and the authori9ation s$stem! These
proide a unified range of functions# irrespectie of database# and also contain functions be$ond
those offered b$ the arious database s$stems!
1pen SC. also goes be$ond Standard SC. to proide statements that# in con2unction "ith other
ABAP constructions# can simplif$ or speed up database access! *t also allo"s $ou to buffer
certain tables on the ABAP application serer# saing e/cessie database access! *n this case# the
database interface is responsible for comparing the buffer "ith the database! Buffers are partl$
stored in the "or-ing memor$ of the current "or- process# and partl$ in the shared memor$ for
all "or- processes on an ABAP application serer! Where NetWeaer AS ABAP is distributed
across more than one ABAP application serer# the data in the arious buffers is s$nchroni9ed at
set interals b$ the buffer management! When buffering the database# $ou must remember that
data in the buffer is not al"a$s up to date! ,or this reason# $ou should onl$ use the buffer for
data "hich does not often change!
Natie SC. is onl$ loosel$ integrated into ABAP# and allo"s access to all of the functions
contained in the programming interface of the respectie database s$stem! *n Natie SC.# $ou
can primaril$ use database-specific SC. statements! The Natie SC. interface sends them as is
to the database s$stem "here the$ are e/ecuted! 3ou can use the full SC. language scope of the
respectie database "hich ma-es all programs using Natie SC. specific for the database s$stem
installed! *n addition# there is a small set of SAP-specific Natie SC. statements "hich are
handled in a special "a$ b$ the Natie SC. interface! ABAP applications contain as little Natie
SC. as possible! *n fact# it is onl$ used in a fe" components (for e/ample# to create or change
table definitions in the ABAP &ictionar$)!
The database-dependent la$er in the diagram seres to hide the differences bet"een database
s$stems from the rest of the database interface! 3ou choose the appropriate la$er "hen $ou
install NetWeaer AS ABAP! Than-s to the standardi9ation of SC.# the differences in the
s$nta/ of statements are er$ slight! 6o"eer# the semantics and behaior of the statements
hae not been full$ standardi9ed# and the differences in these areas can be greater! When $ou
use Natie SC.# the function of the database-dependent la$er is minimal!
-%pes of Wor* Process
Before $ou start NetWeaer AS ABAP# $ou determine ho" man$ "or- processes each ABAP
application serer "ill hae# and "hat their t$pes "ill be! Since all "or- processes hae the same
structure (see preceding section)# the t$pe of "or- process does not determine the technical
attrributes of the ABAP application serer but the t$pe of tas-s to be performed on it! The
dispatcher starts the "or- processes and onl$ assigns them tas-s that correspond to their t$pe!
This means that $ou can distribute "or- process t$pes to optimi9e the use of the resources on
$our ABAP application serers!
The follo"ing diagram sho"s again the structure of an ABAP application serer# but this time#
includes the arious possible "or- process t$pes+

ABAP Programming (BC-ABA) E
)ialog Wor* Process
&ialog "or- processes deal "ith re8uests from an actie user to e/ecute dialog steps (see also
&ialog Programming)!
.pdate Wor* Process
)pdate "or- processes e/ecute database update re8uests! )pdate re8uests are part of an SAP
.)W that bundle the database operations resulting from the dialog in a database .)W for
processing in the bac-ground!
Bac*ground Wor* Process
Bac-ground "or- processes process programs that can be e/ecuted "ithout user interaction
(bac-ground 2obs)!
0n1ueue Wor* Process
The en8ueue "or- process administers a loc- table in the shared memor$ area! The loc- table
contains the logical database loc-s for NetWeaer AS ABAP and is an important part of the SAP
.)W concept! *n NW AS# $ou ma$ onl$ hae one loc- table! 3ou ma$ therefore also onl$ hae one
ABAP application serer "ith en8ueue "or- processes! Normall$# a single en8ueue "or- process is
sufficient to perform the re8uired tas-s!
Spool Wor* Process
The spool "or- process passes se8uential datasets to a printer or to optical archiing! 0ach ABAP
application serer ma$ contain onl$ one spool "or- process!
(ole of Wor* Processes
The t$pes of its "or- processes determine the serices that an ABAP application serer offers!
The application serer ma$# of course# hae more than one function! ,or e/ample# it ma$ be both a
dialog serer and the en8ueue serer# if it has seeral dialog "or- processes and an en8ueue "or-
process!
3ou can use the s$stem administration functions to s"itch a "or- process bet"een dialog and
bac-ground modes "hile the s$stem is still running! This allo"s $ou# for e/ample# to s"itch an SAP
S$stem bet"een da$ and night operation# "here $ou hae more dialog than bac-ground "or-
processes during the da$# and the other "a$ around during the night!
-$e Components of ABAP Application Programs
All ABAP applications# along "ith parts of NetWeaer Application Serer ABAP# are "ritten in
the ABAP Wor-bench deelopment enironment using ABAP (Adanced Business Application
Programming) "hich is SAP=s o"n programming language! The indiidual components of application
programs are stored in a special section of the database "hich is used as the central storage for
all deelopment ob2ects of the SAP S$stem and is called the %epositor$! The follo"ing sections of
this documentation coer the basics and characteristics of ABAP application programming!
ABAP Programming (BC-ABA) 1F

Application Programs on NetWeaer AS ABAP
)ser *nterfaces
ABAP Programming 'odels
Application Programs on NetWeaver AS ABAP
ABAP application programs run on the "or- processes of the ABAP application serers of
NetWeaer AS ABAP! This ma-es them independent of the hard"are and operating s$stem that
$ou are using! 6o"eer# it also means that $ou cannot run them outside NW AS ABAP!
As described in the Wor- Processes section# a "or- process contains a screen processor for
processing user input# an ABAP processor for processing the program logic# and a database
interface for communicating "ith the database! These components determine the follo"ing
structure of an application program+
An ABAP application program consists of t"o components# each of "hich has a different tas-+
Screen 2low ogic
The application program components "hich react to user action on SAP ()* "indo"ss are
implemented using screens! Screens are processed b$ the screen processor of a "or- process!
The$ contain screen mas-s and the screen logic "hich is programmed using a specific
programming language similar to ABAP! The input mas- is displa$ed b$ the SAP ()*# "hich also
transfers the user action on the screen bac- to the flo" logic! *n the program flo"# screens react
to the user actions and call program modules! These program modules form the processing logic!
Processing ogic
ABAP programs run on the ABAP processor of a "or- process! SAP ()*-based applications
receie screen input from and send screen output to the screen processor! 3ou access the
database using the database interface! ABAP contains a special set of commands called 1P0N
SC.! This allo"s $ou to read from and "rite to the database regardless of the database $ou are
using! The database interface conerts the 1P0N SC. commands into commands of the releant
database! 3ou can also use natie SC. commands# "hich are passed to the database "ithout first
being conerted! There is a range of further interfaces such as memor$# se8uential files and
e/ternal interfaces! These proide other means of sending data to and from ABAP programs!
.ser Interfaces
0ach SAP ()* "indo" that a user sees in the SAP S$stem belongs to a screen program of an
ABAP application! Screen programs react to user input on the ()* "indo"s# send data to the
screen and receie data from the screen! There are three "a$s to organi9e "indo" input and
output in the form of user interfaces "hose handling is directl$ integrated into the language!
These differ in the "a$ in "hich the$ are programmed# and in ho" the user t$picall$ interacts
"ith them!
/eneral Screens
7 *n the most general case# application deelopers create their screen programs on their o"n#
programming all details of the screen flo" logic and lin-ing them to self-defined screens! Both
tas-s are e/clusiel$ performed in the Screen Painter of the ABAP Wor-bench!
Selection Screens and ist Screens
ABAP Programming (BC-ABA) 11
7 ,or common cases# NetWeaer AS ABAP comes "ith t"o speciali9ed screen programs called
selection screens and list screens "hose screens and screen flo" logic are generated from ABAP
commands of the processing logic! *n this case# deelopers do not use the Screen Painter!

SAP ()* "indo"s contain menu &ars# standard tool&ars and application tool&ars! These three
ob2ects are used for the direct entr$ of user commands! Together# the$ form the /.I status!
0ach ()* status is an independent deelopment ob2ect of the associated application program and
conse8uentl$ not an internal part of an$ screen! *t can therefore be reused in an$ number of
screens! 3ou define the ()* status using the ,enu Painter in the ABAP Wor-bench! 3ou can
define $our o"n ()* statuses for general screens and lists! Selection screens hae a fi/ed
status!

Screens
0ach screen contains an input mas- that $ou can use for data input and output! 3ou can design the
mas- $ourself! When the screen mas- is displa$ed b$ the SAP ()*# t"o eents are triggered+
PB1 and PA*! Before the screen is displa$ed# the PB1 (Process Before 1utput) eent is
processed! When the user interacts "ith the screen# the PA* (Process After *nput) eent is
processed!
0ach screen is lin-ed to a single PB1 processing bloc- and a single PA* processing bloc- of the
screen flo" logic "hich react to these eents! The PA* of a screen and the PB1 of the
subse8uent screen together form a dialog step in the application program!
The screen flo" control language contains onl$ fe" language elements! Although the statements
are s$ntacticall$ similar to ABAP statements# both should not be confused! The most important
screen language elements are ,O).0# 2I0)# C+AIN# and OOP! Their onl$ function is to lin-
the processing logic to the screen flo" logic# that is# to call modules in the processing logic# and
control data transfer bet"een the screen and the ABAP program# for e/ample# b$ chec-ing fields!
The input;output mas- of a screen contains all of the normal graphical user interface elements#
such as input;output fields# pushbuttons# and radio buttons! The follo"ing diagram sho"s a t$pical
screen mas-+
ABAP Programming (BC-ABA) 14
All of the actie elements on a screen hae a field name and are lin-ed to screen fields in shared
memor$! 3ou can lin- screen fields to the ABAP &ictionar$! This proides $ou "ith automatic field
and alue help# as "ell as consistenc$ chec-s!
When a user action changes the element# the alue of the screen field is changed accordingl$!
Aalues are transported bet"een screens and the processing logic in the PA* eent# "here the
contents of the screen fields are transported to program fields "ith the same name!
0ach screen calls modules in its associated ABAP program "hich prepare the screen (PB1) and
process the entries made b$ the user (PA*)! Although there are ABAP statements for changing
the attributes of screen elements (such as ma-ing them isible or inisible)# but there are none
for defining them!
&ialog screens enable the user and application programs to communicate "ith each other! The$
are used in dialog-oriented programs such as transactions# "here the program consists mainl$ of
processing a se8uence of screens! 0ssentiall$# $ou use screens "hen $ou need more fle/ibilit$ than
is offered b$ selection screens or lists!
Selection Screens
Selection screens are special screens used to enter alues in ABAP programs! *nstead of using
the Screen Painter# $ou create them using ABAP statements in the processing logic of $our
program! The selection screen is then generated according to these statements! The screen flo"
logic is supplied b$ the s$stem# and remains inisible to $ou as the application programmer!
3ou define selection screens in the declaration part of an ABAP program using the special
declaration statements PA(A,0-0(S# S00C--OP-IONS and S00C-ION-SC(00N)! These
statements declare and format the input fields of each selection screen! The follo"ing is a t$pical
selection screen+
ABAP Programming (BC-ABA) 1:
The most important elements on a selection screen are input fields for single alues and for
selection tables! Selection tables allo" $ou to enter more complicated selection criteria! Selection
tables are eas$ to use in ABAP because the s$stem automaticall$ processes them itself! As on
other screens# field and possible alues help is proided for input fields "hich refer to an ABAP
&ictionar$ field! )sers can use pre-configured sets of input alues for selection screens! These
are called ariants!
3ou call a selection screen from an ABAP program using the CA S00C-ION-SC(00N
statement! *f the program is an e/ecutable program# the ABAP runtime enironment
automaticall$ calls the selection screen defined in the declaration part of the program! Selection
screens trigger eents# and can therefore call eent bloc-s in ABAP programs!
Since selection screens contain principall$ input fields# selection screen dialogs are more input-
oriented than the screens $ou define using the Screen Painter! &ialog screens can contain both
input and output fields! Selection screens# ho"eer# are appropriate "hen the program re8uires
data from the user before it can continue processing! ,or e/ample# $ou "ould use a selection
screen before accessing the database# to restrict the amount of data read!
ists
.ists are output-oriented screens "hich displa$ formatted# structured data! The$ are defined#
formatted# and filled using ABAP commands! The s$stem displa$s lists defined in ABAP on a
special list screen! As "ith selection screens# the flo" logic is supplied b$ the s$stem and remains
hidden from the application programmer!
The most important tas- of a list is to displa$ data! 6o"eer# users can also interact "ith them!
.ists can react to mouse clic-s and contain input fields! &espite these similarities "ith other
t$pes of screen# lists are displa$ed using a completel$ different techni8ue! *nput fields on screen
lists cannot be compared "ith those on normal screens# since the method of transferring data
bet"een the list screen and the ABAP program is completel$ different in each case! *f input
fields on lists are lin-ed to the ABAP &ictionar$# the usual automatic field and possible alues
help is aailable! The follo"ing is a t$pical list+
ABAP Programming (BC-ABA) 1>
3ou define lists using a special set of statements (the list statements W(I-0# S"IP# .IN0#
N0W-PA/0 and so on) in the processing bloc-s of ABAP programs! When these statements are
e/ecuted# a list is composed "ithin the s$stem! An internal s$stem program called the list
processor is responsible for displa$ing lists and for interpreting user actions in the list! .ists are
important because onl$ data in list format can be sent to the spool s$stem for printing!
*n an ABAP program# $ou can use the 0A!0 -O IS--P(OC0SSIN/statement to define the
ne/t screen as a list! *f the program is an e/ecutable program# the ABAP runtime enironment
automaticall$ calls the list defined in the program! A single program can be responsible for a
stac- of up to 41 lists! ,rom one basic list# $ou can create up to 4F details lists! )ser actions on a
list screen trigger eents# and can thus call eent bloc-s in the ABAP program!
.ists are output-oriented! When users carr$ out actions on a list screen# it is normall$ to use part
of the list contents in the ne/t part of the program# and not to input alues directl$! )sing lists is
appropriate "hen $ou "ant to "or- "ith output data# to print data or "hen the user=s ne/t action
depends on output data!
ABAP Programming ,odels

ABAP proides t"o programming models+
7 The o&3ec-oriented programming model is based on classes and interfaces!
7 The procedural programming model is based on function modules and subroutines!
SAP recommends that $ou use the ob2ect-oriented programming model!
The follo"ing chapters of this section also gie $ou an introduction to the structure of the
processing logic and to program e/ecution!
O&3ect-Oriented Programming ,odel

The ob2ect-oriented programming model is based on ABAP 1b2ects!
Procedural Programming ,odel

The procedural programming model is based on function modules and subroutines!
Structure of t$e Processing ogic
0ach ABAP program consists of an introductor% program part# a glo&al declaration part and a
number of processing &loc*s "hich implement different functions depending on the application
(procedures# dialog modules# eent bloc-s)! Processing bloc-s are inseparable s$ntactical
modulari9ation units "hich cannot comprise an$ other processing bloc-! Normall$ the$ contain
seeral ABAP statements "hich are organi9ed into statement bloc-s b$ means of control
structures!
The follo"ing diagram sho"s the structure of an ABAP program+
ABAP Programming (BC-ABA) 1?
Introductor% Program Part
0er$ independent ABAP program begins "ith an introductor$ statement "hich depends on the
program t$pe! Some of these statements hae additions "hich $ou can use to ma-e program
settings!
)eclaration Part for /lo&al )ata4 Classes and Selection Screens
*n eer$ ABAP program# the introductor$ program part is follo"ed b$ the declaration part for
glo&al data# classes# and selection screens! This consists of+
7 All declaration statements for global data! (lobal data is isible in all internal processing
bloc-s! 3ou define it using declaratie statements that appear before the first processing bloc-#
in dialog modules# or in eent bloc-s! 3ou cannot declare local data in dialog modules or eent
bloc-s e/cept the follo"ing+
7 All selection screen definitions!
7 All declarations of internal class definitions and interfaces!
&eclaration statements "hich occur in procedures (methods# subroutines# function modules) form
the declaration part for local data in those processing bloc-s! This data is onl$ isible "ithin the
procedure in "hich it is declared!
Container for Processing Bloc*s
3ou can list the processing bloc-s of an ABAP program in the source code of the program in an$
se8uence $ou li-e belo" the global declaration part as the$ are not e/ecuted consecutiel$! 1nl$
the source code contained in a statement bloc- is e/ecuted se8uentiall$!
The follo"ing t$pes of processing bloc-s are aailable "hich can be e/ited prematurel$ using the
(0-.(N statement!
7 &ialog modules (no local data area)
7 0ent bloc-s (no local data area# "ith t"o e/ceptions)
7 Procedures (methods# subroutines and function modules "ith their o"n local data area)!
Whereas dialog modules and procedures are enclosed in the ABAP -e$"ords "hich define them#
eent bloc-s are introduced "ith eent -e$"ords and concluded implicitl$ b$ the beginning of the
ne/t processing bloc-!
All ABAP statements (e/cept declaratie statements in the declaration part of the program) are
part of a processing bloc-! Non-declaratie ABAP statements# "hich occur bet"een the
declaration of global data and a processing bloc- are automaticall$ assigned to the S-A(--O2-
S00C-ION processing bloc-!
Processing Bloc*s in ABAP Programs
The follo"ing sections introduce $ou to the processing bloc-s supported in ABAP programs and
e/plain ho" the$ are called! The$ can be called either from outside the ABAP program (as is the
case for dialog modules and eent bloc-s) or through ABAP commands "hich are themseles
contained in processing bloc-s!
)ialog ,odules
3ou call dialog modules from the screen flow logic (screen command ,O).0)! 3ou can "rite a
dialog module in an ABAP program for each state (PB1# PA*< user input) of an$ of the screens
belonging to it! The PA* modules of a screen together "ith the PB1 modules of the subse8uent
screen form a dialog step! The interaction bet"een the flo" logic and the screen is controlled b$
a dialog processor!
&ialog modules are introduced "ith the ,O).0statement and concluded "ith the 0N),O).0
statement!
ABAP Programming (BC-ABA) 1@
,ields on a dialog screen hae the same name as a corresponding field in the ABAP program! &ata
is passed bet"een identicall$-named fields in the program! 3ou do notdefine dialog screens in the
ABAP programs!
0vent Bloc*s
0ent bloc-s are called through eents "hich are triggered b$ user actions on selection screens
and lists or b$ the ABAP runtime enironment! 3ou onl$ hae to define eent bloc-s for eents to
"hich $ou "ant the program to react ("hereas a subroutine call# for e/ample# must hae a
corresponding subroutine)! This ensures that "hile an ABAP program ma$ react to a particular
eent# it is not forced to do so!
Program Constructor
&irectl$ after an e/ecutable program# a module pool# a function group or a subroutine pool has
been loaded# a special processing bloc- can be e/ecuted e/actl$ once! This processing bloc- is
defined as an eent bloc- using the eent -e$"ord OA)-O2-P(O/(A,! The processing bloc-
for OA)-O2-P(O/(A, has the same function for ABAP programs as a constructor has for
classes!
0vent Bloc*s for Selection Screens
The different eents in a selection screen (PA*# PB1# user input)# are controlled b$ a selection
screen processor! 3ou can program processing logic for these eents in $our program! The
selection screen processor controls the flo" logic of the selection screen!
3ou do not hae to create the screen flo" logic $ourself# neither can $ou create $our o"n dialog
modules for the PB1 or PA* eents ! &ata is passed bet"een selection screen and ABAP program
ABAP Programming (BC-ABA) 1B
using the fields (parameters and selection tables) "hich $ou create in the selection screen
definition in the declaration part of the ABAP program!
0vent Bloc*s for ists
3ou can create them in an$ processing bloc- in an ABAP program using a special set of commands
(such as W(I-0# N0W-PA/0 and so on)! The list processor displa$s the list on the screen and
handles user actions "ithin lists! The list processor controls the flo" logic of the list! 3ou do not
hae to create the list flo" logic $ourself# neither can $ou create $our o"n dialog modules for the
PB1 or PA* eents !
3ou can call arious eent bloc-s "hile the list is being created "hich are used in page formatting!
The aboe illustration contains the eent bloc- -OP-O2-PA/04 "hich is called from the ABAP
program itself! When the list is displa$ed# the user can carr$ out actions "hich trigger eent
bloc-s for interactie list eents (such as A- IN0-S00C-ION)! 3ou can program processing
logic for the interactie list eents in $our program! &ata is transferred from list to ABAP
program ia s$stem fields or an internal memor$ area called the +I)0 area!
0vent Bloc*s for 05ecuta&le Programs ((eports)
When $ou run an e/ecutable program# it is controlled b$ a predefined process in the runtime
enironment! A series of processors is called# one after the other! These processors trigger
eents# for "hich $ou can define eent bloc-s! 0/ecutable ABAP programs are eent-drien!
The process is as follo"s+
ABAP Programming (BC-ABA) 1D
!!!
1! The runtime enironment creates the INI-IAI6A-ION eent and calls the corresponding
eent bloc- (if it has been defined in the ABAP program)!
4! *f there is a selection screen defined in the program# control returns to the selection screen
processor! This generates the corresponding eents and calls their eent bloc-s!
:! Control then passes to the reporting processor! *t creates the S-A(--O2-S00C-ION
eent and calls the corresponding eent bloc- (if it has been defined in the ABAP program)!
>! The logical database# if $ou are using one# calls further eent bloc-s at this point!
?! The reporting processor creates the 0N)-O2-S00C-ION eent and calls the
corresponding eent bloc- (if it has been defined in the ABAP program)!
@! *f the program contains a list description# control no" passes to the list processor! The list
processor displa$s the list defined in the ABAP program! *t conerts user actions on the list into
eents and calls the corresponding eent bloc-s!
B! *f a selection screen is declared in the declaration part of the program# the same program is
automaticall$ called again after the program is ended (the list is e/ited)!
Procedures
Procedures are callable processing bloc-s "hich contain an interface and a local data area!
Su&routines
3ou call subroutines from ABAP programs using the P0(2O(,statement!
Subroutines are introduced "ith the 2O(,statement and concluded "ith the
0N)2O(,statement!
3ou can define subroutines in an$ ABAP program! 3ou can either call a subroutine that is part of
the same program or an e/ternal subroutine# that is# one that belongs to a different program! *f
$ou call an internal subroutine# $ou can use global data to pass alues bet"een the main program
and the subroutine! When $ou call an e/ternal subroutine# $ou must pass actual parameters from
the main program to formal parameters in the subroutine!
2unction ,odules
,unction modules are e/ternal functions "ith a defined interface! 3ou call function modules from
ABAP programs using the CA 2.NC-ION statement!
,unction modules are introduced "ith the 2.NC-ION statement and concluded "ith the
0N)2.NC-ION statement!
ABAP Programming (BC-ABA) 1E
3ou can onl$ create function groups "ithin special ABAP programs called function groups using the
,unction Builder! This means that $ou can onl$ call them e/ternall$ from other ABAP programs!
)nli-e subroutines# $ou al"a$s pass data to function modules using an e/plicit parameter
interface!
,et$ods
'ethods describe the functions of classes! .i-e function modules# the$ hae a defined interface!
3ou call methods from ABAP programs using the CA ,0-+O) statement!
'ethods are introduced "ith the ,0-+O) statement and concluded "ith the 0N),0-+O)
statement!
'ethods can onl$ be defined in the implementation parts of classes! 3ou can either do this
globall$ in the Class Builder# or locall$ "ithin ABAP programs! 'ethods can "or- "ith the
attributes of their class and "ith data that $ou pass to them using their e/plicit parameter
interface!
Program -%pes and 05ecution
When $ou run an ABAP program# $ou call its processing bloc-s in a specific se8uence! This is
controlled from outside the program b$ the processors of the current "or- process! ,or the
ABAP Programming (BC-ABA) 4F
purposes of program flo"# "e can summari9e the screen processor and ABAP processor of the
"or- processes inoled into the ABAP runtime enironment! The runtime enironment contains a
range of special control patterns that call screens and processing bloc-s in certain orders! These
successie sections are also called processors! When $ou run an ABAP program# the control passes
bet"een arious processors!

0ach ABAP program has a program t%pe "hich must be determined in the program attri&utes
"hen the program is created!
There are seen program t$pes from "hich $ou can choose+ e/ecutable program# module pool#
function group# class pool# interface pool# subroutine pool# and include program!
Prior to %elease >!@# $ou had to specif$ the internal one-character *& to select a program t$pe!
An e/ecutable program# for e/ample# "as assigned t$pe 1! No" the program t$pe is chosen based
on the full name! The program t$pe defines the basic technical attributes of a program# that is#
"hich processing bloc-s a program ma$ contain# ho" the program is handled and e/ecuted b$ the
ABAP runtime enironment# and "hether it can "or- "ith its o"n screens!

When $ou run an ABAP application program# $ou must call at least the first processing bloc- from
outside the program# that is# from the runtime enironment! This processing bloc- can then either
call further processing bloc-s or return control to the runtime enironment! When $ou start an
ABAP program# the runtime enironment starts a processor (dependent on the program t$pe)#
"hich calls the first ABAP processing bloc-! The program can be started either b$ the user or b$
the s$stem (for e/ample# in bac-ground processing)# or through an e/ternal interface# for
e/ample# for %emote ,unction Calls (%,C)!

Normall$# the user of an SAP S$stem does not come into direct contact "ith the program!
6o"eer# this is not true for e/ecutable programs "hich can be started b$ entering the program
name after choosing S$stem -G Serices -G %eporting! All other independent programs (that is# all
program t$pes e/cept include programs) can either be called b$ entering a transaction code or be
loaded b$ using their procedures! *n most cases# users do not een need to -no" the program
name or transaction code as the call of a program is normall$ lin-ed to menu paths of the
associated applications!
The transaction code is a t"ent$-character name "hich is assigned to a screen or a method of an
ABAP program and is used for program e/ecution! To e/ecute a program# $ou either enter the
transaction code in the input field of the standard toolbar or use the statements CA
-(ANSAC-ION or 0A!0 -O -(ANSAC-ION! Transaction codes lin-ed to screens are alid
for e/ecutable programs# module pools and function groups! Transaction codes lin-ed to methods
are allo"ed for all program t$pes e/cept include programs!
05ecuta&le Programs
ABAP Programming (BC-ABA) 41
3ou create e/ecutable programs directl$ using the tool called ABAP 0ditor! 0/ecutable programs
can contain all processing bloc-s supported in ABAP# "ith the e/ception of function modules# and
as man$ local classes as re8uired! 0/ecutable programs are onl$ started "ith the S.B,I-
statement! Although NetWeaer AS ABAP offers seeral "a$s to call e/ecutable programs b$
entering their name on the screen# the s$stem still e/ecutes the S.B,I- statement in the
bac-ground!
*t is not necessar$ to control e/ecutable programs directl$ using self-defined screens since the
releant processors of the runtime enironment call the processing bloc-s and screens (selection
screens and lists) automaticall$ and in a predefined se8uence! The process flo" allo"s the user to
enter selection parameters on a selection screen! The data is then selected from the database
and processed! ,inall$# an output list is displa$ed! At no stage does the programmer hae to
define his or her o"n screens! )ser actions on screens can then trigger further processing
bloc-s!
The runtime enironment also allo"s $ou to "or- "ith a logical database# that is# "ith a special
ABAP program for reading data from database tables! The flo" of an e/ecutable program is
oriented to"ards reporting ("hose main tas-s are to read data from the database# process it# and
displa$ the results)! This is "h$ e/ecutable programs are often referred to as reports# and "h$
running an e/ecutable program is often called reporting (see %eport Programming)! Analogousl$#
the source code of an e/ecutable program starts "ith the (0PO(-statement!
Since it is not compulsor$ to define eent bloc-s# $ou can $ourself determine the eents to "hich
$our ABAP program should react! ,urthermore# $ou can call $our o"n screens or processing bloc-s
at an$ time# leaing the prescribed program flo"! 3ou can use this# for e/ample# to present data in
a table on a dialog screen instead of in a list! The simplest e/ecutable program contains onl$ one
processing bloc- (S-A(--O2-S00C-ION)!
No user dialog is re8uired for e/ecutable programs (see &ialog Programming)! 3ou can fill the
selection screen using a ariant and output data directl$ to the spool s$stem instead of to a list!
Conse8uentl$# e/ecutable programs are a prere8uisite for bac-ground processing!
*f a transaction code has been assigned to an e/ecutable program# users can then start it using
the transaction code and not the program name! The reporting-oriented runtime enironment is
also called "hen $ou run a report using a transaction code! This -ind of transaction is called a
report transaction!
*t is appropriate to use e/ecutable programs (reports) "hen the flo" of $our program
corresponds either "holl$ or in part to the pre-defined flo" of the runtime enironment! )ntil
%elease >!?A# the onl$ "a$ to use a logical database "as to use an e/ecutable program! 6o"eer#
from %elease >!?A# it is also possible to call logical databases on their o"n!
,odule Pools
'odule pools are directl$ created using the ABAP 0ditor and are introduced "ith the P(O/(A,
statement! With the e/ception of reporting eent bloc-s and function modules# module pools can
contain all processing bloc-s supported in ABAP and as man$ local classes as re8uired! While the$
are e/ecuted# all eents of the ABAP runtime enironment ma$ be triggered!
The most important technical attribute of a module pool is that it can onl$ be controlled using
screen flo" logic! 3ou must start them using a transaction code# "hich is lin-ed to the program
and one of its screens (initial screen)! Another feature of these programs is that $ou must define
$our o"n screens in the Screen Painter (although the initial screen can be a selection screen)!
When $ou start a program using a transaction code# the runtime enironment starts a processor
that calls the initial screen! This then calls a dialog module in the corresponding ABAP program!
The remainder of the program flo" can ta-e an$ form! ,or e/ample# the dialog module can+
7 return control to the screen# after "hich the processing passes to a subse8uent screen!
0ach screen has a follo"ing screen# set either staticall$ or d$namicall$! Screens and their
subse8uent screens are components of freel$ definable screen se8uences!
7 call other screen se8uences# selection screens or lists# from "hich further processing
bloc-s in the ABAP program are started!
7 call other processing bloc-s itself# either internall$ or e/ternall$!
7 call other application programs using CA -(ANSAC-ION or S.B,I-!
*t is appropriate to use module pools "hen $ou "rite dialog-oriented programs using a large
number of screens "hose flo" logic largel$ determines the program flo" of screen se8uences!
ABAP Programming (BC-ABA) 44
2unction /roups
,unction groups or function pools are introduced "ith the 2.NC-ION-POO statement and are
the onl$ programs that are allo"ed to contain function modules ("hich are special procedures
that can be called from "ithin all other ABAP programs)! The$ can be e/ecuted using transaction
codes but are normall$ loaded b$ their function modules being called! With the e/ception of
reporting eent bloc-s# function groups can contain all processing bloc-s supported in ABAP and as
man$ local classes as re8uired!
.i-e e/ecutable programs and module pools# function groups can contain their o"n screens#
including selection and list screens! Screen processing# that is reacting to user actions in eent
bloc-s and dialog modules# also ta-es place in the function group! The screens are called from
"ithin the function modules of the group! A function group containing screens and a single
function module therefore allo"s $ou to modulari9e screen flo"s!
The 2unction Builder is a tool in the ABAP Wor-bench that $ou can use to create function groups
and function modules!
Class Pools
Class pools ma$ not contain an$ screens of their o"n or an$ processing bloc-s e/cept methods!
The$ are introduced "ith the CASS-POO statement and are e/clusiel$ used as a container
for e/actl$ one glo&al class and as man$ local classes as re8uired! Class pools are loaded b$ using
their global class! As of %elease @!1F# $ou can also lin- transaction codes to methods of global
classes so that an ob2ect of the class is implicitl$ created "hen the$ are used!
The Class Builder is a tool in the ABAP Wor-bench that $ou can use to create class pools!
Interface Pools
*nterface pools ma$ not contain an$ screens of their o"n or an$ processing bloc-s! The$ are
introduced "ith the IN-0(2AC0-POO statement and are e/clusiel$ used as a container for
one glo&al interface "hich can be implemented in an$ global or local classes! The$ are loaded b$
using the interface!
.i-e class pools# $ou create interface pools in the Class Builder of the ABAP Wor-bench!
Su&routine Pools
Subroutine pools are created using the ABAP 0ditor and are introduced "ith the P(O/(A,
statement! The$ ma$ not contain an$ screens of their o"n# and "ith the e/ception of the OA)-
O2-P(O/(A, eent bloc- the$ ma$ onl$ use subroutines as processing bloc-s! Subroutine pools
are loaded b$ e/ternall$ calling their subroutines from "ithin other ABAP programs!
-%pe /roups
T$pe groups or t$pe pools are created using the ABAP &ictionar$ tool and are introduced "ith the
-7P0-POO statement! The$ ma$ not contain an$ screens of their o"n or an$ processing bloc-s!
T$pe groups are e/clusiel$ used as containers for global data t$pes "hich can be made isible in
an$ ABAP program using the -7P0-POOS statement!
Include Programs
*n contrast to all other program t$pes# include programs do not represent stand-alone compilation
units "ith a memor$ area of their o"n! *nclude programs cannot be e/ecuted! The$ merel$ sere
as a librar$ for ABAP source code! The$ are e/clusiel$ used to organi9e program te/ts into small
editable units "hich can be inserted at an$ place in other ABAP programs using the INC.)0
statement! There is no technical relationship bet"een include programs and processing bloc-s!
*ncludes are more suitable for logical programming units# such as data declarations# or sets of
similar processing bloc-s! The ABAP Wor-bench has a mechanism for automaticall$ diiding up
module pools# function groups and class pools into include programs! 3ou create $our o"n include
programs using the ABAP 0ditor!
ABAP Programming (BC-ABA) 4:
)ialog Programming
This is a classical programming method that is based on d$npros and dialog transactions!
Classic Application Programming
Separating the application la$er from the presentation la$er means that "hen $ou run an ABAP
application program re8uiring user interaction# control of the program is continuall$ passed
bac-"ards and for"ards bet"een these la$ers! While a screen is read$ for input# the
corresponding SAP ()* of the presentation la$er is actie! &uring this time# the application la$er
is not actie for the application program! Therefore# the ABAP application serers are free for
other tas-s! 1nce the user has entered data on the screen# program control passes bac- to the
application la$er! No"# the presentation la$er is inactie! The SAP ()* is still isible to the user
during this time# and it is still displa$ing the screen# but it cannot accept user input! The SAP
()* does not become actie again until the application program has called a ne" screen and sent
it to the presentation serer!
Conse8uentl$# if $ou use this method# $ou need to diide dialog programs into single dialog steps4
"ith each of these steps comprising the programming logic bet"een t"o successie screens!
)ispatc$ing )ialog Steps
The number of users logged onto an ABAP application serer is often man$ times greater than the
number of aailable "or- processes! ,urthermore# it is not restricted b$ the SAP NW AS ABAP
architecture! ,urthermore# each user can run seeral applications at once! The dispatcher has the
important tas- of distributing all dialog steps among the "or- processes on the ABAP application
serer!
The follo"ing e/ample sho"s ho" this might happen+
!!!
1! The dispatcher receies the re8uest to e/ecute a dialog step from user 1 and directs it to
"or- process 1# "hich happens to be free! The "or- process addresses the conte/t of the
application program (in shared memor$) and e/ecutes the dialog step! *t then becomes free again!
ABAP Programming (BC-ABA) 4>
4! The dispatcher receies the re8uest to e/ecute a dialog step from user 4 and directs it to
"or- process 1# "hich is no" free again! The "or- process e/ecutes the dialog step as in step 1!
:! While "or- process 1 is still "or-ing# the dispatcher receies a further re8uest from user 1
and directs it to "or- process 4# "hich is free!
>! After "or- processes 1 and 4 hae finished processing their dialog steps# the dispatcher
receies another re8uest from user 1 and directs it to "or- process 1# "hich is free again!
?! While "or- process 1 is still "or-ing# the dispatcher receies a further re8uest from user 4
and directs it to "or- process 4# "hich is free!
,rom this e/ample# "e can see that+
7 A dialog step from a program is assigned to a single "or- process for e/ecution!
7 The indiidual dialog steps of a program can be e/ecuted on different "or- processes# and
the program conte/t must be addressed for each ne" "or- process!
7 A "or- process can e/ecute dialog steps of different programs from different users!
The e/ample does not sho" that the dispatcher tries to distribute the re8uests to the "or-
processes such that the same "or- process is used as often as possible for the successie dialog
steps in an application! This is useful# since it saes the program conte/t haing to be addressed
each time a dialog step is e/ecuted!
)ispatc$ing and t$e Programming ,odel
As alread$ mentioned (see &atabase Connection section)# a wor* process can onl$ ma-e database
changes "ithin a single database logical unit of "or- (.)W)! The contents of the database must
be consistent at its beginning and end! The end of such an inseparable se8uence of database
operations is defined b$ a commit command to the database s$stem (database commit)! &uring a
database .)W# that is# bet"een t"o database commits# the database s$stem itself ensures
consistenc$ "ithin the database! *n other "ords# it ta-es oer tas-s such as loc-ing database
entries "hile the$ are being edited# or restoring the old data (rollbac-) if a step terminates in an
error!
A t$pical SAP application program e/tends oer seeral screens and the corresponding dialog
steps! The user re8uests database changes on the indiidual screens that should lead to the
database being consistent once the screens hae all been processed! 6o"eer# the indiidual
dialog steps run on different "or- processes# and a single "or- process can process dialog steps
from other applications! *t is clear that t"o or more independent applications "hose dialog steps
happen to be processed on the same "or- process cannot be allo"ed to "or- "ith the same
database .)W!
Conse8uentl$# a "or- process must open a separate database .)W for eac$ dialog step! The "or-
process sends a commit command (database commit) to the database at the end of each dialog
step in "hich it ma-es database changes! These commit commands are called implicit database
commits# since the$ are not e/plicitl$ "ritten into the application program!
These implicit database commits mean that a database .)W can be -ept open for a ma/imum of
one dialog step! This leads to a considerable reduction in database load# seriali9ation# and
deadloc-s# and enables a large number of users to use the same s$stem!
6o"eer# the 8uestion no" arises of ho" this method (1 dialog step H 1 database .)W) can be
reconciled "ith the demand to ma-e commits and rollbac-s dependent on the logical flo" of the
application program instead of the technical distribution of dialog steps! &atabase update
ABAP Programming (BC-ABA) 4?
re8uests that depend on one another form logical units in the program that e/tend oer more
than one dialog step! The database changes associated "ith these logical units must be e/ecuted
together and must also be able to be undone together!
The SAP programming model contains a series of bundling techni8ues that allo" $ou to group
database updates together in logical units! The section of an ABAP application program that
bundles a set of logicall$-associated database operations is called an SAP .W! )nli-e a database
.)W# a SAP .)W includes all of the dialog steps in a logical unit# including the database update!
(eport Programming

1bsolete programming techni8ue for creating classic lists!

This techni8ue is based on calling e/ecutable programs using S.B,I-!
Creating and C$anging ABAP Programs

ABAP programs are ob2ects of the %epositor$! .i-e all other %epositor$ ob2ects (such as ABAP
&ictionar$ tables or screens)# $ou maintain them using an ABAP Wor-bench tool - in this case# the
ABAP 0ditor!
This section proides a brief description of the ABAP Wor-bench and an oerie" of ho" to
create and edit ABAP programs! *t describes the different "a$s of starting the ABAP 0ditor! *n
the te/t belo"# Iopen a programI al"a$s means Istart the ABAP 0ditor and use it to open a
programI!
Starting t$e ABAP 0ditor
To start the ABAP 0ditor to create or change ABAP programs# NetWeaer AS ABAP offers
three possibilities+
7 1pening Programs in the 1b2ect Naigator
The 1b2ect Naigator of the ABAP Wor-bench (Transaction S0DF) offers a hierarchical
oerie" of all %epositor$ ob2ects# ordered b$ pac-age# user name of the programmer# ob2ect
t$pes# and so on! B$ selecting a program# the 1b2ect Naigator supplies direct access to all
components of a program# such as main program# includes# classes# or global data! B$ selecting
a program ob2ect in the 1b2ect Naigator and calling a maintenance transaction# $ou directl$
open the appropriate tool for this ob2ect# as# for e/ample# the ABAP 0ditor for the program
source code or the Class Builder for classes!
This "a$ is appropriate for all ABAP programs# as the 1b2ect Naigator gies $ou a constant
oerie" of all components of a program! *n particular# screens and user interfaces are
displa$ed!
7 )sing the ABAP 0ditor
To open ABAP programs directl$ from the tool ABAP 0ditor# select the menu path Tools 7
ABAP Wor-bench 7 &eelopment 7 ABAP 0ditor from the SAP menu of SAP 0as$ Access (or
start Transaction S0:D)! *f $ou "ant to change a program using this method# $ou must alread$
-no" its name and enironment!
This procedure is onl$ suited for maintaining or creating relatiel$ simple or short programs#
"hich hae fe" or no additional components!
7 )sing ,or"ard Naigation
*n an$ of the tools in the ABAP Wor-bench# $ou can open a different %epositor$ ob2ect b$
positioning the cursor on it and double-clic-ing! The s$stem automaticall$ opens the ob2ect
using the correct tool! This also applies to editing ABAP programs!
,or"ard naigation b$ double-clic- can be used at an$ point "here the names of ABAP
programs appear in the ABAP Wor-bench!
Naming ABAP Programs
The name of an ABAP program can be bet"een 1 and :F characters long! The follo"ing s$mbols
and signs must not be used in program names+ Period (!)# comma (#)# space ( )# parentheses ()#
ABAP Programming (BC-ABA) 4@
apostrophe (J)# inerted commas (K)# e8uals sign (H)# asteris- (L)# accented characters or (erman
umlauts (M# N# O# P# Q# and so on)# percentage signs (R)# or underscores (S)!
Program Attri&utes
.i-e man$ other %epositor$ ob2ects# ABAP programs hae attributes# "hich are important in
determining the function of the program "ithin NetWeaer AS ABAP! ,or an oerie" of program
attributes# refer to 'aintaining Program Attributes!
Source Code
ABAP source code defines the processing logic of ABAP application programs! ,or an introduction
to "riting source code# refer to 0diting Programs!
Opening Programs in t$e O&3ect Navigator
To open ABAP programs in the 1b2ect Naigator# select the menu path Tools 7 ABAP Wor-bench
7 1erie" 7 1b2ect Naigator from the SAP menu of SAP 0as$ Access (or start Transaction
S0DF)!
,rom the initial screen of the 1b2ect Naigator $ou can select Program from the top left part of
the screen and enter the name of a program directl$ or displa$ seeral programs of a specific
Pac-age!
Opening a Specific Program
0nter a program name and confirm $our entr$ "ith 0nter!
*f the program does not e/ist# the s$stem displa$s a dialog bo/ for creating programs! *f the
program does e/ist the ob2ects are displa$ed in a tree structure on the left of the screen "hich
allo"s $ou to naigate to the corresponding tools!
Creating a New Program
!!!
1! The dialog bo/ Create Program appears# "hich allo"s $ou to create a T1P *NC.(top include
program)! A Top include is a special include program in "hich $ou "rite $our global data
declarations! When $ou create a module pool# begin the name "ith JSAP'=! This allo"s the s$stem
to propose a default name for the Top include that is automaticall$ included in the ABAP
Wor-bench naigation functions!
4! The ABAP+ Program Attributes screen appears# on "hich $ou must maintain the program
attributes! 'aintaining the program attributes is an important procedure "hen creating a
program! 0nter the program attributes!
:! Sae the program attributes!
The program is no" aailable in the %epositor$ and $ou can enter the source te/t in the ABAP
0ditor!
Opening Programs of a Pac*age
0nter the name of an e/isting pac-age and confirm $our entr$ "ith 0nter! The 1b2ect Naigator
displa$s a hierarchical oerie" of all %epositor$ ob2ects for the selected pac-age!
3ou no" hae seeral possibilities+
7 *f the node Programs does not appear on this screen# $ou can create the node b$ selecting
the node Pac-age and creating a program!
To do this# select the tab Program from the displa$ed dialog bo/ (1b2ect Selection)! 0nter a
name and choose Create!
The Create Program dialog bo/ appears! ,rom here# carr$ on as described in Creating a Ne"
Program aboe!
7 *f the Programs node alread$ e/ists on the screen# $ou can position the cursor on it and
choose Create (from the conte/t menu) to create a ne" program!
7 *n this case# $ou can also e/pand the node to displa$ all of the programs belonging to the
pac-age!
ABAP Programming (BC-ABA) 4B
Position the cursor on a program name and double-clic- or choose &ispla$ or Change (conte/t
menu)! This opens the ABAP 0ditor for the program!
The 1b2ect Naigator displa$s the program as a tree structure "ith the program as its root node
and the indiidual program components (ob2ect t$pes) as subnodes! Note that selecting other
components of the program does not open the ABAP 0ditor to displa$ the source code of the
program# but al"a$s the appropriate tool for the selected component! *n special cases# such as
for include programs# this can also be the ABAP 0ditor! 6o"eer# $ou then edit onl$ the
component and not the source code of the entire program!
Opening Programs in t$e ABAP 0ditor
To open ABAP programs directl$ from "ithin the ABAP 0ditor# select the menu path Tools 7
ABAP Wor-bench 7 &eelopment 7 ABAP 0ditor from the SAP menu of SAP 0as$ Access (or
start Transaction S0:D)!
Creating a New Program
*f the program does not e/ist# choose Create! The ABAP+ Program Attributes screen appears# on
"hich $ou must maintain the program attributes!
*f $ou create a program in this "a$# the s$stem does not offer to create a Top include! This "a$
of creating programs is therefore best suited for reports and short test programs! 1nce $ou
hae entered and saed the program attributes# the ne" program e/ists in the %epositor$!
,aintaining an 05isting Program
To edit an e/isting program# enter its name on the initial screen of the ABAP 0ditor (Transaction
S0:D)# select one of the follo"ing components# and then choose &ispla$ or Change!
7 Source Code
Starts the ABAP 0ditor!
7 Aariants
Starts ariant maintenance! Aariants allo" $ou to define fi/ed alues for the input fields on
the selection screen of a report!
7 Attributes
Allo"s $ou to maintain the program attributes!
7 &ocumentation
Allo"s $ou to "rite documentation for a particular e/ecutable program (report)! The s$stem
starts the SAPscript 0ditor# "here $ou can enter the documentation according to the
predefined template! When e/ecuting the report# the user can displa$ this documentation b$
choosing S$stem 7 Serices 7 %eporting (Transaction SA:D) and (oto 7 &ocumentation! *f the
report is stored as node in a reporting tree (Transaction S0%P)# the user can choose (oto 7
&ispla$ docu! from the tree displa$ to displa$ the documentation!
7 Te/t 0lements
Allo"s $ou to edit the te/t elements of the program! Te/t elements are all te/ts that appear
on the selection screen or on the output screen of a report!
3ou can also access an$ of these components b$ using the (oto menu or for"ard naigation in the
ABAP 0ditor itself!
Opening Programs .sing 2orward Navigation
*f $ou are alread$ "or-ing in the ABAP Wor-bench# $ou can open a program b$ positioning the
cursor on the program name and double-clic-ing!
1ther "a$s of fo"ard naigation are al"a$s aailable in the menus of the ABAP Wor-bench tools#
usuall$ under (oto or 0nironment!
The follo"ing e/amples sho" some of the possibilites of for"ard naigation!
Suppose# $ou are editing a program and find the line
S.B,I- 66+"-S- 89
This statement calls an e/ecutable program (report) from "ithin another ABAP program!
ABAP Programming (BC-ABA) 4D
*f $ou position the cursor on the name TT6UTST1 and double-clic-# there are t"o possibilities+
1! *f the program TT6UTST1 alread$ e/ists+
The s$stem opens TT6UTST1 in the ABAP 0ditor# and $ou can read or edit it!
4! *f the program TT6UTST1 does not e/ist+
A dialog bo/ appears# as-ing $ou if $ou "ant to create the program!
After editing TT6UTST1# $ou can choose Bac- to return to the ABAP 0ditor session of the
original program!
*n the tree structure of the 1b2ect Naigator# open the node of a program that contains at least
one screen as component! Position the cursor on a screen under the Screen node!
*f $ou choose &ispla$# Change# or double-clic- the screen name# the s$stem opens the Screen
Painter tool and displa$s the flo" logic of the screen!
This usuall$ contains a series of ,O).0statements that call ABAP modules in the program!
Position the cursor on a module name and double-clic-! The s$stem opens the ABAP 0ditor for the
corresponding include program at the position in the program "here the releant module is
programmed! The include program is used to modulari9e the source code of the main program!
*f $ou position the cursor on the name of an include in an INC.)0 statement in the ABAP 0ditor
and double-clic-# the s$stem opens the include program in the 0ditor!
,aintaining Program Attri&utes
The most important program attribute in this process is the t%pe# "hich $ou can use to determine
ho" an ABAP program is e/ecuted!
,urthermore# $ou can determine in the program attributes "hich application a program is assigned
to# and determine the logical database for e/ecutable programs (reports) accordingl$!
Ta-e care to enter the correct program attributes# other"ise the s$stem "ill not be able to run
the program properl$! 3ou maintain the program attributes on the ABAP+ Program Attributes
screen!
3ou can obtain the list of possible program t$pes b$ selecting the ,> input help function!
*f $ou select an e/ecutable program (report)# the s$stem automaticall$ fills the input fields for
specific attributes! 1nl$ no" are the additional input fields .ogical &atabase and Selection
Screen isible!
Overview of All Program Attri&utes
The follo"ing sections proide a short oerie" of the program attributes! Note that some of
these attributes onl$ appl$ to e/ecutable programs (reports)# and not to other ABAP program
t$pes! The field help and possible alues help for the fields on the ABAP+ Program Attributes
screen proide further information!
-itle
*n the re8uired entr$ field Title enter a program description that describes the function of the
program!
*n programs containing lists for "hich no list heading is specified in the te/t elements# this title
is used instead of the missing heading!
,aintenance anguage
The maintenance language is the logon language of the user "ho creates the program! The s$stem
fills this field automaticall$! 3ou can change the maintenance language# if $ou maintain the
program or its components in another logon language!
-%pe
*n the field T$pe $ou must specif$ the program t$pe!
,rom "ithin the ABAP 0ditor# $ou can onl$ choose from the follo"ing program t$pes+
7 0/ecutable program
7 'odule pool
7 Subroutine pool
7 *nclude program
ABAP Programming (BC-ABA) 4E
All other program t$pes are not created directl$ from "ithin the ABAP 0ditor but "ith the help
of special tools such as the ,unction Bilder for function groups or the Class Builder for class
pools!
Status
This optional entr$ describes the status of the program deelopment< for e/ample# Test Program
or Productie Customer Program!
Application
This optional field contains the name of the application that is re8uired in the program# for
e/ample ,inancial Accounting!
Aut$ori:ation /roup
*n this field# $ou can enter the name of a program group! This allo"s $ou to group different
programs together for authori9ation chec-s! The group name is a field of the t"o authori9ation
ob2ects SS&0A0.1P (program deelopment and program e/ecution) and SSP%1(%A' (program
maintenance)! Thus# $ou can assign authori9ations to users according to program groups! ,or more
information about authori9ations# refer to the )sers and %olesdocumentation!
Pac*age
The pac-age is important for transports bet"een s$stems! 3ou combine all Wor-bench ob2ects
assigned to one pac-age in one transportation re8uest!
*f $ou are "or-ing in a team# $ou ma$ hae to assign $our program to an e/isting pac-age# or $ou
ma$ be free to create a ne" pac-age! All programs assigned to the pac-age VT'P are priate
ob2ects and cannot be transported into other s$stems! 3ou can enter the pac-age directl$ into
this field! 1ther"ise# the s$stem prompts for it "hen $ou sae the attributes!
Choosing .ocal ob2ect is e8uialent to entering VT'P in the field Pac-age! 3ou can change the
pac-age of a program after"ards!
ogical )ata&ase
Onl% for 05ecuta&le Programs
These attributes determine the logical database used b$ the e/ecutable program (report) to read
data!
Selection Screen !ersion
Onl% for 05ecuta&le Programs
*f $ou do not specif$ a selection screen ersion# the s$stem automaticall$ creates a selection
screen based on the selection criteria of the logical database and the parameters and select-
options statements in the program!
*f $ou "ant to use a different selection screen of the logical database# enter a number in this
field! The number must be smaller than 1FFF and correspond to an additional selection screen of
the logical database! The possible alues help displa$s a list of aailable selection screens! 3ou can
also loo- in the selection include of the logical database (program &B///S0.# "here /// is the
name of the logical database)!
0ditor oc*
*f $ou set this attribute# other users cannot change# rename# or delete $our program! 1nl$ $ou
"ill be able to change the program# its attributes# te/t elements# and documentation# or release
the loc-!
2i5ed Point Arit$metic
*f the attribute ,i/ed point arithmetic is set for a program# the s$stem rounds t$pe P fields
according to the number of decimal places or pads them "ith 9eros The decimal sign in this case
is al"a$s the period (!)# regardless of the user=s personal settings! We recommend that $ou
alwa%s set the fi/ed point arithmetic attribute!
Start .sing !ariant
Onl% for 05ecuta&le Programs
*f $ou set this attribute# other users can onl$ start $our program using a ariant! 3ou must then
create at least one ariant before the report can be started!
0diting Programs
ABAP Programming (BC-ABA) :F
3ou edit programs using the ABAP 0ditor! ,or detailed information# refer to the appropriate
documentation! Belo" are a fe" hints to help $ou to get started+
Program Structure
The follo"ing gies a short oerie" on ho" to structure a program! Apart from the first
statement# the se8uence of statements is not obligator$# but $ou should -eep to it for reasons of
clarit$ and readabilit$!
!!!
1! The first program statement
The first statement in an$ ABAP Program is al"a$s an introductor$ program statement# often
(0PO(-or P(O/(A,! Both statements hae e/actl$ the same function!
The name specified in the statements (0PO(-and P(O/(A, must not necessaril$ be the
program name# but for documentation reasons# $ou should use the correct name!
Wheneer $ou create a ne" program# the s$stem automaticall$ inserts the first ABAP
statement# for e/ample+
%0P1%T name! for e/ecutable programs# or
P%1(%A' name9 for module pools or subroutine pools
The s$stem enters the name $ou used to create the program as the report or program name!
4! &ata declaration
Ne/t# insert all of $our declarations! These include selection screen definitions# the
declarations of local classes and interfaces and global data declarations!
:! Processing logic
After the declarations# "rite the processing logic! This consists of a series of processing
bloc-s!
>! Subroutines
At the end of $our program# include its internal procedures (such as subroutines)!
)sing includes to split up a program into a series of source code modules does not change this
basic structure! *f# for e/ample# $ou follo" the for"ard naigation of the ABAP Wor-bench "hen
creating a dialog program# the s$stem automaticall$ creates a number of include programs# "hich
contain the program parts described aboe in the correct se8uence! The top include program
usuall$ contains the P(O/(A, statement and the global data declarations! The subse8uent
include programs contain the indiidual dialog modules# ordered b$ PB1 and PA*! There ma$ also
be further includes# for e/ample# for subroutines! These include programs do not influence the
program function# the$ onl$ sere to ma-e the program order easier to understand!
Program a%out
A high-8ualit$ ABAP program obseres the follo"ing la$out standards+ Note the follo"ing
suggestions!
Add Comments to 7our Programs
0nsure that $our program is correctl$ commented! ,or e/ample# at the beginning of a subroutine#
e/plain "hat it does# and proide an$ necessar$ information and references! Pre-defined comment
bloc-s are proided in the ABAP 0ditor to help $ou comment $our programs! Comments "ithin
lines of code should be used sparingl$# and onl$ "here the$ do not ma-e the program flo" more
difficult to understand!
Indent Bloc*s of Statements
3ou should combine statements that belong together into a single bloc-! *ndent each bloc- b$ at
least t"o columns+
.se ,odules
'a-e $our programs easier to understand b$ using modules! ,or e/ample# "riting a large
processing bloc- as a method ma-es the logical structure of $our program easier to recogni9e!
ABAP Programming (BC-ABA) :1
Programs "ith classes and methods ma$ be longer# but $ou "ill soon find that this approach
greatl$ increases clarit$# especiall$ in the case of comple/ programs!
Prett% Printer
*f $ou use the Prett$ Printer in the ABAP 0ditor# $our programs "ill conform to the la$out
guidelines!
Statement Patterns
*n the ABAP 0ditor# $ou can use statement patterns to help $ou "rite $our program! The$ proide
the e/act s$nta/ of a statement and follo" the ABAP la$out guidelines! 3ou can insert t"o -inds
of predefined structures into $our program code "hen using the ABAP 0ditor+ -e$"ord
structures and comment lines! *n the ABAP 0ditor# choose Pattern! To displa$ a list of all
predefined -e$"ord structures# place the cursor in the 1ther pattern! field and clic- the possible
entries button to the right of the input field!
C$ec*ing Programs
When $ou hae finished editing# or reach an intermediate stage of the program# choose Chec- to
chec- the s$nta/! The s$stem chec-s the program coding for s$nta/ errors and compatibilit$
problems! *f it finds an error# it displa$s a message describing it and# if possible# offers a
solution or correction! The s$stem positions the cursor on the error in the coding! 1nce $ou
decide that $our program is finished# run the e/tended program chec- on it b$ choosing Program
7 Chec- 7 0/tended Program Chec- from the 0ditor screen! 0nsure that $ou correct all of the
errors and "arnings displa$ed! 'an$ of the errors found during the e/tended program chec-
indicate that program cannot run properl$! 1thers# although the$ do not preent the program
from "or-ing# are e/amples of poor programming! ,urthermore# some "arnings might be escalated
to s$nta/ errors in future releases!
Saving and Activating Programs
Choose Sae to sae the source code!
The s$stem stores the source code in the program librar$! Before $ou can e/ecute the program
from outside the ABAP 0ditor# $ou must generate an actie ersion using the Actiate function!
-esting Programs
3ou can test e/ecutable programs in the ABAP 0ditor! To do so# choose Program 7 0/ecute in the
ABAP 0ditor! The s$stem then creates a temporar$ runtime ob2ect "ith a name that differs from
the program name! 6o"eer# the s$stem e/ecutes the program as if started outside the ABAP
0ditor! ,or e/ample# if $ou hae created an ABAP module pool# $ou cannot test the program in the
ABAP 0ditor! 3ou must create a transaction code and a screen flo" logic before $ou can e/ecute
the program!
Testing a program often inoles a runtime anal$sis# "hich sho"s $ou the amount of time $our
program consumes in the client;serer enironment of the SAP S$stem and "hat this time is used
for! ,or more information# refer to the runtime anal$sis documentation!
Program C$ec*s
The s$stem chec-s ABAP programs staticall$ "hen $ou create them and d$namicall$ "hen the$
are running!
Static C$ec*s
*n the static chec-s# the s$nta/ chec- tests the s$nta/ of the program# and the e/tended
program chec- performs a semantic chec- (including# for e/ample# chec-ing "hether the number
and t$pe of the interface parameters in an e/ternal procedure call is correct)!
S%nta5 C$ec*
The s$nta/ chec- chec-s the s$nta/ and internal semantics of a program! When an error occurs#
the chec- stops# and the s$stem generates an appropriate error message! A dialog bo/ often
appears# in "hich a proposed solution is displa$ed! Choose WCorrectW to adopt this proposed
solution in the program! The s$stem then repeats the s$nta/ chec-!
When $ou run a s$nta/ chec- on an include program# the s$stem combines it "ith the Top include
of the program before chec-ing it! The s$stem onl$ chec-s all of the includes belonging to a
program for consistenc$ and completeness (for e/ample# ensuring that all of the subroutines
called from the program hae actuall$ been defined) "hen $ou run the s$nta/ chec- for the main
program!
The s$nta/ chec- ma$ generate "arnings! *n this case# the s$nta/ chec- does not end
immediatel$# and $ou can# technicall$# run the program! 6o"eer# $ou should al"a$s correct s$nta/
"arnings# since the$ could cause unforeseen errors "hen $ou run the program and could also
become a real s$nta/ error in future releases!
ABAP Programming (BC-ABA) :4
05tended Program C$ec*
'an$ chec-s are e/cluded from the standard s$nta/ chec- for performance reasons! The
e/tended program chec- performs a complete chec- that includes the interfaces of e/ternal
procedures called from $our program!
0rrors in the e/tended program chec- cause e/ceptions "hen $ou run the program "hich# in turn#
lead to runtime errors! 3ou must therefore correct them! The e/ception to this is coding that
cannot be reached! 6o"eer# $ou should delete this to minimi9e the si9e of $our program and
ma-e the source code easier to understand!
Warnings in the e/tended program chec- should also be corrected! *f $our program contains
statements that are definitel$ correct but still produce "arnings in the e/tended program chec-#
$ou can e/clude them from the chec- using pseudocomments (;<0C 999)!
3ou should al"a$s run the e/tended program chec- on a ne" program! 3ou hae not finished
deeloping a ne" program until $ou can run the e/tended program chec- on it "ithout an$ errors
or "arnings! 'essages are permissible# since the$ are generall$ not critical!
The e/tended program chec- is also onl$ a static chec-! *t cannot eliminate all of the
circumstances that could lead to e/ceptions or runtime errors! ,or e/ample# an$ statements in
"hich $ou specif$ arguments d$namicall$ as the contents of fields# or in "hich $ou call procedures
d$namicall$# cannot be chec-ed staticall$!
)%namic C$ec*
0rrors that cannot be detected staticall$ and that occur at runtime are detected b$ the ABAP
runtime enironment! Such errors lead to e/ceptions! *f an e/ception is not handled or cannot be
handled# a runtime error occurs! *f such a runtime error occurs# the ABAP runtime enironment
terminates the program# generates a s$ort dump# and s"itches to a special screen from "hich $ou
can anal$9e it!
Short dumps are diided into bloc-s describing different aspects of the error! *n the oerie"#
$ou can see "hat information is contained in the short dump# for e/ample# the contents of data
ob2ects# actie calls# control structures# and so on! The short dump oerie" also allo"s $ou to
displa$ the point in the program at "hich the termination occurred in the ABAP &ebugger!
The follo"ing -inds of errors can occur+
7 Internal error
The -ernel encountered an error! *n this case# inform SAP!
7 Installation and environment or resource error
An error that occurred due to incorrect s$stem installation or missing resources (for e/ample#
database closed)!
7 0rror in application program
T$pical causes+
Contents of a numeric field hae the "rong format!
Arithmetic oerflo"!
0/ternal procedure does not e/ist!
T$pe conflict "hen passing parameters to an e/ternal procedure!
Short dumps are retained in the s$stem for 1> da$s! )se Transaction ST44 to administer short
dumps! *f $ou "ant to retain a short dump be$ond the default 1> da$s# use the Ueep function! *f
$ou "ant to delete short dumps b$ a date criterion other than the default 1> da$s# choose
%eorgani9e! *f $ou displa$ a short dump using Transaction ST44# $ou cannot branch to the
&ebugger!
*f problems occur in an ABAP program that $ou cannot sole $ourself# $ou can send an e/tract of
the short dump to SAP! The contents of the short dump are essential to the SAP 6otline and
%emote Consulting to enable them to sole $our problem!
-$e ABAP Programming anguage
ABAP Programming (BC-ABA) ::

ABAP S$nta/
&ata T$pes and 1b2ects
1perations on &ata 1b2ects
Controlling the Program ,lo"
B$te and Character String Processing
,ield S$mbols and &ata %eferencing
*nternal Tables and 0/tracts
Saing &ata 0/ternall$
1bsolete Techni8ues
ABAP S%nta5
The s$nta/ of the ABAP programming language consists of ABAP statements and comments!
ABAP Statements
Normall$# each ABAP statement begins "ith a *e%word! A statement can contain operands and
additions of the -e$"ord and is al"a$s concluded "ith a period!
P%1(%A' firstSprogram!
W%*T0 I'$ ,irst ProgramI!

This e/ample contains t"o statements# one on each line! The -e$"ords are P(O/(A, and W(I-0!
The program displa$s a list on the screen! *n this case# the list consists of the line W'$ ,irst
ProgramW!

The program $ou see in the follo"ing diagram sho"s the structure of ABAP statements!
,or some sample ABAP statements# grouped b$ categor$# see 1erie" of ABAP Statements and
*ntroductor$ Statements for Programs!
2ormatting ABAP Statements
ABAP has no format restrictions! 3ou can enter statements in an% format# so a statement can be
indented# $ou can "rite seeral statements on one line# or spread a single statement oer seeral
lines!
3ou must separate "ords "ithin a statement "ith at least one space! The s$stem also interprets
the end of line mar-er as a space!
ABAP Programming (BC-ABA) :>
The program fragment
P%1(%A' test!
W%*T0 IThis is a statementI!
could also be "ritten as follo"s+
P%1(%A' test! W%*T0 IThis is a statementI!
or as follo"s+
P%1(%A'
test!
W%*T0
IThis is a statementI!
As there are no format restrictions# $ou hae the chance to enhance the readabilit$ of $our
programs!
Note
*f a character literal in an ABAP statement e/tends across more than one line# the s$stem
interprets all spaces bet"een the 8uotation mar-s as being part of the character literal! As the
number of spaces inserted depends on the line "idth of the editor# the s$nta/ chec- issues a
"arning if $ou insert spaces outside classes! *nside classes# inserting spaces is generall$ not
allo"ed!
*f $ou "ant to enter character literals that do not fit into a single line# $ou can use the #
character to combine a succession of character literals into a single one!
C$ained Statements
The ABAP programming language allo"s $ou to concatenate consecutie statements "ith an
identical first part into a chain statement! To do this# $ou "rite the identical part for all
statements onl$ once and place a colon (=) after it! After the colon# "rite the remaining parts of
the indiidual statements# separating them "ith commas (#)! 0nsure that $ou place a period (9)
after the last part to inform the s$stem "here the chain ends! When the program is e/ecuted#
the chained statement is handled the same "a$ as the single ABAP statements "ould be in their
defined se8uence!
Statement se8uence+
W%*T0 spfli-cit$from!
W%*T0 spfli-cit$to!
W%*T0 spfli-airpto!

Chain statement+
W%*T0+ spfli-cit$from# spfli-cit$to# spfli-airpto!

*n the chain# a colon separates the beginning of the statement from the ariable parts! After the
colon or commas# $ou can insert an$ number of spaces!

3ou could# for e/ample# "rite the same statement li-e this+
W%*T0+ spfli-cit$from#
spfli-cit$to#
spfli-airpto!

*n a chain statement# the first part (before the colon) is not limited to the -e$"ord of the
statements!
Statement se8uence+
sum H sum 5 1!
sum H sum 5 4!
sum H sum 5 :!
sum H sum 5 >!

Chain statement+
sum H sum 5 + 1# 4# :# >!
Comments
ABAP Programming (BC-ABA) :?
Comments are te/ts that $ou can "rite bet"een the statements of $our ABAP program to e/plain
their purpose to a reader! Comments are distinguished b$ the preceding signs L (at the beginning
of a line) and W (at an$ position in a line)! *f $ou "ant the entire line to be a comment# enter an
asteris- (L) at the beginning of the line! The s$stem then ignores the entire line "hen it
generates the program! *f $ou "ant part of a line to be a comment# enter a double 8uotation mar-
(W) before the comment! The s$stem interprets comments indicated b$ double 8uotation mar-s as
spaces!
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
L P%1(%A' SAP'T0ST L
L W%*TT0N B3 C6A%.*0 B3T0# F@;4B;1EE? L
L .AST C6AN(0& B3 %*TA &*(*T# 1F;F1;1EE? L
L TASU+ &0'1NST%AT*1N L
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
P%1(%A' sapmtest!
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
L &0C.A%AT*1NS L
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
&ATA+ flag(1) T3P0 c# W global flag
number T3P0 i! W counter
!!!!!!
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
L P%1C0SS*N( B.1CUS L
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
!!!!!!
S$nta/ Conentions
The conentions for s$nta/ statements in this documentation are as follo"s+
Ue$ &efinition
STAT0'0NTABAP -e$"ords and their additions are displa$ed in uppercase!
operand 1perands of statements are displa$ed in lo"ercase!
XY S8uare brac-ets indicate that $ou can use none# one# or more
of the enclosed options! &o not include the brac-ets in $our
option!
Z A ertical line bet"een t"o parts of a statement indicates that
onl$ one of these t"o parts can be used "ithin the statement!
() An$ parentheses must be entered as part of the statement!
# A comma indicates that $ou ma$ choose as man$ of the options
sho"n as $ou li-e# separating $our choices "ith commas! The
commas are part of the s$nta/!
f
1
f
4
Aariables "ith indices indicate that $ou can list as man$
ariables as $ou "ant! The$ must be separated "ith the same
s$mbol as the first t"o!
!!! Periods mean that $ou can put an$thing here that is allo"ed in
the conte/t!

Ue$"ords are specified in uppercase in s$nta/ statements! 3ou can disregard case "hen $ou t$pe
-e$"ords in $our program! W%*T0 is the same as Write or "rite!
Screen output is either sho"n as a screen shot or in the follo"ing format+
Screen output
ABAP Statements > an Overview
The first element of an ABAP statement is the ABAP *e%word! This determines the categor$ of
the statement! The different statement categories are as follo"s+
)eclarative Statements
These statements define data t%pes or declare data o&3ects "hich are used b$ the other
statements in a program or routine! The collected declaratie statements in a program or routine
ma-e up its declaration part!
ABAP Programming (BC-ABA) :@
0/amples of declaratie -e$"ords+
T3P0S# &ATA# TAB.0S
,odulari:ation Statements
These statements define the processing &loc*s in an ABAP program!
The modulari9ation -e$"ords can be further diided into+
7 &efining -e$"ords
3ou use statements containing these -e$"ords to define subroutines# function modules# dialog
modules and methods! 3ou conclude these processing bloc-s using the 0N) statements!
0/amples of definitie -e$"ords+
'0T61& !!! 0N&'0T61&# ,)NCT*1N !!! 0N&,)NCT*1N#
'1&).0 !!! 0N&'1&).0!
7 0ent -e$"ords
3ou use statements containing these -e$"ords to define event &loc*s! There are no special
statements to conclude processing bloc-s - the$ end "hen the ne/t processing bloc- is
introduced!
0/amples of eent -e$ "ords+
AT S0.0CT*1N SC%00N# STA%T-1,-S0.0CT*1N# AT )S0%-C1''AN&
Control Statements
3ou use these statements to control the flo" of an ABAP program "ithin a processing bloc-
according to certain conditions!
0/amples of control -e$"ords+
*,# W6*.0# CAS0
Call Statements
3ou use these statements to call processing bloc-s that $ou hae alread$ defined using
modulari9ation statements! The bloc-s $ou call can either be in the same ABAP program or in a
different program!
0/amples of call -e$"ords+
CA.. '0T61&# CA.. T%ANSACT*1N# S)B'*T# .0AA0 T1
Operational Statements
These -e$"ords process the data that $ou hae defined using declaratie statements!
0/amples of operational -e$"ords+
'1A0# A&&
Introductor% Statements for Programs
0ach ABAP program t$pe has a statement that introduces programs of that t$pe+

Program T$pe *ntroductor$ Statement
0/ecutable Program (0PO(-
'odule Pool P(O/(A,
,unction (roup 2.NC-ION-POO
Class Pool CASS-POO
*nterface Pool IN-0(2AC0-POO
Subroutine Pool P(O/(A,
T$pe (roup -7P0-POO
*nclude Program -

*nclude programs are not compilation units! *nstead# the$ are purel$ modulari9ation units that are
onl$ eer used in the conte/t of superior-leel programs! ,or this reason# include programs do not
hae a special introductor$ statement!
Note=
*t is not obligator$# from a s$nta/ point of ie"# to assign introductor$ program statements to
the program t$pes defined in the program properties! 6o"eer# the assignment sho"n in the
aboe table should nonetheless be used al"a$s! When a program is created# the suitable
statement is automaticall$ generated b$ the ABAP Wor-bench and should be changed during
editing in the additions onl$! *n particular# the -e$"ords 2.NC-ION-POO# CASS-POO#
IN-0(2AC0-POO# and -7P0-POO should be created solel$ b$ the respectie tools of the
ABAP Wor-bench and neer be entered in the source te/t themseles in order to aoid
une/pected s$stem behaior!

ABAP Programming (BC-ABA) :B
The follo"ing sections describe the function of introductor$ statements+
(0PO(- and P(O/(A,
The %0P1%T and P%1(%A' statements currentl$ hae the same function! The$ allo" $ou to
specif$ the message class of the program and the formatting options for its default list!
Whether a program is e/ecutable or can onl$ be started using a transaction code depends
e/clusiel$ on the program t$pe and not on the statement that introduces it! Nonetheless# module
pools and subroutine pools should al"a$s begin "ith a P%1(%A' statement# and e/ecutable
programs al"a$s "ith a %0P1%Tstatement!
2.NC-ION-POO
The introductor$ statement ,)NCT*1N-P11. declares a program in "hich $ou can define
function modules! At runtime# it has the effect that [ during program loading [ a ne" program
group "ith its o"n screens and its o"n shared data areas is created in the internal session of the
calling program! ,or this reason# function groups must al"a$s begin "ith a ,)NCT*1N-P11.
statement! The statement ,)NCT*1N-P11. is usuall$ generated b$ the ,unction Builder! 1ther
programs (e/ecutable programs# module pools# and subroutine pools) should not begin "ith a
,)NCT*1N-P11.statement# since the$ "ould then not share common data areas "ith the caller
"hen loaded b$ an e/ternal subroutine call! 6o"eer# in e/ceptional cases# $ou can force
processing of $our o"n screens for e/ternall$ called subroutines if $ou introduce e/ecutable
programs or module pools "ith ,)NCT*1N-P11.! As in the %0P1%T and P%1(%A'statements#
$ou can specif$ the message class for the program and the standard list formatting options of
the program using ,)NCT*1N-P11.!
CASS-POO and IN-0(2AC0-POO
The introductor$ program statements C.ASS-P11. and *NT0%,AC0-P11. are proided solel$
for class and interface definitions! A program introduced "ith the C.ASS-P11.statement can
onl$ contain global t$pe definitions and definitions of classes and interfaces! Programs introduced
"ith *NT0%,AC0-P11. can onl$ contain the definition of a global interface! The C.ASS-P11.
and *NT0%,AC0-P11. statements must be generated solel$ b$ the Class Builder tool!
T3P0-P11.
The introductor$ statement T3P0-P11. can onl$ be used for t$pe groups! A program introduced
"ith the T3P0-P11. statement can onl$ contain global t$pe definitions and constant declarations!
The T3P0-P11. statement must be generated solel$ b$ the &ictionar$ tool!
)ata -%pes and )ata O&3ects
Programs "or- "ith local program data [ that is# "ith b$te se8uences in the "or-ing memor$! B$te
se8uences that belong together are called fields and are characteri9ed b$ a length# an identit$
(name)# and [ as a further attribute [ b$ a data t$pe! All programming languages hae a concept
that describes ho" the contents of a field are interpreted according to the data t$pe!
*n the ABAP t$pe concept# fields are called data ob2ects! 0ach data ob2ect is thus an instance of
an abstract data t$pe! There are separate name spaces for data ob2ects and data t$pes! This
means that a name can be the name of a data ob2ect as "ell as the name of a data t$pe
simultaneousl$!
)ata -%pes
As "ell as occurring as attributes of a data ob2ect# data t$pes can also be defined independentl$!
3ou can then use them later on in con2unction "ith a data ob2ect! The definition of a user-defined
data t$pe is based on a set of predefined elementar$ data t$pes! 3ou can define data t$pes
either locall$ in the declaration part of a program using the -7P0Sstatement) or globall$ in the
ABAP &ictionar$! 3ou can use $our o"n data t$pes to declare data ob2ects or to chec- the t$pes
of parameters in generic operations!
)ata O&3ects
ABAP Programming (BC-ABA) :D
&ata ob2ects are the ph$sical units "ith "hich ABAP statements "or- at runtime! The contents
of a data ob2ect occup$ memor$ space in the program! ABAP statements access these contents b$
addressing the name of the data ob2ect and interpret them according to the data t$pe!! ,or
e/ample# statements can "rite the contents of data ob2ects in lists or in the database# the$ can
pass them to and receie them from routines# the$ can change them b$ assigning ne" alues# and
the$ can compare them in logical e/pressions!
0ach ABAP data ob2ect has a set of technical attributes# "hich are full$ defined at all times "hen
an ABAP program is running (field length# number of decimal places# and data t$pe)! 3ou declare
data ob2ects either staticall$ in the declaration part of an ABAP program (the most important
statement for this is )A-A)# or d$namicall$ at runtime (for e/ample# "hen $ou call procedures)!
As "ell as fields in the memor$ area of the program# the program also treats literals li-e data
ob2ects!

,or more information# refer to the follo"ing chapters+
&ata T$pes
&ata 1b2ects
Built-*n &ata T$pes and &ata 1b2ects
(eneric &ata T$pes for T$ping
.ocal Program &ata T$pes and &ata 1b2ects
)ata -%pes
All programming languages distinguish bet"een arious t$pes of data "ith arious uses# such as \!!
t$pe data for storing or displa$ing alues and numerical data for calculations! The attributes in
8uestion are described using data t$pes! 3ou can define# for e/ample# ho" data is stored in the
repositor$# and ho" the ABAP statements "or- "ith the data!
&ata t$pes can be diided into elementar$# reference# and comple/ t$pes!
0lementar% -%pes
These are data t$pes of fi/ed or ariable length that are not made up of other t$pes!
The difference bet"een ariable length data t$pes and fi/ed length data t$pes is that the length
and the memor$ space re8uired b$ data ob2ects of ariable length data t$pes can
change d$namicall$ during runtime# and that these data t$pes cannot be defined
irreersibl$ "hile the data ob2ect is being declared!
Predefined and .ser-)efined 0lementar% )ata -%pes
3ou can also define $our o"n elementar$ data t$pes in ABAP using the -7P0S statement! 3ou
base these on the predefined data t$pes! This determines all of the technical attributes of the
ne" data t$pe! ,or e/ample# $ou could define a data t$pe PS4 "ith t"o decimal places# based on
the predefined data t$pe P! 3ou could then use this ne" t$pe in $our data declarations!
(eference -%pes
%eference t$pes are deep data t$pes that describe reference ariables# that is# data ob2ects
that contain references! A reference ariable can be defined as a component of a comple/ data
ob2ect such as a structure or internal table as "ell as a single field!
Comple5 )ata -%pes
Comple/ data t$pes are made up of other data t$pes! A distinction is made here bet"een
structured t$pes and table t$pes!
Structures
The instances of structured t$pes are -no"n as structures# and are used in ABAP programs to
group "or- areas that logicall$ belong together! Since the indiidual elements "ithin a structure
can be of an$ t$pe# and can also themseles be structures or internal tables# the possible uses of
structures are er$ "ide-ranging! ,or e/ample# $ou can use a structure "ith elementar$ data
t$pes to displa$ lines from a database table "ithin a program! 3ou can also use structures
ABAP Programming (BC-ABA) :E
containing aggregated elements to include all of the attributes of a screen or control in a single
data ob2ect!
The follo"ing terms are important "hen "e tal- about structures+
7 Nested and non-nested structures
7 ,lat and deep structures

Nestedstructures are structures that in turn contain one or more other structures as
components!
2latstructures contain onl$ elementar$ data t$pes of fi/ed length (no internal tables# reference
t$pes# or strings)! The term flat structure can appl$ regardless of "hether the structure is
nested or not! Nested structures are flat so long as none of the specified t$pes is contained in
an$ nesting leel!
An$ structure that contains at least one internal table# reference t$pe# or string as a component
(regardless of nesting) is -no"n accordingl$ as a deep structure!
1nl$ in the case of flat structures is the data content of the structure actuall$ "ithin the
memor$ of the structure itself# "hile deep structures contain pointers to the data at the position
of the deepest components! Since the field contents are not stored "ith the field descriptions in
the case of deep structures# assignments# offset and length specifications and other operations
are handled differentl$ from flat structures!
Internal -a&les
*nternal tables consists of a series of lines that all hae the same data t$pe! *nternal tables are
characteri9ed b$+
7 Their line t$pe
7 A table -e$ that is used to identif$ table ro"s! The -e$ can be uni8ue or non-uni8ue!
7 The table t$pe that defines ho" ABAP "ill access indiidual table entries (non-sorted and
sorted inde/ tables and hash tables)!
3ou should use internal tables "heneer $ou need to use structured data "ithin a program! 1ne
imprint use is to store data from the database "ithin a program!
05amples for Comple5 )ata -%pes
The follo"ing list contains e/amples of comple/ data t$pes in ascending order of comple/it$+
!!
1! Structures consisting of a series of elementar$ data t$pes of fi/ed length (non-nested# flat
structures)
4! An internal table "hose line t$pe is an elementar$ t$pe (ector)!
:! *nternal tables "hose line t$pe is a non-nested structure (IrealI table)
>! Structures "ith structures as components (nested structures# flat or deep)
?! structures containing internal tables as components (deep structures)
@! *nternal tables "hose line t$pe contains further internal tables!
ABAP Programming (BC-ABA) >F
The graphic sho"s ho" elementar$ fields can be combined to form comple/ t$pes!
2urt$er Information a&out )ata -%pes
- &efinition and isibilit$ of data t$pes at arious leels of the SAP s$stem!
- Compatibilit$!
)efinition and !isi&ilit% of )ata -%pes
The follo"ing graphic sho"s "here $ou can define data t$pes in ABAP+
This differentiates bet"een
7 Predefined ABAP t$pes that are built into the -ernel!
7 .ocal data t$pes that $ou can define in ABAP programs!
7 &ata t$pes in the %epositor$ that are aailable to %epositor$ ob2ects in all programs!
!isi&ilit% of )ata -%pes
7 The predefined ABAP t$pes (c# d# f# i# n# p# t# 5) are al"a$s isible! 3ou cannot declare t$pes
"ith the same names as these data t$pes# either in the program or in the ABAP &ictionar$!
7 When "e tal- about the isibilit$ of local data t$pes in the program# "e must differentiate
bet"een local data t$pes in procedures and global data t$pes! &ata t$pes defined in a procedure
obscure other ob2ects "ith the same name that are declared in the global declarations of the
program! All local data t$pes in a program obscure data t$pes "ith the same names in the ABAP
&ictionar$! This also applies to data t$pes from t$pe groups!
7 *n the ABAP &ictionar$# different isibilit$ rules appl$ to standalone data t$pes and the
data t$pes stored in t$pe groups! &ata t$pes in t$pe groups obscure standalone data t$pes "ith
ABAP Programming (BC-ABA) >1
the same names! 6o"eer# this should be an e5ceptional situation! All data t$pes in the ABAP
&ictionar$ should be in the same namespace! When $ou create a standalone data t$pe# the s$stem
displa$s a "arning if the name begins "ith the name of a t$pe group follo"ed b$ an underscore!
08uall$# $ou cannot create a t$pe group if there is alread$ a standalone data t$pe "ith the same
name follo"ed b$ an underscore!
The graphic sho"s the isibilit$ of local and ABAP &ictionar$ data t$pes+
The s$stem searches from the inside out! *f $ou specif$ T3P01 in a -7P0 addition in the program#
the s$stem uses the ABAP &ictionar$ t$pe both in the procedure and the main program! *f $ou
specif$ T3P04 in the procedure# the s$stem uses the local t$pe from the procedure! 6o"eer# if
$ou specif$ T3P4 in the main program# the s$stem uses the t$pe from the main program! T3P04
from the ABAP &ictionar$ is obscured! *f $ou specif$ T3P0: either in the procedure or the main
program# the s$stem uses the t$pe from the main program T3P0: from the ABAP &ictionar$ is
obscured!
Compati&ilit%
T"o non-generic data t$pes or data ob2ects are referred to as compatible if all of their technical
attributes (field length# number of decimal places# t$pe) are e/actl$ the same!
&o not confuse the t"o terms compatible and conertible! When "or-ing "ith data ob2ects# $ou
"ill often ma-e assignments bet"een data ob2ects that hae different technical attributes! *n
this case# the data t$pes are conerted! *n order for non-compatible data t$pes to be conerted#
a conersion rule must e/ist! 1nl$ compatible data ob2ects can be assigned to one another "ithout
a conersion being necessar$!
Compatibilit$ applies to full$-specified data t$pes# since all data ob2ects are full$ t$ped at
runtime! This compatibilit$ is s$mmetrical! There is also an as$mmetrical compatibilit$# "hich is
used to test the t$pes of interface parameters in procedures and of field s$mbols! *n this case#
generic t$pes are compared "ith full$-specified data t$pes!
Conse8uences of definition for the compatibilit$ of data t$pes+
0lementar% )ata -%pes
0lementar$ data t$pes are compatible "ith other elementar$ data t$pes if the$ are identical in
t$pe# field length# and the number of decimal places!
0lementar$ data t$pes are not compatible "ith references or comple/ t$pes!
(eferences
%eferences are compatible "ith other references "hen their construction rules (t$pe constructor
%0, T1 ]classGZ]interfaceG) are the same!
%eferences are not compatible "ith elementar$ data t$pes or comple/ t$pes!
ABAP Programming (BC-ABA) >4
Comple5 )ata -%pes
Comple/ data t$pes are compatible "ith other comple/ data t$pes if their construction rules are
the same!
Comple/ data t$pes are not compatible "ith elementar$ data t$pes or references!
Structures
Structures are compatible "ith other structures if their constructions are identical and their
components are compatible! This means that the "a$ in "hich field strings are constructed from
elementar$ fields to form the oerall structure from sub-structures must be the same and their
elementar$ components must be compatible "ith each other! *f t"o structures consist of the
same se8uence of elementar$ fields# but these fields are combined differentl$ to substructures#
the structures are not compatible!
Structures are not compatible "ith internal tables!
Internal -a&les
*nternal tables are compatible "ith other internal tables if their line t$pes are compatible and all
other attributes are also the same for both tables! The compatibilit$ of internal tables does not
depend on the number of lines!
*nternal tables are not compatible "ith structures!
)ata O&3ects
A data ob2ect is a part of the repositor$ "hose content can be addressed and interpreted b$ the
program! All data ob2ects must be declared in the ABAP program and are not persistent# meaning
that the$ onl$ e/ist "hile the program is being e/ecuted! Before $ou can process persistent data
(such as data from a database table or from a se8uential file)# $ou must read it into data ob2ects
first! Conersel$# if $ou "ant to retain the contents of a data ob2ect be$ond the end of the
program# $ou must sae it in a persistent form!
)eclaring )ata O&3ects
Apart from the interface parameters of procedures# $ou declare all of the data ob2ects in an
ABAP program or procedure in its declaration part! These declaratie statements establish the
data t$pe of the ob2ect# along "ith an$ missing technical attributes! This ta-es place before the
program is actuall$ e/ecuted! The technical attributes can then be 8ueried "hile the program is
running!
The interface parameters of procedures are generated as local data ob2ects# but onl$ "hen the
procedure is actuall$ called! 3ou can define the technical attributes of the interface parameters
in the procedure itself! *f $ou do not# the$ adopt the attributes of the parameters from "hich
the$ receie their alues!
ABAP contains the follo"ing -inds of data ob2ects+
iterals
.iterals are not created b$ declaratie statements! *nstead# the$ e/ist in the program source
code! .i-e all data ob2ects# the$ hae fi/ed technical attributes (field length# number of decimal
places# data t$pe)# but no name! The$ are therefore referred to as unnamed data ob2ects!
Named )ata O&3ects
&ata ob2ects that hae a name that $ou can use to address the ABAP program are -no"n as
named ob2ects! These can be ob2ects of arious t$pes# including te/t s$mbols# ariables and
constants!
Te/t s$mbols are pointers to te/ts in the te/t pool of the ABAP program! When the program
starts# the corresponding data ob2ects are generated from the te/ts stored in the te/t pool!
The$ can be addressed using the name of the te/t s$mbol!
ABAP Programming (BC-ABA) >:
Aariables are data ob2ects "hose contents can be changed using ABAP statements! 3ou declare
ariables using the )A-A4 CASS-)A-A4 S-A-ICS4 PA(A,0-0(S4 S00C--OP-IONS# and
(AN/0Sstatements!
Constants are data ob2ects "hose contents cannot be changed! 3ou declare constants using the
CONS-AN-Sstatement!
Anon%mous )ata
O&3ects
&ata ob2ects that cannot be addressed using a name are -no"n as anon$mous data ob2ects! The$
are created using the C(0A-0 )A-Astatement and can be addressed using reference ariables!
S%stem-)efined )ata O&3ects
S$stem-defined data ob2ects do not hae to be declared e/plicitl$ - the$ are al"a$s aailable at
runtime!
Interface Wor* Areas
*nterface "or- areas are special ariables that sere as interfaces bet"een programs# screens#
and logical databases! 3ou declare interface "or- areas using the -AB0S and
NO)0Sstatements!
iterals
.iterals are unnamed data ob2ects that $ou create "ithin the source code of a program! The$ are
full$ defined b$ their alue! 3ou cannot change the alue of a literal! There are t"o t$pes of
literals+ numeric and c$aracter!
Numeric iterals
Number literals are se8uences of digits "hich can hae a prefi/ed sign! *n number literals there
are no decimal separators and no notation "ith mantissa and e/ponent
IXmantissaYX0YXe/ponentYI
are possible as "ell!
0/amples of numeric literals+
14:
-E:
5>?@
Numeric literals in ABAP statements+
&ATA number T3P0 i AA.)0 -14:>!
W%*T0 @BDE!
'1A0 1FF T1 number!
C$aracter iterals
Character literals are se8uences of alphanumeric characters in the source code of an ABAP
program enclosed in single 8uotation mar-s or bac-8uotes! Character literals enclosed in 8uotation
mar-s hae the predefined ABAP t$pe c and are described as te5t field literals! .iterals
enclosed in bac-8uotes hae the ABAP t$pe string and are described as string literals! The field
length is defined b$ the number of characters! With te/t field literals trailing blan-s are ignored
"hile in string literals the$ are ta-en into account!
0/amples of te/t field literals+
IAnton$ SmithI
I@E1EF WalldorfI
0/amples of string literals+
^Anton$ Smith ^
^@E1EF Walldorf ^
*f $ou use character literals in operand positions at "hich a numeric alue is e/pected# the$ are
conerted into a numeric alue!
0/amples of character literals that can be conerted into numeric t$pes+
ABAP Programming (BC-ABA) >>
I14:>?@BDEF14:>?@BDEFI
I5F!?D>EDI
I-D>B:!@BI
I-14!:>?@BI
I-B@?0-F>I
I14:>0?I
I514054:I
I514!:0->I
I101@FI
-e5t S%m&ols
A te/t s$mbol is a named data ob2ect that is generated "hen $ou start the program from the
te/ts in the te/t pool of the ABAP program! *t al"a$s has the data t$pe c! *ts field length is that
of the te/t in the te/t pool!
Te/t s$mbols# along "ith the program title# list headings# and selection te/ts# belong to the te5t
elements of a program! Te/t elements allo" $ou to create language-independent programs! An$
te/t that the program sends to the screen can be stored as a te/t element in a te/t pool!
&ifferent te/t pools can be created for different languages! When a te/t element is changed or
translated# there is no need to change the actual program code! Te/t elements in an ABAP
program are stored in the ABAP 0ditor (see Te/t 0lement 'aintenance)!
*n the te/t pool# each te/t s$mbol is identified b$ a three-character *&! Te/t s$mbols hae a
content# an occupied length# and a ma/imum length!
0/amples for te/t s$mbols in an ABAP program+
*& Contents 1ccupied length 'a/imum length
F1F Te/t s$mbol F1F 1? 1:4
F:F Te/t s$mbol F:F 1? 1FF
AAA Te/t s$mbol AAA 1? 1?
*n the program# $ou can address te/t s$mbols using the follo"ing form+
te5t-<<<
This data ob2ect contains the te/t of the te/t s$mbol "ith *& <<< in the logon language of the
user! *ts field length is the same as the ma/imum length of the te/t s$mbol! )nfilled characters
are filled up "ith spaces! 3ou can address te/t s$mbols an$"here in a program "here it is also
possible to address a ariable!
*f there is no te/t s$mbol <<< in the te/t pool for the logon language# the name te5t-<<<
addresses the predefined data ob2ect space instead!
3ou can also address te/t s$mbols as follo"s+
999 ?te5tliteral?(<<<) 999
*f the te/t s$mbol <<< e/ists in the te/t pool for the logon language# this is the same as using
te5t-<<<! 1ther"ise# the literal Ite/tliteralI is used as the contents of the te/t s$mbol! This is
onl$ possible at positions in the program "here a ariable can occur! 3ou can create a te/t s$mbol
for an$ te/t literal b$ double-clic-ing the literal in the ABAP 0ditor and replacing the literal "ith
the te/t s$mbol!
3ou should use te/t s$mbols in $our program "heneer the$ need to be language-specific - for
e/ample# in a W(I-0statement!
*f $ou program a list "hose la$out depends on field lengths# $ou should be careful# since the field
length of te/t s$mbols "ill be different in different languages! 3ou should therefore set the
ma/imum field length of the field s$mbol so that there is enough space to translate it into other
languages! ,or e/ample# the 0nglish "ord IprogramI has seen letters# but its e8uialent (erman
translation IProgrammI has eight!
The follo"ing e/ample sho"s the use of te/t s$mbols in W(I-0 statements!
S0- BAN" IN0S ON9
W(I-0= te5t-@8@4
A te5t-aaa4
A te5t-@B@4
ABAP Programming (BC-ABA) >?
A ?)efault -e5t @C@?(@C@)4
A ?)efault -e5t @D@?(@D@)9
*f the te/t s$mbols of the aboe screen shots are lin-ed to this program# the output loo-s as
follo"s+
Te/t s$mbols F4F and F>F hae no te/t s$mbols! ,or te/t s$mbol F4F# the s$stem displa$s a
space! This is onl$ displa$ed in this case because the blan- line suppression has been turned off
(see Creating Blan- .ines)! ,or te/t s$mbol F>F# the literal specified in the program code is
displa$ed!
!aria&les
Aariables are named data ob2ects that $ou can declare staticall$ using declaratie statements# or
d$namicall$ "hile a program is running! The$ allo" $ou to store changeable data under a particular
name "ithin the memor$ area of a program!
3ou can declare ariables staticall% using the follo"ing statements+
7 )A-A+ To declare ariables "hose lifetime is lin-ed to the conte/t of the declaration
7 S-A-ICS+ To declare ariables "ith static alidit$ in procedures
7 CASS-)A-A+ To declare static ariables "ithin classes
7 PA(A,0-0(S+ To declare elementar$ data ob2ects that are also lin-ed to an input field on
a selection screen
7 S00C--OP-IONS+ To declare an internal table that is also lin-ed to input fields on a
selection screen
7 (AN/0S+ To declare an internal table "ith the same structure as in S0.0CT-1PT*1NS#
but "ithout lin-ing it to a selection screen!
This section e/plains the &ATA and STAT*CSstatements! ,or further information about C.ASS-
&ATA< refer to Classes! ,or further information about PA%A'0T0%S# S0.0CT-1PT*1NS and
%AN(0S# refer to Selection Screens!
)eclaring !aria&les )%namicall%
3ou can also create data ob2ects d$namicall$ "hen $ou call procedures! These data ob2ects are
the formal parameters of the interface definition# "hich onl$ hae technical attributes "hen
the$ inherit them from the actual parameters passed to them!
Static !aria&les in Procedures
Aariables that $ou declare "ith the )A-A statement lie for as long as the conte/t in "hich the$
are defined! Therefore ariables in an ABAP main program e/ist for the entire runtime of the
program# and local ariables in procedures onl$ e/ist for as long as the procedure is running!
To retain the alue of a local ariable be$ond the runtime of the procedure# $ou can declare it
using the S-A-ICS statement! This declares a ariable "ith the lifetime of the conte/t of the
main program# but "hich is onl$ isible "ithin the procedure!
The first time $ou call a subroutine or function module# the corresponding main program is al"a$s
loaded into the internal session of the calling program! *t is not deleted "hen the procedure ends!
This enables ariables defined using S-A-ICSto retain their alues be$ond the runtime of the
procedure# allo"ing them to be reused the ne/t time the procedure is called (see the e/ample in
the .ocal &ata in Subroutines section)!
*n methods# ariables defined "ith S-A-ICS are static attributes that are onl$ isible in the
corresponding method# but for all instances of a class (see Classes)!
The s$nta/ of the S-A-ICS statement is identical to that of the )A-A statement!
Constants
Constants are named data ob2ects that $ou create staticall$ using a declaratie statement! The$
allo" $ou to store data under a particular name "ithin the memor$ area of a program! The alue of
a constant must be defined "hen $ou declare it! *t cannot subse8uentl$ be changed! The alue of
ABAP Programming (BC-ABA) >@
a constant cannot be changed during the e/ecution of the program! *f $ou tr$ to change the alue
of a constant# a s$nta/ error or runtime error occurs!
3ou declare constants using the C1NSTANTS statement! Within the program# $ou can also
declare local ariables "ithin procedures using C1NSTANTS! The same rules of isibilit$ appl$ to
constants as appl$ to the isibilit$ of data t$pes! .ocal constants in procedures obscure
identicall$-named ariables in the main program! Constants e/ist for as long as the conte/t in
"hich the$ are declared!
The s$nta/ of the C1NSTANTS statement is e/actl$ the same as that of the &ATA statement#
but "ith the follo"ing e/ceptions+
7 3ou must use the AA.)0 addition in the C1NSTANTS statement! The start alue specified
in the AA.)0 addition cannot be changed during the e/ecution of the program!
7 3ou cannot define constants for _ST%*N(S# references# internal tables# or structures
containing internal tables!
0lementar$ constants+
C1NSTANTS+ pi T3P0 p &0C*'A.S 1F AA.)0 I:!1>1?E4@?:@I!
refSc1 T3P0 %0, T1 C1 AA.)0 *S *N*T*A.!
The last line sho"s ho" $ou can use the *S *N*T*A. argument in the AA.)0addition! Since $ou
must use the AA.)0 addition in the C1NSTANTS statement# this is the onl$ "a$ to assign an
initial alue to a constant "hen $ou declare it!
Comple/ constants+
C1NSTANTS+ B0(*N 1, m$address#
name T3P0 c .0N(T6 4F AA.)0 I,red ,lintstoneI#
street T3P0 c .0N(T6 4F AA.)0 ICae AenueI#
number T3P0 p AA.)0 11#
postcode T3P0 n .0N(T6 ? AA.)0 EDB@?#
cit$ T3P0 c .0N(T6 4F AA.)0 IBedroc-I#
0N& 1, m$address!
This declares a constant structure m%address! The components can be addressed b$ m%address-
name# m%address-street# and so on# but the$ cannot be changed!
Interface Wor* Areas
The follo"ing statements are practicall$ obsolete and are onl$ aailable to ensure
compatibilit$ "ith earlier %eleases! To find out "hen $ou can still use these statements# see the
-e$"ord documentation!

*nterface "or- areas are special named data ob2ects that are used to pass data bet"een
7 Screens and ABAP programs
7 .ogical databases and ABAP programs
7 ABAP programs and e/ternal subroutines!
*nterface "or- areas are created in a shared data area of the programs bet"een "hich the data
is to be e/changed! All of the programs and procedures inoled access this "or- area! To find
out ho" to protect shared "or- areas against changes in procedures# refer to (lobal &ata of the
'ain Program!
Screen Interfaces
1ne common -ind of interface "or- area are table "or- areas# "hich $ou declare using the
TAB.0S dbtab!
This statement creates a structure "ith the same data t$pe and the same name as a database
table# a ie"# or a structure from the ABAP &ictionar$!
Before %elease >!F# it "as necessar$ to declare a database table dbtab to an ABAP program using
the statement TAB.0S dbtab before $ou could access the table using 1pen SC. statements!
This restriction no longer applies to 1pen SC. statements!
6o"eer# $ou still need to use the TAB.0Sstatement if $ou "ant to define input;output fields on
a screen "ith reference to database tables# ie"s# or ABAP &ictionar$ structures ((et from &ict!
function in the la$out editor of the Screen Painter)! *n the PB1 eent# the ABAP program
ABAP Programming (BC-ABA) >B
sends the contents of the fields to the screen fields! *n the PA* eent# it receies the contents
of the screen fields bac- into the corresponding components of the table "or- area!
ogical )ata&ase Interfaces
.ogical databases are special ABAP programs that read data for application programs! When a
logical database is lin-ed "ith an e/ecutable program# it passes data to the interface "or- area
declared "ith the statement
N1&0S node!
This statement creates a ariable node "ith reference to an ABAP &ictionar$ data t$pe of the
same name! *f a node of the logical database refers to the same data t$pe# the ariable seres as
an interface bet"een the logical database and the e/ecutable program! *f a node of a logical
database refers to a database table# a ie"# or a flat structure from the ABAP &ictionar$# $ou
can use the TAB.0S statement instead of N1&0S!
,or further information refer to .ogical &atabases!
05ternal Su&routine Interfaces
*f $ou hae similar ariables in different programs# $ou can store them in a shared data area! To
do this# use the C1''1N PA%Taddition of the &ATA statement! Common data areas of this -ind
can sere as interfaces to e/ternal subroutines! 3ou can also use interface "or- areas defined
"ith the TAB.0S and N1&0S statement as a common data area for e/ternal subroutines!
)etermining t$e Attri&utes of )ata O&3ects
3ou ma$ sometimes need to find out the attributes of a data ob2ect during runtime that "ere not
staticall$ aailable! ,or e/ample# $ou ma$ need to find out the t$pe of a generic interface
parameter in a subroutine! To do this# $ou "ould use the statement+
&0SC%*B0 ,*0.& dob2 X.0N(T6 lenY XT3P0 t$pe XC1'P1N0NTS nYY
X1)TP)T-.0N(T6 outY X&0C*'A.S decY
X0&*T 'ASU mas-Y X60.P-*& helpY!
The attributes of the data ob2ect do&3 specified b$ the parameters of the statement are "ritten
to the ariables follo"ing the parameters! 3ou can use an$ number of the additions in the same
statement!
&0SC%*B0 ,*0.& )IS-ANC0 B0-W00N do&38 AN) do&3B IN-O dec!
This statement returns the distance bet"een the data ob2ects do&38und do&3B!
,or a description of the s$nta/ of the indiidual additions see the -e$"ord documentation!
6ere is an e/ample using the statement &0SC%*B0 ,*0.&!
%0P1%T !!!

C.ASS conSe/c &0,*N*T*1N *N60%*T*N( ,%1' c/SstaticSchec-!
0N&C.ASS!
ABAP Programming (BC-ABA) >D

PA%A'0T0%S+ t$pe1 T3P0 c .0N(T6 :F#
t$pe4 T3P0 c .0N(T6 :F!

&ATA+ dref1 T3P0 %0, T1 data#
dref4 T3P0 %0, T1 data!

,*0.&-S3'B1.S+ ]data1G T3P0 AN3#
]data4G T3P0 AN3!

&ATA+ tdescr1 T3P0 c .0N(T6 1#
tdescr4 T3P0 c .0N(T6 1#
mess T3P0 string!

STA%T-1,-S0.0CT*1N!


T%3!
C%0AT0 &ATA+ dref1 T3P0 (t$pe1)#
dref4 T3P0 (t$pe4)!

ASS*(N+ dref1-GL T1 ]data1G#
dref4-GL T1 ]data4G!

CATC6 c/Ss$ScreateSdataSerror!
'0SSA(0 ICreate data error`I T3P0 I*I &*SP.A3 .*U0 I0I!
.0AA0 P%1(%A'!
0N&T%3!

!!!

&0SC%*B0 ,*0.&+ ]data1G T3P0 tdescr1#
]data4G T3P0 tdescr4!
T%3!
*, tdescr1 ]G tdescr4!
%A*S0 0_C0PT*1N T3P0 conSe/c!
0.S0!
]data4G H ]data1G!
0N&*,!
CATC6 conSe/c!
C1NCAT0NAT0 ^Assignment from t$pe ^ tdescr4 ^ to ^ tdescr1 ^ not allo"ed`^ *NT1 mess!
'0SSA(0 mess T3P0 I*I &*SP.A3 .*U0 I0I!
(un -ime -%pe Identification
Abbreiation %TT*! &etermining data t$pes during program run time!
,or more information# see -e$"ord documentation!
6ere is an e/ample of %TT*! Chec- "hether t"o data t$pes are identical!
%0P1%T !!!

C.ASS conSe/c &0,*N*T*1N *N60%*T*N( ,%1' c/SstaticSchec-!
0N&C.ASS!

PA%A'0T0%S+ t$pe1 T3P0 c .0N(T6 :F#
t$pe4 T3P0 c .0N(T6 :F!

&ATA+ dref1 T3P0 %0, T1 data#
dref4 T3P0 %0, T1 data!
ABAP Programming (BC-ABA) >E

,*0.&-S3'B1.S+ ]data1G T3P0 AN3#
]data4G T3P0 AN3!

&ATA+ descrSref1 T3P0 %0, T1 clSabapSt$pedescr#
descrSref4 T3P0 %0, T1 clSabapSt$pedescr#
mess T3P0 string!

STA%T-1,-S0.0CT*1N!

T%3!
C%0AT0 &ATA+ dref1 T3P0 (t$pe1)#
dref4 T3P0 (t$pe4)!

ASS*(N+ dref1-GL T1 ]data1G#
dref4-GL T1 ]data4G!

CATC6 c/Ss$ScreateSdataSerror!
'0SSA(0 ICreate data error`I T3P0 I*I &*SP.A3 .*U0 I0I!
.0AA0 P%1(%A'!
0N&T%3!

!!!

descrSref1 H clSabapSt$pedescrHGdescribeSb$Sdata( ]data1G )!
descrSref1 H clSabapSt$pedescrHGdescribeSb$Sdata( ]data1G )!

T%3!
*, descrSref1 ]G descrSref4!
%A*S0 0_C0PT*1N T3P0 conSe/c!
0.S0!
]data4G H ]data1G!
0N&*,!
CATC6 conSe/c!
C1NCAT0NAT0 ^Assignment from t$pe ^
descrSref4-GabsoluteSname
^ to ^
descrSref1-GabsoluteSname
^ not allo"ed`^
*NT1 mess!
'0SSA(0 mess T3P0 I*I &*SP.A3 .*U0 I0I!
0N&T%3!

0/amples of %TT* and 1b2ects
%0P1%T !!!

C.ASS conSe/c &0,*N*T*1N *N60%*T*N( ,%1' c/SstaticSchec-!
0N&C.ASS!

PA%A'0T0%S+ ot$pe1 T3P0 c .0N(T6 :F#
ot$pe4 T3P0 c .0N(T6 :F!

&ATA+ oref1 T3P0 %0, T1 ob2ect#
oref4 T3P0 %0, T1 ob2ect!


&ATA+ descrSref1 T3P0 %0, T1 clSabapSt$pedescr#
descrSref4 T3P0 %0, T1 clSabapSt$pedescr#
ABAP Programming (BC-ABA) ?F
mess T3P0 string!

STA%T-1,-S0.0CT*1N!

T%3!
C%0AT0 1Ba0CT+ oref1 T3P0 (ot$pe1)#
oref4 T3P0 (ot$pe4)!

CATC6 c/Ss$ScreateSob2ectSerror!
'0SSA(0 ICreate ob2ect error`I T3P0 I*I &*SP.A3 .*U0 I0I!
.0AA0 P%1(%A'!
CATC6 c/Sroot!
'0SSA(0 I1ther error`I T3P0 I*I &*SP.A3 .*U0 I0I!
.0AA0 P%1(%A'!
0N&T%3!

!!!

descrSref1 H
clSabapSt$pedescrHG&0SC%*B0SB3S1Ba0CTS%0,( oref1 )!
descrSref4 H
clSabapSt$pedescrHG&0SC%*B0SB3S1Ba0CTS%0,( oref4 )!

T%3!
*, descrSref1 ]G descrSref4!
%A*S0 0_C0PT*1N T3P0 conSe/c!
0.S0!
oref1 H oref4!
0N&*,!
CATC6 conSe/c!
C1NCAT0NAT0 ^Assignment from t$pe ^
descrSref4-GabsoluteSname
^ to ^
descrSref1-GabsoluteSname
^ not allo"ed`^
*NT1 mess!
'0SSA(0 mess T3P0 I*I &*SP.A3 .*U0 I0I!
0N&T%3!
Built-In )ata -%pes and )ata O&3ects
Built-in data t$pes refer to t$pes that are made aailable to an ABAP program b$ the runtime
s$stem! Currentl$# all built-in data t$pes are also simultaneousl$ elementar% data t%pes [ that is#
none of them are made up of other t$pes! We distinguish bet"een t"o t$pes of built-in t$pes!
There are built-in t$pes "hose length is staticall$ defined through their definition# and there are
built-in t$pes "hose length can change d$namicall$ during runtime!
*f $ou "ish to "or- "ith data that is aailable to all programs of an SAP S$stem or if $ou "ish to
pass data bet"een programs# $ou re8uire t$pe information that is independent of an indiidual
ABAP program! ,or this purpose# $ou use the ABAP &ictionar$! The ABAP &ictionar$ is a cross-
program storage area for t$pe descriptions! All %epositor$ ob2ects hae access to it! All data
t$pes of the ABAP &ictionar$ can be used in ABAP programs 2ust li-e local program t$pes!
ABAP also contains a set of built-in data ob2ects that can al"a$s be accessed in ABAP programs!
Predefined ABAP -%pes
These data t$pes are predefined in t$e SAP We& AS ABAP *ernel# and are isible in all ABAP
programs! 3ou can use predefined t$pes to define local data t$pes and ob2ects in a program and to
specif$ the t$pe of interface parameters and field s$mbols!
Predefined 0lementar% ABAP -%pes wit$ 2i5ed engt$
ABAP Programming (BC-ABA) ?1
These predefined elementar$ data t$pes are used to specif$ the t$pes of indiidual fields "hose
lengths are al"a$s fi/ed at runtime! The follo"ing table sho"s the different fi/ed-length data
t$pes! All field lengths are specified in b$tes!
)ata -%pe

Initial
2ield
engt$
!alid 2ield
engt$
Initial !alue

,eaning

Numeric -%pes
* > > F *nteger ("hole number)
, D D F ,loating point number
P D 1 - 1@ F Pac-ed number
C$aracter t%pes
C 1 1 - @??:? I \ I -e5t 2ield
(alphanumeric characters)
& D D IFFFFFFFFI )ate field
(,ormat+ 3333''&&)
N 1 1 - @??:? IF \ FI Numeric te5t field
(numeric characters)
T @ @ IFFFFFFI (format+ 66''SS)
+e5adecimal t%pe
_ 1 1 - @??:? _IF \ FI 6e/adecimal field
&ata t$pes &# ,# *# and T describe the technical attributes of a data ob2ect full$! &ata t$pes C#
N# P# and _ are generic! When $ou use a generic t$pe to define a local data t$pe in a program or a
data ob2ect# $ou must specif$ the field length and# in the case of t$pe P# the number of decimal
places! When $ou user generic t$pes to specif$ the t$pes of interface parameters of field
s$mbols# $ou do not hae to specif$ the technical attributes!
The initial alue (and initial field length in the case of the generic t$pes)# are alues that are used
implicitl$ in short forms of the T3P0S and &ATA statements!
The fi/ed-length predefined t$pes are diided into+
Numeric -%pes
3ou can use t$pe * data for counters# numbers of items# inde/es# time periods# and so on!
3ou can use t$pe P data for such alues as distances# "eights# amounts of mone$# and so on!
3ou use t$pe , fields "hen $ou need to cope "ith er$ large alue ranges and rounding errors
are not critical!
)sing * and , fields for calculations is 8uic-er than using P fields! Arithmetic operations using *
and , fields are er$ similar to the actual machine code operations# "hile P fields re8uire more
support from the soft"are! Neertheless# $ou hae to use t$pe P data to meet accurac$ or alue
range re8uirements!
C$aracter t%pes
1f the fie non-numeric t$pes# the four t$pes C# &# N# and T are c$aracter t%pes! ,ields "ith
these t$pes are -no"n as c$aracter fields! 0ach position in one of these fields ta-es up enough
space for the code of one character! Currentl$# ABAP onl$ "or-s "ith single-b$te codes such as
ASC** and 0BC&*!
As of %elease @!1F# Web Application Serer supports both unicode and non-unicode s$stems! Non-
unicode s$stems are conentional SAP s$stems in "hich a character is generall$ represented b$ a
b$te! )nicode s$stems are SAP s$stems that are based on a unicode character displa$ and are
supported b$ an appropriate operating s$stem and database!

+e5adecimal -%pe
The remaining non-numeric t$pe - _ - alwa%s interprets indiidual b$tes in memor$! One b$te is
represented b$ a two-digit he/adecimal displa$! The fields "ith this t$pe are called $e5adecimal
fields! *n he/adecimal fields# $ou can process single bits!
Predefined 0lementar% ABAP -%pes wit$ !aria&le engt$
These predefined elementar$ data t$pes are used to specif$ the t$pes of indiidual fields "hose
lengths are not fi/ed until runtime! There are t"o predefined ABAP data t$pes "ith ariable
length that are genericall$ -no"n as strings+
ABAP Programming (BC-ABA) ?4
7 ST%*N( for character strings
A string is a se8uence of characters "ith ariable length! A string can contain an$ number of
alphanumeric characters! The length of a string is the number of characters multiplied b$ the
length re8uired for the internal representation of a single character!
7 _ST%*N( for b$te strings
A b$te string is a he/adecimal t$pe "ith ariable length! *t can contain an$ number of b$tes!
The length of a b$te string is the same as the number of b$tes!
When $ou create a string as a data ob2ect# onl$ a string header is created staticall$! This
contains administratie information! The actual data ob2ects are created and modified
d$namicall$ at runtime b$ operational statements!
The initial alue of a string is the empt$ string "ith length F! A structure that contains a string is
handled li-e a deep structure! This means that there are no conersion rules for structures that
contain strings!
Predefined Comple5 )ata -%pes
ABAP contains no predefined comple/ data t$pes that $ou can use to define local data t$pes or
data ob2ects in a program! All comple/ data t$pes are based on elementar$ ABAP t$pes# and are
constructed in ABAP programs or in the ABAP &ictionar$!
)ata -%pes in t$e ABAP )ictionar%
The ABAP &ictionar$ allo"s $ou to define global data t$pes! 3ou can use the -7P0 addition of an
appropriate ABAP statement to refer to these data t$pes in an$ ABAP program!
3ou define these data t$pes using the ABAP &ictionar$! The follo"ing input fields are releant
to data t$pes+
There are three groups on the initial screen+
)ata&ase -a&les and !iews
1ne of the most important tas-s of the ABAP &ictionar$ is to administer database tables in
the central database of the SAP s$stem!! The &ictionar$ contains meta-descriptions of the
database tables# and uses these to create the ph$sical tables in the database! A ie" is a Wirtual
tableW containing fields from one or more tables!
*n the description of a database table# the table lines consist of single fields or columns! An
elementar$ data t$pe must be assigned to each column! The elementar$ t$pes in the ABAP
&ictionar$ are data elements! .i-e data ob2ects in ABAP programs# database tables and ie"s
hae data t$pes as attributes! A line of a database table or ie" has the data t$pe of a flat
structure# "hich consists of indiidual data elements!
ABAP Programming (BC-ABA) ?:
*n ABAP programs# $ou can use the -7P0 addition "ith the data t$pe of a database table or ie"!
3ou ma$ refer to the "hole structure or to indiidual components+
!!! T3P0 dbtab !!!
refers to the comple/ data t$pe of the structure#
!!! T3P0 dbtab-comp !!!
refers to the elementar$ data t$pe of component comp!
*f $ou define a comple/ data t$pe t%pe as a structure using
T3P0S t$pe T3P0 dbtab!
the components of the data t$pe t%pe inherit the names of the components of the database table
or ie"# and can be addressed in the program using t%pe-comp !
To ensure compatibilit$ "ith preious releases# $ou can still use the I"0 addition to refer to
database tables or ie"s# e/cept "ithin classes! The reason for this is that in earlier releases#
the ph$sical presence of the database tables as ob2ects "as emphasi9ed# een though the
&ictionar$ onl$ contains meta-descriptions and data t$pes!
&efining program-local data t$pes b$ referring to database tables and ie"s is one of the
essential techni8ues for processing data from database tables in ABAP! &ata ob2ects that $ou
define in this "a$ al"a$s hae the rig$t t%pe to contain data from the corresponding database
table! ABAP 1pen SC. allo"s $ou to read a single field# a range of fields# or an entire database
table or ie" into an internal table!
T3P0S+ cit$ T3P0 spfli-cit$from#
spfliSt$pe T3P0 STAN&A%& TAB.0 1, spfli W*T6 &0,A).T U03!
&ATA+ "aScit$ T3P0 cit$#
"aSspfli T3P0 spfliSt$pe!
!!!
S0.0CT S*N(.0 cit$from ,%1' spfli
*NT1 "aScit$
W60%0 carrid H I.6I AN& connid H I>FFI!
!!!
S0.0CT L ,%1' spfli *NT1 TAB.0 "aSspfli!
999
This e/ample defines an elementar$ data t$pe cit% that refers to a single field of the database
table SP,.* and an internal table spfliEt%pe# "hose line t$pe is the same as the structure of the
database table! The S00C-statement reads data from the database into the corresponding data
ob2ects!
)ata -%pes
&ata t$pes are the actual t$pe definitions in the ABAP &ictionar$! The$ allo" $ou to define
elementar$ t$pes# reference t$pes# and comple/ t$pes that are isible globall$ in the s$stem! The
data t$pes of database tables are a subset of all possible t$pes# namel$ flat structures! (lobal
ob2ect t$pes (classes and interfaces) are not stored in the ABAP &ictionar$# but in the class
librar$! 3ou create them using the Class Builder!
,or a detailed description of data t$pes and their definitions# refer to the T$pes section of
the ABAP &ictionar$ documentation! The follo"ing descriptions mention the t$pes onl$ briefl$#
along "ith ho" $ou can refer to them from ABAP programs!
)ata 0lements
&ata elements in the ABAP &ictionar$ describe indiidual fields! The$ are the smallest indiisible
units of the comple/ t$pes described belo"# and are used to specif$ the t$pes of columns in the
database! &ata elements can be elementar$ t$pes or reference t$pes!
7 0lementar% -%pes
0lementar$ t$pes are part of the dual-leel domain concept for fields in the ABAP &ictionar$!
The elementar$ t$pe has semantic attributes# such as te/ts# alue tables# and documentation#
and has a data t$pe! There are t"o different "a$s to specif$ a data t$pe+
7 B$ directl$ assigning an ABAP &ictionar$ t$pe!
3ou can assign a predefined ABAP &ictionar$ t$pe and a number of characters to an
elementar$ t$pe! The ABAP &ictionar$ has considerabl$ more predefined t$pes than the ABAP
programming language! The number of characters here is not the field length in b$tes# but the
number of alid characters e/cluding formatting characters! The data t$pes are different
ABAP Programming (BC-ABA) ?>
because the predefined data t$pes in the ABAP &ictionar$ hae to be compatible "ith the
e/ternal data t$pes of the database tables supported b$ the SAP Web AS ABAP!
When $ou refer to data t$pes from the ABAP &ictionar$ in an ABAP program# the predefined
&ictionar$ t$pes are conerted to ABAP t$pes as follo"s+
&ictionar$
t$pe
'eaning 'a/imum length n ABAP t$pe
&0C Calculation;amount field 1-:1# 1-1B in tables P((n51);4)
*NT1 Single-b$te integer : *nternal onl$
*NT4 T"o-b$te integer ? *nternal onl$
*NT> ,our-b$te integer 1F *
C)%% Currenc$ field 1-1B P((n51);4)
C)U3 Currenc$ -e$ ? C(?)
C)AN Cuantit$ 1-1B P((n51);4)
)N*T )nit 4-: C(n)
P%0C Accurac$ 1@ *nternal onl$
,.TP ,loating point number 1@ ,(D)
N)'C Numeric te/t 1-4?? N(n)
C6A% Character 1-4?? C(n)
.C6% .ong character 4?@-ma/ C(n)
ST%*N( String of ariable length 1-ma/ ST%*N(
%AWST%*N( B$te se8uence of ariable
length
1-ma/ _ST%*N(
&ATS &ate D &
ACCP Accounting period
3333''
@ N(@)
T*'S Time 66''SS @ T
%AW B$te se8uence 1-4?? _(n)
.%AW .ong b$te se8uence 4?@-ma/ _(n)
C.NT Client : C(:)
.AN( .anguage internal 1# e/ternal 4 C(1)
(Wma/W in .C6% and .%AW is the alue of a preceding *NT4 field! The WinternalW length of a
.AN( field is in the &ictionar$# the We/ternalW length refers to the displa$ on the screen!
7 Assigning a domain
The technical attributes are inherited from a domain! &omains are standalone %epositor$
ob2ects in the ABAP &ictionar$! The$ can specif$ the technical attributes of a data element!
1ne domain can be used b$ an$ number of data elements! When $ou create a domain# $ou must
specif$ a &ictionar$ data t$pe (see aboe table) and the number of characters!
7 (eference -%pes
%eference t$pes describe single fields that can contain references to glo&al classes and
interfaces from the ABAP class librar$!
*n an ABAP program# $ou can use the -7P0 addition to refer directl$ to a data element! The
predefined &ictionar$ data t$pes of the domain are then conerted into the corresponding ABAP
t$pes!
*f $ou define a local data t$pe in a program b$ referring to a data element as follo"s+
T3P0S dt$pe T3P0 dataSelement!
the semantic attributes of the data element are inherited and "ill be used# for e/ample# "hen $ou
displa$ a data ob2ect "ith t$pe dt%pe on the screen! Since all data t$pes in the ABAP &ictionar$
are based on data elements# the$ all contain the corresponding semantic attributes!
-7P0S compan% -7P0 sEcarrEid9
)A-A waEcompan% -7P0 compan%9
waEcompan% F ?.A ?9
W(I-0= ?Compan%=?4 waEcompan%9
This e/ample defines a local t$pe compan% that refers to the data element SSCA%%S*&! The
data element is lin-ed to the identicall$-named domain SSCA%%S*&! The domain defines the
technical attributes as data t$pe C6A% "ith length :! The local data t$pe CO,PAN7 in the
program therefore has the ABAP t$pe c(C)! CO,PAN7 also adopts the semantic attributes of the
ABAP Programming (BC-ABA) ??
data element! *n the aboe e/ample# "e declare a data ob2ect waEcompan% "ith this t$pe and
displa$ it on a list! *f the user chooses ,1 help for the output field# the help te/t stored in the
ABAP &ictionar$ "ill appear in a dialog bo/!
Structures
A structure is a se8uence of an$ other data t$pes from the ABAP &ictionar$# that is# data
elements# structures# table t$pes# or database tables! When $ou create a structure in the ABAP
&ictionar$# each component must hae a name and a data t$pe!
*n an ABAP program# $ou can use the -7P0addition to refer directl$ to a structure!
*f $ou define a local data t$pe in a program b$ referring to a structure as follo"s+
T3P0S dt$pe T3P0 structure!
the construction blueprint of the structure is used to create a local structure dt%pe in the
program! The predefined &ictionar$ data t$pes of the domains used b$ the data elements in the
structure are conerted into the corresponding ABAP t$pes! The semantic attributes of the data
elements are used for the corresponding components of the structure in the program! The
components of the local structure dt%pe hae the same names as those of the structure in the
ABAP &ictionar$!
To ensure compatibilit$ "ith preious releases# it is still possible to use the I"0 addition in an
ABAP program to refer to a structure in the ABAP &ictionar$ (e/cept in classes)!
Suppose the structure ST%)CT is defined as follo"s in the ABAP &ictionar$+
,ield name T$pe name Short &escription
C1.1 C6A%F1 Character field "ith length 1
C1.4 C6A%FD Character field "ith length D
C1.: C6A%1F Character field "ith length 1F
The t$pes C6A%F1 to C6A%1F are data elements "ith corresponding domains! We can refer to
this structure in ABAP+
-7P0S structEt%pe -7P0 struct9
)A-A wa -7P0 structEt%pe9
wa-col8 F ?8?9
wa-colB F ?8BCDGHIJ?9
wa-colC F ?8BCDGHIJK@?9
This program creates a local structure in the program - structEt%pe - and a corresponding data
ob2ect wa! We can address the components using the component names from the original
structure!
-a&le t%pes
Table t$pes are construction blueprints for internal tables that are stored in the ABAP
&ictionar$! When $ou create a table t$pe in the ABAP &ictionar$# $ou specif$ the line t$pe#
access t$pe# and -e$! The line t$pe can be an$ data t$pe from the ABAP &ictionar$# that is# a data
element# a structure# a table t$pe# or the t$pe of a database table! 3ou can also enter a
predefined &ictionar$ t$pe directl$ as the line t$pe# in the same "a$ that $ou can "ith a domain!
*n an ABAP program# $ou can use the -7P0addition to refer directl$ to a table t$pe!
*f $ou define a local data t$pe in a program b$ referring to a table t$pe as follo"s+
T3P0S dt$pe T3P0 table!
ABAP Programming (BC-ABA) ?@
the construction blueprint of the table t$pe is used to create a local internal table dt%pe in the
program! The predefined &ictionar$ data t$pes of the domains used b$ the data elements in the
structure are conerted into the corresponding ABAP t$pes! The semantic attributes of the data
elements are used for the corresponding components of the internal table in the program!
Suppose the table t$pe ST%)CTSTAB.0 is defined in the &ictionar$ "ith the line t$pe ST%)CT
from the preious e/ample! We can refer to this in ABAP+
-7P0S ta&leEt%pe -7P0 structEta&le9
)A-A= ta&leEwa -7P0 ta&leEt%pe4
lineEwa I"0 IN0 O2 ta&leEwa9
999
OOP A- ta&leEwa IN-O lineEwa9
999
W(I-0= lineEwa-col84 lineEwa-col84 lineEwa-col89
999
0N)OOP9
This program defines an internal table t$pe ta&leEt%pe ! ,rom it# "e define data ob2ects
ta&leEwa and# conse8uentl$# lineEwa9 lineEwa corresponds to the line t$pe of the table t$pe in
the &ictionar$# and is therefore compatible "ith the structure ST%)CT
-%pe /roups
Before %elease >!?A# it "as not possible to define standalone t$pes in the ABAP &ictionar$ to
"hich $ou could refer using a -7P0addition in an ABAP program! *t "as onl$ possible to refer to
flat structures! Structures in programs corresponded to the structures of database tables or
structures in the ABAP &ictionar$! *n ABAP programs# $ou could onl$ refer to database tables
and structures in the ABAP &ictionar$ using I"0! *t "as# ho"eer# possible to refer to indiidual
components of the &ictionar$ t$pe! Comple/ local data t$pes such as internal tables or deep
structures had no e8uialent in the ABAP &ictionar$! The solution to this from %elease :!F
on"ards "as to use t$pe groups! T$pe groups "ere based on the include techni8ue# and allo"ed
$ou to store an$ t$pe definitions globall$ in the &ictionar$ b$ defining them using -7P0S
statements!
The definition of a t$pe group is a fragment of ABAP code "hich $ou enter in the ABAP 0ditor!
The first statement for the t$pe group pool is al"a$s+
T3P0-P11. pool!
After that# $ou define data t$pes using the statement -7P0S! *t "as also possible to define
global constants using the CONS-AN-S statement! All the names of these data t$pes and
constants must begin "ith the name of the t$pe group and an underscore+ poolE
*n an ABAP program# $ou must declare a t$pe group as follo"s before $ou can use it+
T3P0-P11.S pool!
This statement allo"s $ou to use all the data t$pes and constants defined in the t$pe group pool
in $our program! 3ou can use seeral t$pe groups in the same program!
Note=
As of release @!>F# $ou can also define data t$pes and constants in the public isibilit$ area of
global classes# b$ "hich t$pe groups can be completel$ replaced!
.et the t$pe group 6UTST be created as follo"s in the ABAP &ictionar$+
-7P0-POO $*tst9
-7P0S= B0/IN O2 $*tstEt%p84
col8(8@) -7P0 c4
colB -7P0 i4
0N) O2 $*tstEt%p89
-7P0S $*tstEt%pB -7P0 p )0CI,AS B9
CONS-AN-S $*tstEeleven -7P0 i !A.0 889
This t$pe group defines t"o data t$pes 6UTSTST3P1 and 6UTSTST3P4# as "ell as a constant
6UTSTS0.0A0N "ith the alue 11!
An$ ABAP program can use this definition "ith the -7P0-POOS statement+
-7P0-POOS $*tst9
)A-A= dat8 -7P0 $*tstEt%p84
datB -7P0 $*tstEt%pB !A.0 ?89BC?9
ABAP Programming (BC-ABA) ?B
W(I-0= datB4 A $*tstEeleven9
The output is+
1#4:
11
The data t$pes defined in the t$pe group are used to declare data ob2ects "ith the
)A-Astatement and the alue of the constant is# as the output sho"s# -no"n in the program!
Predefined )ata O&3ects
At runtime# the follo"ing data ob2ects are al"a$s present# and do not hae to be declared+
Constant LspaceM
The data ob2ect space is a constant "ith t$pe c! *t is one b$te long# and contains a space
character! As a constant# space cannot be changed!
Self-reference LmeM
A self-reference is an ob2ect reference ariable called me that is aailable as a predefined local
ob2ect in all instance methods and sho"s the instance in "hich the method is being e/ecuted! The
reference t$pe of me is the class in "hich the instance method is implemented!
Structure LscreenM
3ou can access the data ob2ect screen during screen processing in dialog modules! screen is a
structure "hose components correspond to the attributes of a screen element!
S%stem 2ields in Structure S7
s% is a structure "ith the ABAP &ictionar$ data t$pe S3ST! The components of s% are -no"n as
s$stem fields! S$stem fields contain alues that proide information about the current state of
the s$stem! The$ are automaticall$ filled and updated b$ the ABAP runtime enironment!
0/amples of s$stem fields+
7 s%-su&rc %eturn code for ABAP statements
(9ero if a statement is e/ecuted successfull$)
7 s%-uname )ser name
7 s%-repid Current ABAP program
7 s%-tcode Current transaction
7 s%-inde5 Number of the current loop pass
S$stem fields are ariables and can be changed b$ the program! 6o"eer# $ou should onl$ do so
"here the s$stem documentation recommends it for a specific field (for e/ample# $ou can change
the alue of s%-lsind to naigate bet"een detail lists)! *n all other cases# $ou should treat s$stem
fields as though the$ "ere constants# and onl$ read them! *f $ou change their alues# important
information for the flo" of the program ma$ be lost!
,or a complete list of all s$stem fields "ith notes on their use# refer to
ABAP S$stem ,ields
/eneric )ata -%pes for -%ping
T$ping means to specif$ the data t$pe behind a -7P0 addition "hen $ou define interface
parameters for procedures# or "hen $ou define field s$mbols! The actual data t$pe of interface
parameters and fields s$mobls is onl$ adopted at the runtime of the program "hen a data ob2ect
is assigned! The effect of t$ping is that $ou can onl$ assign specific data ob2ects! *f $ou specif$ a
completel$ -no"n data t$pe for a t$ping "hich "as defined# for e/ample# using -7P0S or in the
ABAP &ictionar$# $ou can onl$ use data ob2ects of e/actl$ this t$pe as transfer parameters for
procedures or assign these to field s$mbols!
*n man$ cases# ho"eer# $ou need to t$pe interface parameters and field s$mbols genericall$!
This means that the data t$pe transferred at runtime is onl$ chec-ed in some cases or een not
at all! This is the basis of d$namic programming "here procedures can "or- "ith seeral t$pes of
transfer parameters# for e/ample! 1n the other hand# partial t$ping is often necessar$ to ensure
a certain degree of t$pe securit$!
There is a set of predefined generic t$pes in ABAP s$nta/ that $ou can use to specif$ the t$pes
of interface parameters and field s$mbols! 3ou can onl$ use them after the -7P0 addition in the
2O(,# ,0-+O)S# and 2I0)-S7,BOS statements!
3ou cannot use these t$pes to define local data t$pes in a program or data ob2ects! The$ onl$
allo" $ou to chec- the data t$pe of fields that $ou pass to procedures or of field s$mbols!
,or more information# refer to the -e$"ord documentation!
ocal )ata -%pes and )ata O&3ects in a Program
ABAP Programming (BC-ABA) ?D
With predefined data t$pes# $ou hae learned about the basic elements that $ou need in order to
create local data t$pes and data ob2ects in a program! The statement for defining $our o"n local
data t$pes in a program is -7P0S! The statement for declaring or creating data ob2ects is )A-A!
The s$nta/ of both statements is irtuall$ identical! This reflects the fact that each data t$pe
can be defined either independentl$ or lin-ed to a data ob2ect! .i-e predefined data t$pes#
independentl$ created data t$pes can be used in all statements "ith the addition -7P0# in
particular for defining further comple/ data t$pes or creating data ob2ects of this t$pe! &ata
ob2ects of this -ind are instances of data t$pes# in the same "a$ that ob2ects are instances of
classes (ob2ect t$pes)!

-$e Statements -7P0S and )A-A
0ach ABAP program define its o"n data t$pes using the statement!
T3P0S dt$pe XT3P0 t$peZ.*U0 dob2Y !!!
and declare its o"n ariables or instance attributes of classes using the statement
&ATA ar XbT3P0 t$pecZb.*U0 dob2cY !!!

Within the program or a class# $ou can also define local data t$pes and ariables "ithin
procedures! .ocal ariables in procedures obscure identicall$-named ariables in the main program
or class!
When creating data t$pes and data ob2ects# there are a number of naming conention that also
appl$ for other local program definitions# such as procedures! These are described in detail in the
-e$"ord documentation!
-$e Additions -7P0 and I"0
The additions T3P0 t$pe and I"0 do&3 are used in arious ABAP statements! The additions can
hae arious meanings# depending on the s$nta/ and conte/t!
7 &efinition of local t$pes in a program
7 &eclaration of data ob2ects
7 &$namic creation of data ob2ects
7 Specification of the t$pe of formal parameters in subroutines
7 Specification of the t$pe of formal parameters in methods
7 Specification of the t$pe of field s$mbols
Constructing New )ata -%pes
The -7P0 addition allo"s $ou to construct ne" data t$pes in the -7P0S# )A-A< CONS-AN-S<
and S-A-ICSstatements! *n the -7P0S statement# these are local data t$pes in the program! *n
the other statements# the$ are attributes of ne" data ob2ects# meaning that the ne"l$ defined
data t$pes are not free-standing! %ather# the$ are lin*ed to database ob2ects!This means that
$ou can refer to them using the I"0addition# but not using -7P0!
To construct ne" data t$pes# the addition -7P0 can be used "ith the follo"ing t$pe constructors+
7 Construction of reference t$pes
%0, T1 t$peZdob2
7 Construction of structured data t$pes
B0(*N 1, strucSt$pe!
!!!
0N& 1, strucSt$pe!
7 Construction of table t$pes
tab-ind 1, linet$pe XW*T6 -e$Y
These data t$pes onl$ e/ist during the runtime of the ABAP program!
(eferring to "nown )ata -%pes or )ata O&3ects
)sing the additions T3P0 or .*U0 in the T3P0Sstatement# local data t$pes in a program can be
referred to -no"n data t$pes or data ob2ects! This is mainl$ the case "ith user-defined
elementar$ data t$pes! *f $ou declare ariables using the additions T3P0 t$pe or .*U0 dob2 "ith
statement &ATA# the data t$pe of ar is alread$ full$ defined before the declaration is made!
The -no"n t$pes or data that are referred to must be visi&le at the point "here the data t$pe or
ariable is declared!
A -no"n data t$pe can be an$ of the follo"ing+
7 A predefined ABAP t$pe to "hich $ou refer using the -7P0 addition
ABAP Programming (BC-ABA) ?E
7 An e/isting local data t$pe in the program to "hich $ou refer using the -7P0 addition
7 The data t$pe of a local data ob2ect in the program to "hich $ou refer using the I"0
addition
7 A data t$pe in the ABAP &ictionar$ to "hich $ou refer using the -7P0 addition! To ensure
compatibilit$ "ith earlier releases# it is still possible to use the I"0 addition to refer to
database tables and flat structures in the ABAP &ictionar$! 6o"eer# $ou should use the -7P0
addition in ne" programs!
The I"0 addition ta-es its technical attributes from a visi&le data ob2ect! As a rule# $ou can use
I"0 to refer to an$ ob2ect that has been declared using )A-A or a similar statement# and is
isible in the current conte/t! The data ob2ect onl$ has to hae been declared! *t is irreleant
"hether the data ob2ect alread$ e/ists in memor$ "hen $ou ma-e the I"0 reference!
7 *n principle# the local data ob2ects in the same program are isible! As "ith local data
t$pes# there is a difference bet"een local data ob2ects in procedures and global data ob2ects!
&ata ob2ects defined in a procedure obscure other ob2ects "ith the same name that are declared
in the global declarations of the program!
7 3ou can also refer to the data ob2ects of other isible ABAP programs! These might be# for
e/ample# the isible attributes of global classes in class pools! *f a global class clElo&al has a
public instance attribute or static attribute attr# $ou can refer to it as follo"s in an$ ABAP
program+
)A-A dref -7P0 (02 -O clEglo&al9
)A-A= f8 I"0 clEglo&alFNattr4
fB I"0 dref-Nattr9
3ou can access the technical properties of an instance attribute using the class name and a
reference ariable "ithout first haing to create an ob2ect! The properties of the attributes
of a class are not instance-specific and belong to the static properties of the class!
T3P0S+ B0(*N 1, struct#
numberS1 T3P0 i#
numberS4 T3P0 p &0C*'A.S 4#
0N& 1, struct!
&ATA+ "aSstruct T3P0 struct#
number .*U0 "aSstruct-numberS4#
date .*U0 s$-datum#
time T3P0 t#
te/t T3P0 string#
compan$ T3P0 sScarrSid!
This e/ample declares ariables "ith reference to the internal t$pe S-(.C- in the program# a
component of an e/isting data ob2ect waEstruct# the predefined data ob2ect S7-)A-.,# the
predefined ABAP t$pe t and S-(IN/# and the data element SSCA%%S*& from the ABAP
&ictionar$!
(eferring to /eneric )ata -%pes
*f $ou refer to one of the generic predefined ABAP t$pes of fi/ed length (c# n# p# 5) in the
-7P0S or )A-A statement# $ou must specif$ the undefined technical attributes!
-7P0SO)A-A varP(lengt$)Q -7P0 t%pe P)0CI,AS decQ999
T3P0SZ&ATA ar T3P0 t$pe X.0N(T6 lenY X&0C*'A.S decY!!!
&ATA+ te/t1#
te/t4 .0N(T6 4#
te/t: T3P0 c .0N(T6 :#
pac- T3P0 p &0C*'A.S 4 AA.)0 I1!44?I!
This e/ample creates three character ariables "ith field lengths of one# t"o# and three b$tes
respectiel$# and a pac-ed number ariable "ith field length D b$tes and t"o decimal places! *f
the attribute ,i/ed point arithmetic is set# the alue of pac* is 1!4:!
This e/ample sho"s ho" to declare elementar$ data ob2ects "ith reference to predefined ABAP
t$pes!
P(O/(A, demoEelementar%EdataEo&3ects9
ABAP Programming (BC-ABA) @F
)A-A te5t8 -7P0 c 0N/-+ B@9
)A-A te5tB -7P0 string9
)A-A num&er -7P0 i9
te5t8 F ?-$e num&er?9
num&er F 8@@9
te5tB F ?is an integer9?9
W(I-0= te5t84 num&er4 te5tB9
This program produces the follo"ing output on the screen+
The number 1FF is an integer!
*n this e/ample# the data o&3ects te5t8# te5tB and num&er are declared "ith the )A-A
statement! The technical attributes are determined b$ referring to the predefined ABAP t$pes
c# string# and I! Aalues from unnamed literals are assigned to the data ob2ects! The contents of
the named data ob2ects are displa$ed on the list!
Specif%ing a Start !alue
When $ou declare an elementar$ fi/ed-length ariable# the )A-Astatement automaticall$ fills it
"ith the t$pe-specific initial alue as listed in the table in the Predefined ABAP T$pes section!
6o"eer# $ou can also specif$ a starting alue of a fi/ed-length elementar% ariable (also "ithin a
structure declaration) using the !A.0 addition in the )A-Astatement+
&ATA ar !!! AA.)0 alZb*S *N*T*A.c!
Specif$ing start alues+
&ATA+ counter T3P0 p AA.)0 1#
date T3P0 d AA.)0 I1EEDF@F1I#
flag T3P0 n AA.)0 *S *N*T*A.!
After this data declaration# the character string flag contains its t$pe specific
*nitial alue JF=!
Self-)efined 0lementar% )ata -%pes and )ata O&3ects
0lementar$ data t$pes and data ob2ects in a local program are e/clusiel$ defined and declared
b$ reference to -no"n data t$pes and data ob2ects (see+ Statements T3P0S and &ATA)! *f $ou
use the addition -7P0# $ou can either reference to an inbuilt ABAP t$pe# a predefined elementar$
t$pe in the local program# or to a data element defined in the ABAP &ictionar$! *f $ou use a I"0
reference# do&3 can be an e/isting data ob2ect "ith an elementar$ data t$pe! *f $ou do not use
the -7P0 or I"0 addition# the s$stem uses the default predefined t$pe c! 6o"eer# $ou should
al"a$s use the e/plicit statement! 0speciall$ the short form is not allo"ed "ithin classes!
0lementar$ local data t$pes in a program ma-e $our programs easier to read and understand! *f
$ou hae used such a t$pe to define seeral data ob2ects# $ou can change the t$pe of all of those
ob2ects in one place# 2ust be changing the definition in the -7P0S statement! Alternatiel$# if
$ou use a set of data t$pes regularl$ in different programs but do not "ant to store them in the
ABAP &ictionar$# $ou can create an include program for the t$pe definitions# and incorporate this
into the releant programs!
T3P0S+ number T3P0 i#
length T3P0 p &0C*'A.S 4#
code(:) T3P0 c!
!!!
*n this e/ample# a data t$pe called N.,B0(is defined! *t is the same as the predefined data
t$pe i# e/cept it has a different name to ma-e the program easier to read!
The program defines a data t$pes 0N/-+4based on the generic ABAP t$pe p! 0N/-+ is
defined "ith a gien number of decimals! *f it becomes necessar$ to change the accurac$ of
length specifications# for e/ample# $ou onl$ hae to change the -7P0Sstatement in the program!
A third data t$pe# CO)0# is also defined! CO)0 is based on the predefined generic ABAP t$pe c!
The length is defined as : b$tes!
&ATA counts T3P0 i!
T3P0S+ compan$ T3P0 spfli-carrid#
noSflights .*U0 counts!
ABAP Programming (BC-ABA) @1
This e/ample sho"s ho" $ou can use the -7P0 addition to refer to a column (CA%%*&) of a
database table (SP,.*)! The I"0 addition refers to an e/isting data ob2ect!
(0PO(- demoEt%pesEstatement9
-7P0S m%te5t -7P0 c .0N(T6 1F9
-7P0S m%amount -7P0 p )0CI,AS B9
)A-A te5t -7P0 m%te5t9
)A-A amount -7P0 m%amount9
te5t F ? D A C F ?9
amount F D A C 9
W(I-0= te5t4 amount9
This program produces the follo"ing output on the screen+
> ; : H 1!::
The program uses the -7P0Sstatement to create the local data t$pes m%te5t and m%amount! The
technical attributes are defined "ith reference to predefined ABAP t$pes! Then# the data
ob2ects te5t and amount are declared "ith the )A-A statement! Their data t$pes are defined
"ith reference to m%te5t and m%amount! Aalues are assigned to the data o&3ects and the
contents of the data ob2ects are displa$ed on the screen!
(eference -%pes and (eference !aria&les
3ou use the follo"ing s$nta/ to define reference t$pes+
-7P0S dt%pe R-7P0 (02 -O t%peSORI"0 (02 -O do&3S9
The s$nta/ for a direct declaration of a reference ariable is as follo"s+
&ATA ref bT3P0 %0, T1 t$pecZb.*U0 %0, T1 dob2c!
The addition (02 -O defines a data t$pe dt%pe for a reference ariable and declares the
reference ariable ref! The specification after (02 -O specifies the static t$pe of the
reference ariable! The static t$pe constricts the ob2ect set to "hich a reference ariable can
point! The d$namic t$pe of a reference ariable is the data t$pe and the class of the ob2ect
respectiel$# to "hich it currentl$ points! The static t$pe is al"a$s more uniersal or e8ual to the
d$namic t$pe
3ou can use the -7P0 addition to define data t$pes for data and ob2ect reference ariables! The
I"0 addition e/clusiel$ defines data t$pes for data reference ariables!
The s$nta/ and meaning of the additions -7P0 and I"0 are completel$ e8ual for both
statements "ith the e/ception that -7P0S creates an independent reference t$pe# "hereas
)A-A creates a bound reference t$pe!
,or further details and additions to this topic# see the -e$"ord documentation!
Self-)efined Comple5 )ata -%pes
With the e/ception of the S3 structure# there are no built-in comple/ data t$pes in ABAP!
Therefore# comple/ data t$pes must either be programmer locall$ or defined in the &ictionar$! *f
$ou "ant to combine a ne" local comple/ data t$pe from other data t$pes# use the
-7P0Sstatement as a construction rule!
1n the one hand# $ou can construct the ne" comple/ t$pe according to the -no"n t$pe in the case
of -7P0 or I"0 reference to a -no"n comple/ t$pe! When $ou refer to the comple/ ABAP
&ictionar$ t$pes Structure or Table T$pe# "hich are based on elementar$ &ictionar$ data
elements# the structure from the &ictionar$ is used# and the data elements are conerted into
elementar$ ABAP t$pes!
1n the other hand# using the -7P0S statement# $ou can also define ne" structured t$pes or table
t$pes "ithout reference to -no"n data t$pes or data ob2ects!
Structured )ata -%pes
To construct a ne" structured data t$pe strucEt%pein a program# $ou use seeral -7P0S
statements+
-7P0S B0/IN O2 strucEt%pe9
999
R-7P0S dt%pe 999S O RINC.)0 R-7P0OS-(.C-.(0S 999S9
999
-7P0S 0N) O2 strucEt%pe9
ABAP Programming (BC-ABA) @4
The t"o -7P0S statements "ith the additions B0/IN O2 und 0N) O2ma$ enclose as man$
-7P0Sstatements as re8uired# including additional complete structure definitions# as "ell as the
statements INC.)0 -7P0 and INC.)0 S-(.C-.(0! This "a$ $ou can create nested
structures!
The indiidual components of a structured data t$pe are addressed in the program "ith the
structure component selector (-) bet"een the structure name and component name as follo"s+
strucEt%pe-dt%pe!
,or more information# refer to the -e$"ord documentation!
T3P0S+ spfliSt$pe T3P0 spfli#
surname(4F) T3P0 c#
B0(*N 1, address#
name T3P0 surname#
street(:F) T3P0 c#
cit$ T3P0 spfliSt$pe-cit$from#
0N& 1, address#
to"n T3P0 address-cit$!
This e/ample sho"s the definition of t"o structure t$pes in a program - spfliEt%pe and address!
The structure of the data t$pe spfliEt%pe is ta-en from the database table SP,.* in the ABAP
&ictionar$! The components of spfliEt%pe are the same as the columns of SP,.*! The indiidual
data t$pes of the components are the ABAP e8uialents of the data t$pes of the columns of the
database table! The structure t$pe address is ne"l$ defined! The component address-name ta-es
the data t$pe of the preiousl$ defined t$pe surname# the component address-street is ne"l$
defined# address-cit% ta-es the data t$pe of column cit%from of the structure t$pe spfliEt%pe!
T3P0S+ B0(*N 1, struct1#
col1 T3P0 i#
B0(*N 1, struct4#
col1 T3P0 i#
col4 T3P0 i#
0N& 1, struct4#
0N& 1, struct1!
-7P0S m%t%pe -7P0 struct8-structB-colB9
The e/ample sho"s ho" $ou can construct a nested structure t$pe struct8 "ith a comple/
component structB b$ nesting -7P0S B0/IN O2 999 -7P0S 0N) O2 bloc-s# and ho" $ou can
address the inner components!
L .ocal t$pes in program
L referring to predefined ABAP t$pes+
T3P0S+ surname(4F) T3P0 c#
street(:F) T3P0 c#
9ipScode(1F) T3P0 n#
cit$(:F) T3P0 c#
phone(4F) T3P0 n#
date .*U0 s$-datum!
L .ocal structure in program
L referring to the aboe t$pes
T3P0S+ B0(*N of address#
name T3P0 surname#
code T3P0 9ipScode#
to"n T3P0 cit$#
str T3P0 street#
0N& 1, address!
L .ocal nested structure in program
L referring to the aboe t$pes
T3P0S+ B0(*N of phoneSlist#
adr T3P0 address#
ABAP Programming (BC-ABA) @:
tel T3P0 phone#
0N& 1, phoneSlist!
This e/ample sho"s ho" to create comple/ data t$pes from simple t$pe definitions! After a set
of simple data t$pes are created "ith ABAP predefined t$pes# a structured t$pe address is
defined using the data t$pes defined earlier! ,inall$# a nested structure t$pe# p$oneElist # is
created# "hose first component has the t$pe address!
%0P1%T demoSstructure!
T3P0S+ B0(*N 1, name#
title T3P0 c .0N(T6 ?#
firstSname T3P0 c .0N(T6 1F#
lastSname T3P0 c .0N(T6 1F#
0N& 1, name!
T3P0S+ B0(*N 1, m$list#
client T3P0 name#
number T3P0 i#
0N& 1, m$list!
&ATA list T3P0 m$list!
list-client-title H I.ordI!
list-client-firstSname H I6o"ardI!
list-client-lastSname H I'ac &uffI!
list-number H 1!
W%*T0 list-client-title!
W%*T0 list-client-firstSname!
W%*T0 list-client-lastSname!
W%*T0 ; INumberI!
W%*T0 list-number!
This program produces the follo"ing output on the screen+
.ord 6o"ard 'ac &uff
Number 1
The local data t$pes name and m%listare defined as structures using the -7P0Sstatement! The
structure namecontains the three components title# firstEname and lastEname "ith reference to
the built-in ABAP t$pe c! The structure m%list contains the t"o components client and num&er!
client is a substructure as it refers to the structure name! num&er is elementar$ "ith the built-in
t$pe i! A data ob2ect list is declared "ith reference to the data t$pe m%list! Aalues are assigned
to the components and their contents are then displa$ed on the screen!
Structures
The s$nta/ for directl$ declaring a ariable as a structure is the same as $ou "ould use to define
a structured data t$pe using the -7P0S statement+
)A-A B0/IN O2 struc9
999
R)A-A comp 999S O RINC.)0 R-7P0OS-(.C-.(0S 999S9
99
)A-A 0N) O2 struc9
The indiidual components of a structure are addressed in the program "ith the structure
component selector (-) bet"een the structure name and component name as follo"s+ strucEcomp!
,or more information# refer to the -e$"ord documentation!
&ATA+ B0(*N 1, address#
name T3P0 c .0N(T6 4F#
street T3P0 c .0N(T6 4F#
number T3P0 p#
postcode T3P0 n .0N(T6 ?#
cit$ T3P0 c .0N(T6 4F#
0N& 1, address!
This e/ample defines a structure called address! The components can be addressed using
address-name# address-street# and so on!
ABAP Programming (BC-ABA) @>
Self-)efined -a&le -%pes
3ou can start a screen se8uence from an ABAP program using
T3P0S dt$pe T3P0Z.*U0 tab-ind 1, linet$pe XW*T6 -e$Y !!! !
This defines an internal table t$pe "ith access t$pe ta&*ind# line t$pe linet%pe and -e$ *e%! The
line t$pe linet%pe can be an$ -no"n data t$pe! Specif$ing the -e$ is optional! *nternal tables can
thus be generic!
Internal -a&les
The s$nta/ for declaring an internal table directl$ as a data t$pe of a ariable is the same as $ou
"ould use to define one using the -7P0S statement+
&ATA itab T3P0Z.*U0 tab-ind 1, linet$pe XW*T6 -e$Y !!! !
The ariable ita&is declared as an internal table "ith access t$pe ta&*ind# line t$pe linet%pe#
and -e$ *e%! The line t$pe linet%pe can be an$ -no"n data t$pe!
,or more information# refer to *nternal Tables!
(ange -a&les
)sing the statements+
-7P0S dt%pe R-7P0 (AN/0 O2 t%peSORI"0 (AN/0 O2 do&3S 999 9
)A-A rta& R-7P0 (AN/0 O2 t%peSORI"0 (AN/0 O2 do&3S 999 9
$ou can define a special table t$pe as a separate data t$pe for %ange tables# or as an attribute of
the data ob2ect rta& of the t$pe standard table# "ith a standard -e$ and a speciall$ structured
line t$pe!
,or more information on %ange Tables see the -e$"ord documentation!
P%1(%A' demoSinternalStable!
T3P0S+ B0(*N 1, m$te/t#
number T3P0 i#
name T3P0 c .0N(T6 1F#
0N& 1, m$te/t!
T3P0S m$tab T3P0 STAN&A%& TAB.0 1, m$te/t W*T6 &0,A).T U03!
&ATA te/t T3P0 m$te/t!
&ATA itab T3P0 m$tab!
te/t-number H 1! te/t-name H IaohnI!
APP0N& te/t T1 itab!
te/t-number H 4! te/t-name H IPaulI!
APP0N& te/t T1 itab!
te/t-number H :! te/t-name H I%ingoI!
APP0N& te/t T1 itab!
te/t-number H >! te/t-name H I(eorgeI!
APP0N& te/t T1 itab!
.11P AT itab *NT1 te/t!
W%*T0+ ; te/t-number# te/t-name!
0N&.11P!
This program produces the follo"ing output on the screen+
1 aohn
4 Paul
: %ingo
> (eorge
*n this e/ample# first a data t$pe m%te5t is defined as a structure! Then# a data t$pe m%ta& is
defined as an internal table "ith the line t$pe m%te5t! The data ob2ects te5t and ita& are
declared "ith reference to the internal data t$pes m%te5t und m%ta&! This lines of the internal
table ita& are generated d$namicall$ "ith the APP0N) statement! The contents of the internal
table ita& are "ritten to the list using the structure te5t! See also+ *nternal Tables
Operations on )ata O&3ects
This section illustrates the basic operations that can be used for data ob2ects# and ho" these
operations depend on the data t$pe of the respectie data ob2ect! *t contains the follo"ing
topics+
ABAP Programming (BC-ABA) @?
Assigning Aalues
Numeric 1perations
Assigning !alues
There are man$ different "a$s in "hich $ou can change the alue of a ariable< for e/ample# using
the user interface# 1pen SC.# or b$ assigning the alues of data ob2ects in $our program to a
ariable! The most important statement for the latter method is ,O!0! *t has the same meaning
as the e8ual sign (H)! The ABAP statement C0A( can be used to reset a data ob2ect to the
original alue for its t$pe!
*n contrast to other programming languages# "here the assignment bet"een different data t$pes
is often restricted to a small number of possible combinations# ABAP proides a "ide range of
automatic t$pe conertions!
As "ell as the statement ,O!0# that conerts the alue of the source field# "hen necessar$# into
the data t$pe of the target field# ABAP has the statement W(I-0 -O! This statement allo"s
the formatted contents of a character field# "hich can also be entered d$namicall$# to be
assigned to a different character field!
,or more information about the statement W(I-0 -O see the -e$"ord documentation!
Assigning !alues wit$ ,O!0
To assign the alue of a data ob2ect source to a ariable destination# use the follo"ing statement+
'1A0 source T1 destination!
or the e8uialent statement
destination H source!
The content of source remains unchanged# source does not therefore hae to be a ariable - it
can also be a literal# a te/t s$mbol# or a constant! 3ou must al"a$s specif$ decimal points "ith a
period (!)# regardless of the user=s personal settings!
'ultiple assignments
f> H f: H f4 H f1!
are also possible! ABAP processes them from right to left as follo"s+
'1A0 f1 T1 f4!
'1A0 f4 T1 f:!
'1A0 f: T1 f>!
*n the ,O!0 statement (or "hen $ou assign one alue to another "ith the e8ual sign)# it is not
possible to specif$ the field names d$namicall$ as the contents of other fields! *f $ou need to do
this# $ou must use field s$mbols !
The source and target fields can be of different data t$pes! The result of the alue assignment
depends on "hether these data t$pes are compatible and "hether a t$pe conersion can be
performed! *f there is no conersion rule bet"een the data t$pes in 8uestion# no assignment can
be made!
)A-A= t(8@) -7P0 c4
num&er -7P0 p )0CI,AS B4
count -7P0 i9
t F 88889
,O!0 ?G9IG? -O num&er9
count F num&er9
,ollo"ing these assignments# the fields t# num&er and count hae the alues J1111 =# ?!B?# and @
respectiel$! When $ou assign the number literal 1111 to T# it is conerted into a character field
"ith length 1F! When $ou assign num&er to count # the decimal number is rounded to an integer
(as long as the program attribute ,i/ed pt! arithmetic has been set)!
Assigning !alues Between Components of Structures
The rules for alue assignments bet"een data ob2ects also appl$ to structures! With the
command
)A-A= struct8 -7P0 structure4
structB -7P0 structure9
struct8 F structB9
t"o structures of the same t$pe can be assigned to one another "ithout difficult$! 6ere# the
entire source structure is seen as a unit and copied to the source structure! *t is then possible to
ABAP Programming (BC-ABA) @@
access the components indiiduall$ again! *f the structures in 8uestion are not compatible# see
the conersion rules for structures!
*n practice# ho"eer# $ou "ill often onl$ need to assign certain components of a structure to be
certain components of another structure! ABAP has a special statement for this purpose+
'1A0-C1%%0SP1N&*N( sourcestruct T1 destinationstruct!
This statement assigns the contents of the components of structure sourcestruct to the
components of the destinationstruct structure that hae identical names!
When it is e/ecuted# it is bro-en do"n into a set of ,O!0statements# one for each pair of fields
"ith identical names# as follo"s+
'1A0 sourcestruct-comp1 T1 destinationstruct-comp1!
'1A0 sourcestruct-comp4 T1 destinationstruct-comp4!
!!!
An$ necessar$ t$pe conersions are performed indiiduall$!
&ATA+ B0(*N 1, address#
firstname(4F) T3P0 c AA.)0 I,redI#
surname(4F) T3P0 c AA.)0 I,lintstoneI#
initials(>) T3P0 c AA.)0 I,,I#
street(4F) T3P0 c AA.)0 ICae AenueI#
number T3P0 i AA.)0 I11I#
postcode(?) T3P0 n AA.)0 IEDB@?I#
cit$(4F) T3P0 c AA.)0 IBedroc-I#
0N& 1, address!
&ATA+ B0(*N 1, name#
surname(4F) T3P0 c#
firstname(4F) T3P0 c#
initials(>) T3P0 c#
title(1F) T3P0 c AA.)0 I'isterI#
0N& 1, name!
,O!0-CO((0SPON)IN/ address -O name9
*n this e/ample# the alues of name-surname# name-firstname and name-initials are set to
I,lintstone=# J,red=# and I,,I! name-title al"a$s has the alue J'ister=!
(esetting !aria&les to -$eir Initial !alue
To reset a ariable var to the appropriate initial alue for its t$pe# use the statement
C.0A% ar!
This statement has different effects for different data t$pes+
7 0lementar$ ABAP t$pes
The C0A( statement sets the alue of elementar$ ariables to their initial alue (see the
-e$"ord documentation) not to the start alue# "hich is set using the !A.0 parameter of
the )A-A statement!
ABAP Programming (BC-ABA) @B
7 %eferences
The C0A( statement resets a reference ariable to its initial alue# that is# so that it does
not point to an ob2ect!
7 Structures
The C0A( statement resets the indiidual components of a structure to their respectie
initial alues!
7 *nternal tables
The C0A( statement deletes the entire contents of an internal table (see also *nitiali9ing
*nternal Tables)!
3ou cannot use the C0A( statement to reset a constant!
(0PO(- demoEdataEclear9
)A-A num&er -7P0 i !A.0 ?8@?9
W(I-0 num&er9
C0A( num&er9
W(I-0 A num&er9
The output appears as follo"s+
1F
F
The C.0A% statement resets the contents of the field num&er from 1F to its initial alue F!
-%pe Conversions
0er$ time $ou assign a data ob2ect to a ariable# the data t$pes inoled must either be
compatible # that is# their technical attributes (data t$pe# field length# number of decimal places)
must be identical# or the data t$pe of the source field must be conertible into the data t$pe of
the target field!
*n ABAP# t"o non-compatible data t$pes can be conerted to each other if a corresponding
conersion rule e/ists! *f data t$pes are compatible# no conersion rule is necessar$!
*n each ,O!0 statement# the content of the source field for an$ compatible data ob2ects is
copied to the target field b$te b$ b$te! ,or an$ non-compatible data ob2ects# the content of the
source field is conerted to the data t$pe of the target ob2ect! T$pe conersions ta-e longer
than cop$ing! ,or all ABAP operations that perform alue assignments bet"een data ob2ects (for
e/ample# arithmetic operations or filling internal tables)# the s$stem handles all the necessar$
t$pe conersions as for the ,O!0statement! *f $ou tr$ to assign alues bet"een t"o data t$pes
for "hich no conersion rule e/ists# a s$nta/ error or runtime error occurs!
,or more information about the e/plicit conersion rules bet"een non-compatible elementar$ data
t$pes in ABAP# see the ABAP -e$"ord documentation (,1 help)!
Assignment %ules for %eference Aariables
Conersion %ules for Structures
Conersion %ules for *nternal Tables
ABAP Programming (BC-ABA) @D
,or some ABAP statements that pass data bet"een different ob2ects# the alignment of the data
ob2ects is also important!

Assignment (ules for (eference !aria&les
The content of a reference ariable can be assigned onl$ to another reference ariable! 6ere#
data references can be assigned onl$ to data reference ariables and ob2ect references onl$ to
ob2ect reference ariables!
No conersion ta-es place during these assignments!
So that such an assignment can ta-e place# the static t$pe of the target reference ariable must
be more general than or the same as the d$namic t$pe of the source reference ariable! This
basic rule determines all assignments bet"een reference ariables!
,or e/ample# a subclass reference can al"a$s be assigned to a superclass reference ariable#
"hile the assignment of an interface reference ariable to a class reference ariable must be
chec-ed d$namicall$!
,or more information# refer to the -e$"ord documentation!
Conversion (ules for Structures
ABAP has one rule for conerting structures that do not contain internal tables and do not
contain strings as components! There are no conersion rules for structures that contain internal
tables or strings! 3ou can onl$ ma-e assignments bet"een structures that are compatible!
3ou can combine conertible structures in the follo"ing combinations+
7 Conerting a structure into a non-compatible structure
7 Conerting elementar$ fields into structures
7 Conerting structures into elementar$ fields
*n each case# the s$stem first conerts all the structures concerned to t$pe c fields and then
performs the conersion bet"een the t"o resulting elementar$ fields! The length of t$pe c fields
is the sum of the lengths of the components! This rule applies to all operations using structures
that do not contain internal ta&les!
*f a structure is aligned# the filler fields are also added to the length of the t$pe C field!
A non-aligned structure "ithout filler fields+
*f $ou conert a structure into a shorter structure# the original structure is truncated! *f $ou
conert a structure into a longer one# the parts at the end are not initiali9ed according to their
t$pe# but filled "ith blan-s!
*t can ma-e sense to assign a structure to another# incompatible# structure if# for e/ample# the
target structure is shorter than the source# and both structures hae the same construction oer
the length of the shorter structure! 6o"eer# numeric components of structures that are filled
in incompatible assignments ma$ contain nonsensical or inalid alues that ma$ cause runtime
errors!
%0P1%T demoSdataSconersionSstructure!
&ATA+ B0(*N 1, fs1#
int T3P0 i AA.)0 ?#
pac- T3P0 p &0C*'A.S 4 AA.)0 I4!4@I#
te/t(1F) T3P0 c AA.)0 I,ine Te/tI#
float T3P0 f AA.)0 I1!4:>e5F?I#
date T3P0 d AA.)0 I1EE?FE1@I#
0N& 1, fs1!
&ATA+ B0(*N 1, fs4#
int T3P0 i AA.)0 :#
pac- T3P0 p &0C*'A.S 4 AA.)0 IB4!:>I#
te/t(?) T3P0 c AA.)0 I6elloI#
0N& 1, fs4!
ABAP Programming (BC-ABA) @E
W%*T0+ ; fs1-int# fs1-pac-# fs1-te/t# fs1-float# fs1-date!
W%*T0+ ; fs4-int# fs4-pac-# fs4-te/t!
'1A0 fs1 T1 fs4!
W%*T0+ ; fs4-int# fs4-pac-# fs4-te/t!
1utput+
? 4!4@ ,ine Te/t 1!4:>FFFFFFFFFFFF05F? FE1@1EE?
: B4!:> 6ello
? 4!4@ ,ine
This e/ample defines t"o different structures# fs8 and 2SB! *n each one# the first t"o
components hae the same data t$pe! After assignment of fs8 to fsB# onl$ the result for the
first t"o components is as if the$ had been transferred component b$ component! fsB-te5t is
filled "ith the first fie figures of fs8-te5t! All the remaining positions of fs8 are omitted!
Conversion (ules for Internal -a&les
*nternal tables can onl$ be conerted into other internal tables! 3ou cannot conert them into
structures or elementar$ fields!
*nternal tables are conertible if their line t$pes are conertible! The conertibilit$ of internal
tables does not depend on the number of lines!
Conersion rules for internal tables+
7 *nternal tables "hich hae internal tables as their line t$pe are conertible if the internal
tables "hich define the line t$pes are conertible!
7 *nternal tables "hich hae line t$pes that are structures "ith internal tables as
components are conertible according to the conersion rules for structures if the structures are
compati&le!
Alignment of )ata O&3ects
0lementar$ fields "ith t$pes i and f occup$ special memor$ addresses that are platform-specific!
,or e/ample# the address of a t$pe i field must be diisible b$ ># and the address of a t$pe f field
b$ D! Conse8uentl$# t$pe i and f fields are -no"n as aligned fields! Structures containing fields
"ith t$pe i oer f are also aligned# and ma$ contain filler fields immediatel$ before their aligned
components!
The s$stem normall$ aligns fields and structures automaticall$ "hen $ou declare them!
3ou must ta-e alignment into account in the follo"ing cases+
7 When $ou pass elementar$ fields or structures to a procedure as actual parameters "here
the corresponding formal parameter is not t$ped accordingl$!
7 When $ou declare field s$mbols
7 When $ou use a "or- area "ith an ABAP 1pen SC. statement that does not hae the same
t$pe as the database table as defined in the ABAP &ictionar$!
7 When $ou process components of structures!
Numeric operations
To assign the result of a mathematical calculation to a ariable# use the CO,P.-0 statement or
the assignment operator (H)!
C1'P)T0 n H e/pression!
CO,P.-0 is optional# so $ou can also "rite the statement as follo"s+
n H e/pression!
The result of the mathematical operation specified in e5pression is assigned to the field n!
ABAP e/ecutes a numerical operation "ith a numerical precision that corresponds to one of the
numerical data t$pes i# p or f! The numerical precision is defined b$ the operand "ith the highest
hierarchical leel! *n this conte/t# the result field n and fi/ed point functions (t$pe f) also count
as operands! The hierarchical order is f before p before i! Before performing the calculation#
ABAP conerts all of the operands into the highest-occurring data t$pe! After the operation# the
result is assigned to the result field using the same logic as the '1A0 statement# that is# the
s$stem conerts the result into the data t$pe of the result field if necessar$!
*n ABAP# the se8uence of t$pe conersions during numerical operations is different from other
programming languages! Note# in particular# that the data t$pe of the result field influences the
accurac$ of the entire calculation!
*n mathematical e/pressions# $ou can combine operations in an$ permutation and use an$ number
of parentheses!
ABAP Programming (BC-ABA) BF
ABAP interprets mathematical e/pressions in the follo"ing order+
!!!
1! 0/pressions in parentheses
4! ,eatures
:! LL (po"ers)
>! L# ; # '1&# &*A (multiplication# diision)
?! 5# - (addition# subtraction)
The mathematical e/pressions that $ou can use in e5pression are described in the follo"ing
sections+
Performing Arithmetic 1perations
'athematical ,unctions
Business Calculations
&ate and Time Calculations
Arit$metic Calculations
Arithmetic calculations use arithmetic operations and special ABAP statements!
Basic Arit$metic Operations
ABAP supports the four basic arithmetic operations and po"er caluclations! 3ou can use the
follo"ing arithmetic operators in mathematical e/pressions+
1perator 'eaning
5 Addition
- Subtraction
'ultiplication
&iision
)I! *nteger diision
,O) %emainder of integer
diision
Po"ers
*nstead of using operators in mathematical e/pressions# $ou can perform basic arithmetic
operations "ith the -e$"ords A))# S.B-(AC-# ,.-IP7# and )I!I)0!
The follo"ing table sho"s the different "a$s of e/pressing basic arithmetic operations in ABAP+
1peration

Statement using
mathematical e/pression
Statement using
Ue$"ord
Addition p H n 5 m! A&& n T1 m!
Subtraction P H m [ n! S)BT%ACT n ,%1' m!
'ultiplication P H m L n! ').T*P.3 m B3 n!
&iision P H m ; n! &*A*&0 m B3 n!
*nteger diision P H m &*A n! ---
%emainder of diision P H m '1& n! ---
Po"ers P H m LL n! ---
*n the statements using -e$"ords# the results of the operations are assigned to field ]mG!
The operands m# n# p can be an$ numeric fields! *f the fields are not of the same data t$pe# the
s$stem conerts all fields into the hierarchicall$ highest data t$pe that occurs in the statement!
When using mathematical e/pressions# please note that the operators T# -# U# UU and A# as "ell as
opening and closing parentheses# are interpreted as "ords in ABAP and must therefore be
preceded and follo"ed b$ blan-s!
*n diision operations# the diisor cannot be 9ero if the diidend is not 9ero! With integer
diision# $ou use the operators )I! or ,O) instead of A! )I! calculates the integer 8uotient#
,O) calculates the remainder!
*f $ou combine seeral arithmetic e/pressions together# calculations are performed from left to
right for operators of e8ual priorit$# e/cept in the case of e/ponentiation "hich is performed
from right to left! So n UU m UU p is the same as n UU ( m UU p )# not
( n UU m ) UU p
&ATA+ counter T3P0 i!
C1'P)T0 counter H counter 5 1!
ABAP Programming (BC-ABA) B1
counter H counter 5 1!
A&& 1 T1 counter!
6ere# the three operational statements perform the same arithmetic operation# i!e! adding 1 to
the contents of the field counterand assigning the result to counter!
&ATA+ pac- T3P0 p &0C*'A.S >#
n T3P0 f AA.)0 I5?!4I#
m T3P0 f AA.)0 I51!1I!
pac- H n ; m!
W%*T0 pac-!
pac- H n &*A m!
W%*T0 ; pac-!
pac- H n '1& m!
W%*T0 ; pac-!
The output appears as follo"s+
>!B4B:
>!FFFF
F!DFFF
This e/ample sho"s the different t$pes of diision!
Arit$metic Calculations .sing Structures
These statements are obsolete and are onl$ aailable to ensure compatibilit$ "ith %eleases
prior to >!@ and @!1F! The statements ma$ appear in older programs but should no longer be used!

*n the same "a$ that $ou can transfer alues component b$ component bet"een structures using
the '1A0-C1%%0SP1N&*N( statement# $ou can also perform arithmetic operations bet"een
the components of structures using the follo"ing statements+
7 A))-CO((0SPON)IN/
7 S.B-(AC--CO((0SPON)IN/
7 ,.-IP7-CO((0SPON)IN/
7 )I!I)0-CO((0SPON)IN/
ABAP performs the corresponding calculation for all components that hae the same name in both
structures! 6o"eer# it onl$ ma-es sense to use the operations if all of the components inoled
hae a numeric data t$pe!
&ATA+ B0(*N 1, rate#
usa T3P0 f AA.)0 IF!@@@BI#
frg T3P0 f AA.)0 I1!FI#
aut T3P0 f AA.)0 IB!FI#
0N& 1, rate!

&ATA+ B0(*N 1, mone$#
usa T3P0 i AA.)0 1FF#
frg T3P0 i AA.)0 4FF#
aut T3P0 i AA.)0 :FF#
0N& 1, mone$!
').T*P.3-C1%%0SP1N&*N( mone$ B3 rate!
W%*T0 ; mone$-usa!
W%*T0 ; mone$-frg!
W%*T0 ; mone$-aut!
The output appears as follo"s+
@B
4FF
4#1FF
6ere# mone%-usa is multiplied b$ rate-usa and so on!
Adding Se1uences of 2ields
ABAP Programming (BC-ABA) B4
This statement is obsolete and is onl$ aailable to ensure compatibilit$ "ith %eleases prior to
>!@ and @!1F! The statement ma$ appear in older programs but should no longer be used!

There are ariants of the A))statement that allo" $ou to add se8uences of fields in memor$! ,or
e/ample+
Adding se8uences of fields and assigning the result to another field
A&& n1 T60N n4 )NT*. n9 (*A*N( m!
*f n8# nB# !!! # n: is a se8uence of e8uidistant fields of the same t$pe and length in memor$# the$
are summed and the result is assigned to m!
Adding se8uences of fields and adding the result to the contents of another field
A&& n1 T60N n4 )NT*. n9 T1 m!
This statement "or-s e/actl$ li-e the preious one# but "ith the e/ception that the sum of the
field alues is added to the old contents of m!
,or further information about other similar ariants# see the -e$"ord documentation for the
A&& statement!
)A-A= B0/IN O2 series4
n8 -7P0 i !A.0 8@4
nB -7P0 i !A.0 B@4
nC -7P0 i !A.0 C@4
nD -7P0 i !A.0 D@4
nG -7P0 i !A.0 G@4
nH -7P0 i !A.0 H@4
0N) O2 series9
)A-A sum -7P0 i9
A)) series-n8 -+0N series-nB .N-I series-nG /I!IN/ sum9
W(I-0 sum9
A)) series-nB -+0N series-nC .N-I series-nH -O sum9
W(I-0 A sum9
The output is as follo"s+
1?F
:?F
6ere# the contents of components n8 to nG are summed and assigned to the field sum! Then# the
contents of components nB to nH are summed and added to the alue of sum!
,at$ematical functions
ABAP contains a range of built-in functions that $ou can use as mathematical e/pressions# or as
part of a mathematical e/pression+
XC1'P)T0Y n H func( m )!
The blan-s bet"een the parentheses and the argument m are obligator$! The result of calling the
function func "ith the argument m is assigned to m!
2unctions for all Numeric )ata -%pes
The follo"ing built-in functions "or- "ith all three numeric data t$pes (f# i# p) as arguments!
,unctions for all Numeric &ata T$pes
,unction %esult
a&s Absolute alue of argument!
sign Prefi/ of the argument = 8 5 N @
SI/N( 5 ) H F if 5 H F
-1 5 ] F
ceil Smallest integer alue not smaller than the argument!
floor .argest integer alue not larger than the argument!
trunc *nteger part of argument!
2(AC ,raction part of argument!
The argument of these functions does not hae to be a numeric data t$pe! *f $ou choose another
t$pe# it is conerted to a numeric t$pe! ,or performance reasons# ho"eer# $ou should use the
correct t$pe "heneer possible! The functions itself do not hae a data t$pe of their o"n! The$
do not change the numerical precision of a numerical operation!
ABAP Programming (BC-ABA) B:
&ATA n T3P0 p &0C*'A.S 4!
&ATA m T3P0 p &0C*'A.S 4 AA.)0 I-?!??I!
n H abs( m )! W%*T0+ IABS+ I# n!
n H sign( m )! W%*T0+ ; IS*(N+ I# n!
n H ceil( m )! W%*T0+ ; IC0*.+ I# n!
n H floor( m )! W%*T0+ ; I,.11%+I# n!
n H trunc( m )! W%*T0+ ; IT%)NC+I# n!
n H frac( m )! W%*T0+ ; I,%AC+ I# n!
The output appears as follo"s+
ABS+ ?!??
S*(N+ 1!FF-
C0*.+ ?!FF-
,.11%+ @!FF-
T%)NC+ ?!FF-
,%AC+ F!??-
&ATA+ t1(1F) T3P0 c#
t4(1F) T3P0 c AA.)0 I-1FFI!
t1 H ABS( t4 )!
W%*T0 t1!
%esult+
1FF
T"o conersions are performed! ,irst# the contents of field tB (t$pe c) are conerted to t$pe p!
Then the s$stem processes the a&s function using the results of the conersion! Then# during the
assignment to the t$pe c field t8# the result of the function is conerted bac- to t$pe c!
2loating-Point 2unctions
The follo"ing built-in functions "or- "ith floating point numbers (data t$pe f) as an argument!
,loating point functions
,unction 'eaning
acos# asin# atan< cos# sin# tan Trigonometric functions!
cos$# sin$# tan$ 6$perbolic functions!
e5p 0/ponential function "ith base e
(eH4!B1D4D1D4D?)!
log Natural logarithm "ith base e!
log8@ .ogarithm "ith base 1F!
s1rt S8uare root!
,or all functions# the normal mathematical constraints appl$ (for e/ample# s8uare root is onl$
possible for positie numbers)! *f $ou fail to obsere them# a runtime error occurs!
The argument of these functions does not hae to be a floating point field! *f $ou choose another
t$pe# it is conerted to t$pe f! The functions themseles hae the data t$pe f! This can change
the numerical precision of a numerical operation!
)A-A= result -7P0 f4
pi(8@) -7P0 c !A.0 ?C98D8GKBHG?9
result F cos( pi )9
W(I-0 result9
The output is -1!FFFFFFFFFFFFFF05FF! The character field pi is automaticall$ conerted to a
t$pe f field before the calculation is performed!
Business Calculations
,or calculations in business applications# use pac-ed numbers! The program attribute ,i/ed point
arithmetic affects calculations using pac-ed numbers!
*f the program attribute ,i/ed point arithmetic is not set# t$pe P fields are interpreted as
integers "ithout decimal places! The decimal places that $ou specif$ in the )0CI,AS addition
of the -7P0S or )A-A statement onl$ affect ho" the field is formatted in the W(I-0
statement!
ABAP Programming (BC-ABA) B>
)A-A= pac* -7P0 p )0CI,AS B9
pac* F ?8BCDG?9
W(I-0 pac*9
*f the program attribute ,i/ed point arithmetic is not set# the output is as follo"s+
14:#>?
*f the program attribute ,i/ed point arithmetic is set# the output is as follo"s+
14:!>?#FF
*f the ,i/ed point arithmetic attribute is set# the decimal places are also ta-en into account in
arithmetic operations! Calculations "ith pac-ed numbers in ABAP use the same arithmetic as a
calculator! *ntermediate results are calculated using up to :1 digits (before and after the decimal
point)! 3ou should therefore al"a$s set the ,i/ed point arithmetic attribute "hen $ou use t$pe p
fields!
(0PO(- demoEdataEpac*edEnum&ers 9
)A-A= pac* -7P0 p )0CI,AS @9
pac* F 8 A C U C9
W(I-0 pac*9
*f $ou hae not set the ,i/ed point arithmetic attribute# the result is F# since the calculation is
performed using integer accurac$# and the result is therefore rounded internall$ to F!
*f the program attribute ,i/ed point arithmetic is set# the result is 1 because the result of the
diision is stored internall$ as F!:::::::::::::::::::::::::::::: "ith an accurac$ of up to
:1 digits!
)ate and -ime Calculations
&ate and time fields hae character t$pes# not numeric ones! 6o"eer# $ou can still use date and
time fields in numeric operations! To allo" $ou to do so# the s$stem performs automatic t$pe
conersions! 3ou ma$ also find it useful to use offset and length specifications "hen using date
and time fields in calculations!
0/ample of a date calculation+
&ATA+ ultimo T3P0 d!
ultimo H s$-datum!
ultimo5@(4) H IF1I! W H first da$ of this month
ultimo H ultimo - 1! W H last da$ of preious month
6ere# the last da$ of the preious month is assigned to the date field ultimo!
d ultimois filled "ith the present date!
d )sing an offset specification# the da$ is changed to the first da$ of the
current month!
d 1 is subtracted from ultimo! *n this "a$# the content of ultimo is changed to
the last da$ of the preious month! Before performing the subtraction# the s$stem
conerts ultimo to the number of da$s since F1!F1!FFF1 and conerts the result
bac- to a date!
0/ample of a time calculation+
&ATA+ diff T3P0 i#
seconds T3P0 i#
hours T3P0 i!
&ATA+ t1 T3P0 t AA.)0 I4FFFFFI#
t4 T3P0 t AA.)0 IF4FFFFI!
diff H t4 - t1!
seconds H diff '1& D@>FF!
hours H seconds ; :@FF!
The number of hours bet"een F4+FF+FF and 4F+FF+FF is calculated!
d ,irst# the difference bet"een the time fields is calculated! This is -@>DFF#
since t8 is conerted internall$ to B4FFF and tB to B4FF!
ABAP Programming (BC-ABA) B?
d Then# "ith the operation ,O)# this negatie difference is conerted to the
total number of seconds! A positie difference "ould be unaffected b$ this
calculation!
d Third# the number of hours is calculated b$ diiding the number of seconds
b$ :@FF!
The last three lines can be replaced b$ the follo"ing line
61)%S H ( ( t4 - t1) '1& D@>FF) ; :@FF!
Inverted )ates
These statements are obsolete and are onl$ aailable to ensure compatibilit$ "ith %eleases
prior to >!@ and @!1F! The statements ma$ appear in older programs but should no longer be used!

*n some cases (for e/ample# "hen sorting dates in descending order)# it is useful to conert a
date from format d to an inerted date b$ using the -e$"ord CON!0(-!
C1NA0%T &AT0 d1 *NT1 *NA0%T0&-&AT0 d4!
After"ards# $ou can conert the inerted data bac- into a normal date using the statement
C1NA0%T &AT0 d1 *NT1 *NA0%T0&-&AT0 d4!
These statements conert the field d8 from the formats )A-0 or IN!0(-0)-)A-0 to the
formats IN!0(-0)-)A-0 or )A-0 and assign it to the field dB!
,or the conersion# ABAP forms the nineIs complement!
&ATA+ odate T3P0 d AA.)0 I1EE??F11I#
idate .*U0 odate!
&ATA field(D) T3P0 c!
field H odate! W%*T0 ; field!
C1NA0%T date odate *NT1 *NA0%T0&-&AT0 idate!
field H idate! W%*T0 ; field!
C1NA0%T *NA0%T0&-&AT0 idate *NT1 &AT0 odate!
field H odate! W%*T0 ; field!
The output loo-s li-e this+
1EE??F11
DFF>E>DD
1EE??F11
Controlling t$e Program 2low
.ogical 0/pressions
Control Structures
0/ception 6andling

ogical 05pressions
When "riting application programs# $ou often need to formulate conditions! These are used
mostl$ in control structures# or sere to decide "hether to e/it a processing bloc-! Conditions use
logical e/pressions that ma$ be either true or false!
Note+ Since %elease @!1F it is possible to use not onl$ data ob2ects but also return alues of built-
in functions and function methods at the operand positions of logical e/pressions!
Comparing )ata O&3ects
.ogical e/pressions can be used as comparisons in the form+
!!! operand1 operator operand4 !!!
&epending on "hich data t$pe the operands operand1 and operand4 are# different logical
relational operators can be used!
7 %elational 1perators for 1perands of All &ata T$pes
7 %elational 1perators for Character-T$pe and B$te-T$pe &ata T$pes
7 %elational 1perators for Bit Templates
Ot$er ogical 05pressions
Along "ith operand comparisons# $ou can formulate logical e/pressions that chec- "hether the
operands meet certain re8uirements+
ABAP Programming (BC-ABA) B@
Com&ining Several ogical 05pressions
Seeral logical e/pressions can be lin-ed "ith a condition!
Comparisons for Operands of Ar&itrar% )ata -%pes
,or comparisons bet"een operands of arbitrar$ data t$pes# $ou hae in ABAP the operators+
F# VN# V# N# VF# NF or their e8uialents 0W# N0# -# /-# 0# /0 at $our disposal! We al"a$s
recommend using either onl$ the mathematical s$mbols or onl$ the appropriate letter
abbreiations! 6o" the content comparison ta-es place depends on the data t$pes of the
operands!
Comparisons Between )ifferent )ata -%pes
,or comparisons bet"een operands of elementar$ data t$pes# $ou must first decide "hether the
data t$pes are compatible or not+
7 ,or compatible elementar$ data t$pes# the content is compared "ithout prior conersion!
7 ,or incompatible elementar$ data t$pes# the content of the operands is first conerted in
accordance "ith certain rules and then compared!
The appropriate conersion rules and details on the rules concerning "hich operands of
elementar$ data t$pes in ABAP are to be compared can be found in the -e$"ord documentation!
)A-A= $e58(C) -7P0 5 !A.0 ?CDBIA8?4
$e5B(8) -7P0 5 !A.0 ?2@?9
I2 $e5B N $e589
999
0N)I29
The logical e/pression in the I2 statement is true# since the first b$te of $e5B is greater than
the first b$te of $e58!
)A-A= num(D) -7P0 n !A.0 ?8BCD?4
te5t(G) -7P0 c !A.0 ?GHI9J?9
I2 num N te5t9
999
0N)I29
The logical e/pression in the I2 statement is true# since the alue of num is greater than the
alue of te5t after the conersion to pac-ed numbers! *f num "ere of t$pe C# the logical
e/pression "ould be false# since there "ould be no conersion to a pac-ed number!
Comparisons Between (eference !aria&les
When $ou compare compatible or conertible reference ariables in ABAP 1b2ects# it onl$ ma-es
sense to use the e8ual (0W# H) and not-e8ual (N0# ]G# G]) operators! The e8ualit$ comparison is true
if both reference ariables contain references to the same ob2ect! *t is false if the$ contain
references to different ob2ects! The conerse is true if $ou are testing for ine8ualit$!
*NT0%,AC0 i1!
!!!
0N&*NT0%,AC0!
C.ASS c1 &0,*N*T*1N!
P)B.*C S0CT*1N!
*NT0%,AC0S i1!
!!!
0N&C.ASS!
&ATA+ r1 T3P0 %0, T1 i1#
r4 T3P0 %0, T1 c1!
C%0AT0 1Ba0CT r4!
r1 H r4!
*, r1 H r4!
!!!
0N&*,!
ABAP Programming (BC-ABA) BB
The logical e/pression in the I2 statement is true# since both references point to the same
ob2ect!
Comparisons Between Structures
Compati&lestructures are bro-en do"n into their elementar$ components# "hich are then
compared! T"o structures are e8ual if all of their elementar$ components are e8ual! *f the
structures are une8ual# the first pair of elements that are une8ual determine "hich structure is
larger!
&ATA+ B0(*N 1, struct1#
col1 T3P0 i AA.)0 1#
col4 T3P0 p &0C*'A.S 4 AA.)0 I?@!BDI#
0N& 1, struct1!
&ATA+ B0(*N 1, struct4#
comp1 T3P0 i AA.)0 1F#
comp4 T3P0 p &0C*'A.S 4 AA.)0 I14!:>I#
0N& 1, struct4!
*, struct1 ] struct4!
!!!
0N&*,!
The logical e/pression in the I2 statement is true# since the alue of the first component of
struct8 is less than the alue of the second component!
When $ou compare incompati&le structures# or compare structures "ith elementar$ fields# the
structures inoled are conerted into t$pe c fields before the conersion# and then treated li-e
elementar$ fields!
&ATA+ B0(*N 1, struct#
col1(?) T3P0 c AA.)0 I14:>?I#
col4(?) T3P0 n AA.)0 I14:>?I#
0N& 1, struct!
&ATA te/t(1F) T3P0 c AA.)0 I14:>?14:>?I!
*, struct H te/t!
!!!
0N&*,!
The logical e/pression in the I2 statement is true# since structure struct has the same contents
as the field te5t once it has been conerted into a field of t$pe c!
Comparisons Between Internal -a&les
.i-e other data ob2ects# $ou can use internal tables as operands in logical e/pressions!
*f $ou are using internal tables "ith header lines# remember that the header line and the bod$ of
the table hae the same name! *f $ou "ant to address the bod$ of the table in a comparison# $ou
must place t"o brac-ets (PQ) after the table name!
Comparisons Between C$aracter Strings and B%te Strings
aust as there are special statements for processing character strings# ABAP contains special
compare operators for character-t$pe data t$pes! The follo"ing operators compare data ob2ects
of the t$pes c# d# n# t# and string!
operator 'eaning
C1 Contains onl$
CN Contains not onl$
CA Contains an$
NA Contains not an$
CS Contains string
NS Contains no string
CP Suits pattern
NP &oes not suit pattern
There are no conersions "ith these comparisons! *nstead# the s$stem compares the characters
of the string!
ABAP Programming (BC-ABA) BD
,or more information on the indiidual operators# refer to the -e$"ord documentation!
&ATA+ f1(?) T3P0 c AA.)0 ]f1G#
f4(?) T3P0 c AA.)0 ]f4G!
*, f1 ]operatorG f4!
W%*T0+ ; ICompare true# S3-,&P1SHI# s$-fdpos!
0.S0!
W%*T0+ ; ICompare false# S3-,&P1SHI# s$-fdpos!
0N&*,!
The follo"ing table sho"s the results of e/ecuting this program# depending on "hich operators
and alues of f1 and f4!
f1 operator ,4 %esult s$-fdpos
IB& I C1 IABC& I true ?
IB& I C1 IABC&0I false 4
IABC14I CN IABC& I true :
IABABCI CN IABC& I false ?
IABcdeI CA IBd I true 1
IABcdeI CA Ib& I false ?
IABAB I NA IAB I false F
IababaI NA IAB I true ?
IABcdeI CS IbC I true 1
IABcdeI CS Ice I false ?
IABcdeI NS IbC I false 1
IABcdeI NS Ice I true ?
IABcdeI CP ILbLI true 1
IABcdeI CP ILebLI false ?
IABcdeI NP ILbLI false 1
IABcdeI NP ILebLI true ?

(elational Operators for B%te--%pe )ata -%pes
Since %elease @!1F# $ou can onl$ use relational operators of character-t$pe data t$pes for
comparing operands of b$te-t$pe data t$pes outside of )nicode programs! To e/ecute suitable
comparisons for b$te-t$pe ob2ects in )nicode programs# use the relational operators for b$te-
t$pe data t$pes (B7-0-CO# B7-0-CN# B7-0-CA# B7-0-NA# B7-0-CS# B7-0-NS)! See also+
Ue$"ord &ocumentation!
Comparisons Between Bit Samples
)sing the operators O# 6# and , (see -e$"ord documentation)# $ou can compare the bit se8uence
of the first operand "ith that of the second+
*mportant+ The follo"ing programs are no longer supported in )nicode s$stems+ (0PO(-
demoElogEe5prE&its 9
&ATA+ te/t(1) T3P0 c AA.)0 ICI#
he/(1) T3P0 /#
i T3P0 i!
he/ H F!
&1 4?@ T*'0S!
i H he/!
*, te/t 1 he/!
W%*T0+ ; he/# i!
0N&*,!
he/ H he/ 5 1!
0N&&1!
The list output is as follo"s+
FF F
F1 1
F4 4
ABAP Programming (BC-ABA) BE
F: :
>F @>
>1 @?
>4 @@
>: @B
6ere# the bit structure of the character ICI is compared to all he/adecimal numbers $e5 bet"een
IFFI and I,,I (4?? in the decimal s$stem)# using the operator O! The decimal alue of $e5 is
determined b$ using the automatic t$pe conersion during the assignment of $e5 to i! *f the
comparison is true# the he/adecimal number and its decimal alue are displa$ed on the screen! The
follo"ing table sho"s the bit se8uences of the numbers+
+e5adecimal )ecimal Bit Se1uence
FF F FFFFFFFF
F1 1 FFFFFFF1
F4 4 FFFFFF1F
F: : FFFFFF11
>F @> F1FFFFFF
>1 @? F1FFFFF1
>4 @@ F1FFFF1F
>: @B F1FFFF11
The bit se8uence of the character ICI is defined for the current hard"are platform b$ its ASC**
code number @B! The numbers that occur in the list displa$ are those in "hich the same bit
position is filled "ith 1 as in the bit se8uence of JC=! The se8uence F1FFFF11 is the uniersal set of
the bit se8uences!
C$ec*ing (e1uirements
*n addition to the logical e/pressions for comparisons# there is in ABAP a set of logical
e/pressions that $ou can use to chec- certain re8uirements of data ob2ects!
C$ec*ing W$et$er a 2ield Belongs to a (ange
)se the follo"ing logical e/pression to chec- "hether the alue of a field lies "ithin a particular
range+
999 f8 B0-W00N fB AN) fC 999
0/ample for Chec-ing Whether ,ield Belongs to a %ange+
)A-A= num&er -7P0 i4
flag(8) -7P0 c9
999
num&er F 999
999
I2 num&er B0-W00N C AN) I9
flag F ?X?9
0S09
flag F ? ?9
0N)I29
*n this e/ample# the content of the field flag is set to _ if the alue of num&er is bet"een : and
B!
C$ec*ing for t$e Initial !alue
)se the follo"ing logical e/pression to chec- "hether the alue of a field is initial+
999 f IS INI-IA 999
0/ample for chec-ing the initial alue of a data ob2ect+
%0P1%T demoSlogSe/prSisSinitial !
&ATA flag(1) T3P0 c AA.)0 I_I!
*, flag *S *N*T*A.!
W%*T0 ; I,lag is initialI!
0.S0!
W%*T0 ; I,lag is not initialI!
0N&*,!
C.0A% flag!
ABAP Programming (BC-ABA) DF
*, flag *S *N*T*A.!
W%*T0 ; I,lag is initialI!
0.S0!
W%*T0 ; I,lag is not initialI!
0N&*,!
The list output is as follo"s+
,lag is not initial
,lag is initial!
6ere# the character field flag does not contain its initial alue after declaration through the
)A-A statement because it "as set to start alue I_I using the !A.0 parameter! When the
C0A( statement is e/ecuted# it is reset to its initial alue!
C$ec*ing Selection Criteria
)se the follo"ing logical e/pression to chec- "hether the contents of a field satisf$ the criteria
in a selection table+
999 f IN selta& 999
,or further information about selection criteria and ho" to use them# refer to Selection
Screens!
%0P1%T demoSlogSe/prSinSseltab !
&ATA "a T3P0 spfli!
S0.0CT-1PT*1NS sScarrid ,1% "a-carrid!
*, I.6I *N sScarrid!
W%*T0 I.6 "as selectedI!
0N&*,!
The logical e/pression in the If statement is true if the user has entered a selection on the
selection screen containing the alue J.6=!
C$ec*ing W$et$er a 2ield S%m&ol is Assigned
To chec- "hether a field is assigned to a field s$mbol# use the follo"ing logical e/pression+
!!! ]fsG *S ASS*(N0& !!!
The e/pression is true if a field has been assigned e/plicitl$ or implicitl$ to the field s$mbol
VfsN!
&irectl$ after the definition of a field s$mbol# the e/pression behaes as follo"s+
7 With non-t$ped field s$mbols# it is true since these point to space!
7 With t$ped field s$mbols# it is false since these do not point to an$ field!
7 *n the case of fields "ith a defined structure# it is true since the field assignment ta-es
place alread$ during the declaration!
The e/pression can be false in the follo"ing cases+
7 &irectl$ after the declaration of a t$ped field s$mbol
7 After the statement .NASSI/N VfsN
7 *f a local field to "hich ]fsG pointed no longer e/ists!
7 *f ]fsG points to a global parameter of the interface of a function module that is currentl$
inactie
%0P1%T demoSlogSe/prSisSassigned !
,*0.&-S3'B1.S ]fsG T3P0 AN3!
&ATA te/t(1F) T3P0 c AA.)0 IAssigned`I!
ASS*(N te/t T1 ]fsG!
*, ]fsG *S ASS*(N0&!
W%*T0 ]fsG!
0N&*,!
The output is+
Assigned`
since the logical e/pression in the If statement is true!
Com&ining Several ogical 05pressions
ABAP Programming (BC-ABA) D1
3ou can combine seeral logical e/pressions together in one single e/pression b$ using the logical
lin- operators AN)and O(+ To negate the result of a logical e/pression# $ou can precede it "ith
the NO- operator!
NO- ta-es priorit$ oer AN)# and AN)ta-es priorit$ oer O(! 6o"eer# $ou can use an$
combination of parentheses to specif$ the processing se8uence! As in mathematical e/pressions#
ABAP interprets each parenthesis as a separate "ord! 3ou must therefore leae at least one
space before and after each one!
ABAP processes logical e/pressions from left to right! *f it recogni9es one of the component
e/pressions as true or false# it does not perform the remaining comparisons or chec-s in this
component! This means that $ou can improe performance b$ organi9ing logical e/pressions in such
a "a$ that $ou place comparisons "hich are often false at the beginning of an AN)chain and
e/pensie comparisons# such as searches for character strings# at the end!
%0P1%T demoSlogSe/prSconnected!
&ATA+ f T3P0 f AA.)0 I1FF!FFI#
n(:) T3P0 n AA.)0 I14:I#
c(:) T3P0 c AA.)0 I>?@I!
W%*T0 IThe follo"ing logical e/pression is true+I!
*, ( c .T n ) AN& ( n (T f )!
W%*T0+ ; I(I#c#IltI#n#I) AN& (I#n#IgtI#f#I)I!
0.S0!
W%*T0+ ; I(I#c#IgeI#n#I) 1% (I#n#IleI#f#I)I!
0N&*,!
The list output is+
The follo"ing logical e/pression is true+
( >?@ ge 14: ) 1% ( 14: le 1!FFFFFFFFFFFFFFF05F4 )
The logical e/pression in the I2 statement is true# and the inerted e/pression is displa$ed!
Control Structures
To e/ecute different program parts in connection "ith certain conditions or to combine recurring
statement se8uences as loops# $ou can use standard -e$"ords li-e I2# CAS0# )O# and W+I0 in
the flo" control of a program!
,or controlling the flo" of an ABAP program# remember that the structure of the program is
made up of processing bloc-s that cannot be nested! This section describes ho" to control the
flo" of a program "ithin a processing bloc-! The -e$"ords coered here do not allo" $ou to
branch outside the processing bloc- in "hich $ou use them! 3ou can regard this as internal
control of an ABAP program# as opposed to the e5ternal control proided b$ eents in the ABAP
runtime enironment!
To control the internal flo" of a processing bloc-# $ou can use control structures to diide it up
into smaller statement bloc-s according to the principles of structured programming! 0ach
statement bloc- ta-es care of one sub-tas-!
ABAP Programming (BC-ABA) D4
)nli-e processing bloc-s# control structures can be nested! *n the follo"ing section# $ou "ill learn
more about branching conditionall$ and about loops
Branc$ing Conditionall%
When $ou branch conditionall$# a processing bloc- is e/ecuted or not based on the result of one
or more logical conditions! ABAP contains t"o control structures for conditional branching!
-$e I2 Control Structure
3ou can nest I2 control structures!
6o"eer# the statement bloc-s must all end "ithin the current processing bloc-! So# for e/ample#
an I2 - 0N)I2 bloc- ma$ not contain an eent -e$"ord!
(0PO(- demoEflowEcontrolEif9
&ATA+ te/t1(:F) T3P0 c AA.)0 IThis is the first te/tI#
te/t4(:F) T3P0 c AA.)0 IThis is the second te/tI#
te/t:(:F) T3P0 c AA.)0 IThis is the third te/tI#
string(?) T3P0 c AA.)0 IecoI!
*, te/t1 CS string!
W%*T0 ; ICondition 1 is fulfilledI!
0.S0*, te/t4 CS string!
W%*T0 ; ICondition 4 is fulfilledI!
0.S0*, te/t: CS string!
W%*T0 ; ICondition : is fulfilledI!
0.S0!
W%*T0 ; INo condition is fulfilledI!
0N&*,!
The list output is+
Condition 4 is fulfilled!
6ere# the second logical e/pression te5tB CS string is true because the string WecoW occurs in
te5tB!
ABAP Programming (BC-ABA) D:
-$e CAS0 Control Structure
3ou can nest CAS0 control structures and also combine them "ith If control structures!
6o"eer# the$ must al"a$s end "ith an 0N)CAS0 statement "ithin the current processing bloc-!
(0PO(- demoEflowEcontrolEcase9
&ATA+ te/t1 T3P0 c AA.)0 I_I#
te/t4 T3P0 c AA.)0 I3I#
te/t: T3P0 c AA.)0 ITI#
string T3P0 c AA.)0 IAI!
CAS0 string!
W60N te/t1 1% te/t4!
W%*T0+ ; IString isI# te/t1# I1%I# te/t4!
W60N te/t:!
W%*T0+ ; IString isI# te/t:!
W60N 1T60%S!
W%*T0+ ; IString is notI# te/t1# te/t4# te/t:!
0N&CAS0!
The list output is+
String is not _ 3 T
6ere# the last statement bloc- after W+0N O-+0(S is processed because the contents of
string JA= does not e8ual J_=# J3=# or JT=!
oops
*n a loop# a statement bloc- is e/ecuted seeral times in succession! There are four -inds of loops
in ABAP+
7 )nconditional loops using the )O statement!
7 Conditional loops using the W+I0 statement!
7 .oops through internal tables and e/tract datasets using the OOP statement!
7 .oops through datasets from database tables using the S00C- statement!
This section deals "ith )O and W+I0 loops! S00C- is an 1pen SC. statement# and is
described in the 1pen SC.section! The OOP statement is described in the sections on internal
tables and e/tract datasets!
.nconditional oops
To process a statement bloc- seeral times unconditionall$# use the follo"ing control structure+
&1 Xn T*'0SY !!!
XstatementSbloc-Y
0N&&1!
)se the -I,0S addition to restrict the number of loop passes to n!
*f $ou do not specif$ an$ additions# the statement bloc- is repeated until it reaches a termination
statement such as 0XI- or S-OP (see belo")! The s$stem field s%-inde5 contains the number of
loop passes# including the current loop pass!
3ou can nest )O loops and combine them "ith other loop forms!
Simple e/ample of a )O loop+
&1!
W%*T0 s$-inde/!
*, s$-inde/ H :!
0_*T!
0N&*,!
0N&&1!
The list output is+
1 4 :
The loop is processed three times! 6ere# the processing passes through the loop three times and
then leaes it after the 0_*T statement!
0/ample of t"o nested loops "ith the T*'0S addition+
&1 4 T*'0S!
W%*T0 s$-inde/!
ABAP Programming (BC-ABA) D>
SU*P!
&1 : T*'0S!
W%*T0 s$-inde/!
0N&&1!
SU*P!
0N&&1!
The list output is+
1
1 4 :
4
1 4 :
The outer loop is processed t"ice! 0ach time the outer loop is processed# the inner loop is
processed three times! Note that the s$stem field s$-inde/ contains the number of loop passes
for each loop indiiduall$!
Conditional oops
To repeat a statement bloc- for as long as a certain condition is true# use the follo"ing control
structure+
W6*.0 logSe/p
XstatemaentSbloc-Y
0N&W6*.0!
logSe/p can be an$ logical e/pression! The statement bloc- bet"een W6*.0 and 0N&W6*.0 is
repeated as long as the condition is true or until a termination statement such as 0_*T or ST1P
occurs! The s$stem field s%-inde5 contains the number of loop passes# including the current loop
pass!
3ou can nest W6*.0 loops to an$ depth# and combine them "ith other loop forms!
%0P1%T demoSflo"ScontrolS"hile!
&ATA+ length T3P0 i AA.)0 F#
strl T3P0 i AA.)0 F#
string(:F) T3P0 c AA.)0 ITest StringI!
strl H strlen( string )!
W6*.0 string N0 space!
W%*T0 string(1)!
length H s$-inde/!
S6*,T string!
0N&W6*.0!
W%*T0+ ; IST%.0N+ I# strl!
W%*T0+ ; I.ength of string+I# length!
The output appears as follo"s+
T e s t S t r i n g
ST%.0N+ 11
.ength of String+ 11
6ere# a W+I0 loop is used to determine the length of a character string! This is done b$
shifting the string one position to the left each time the loop is processed until it contains onl$
blan-s! This e/ample has been chosen to demonstrate the W+I0 statement! 1f course# $ou can
determine the length of the string far more easil$ and efficientl$ using the strlen function!
-erminating oops
ABAP contains termination statements that allo" $ou to terminate a loop prematurel$! There are
t"o categories of termination statement - those that onl$ appl$ to the loop# and those that appl$
to the entire processing bloc- in "hich the loop occurs! The S-OPand (0Y0C- statements belong
to the latter group (see 0/iting 0entbloc-s)!
The termination statements that appl$ onl$ to the loop in "hich the$ occur are C1NT*N)0#
C60CUand 0_*T! 3ou can onl$ use the C1NT*N)0 statement in a loop! C60CU and 0_*T# on the
other hand# are conte/t-sensitie! Within a loop# the$ onl$ appl$ to the e/ecution of the loop
ABAP Programming (BC-ABA) D?
itself! 1utside of a loop# the$ terminate the entire processing bloc- in "hich the$ occur
(subroutine# dialog module# eent bloc-# and so on)!
C1NT*N)0# C60CU and 0_*Tcan be used in all four loop t$pes in ABAP (&1# W6*.0# .11P and
S0.0CT)!
-erminating a oop Pass .nconditionall%
To terminate a single loop pass immediatel$ and unconditionall$# use the CON-IN.0 statement in
the statement bloc- of the loop!
C1NT*N)0!
After the statement# the s$stem ignores an$ remaining statements in the current statement
bloc-# and starts the ne/t loop pass!
&1 > T*'0S!
*, s$-inde/ H 4!
C1NT*N)0!
0N&*,!
W%*T0 s$-inde/!
0N&&1!
The list output is+
1 : >
The second loop pass is terminated "ithout the W(I-0 statement being processed!
-erminating a oop Pass Conditionall%
To terminate a single loop pass conditionall$# use the C+0C" condition statement in the
statement bloc- of the loop!
C60CU condition!
*f the condition is not true# an$ remaining statements in the current statement bloc- after the
C+0C" statement are ignored# and the ne/t loop pass starts! condition can be an$ logical
e/pression!
&1 > T*'0S!
C60CU s$-inde/ B0TW00N 4 and :!
W%*T0 s$-inde/!
0N&&1!
The list output is+
4 :
The first and fourth loop passes are terminated "ithout the W(I-0 statement being processed#
because s%-inde5 is not bet"een 4 and :!
05iting a oop
To terminate an entire loop immediatel$ and unconditionall$# use the 0XI- statement in the
statement bloc- of the loop!
0_*T!
After this statement# the loop is terminated# and processing resumes after the closing statement
of the loop structure (0N))O# 0N)W+I0# 0N)OOP# 0N)S00C-)! *n nested loops# onl$ the
current loop is terminated!
&1 > T*'0S!
*, s$-inde/ H :!
0_*T!
0N&*,!
W%*T0 s$-inde/!
0N&&1!
The list output is+
1 4
*n the third loop pass# the loop is terminated before the W(I-0 statement is processed!
)ealing wit$ 05ceptions
ABAP Programming (BC-ABA) D@
0/ceptions are situations that occur "hile an ABAP program is being e/ecuted# in "hich normal
continuation of the program does not ma-e an$ sense! 0/ceptions can be raised either implicitl$ in
the ABAP runtime enironment or e/plicitl$ in the ABAP program! ,or e/ample# diision b$ 9ero
leads to an e/ception in the ABAP runtime enironment! *t is possible to determine this situation
through a 8uer$ in the ABAP program and to trigger an e/ception there!
There are t"o main t$pes of e/ceptions+ those that can be $andled and those that cannot &e
$andled!
7 0/ceptions that can be handled occur in error situations in the runtime enironment or
in the ABAP program# "here the program can continue e/ecuting after the ABAP program
has handled the e/ception# "ithout the s$stem ending up in a critical state! *f such an
e/ception is not $andled# a runtime error occurs!
7 The second t$pe of e/ceptions are those that cannot be handled! These are critical
error situations in the runtime enironment! 6andling "ith ABAP means is not possible and
the$ alwa%s cause a runtime error!
As of %elease @!1F# e/ceptions and their handling are generall$ based on e/ception classes! This
concept coers the functions of the preceding concepts# enhances them# and thus replaces them!
Class-Based 05ceptions

1erie" of Class-Based 0/ceptions
6andling 0/ceptions
%aising 0/ceptions
Propagating 0/ceptions
&efining 0/ceptions
0/ception Te/ts

Overview of Class-Based 05ceptions
Class-based e/ception handling is based on e/ception classes! 0/ception classes can be defined b$
the user "ith the 0/ception Builder in the ABAP Wor-bench! A series of predefined e/ception
classes is also aailable! *n an e/ception situation# an e/ception is represented b$ an e/ception
ob2ect# in other "ords# b$ an instance of an e/ception class! The attributes of an e/ception
ob2ect ma$ contain information on the error situation! All e/ception classes are part of an
inheritance hierarch$ "ith a common superclass# C_S%11T!
The use of class-based e/ceptions is not restricted to ABAP 1b2ects! 1n the contrar$# class-
based e/ceptions are designed to replace the preious concepts! Class-based e/ceptions can#
therefore# be raised and handled in all ABAP conte/ts (programs# processing bloc-s)! *n
particular# all the preious catchable runtime errors can be handled as class-based e/ceptions!
Class-based e/ceptions are either raised b$ the ABAP statement %A*S0 0_C0PT*1N or b$ the
ABAP runtime enironment! *f a class-based e/ception occurs# the s$stem interrupts the normal
program flo" and tries to find a suitable handler! *f it does not find a handler# a runtime error
occurs!
6andlers are not onl$ defined for the statements "ithin a program but are defined for entire call
se8uences! 0/ceptions that are raised in procedures but are not handled in the procedure itself
are for"arded to the caller! The caller can either handle the e/ception or for"ard it! To ensure
that the caller of a procedure -no"s "hich e/ceptions ma$ occur in a procedure# all the unhandled
e/ceptions of the procedure must usuall$ be listed in their interface after the (AISIN/
interface parameter! This rule can be circumented using specific e/ception classes!
6andlers are defined for one or more e/ception classes! To define handlers for all the
subordinate classes of the e/ception classes# a superclass is specified! This enables entire groups
of related e/ceptions to be handled!
(rouping self-defined and predefined e/ceptions on the basis of e/ception classes proides users
"ith the option of raising all the e/ceptions themseles! *t also offers the adantage of
consistent error handling throughout the entire program flo"! The ABAP s$nta/ for class-based
e/ceptions results in a clear distinction bet"een normal program processing and error handling!
The s$nta/ chec- supports the programming of the e/ception handling as far as possible b$
identif$ing e/ceptions that hae not been handled or for"arded!
+andling 05ceptions
ABAP Programming (BC-ABA) DB
The occurrence of an e/ception is normall$ used to displa$ an error situation! The handler of an
e/ception must tr$ to correct the error that has occurred# find an alternatie solution# or (if this
is not possible) at least bring the affected conte/t into a consistent state and then for"ard the
error! *f a call hierarch$ does not contain a handler for an e/ception# the program is ended "ith a
runtime error! Since e/ceptions cannot be handled b$ means of program calls# all possible
e/ceptions "ithin the program itself must be handled to preent a runtime error! This rule does
not appl$ to the coding "ithin procedures "hose e/ceptions can easil$ be propagated to (e/ternal)
callers!
Class-based e/ceptions are handled in the follo"ing control structure+
T%3!
!!! W T%3 bloc- (application coding)
CATC6 c/S!!! c/S!!! !!!
!!! W CATC6 bloc- (e/ception handler)
CATC6 c/S!!! c/S!!! !!!
!!! W CATC6 bloc- (e/ception handler)
!!!
C.0AN)P!
!!! W C.0AN)P bloc- (cleanup conte/t)
0N&T%3!
The T%3 statement opens a control structure to be ended "ith 0N&T%3# in "hich three
statement bloc-s can be listed in a specified order (this is not obligator$)!
!!!
1! A T%3 bloc-# in "hich e/ceptions can occur!
This e/ception bloc- consists of all the statements bet"een the T%3 and the CATC6 statement!
4! 1ne or more CATC6 bloc-s for catching e/ceptions!
These e/ception bloc-s are initiated "ith CATC6 and ended "ith a further CATC6# C.0AN)P# or
0N&T%3!
:! A C.0AN)P bloc- for cleanup "or- after the e/ceptions hae been caught!
This statement bloc- is initiated b$ C.0AN)P and ended "ith 0N&T%3! A T%3-0N&T%3structure
must not contain more than one C.0AN)P bloc- in precisel$ this position!
.i-e all ABAP control structures# T%3-0N&T%3 structures can be nested in an$ statement bloc-s
(see Control Structures)! *n particular# the three statements bloc-s aboe can also contain
complete T%3-0N&T%3 bloc-s! .i-e all ABAP control structures# each T%3-0N&T%3 structure
must be contained full$ in a processing bloc- (eent bloc-# dialog module# procedure)! This means
that the application coding of a T%3-0N&T%3 structure cannot include seeral processing bloc-s!
-(7 Bloc*
The T%3 bloc- contains the application coding "hose e/ceptions are to be handled! This
statement bloc- is processed se8uentiall$! *t can contain further control structures and calls of
procedures or other ABAP programs!
*f an e/ception occurs in the T%3 bloc- or in a procedure called up here# the s$stem starts b$
searching for a CATC6 statement of the same T%3-0N&T%3 structure! *t then searches from
the inside out for a CATC6 statement in an$ enclosing T%3-0N&T%3structures that handle the
eent! The s$stem ma$ call this handler! *f the s$stem does not find a handler# but the T%3-
0N&T%3 structure is contained in a procedure# it tries to propagate the e/ception to the caller
(see also Propagating 0/ceptions)! 0/ceptions cannot be propagated in an$ processing bloc-s
"ithout a local data area (eent bloc-s# dialog modules)! A runtime error occurs immediatel$ if the
handler is missing!
*f no e/ceptions occur in the T%3 bloc-# program e/ecution is continued directl$ after 0N&T%3
after the bloc- has been completed!
CA-C+ Bloc*
A catch bloc- contains the e/ception handler that is e/ecuted "hen a particular e/ception has
occurred in theT%3bloc- of the same T%3-0N&T%3 structure! A T%3-0N&T%3 structure can
contain seeral e/ception handlers! The s$nta/ for introducing an e/ception handler is+
CATC6 c/S!!! c/S!!! *NT1 ref!
An$ number of e/ception classes can be specified after CATC6! This defines an e/ception
handler for all the specified e/ception classes and their subordinate classes!
ABAP Programming (BC-ABA) DD
After an e/ception occurs# the s$stem searches through the listed e/ception handlers in the
specified order! The first e/ception handler "hose CATC6 statement contains the corresponding
e/ception class or one of its superclasses is e/ecuted! The s$stem then continues program
e/ecution directl$ after 0N&T%3! No subse8uent e/ception handlers are considered! ,or this
reason# the order of the different e/ception handlers "ithin a T%3-0N&T%3structure must be
based on the inheritance hierarch$ of the specified e/ception classes!
The s$nta/ chec- ensures that the handlers for more specific e/ceptions (subordinate classes)
can onl$ be listed before the handlers for more general e/ceptions (superclasses)! ,or e/ample# a
handler for the most general e/ception class C_S%11T can onl$ eer be the last statement bloc-
before C.0AN)P or 0N&T%3! 1ther"ise# none of the subse8uent handlers "ould eer be
reached!
With the *NT1 addition# a reference to the e/ception ob2ect can be placed a reference ariable!
This enables the attributes of the e/ception ob2ect to be accessed in the handler! The reference
ariable must be suitable for the e/ception! *ts static t$pe must be the e/ception class itself or
one of its superclasses! 3ou are adised to use an e/ception class belo" C_S%11T or C_S%11T
itself rather than the general class 1Ba0CT! 1nl$ these classes contain the methods releant for
e/ceptions!
C0AN.P Bloc*
*f the s$stem does not find a handler for an e/ception in a T%3-0N&T%3 structure# it searches
for a handler in the enclosing T%3-0N&T%3 structures from the inside out (as mentioned aboe)!
*f the s$stem does not find a handler here# it tries to propagate the e/ception to a procedure
caller!
Precisel$ one C.0AN)P bloc- can be defined in each T%3-0N&T%3 structure! *f the s$stem has
not found a handler for an e/ception# but the e/ception is handled in an enclosing T%3-0N&T%3
structure or is propagated to a caller# the bloc- is e/ecuted before the T%3-0N&T%3 structure
is e/ited!
*n the C.0AN)P bloc-# cleanup "or- can be e/ecuted for the conte/t of the T%3 bloc-! ,or
e/ample# ob2ects often hae to be brought into a consistent state or e/ternal resources# to "hich
an e/ternal handler no longer has access# hae to be released! The nesting of T%3-0N&T%3
bloc-s and the possible propagation of e/ceptions ma$ mean that seeral C.0AN)P bloc-s are
e/ecuted before an e/ception is actuall$ handled!
Since the onl$ purpose of the C.0AN)P bloc- is to restore the consistenc$ of a conte/t# it can
onl$ be e/ited in the normal "a$# in other "ords# once its last statement is reached! ,or this
reason# all the statements that change the control flo"# "hich cause the C.0AN)P bloc- to be
e/ited and "ould initiate a processing bloc- of the same program# are forbidden! This applies to
statements such as %0T)%N# ST1P# for e/ample! ,or the same reason# all the e/ceptions that
occur "ithin a C.0AN)P bloc- must also be handled here! *t is# ho"eer# permissible to leae the
oerall program (.0AA0 P%1(%A') or call up procedures# programs# and screen se8uences if the
s$stem returns to the C.0AN)P bloc-! The runtime enironment al"a$s recogni9es that a
C.0AN)P bloc- is being e/ited illegall$ and then reacts "ith a runtime error!
05ample
report &0'1S6AN&.0S0_C0PT*1NS!
parameters N)'B0% t$pe *!
data %0S).T t$pe P decimals 4!
data 1%0, t$pe ref to C_S%11T!
data T0_T t$pe ST%*N(!
start-of-selection!
"rite+ ; ITesting diison and S8are root "ithI# N)'B0%!
uline!
tr$!
if ABS( N)'B0% ) G 1FF!
raise e/ception t$pe C_S&0'1SABSST11S.A%(0!
endif!
tr$!
%0S).T H 1 ; N)'B0%!
"rite+ ; I%esult of diision+I# %0S).T!
%0S).T H SC%T( N)'B0% )!
ABAP Programming (BC-ABA) DE
"rite+ ; I%esult of s8uare root+I# %0S).T!
catch C_SS3ST0%1&*A*&0 into 1%0,!
T0_T H 1%0,-G(0TST0_T( )!
cleanup!
clear %0S).T!
endtr$!
catch C_SS3SA%*T6'0T*CS0%%1% into 1%0,!
T0_T H 1%0,-G(0TST0_T( )!
catch C_S%11T into 1%0,!
T0_T H 1%0,-G(0TST0_T( )!
endtr$!
if not T0_T is initial!
"rite ; T0_T!
endif!
"rite+ ; I,inal result+I# %0S).T!
*n this e/ample# a T%3-0N&T%3 structure is nested in the T%3 bloc- of a different T%3-
0N&T%3 structure! The follo"ing four scenarios are demonstrated in the e/ample+
Catc$ing an 05ception &% +andling a Superclass
*f N)'B0% is greater than 1FF# the e/ception C_S&0'1SABSST11S.A%(0 that is self-
defined in the 0/ception Builder of the ABAP Wor-bench is raised in the T%3 bloc- of the
e/ternal T%3-0N&T%3 structure! This e/ception is the subordinate class of the most general
e/ception# C_S%11T# and is handled b$ the second CATC6 bloc- of the same T%3-0N&T%3
structure!
Catc$ing an 05ception &% +andling t$e Suita&le Class
*f N)'B0% is e8ual to 9ero# the e/ception C_SS3ST0%1&*A*&0 predefined in the s$stem is
raised as a result of the diision in the T%3 bloc- of the internal T%3-0N&T%3 structure and
handled in the corresponding CATC6 bloc- of the same T%3-0N&T%3 structure!
0/ecuting a C.0AN)P Bloc- Before Catching an 0/ception
*f N)'B0% is a negatie number# the e/ception C_SS3SA%(S1)TS1,S&1'A*N predefined in
the s$stem is raised in the T%3 bloc- of the internal T%3-0N&T%3 structure using the SC%T
function! Since a handler is not defined for this e/ception in the internal T%3-0N&T%3 structure
but is defined in the e/ternal T%3-0N&T%3 structure# the C.0AN)P bloc- of the internal T%3-
0N&T%3 structure is e/ecuted! The e/ception is then handled in the first CATC6 bloc- of the
e/ternal T%3-0N&T%3 structure# since C_SS3SA%(S1)TS1,S&1'A*N is the subordinate
class of C_SS3SA%*T6'0T*CS0%%1%!
No 05ception
*n all other cases# an e/ception is not raised and the -(7 bloc-s of both -(7-0N)-(7structures
are full$ processed!
*n all CA-C+ statements in the e/ample# the ob2ect references to the corresponding e/ception
ob2ects are stored in the O(02 reference ariable! )sing O(02# the indiidual handlers access
the e/ception te/ts of the indiidual e/ception ob2ects and store them in the -0X- string
ariable!
(aising 05ceptions
There are t"o options for raising class-based e/ceptions!
1! S$stem-drien raising in the runtime enironment
4! Program-drien raising in the ABAP program
05ceptions of t$e (untime 0nvironment
*f error situations occur "hile ABAP statements are being e/ecuted in the ABAP runtime
enironment# e/ceptions that can be handled or cannot be handled are raised# depending on the
error! The e/ceptions that can be handled are class-based and can be handled bet"een -(7 and
0N)-(7! The associated e/ception classes are predefined in the s$stem and begin "ith the
prefi/ C_SS3S# such as C_SS3ST0%1&*A*&0! *n the ABAP -e$"ord documentation# the
e/ception classes "hose e/ceptions ma$ occur "hen a corresponding ABAP statement is e/ecuted
are listed for each -e$"ord! A t$pical e/ample is the aboe class C_SS3ST0%1&*A*&0# "hich
ABAP Programming (BC-ABA) EF
can occur "hen an arithmetic e/pression is calculated in the CO,P.-0 statement! 1ne or more
runtime errors are assigned to each predefined e/ception class# depending on the cause of the
error! The runtime errors onl$ occur if the e/ception is not caught!
05ceptions in t$e ABAP Program
With error situations in the ABAP program# e/ceptions can be raised in a program-drien manner
using the (AIS0 0XC0P-IONstatement! 0/ceptions based on both self-defined e/ception
classes and on e/ception classes predefined in the s$stem are possible here!
The (AIS0 0XC0P-ION statement has t"o ariants+
(aising an 05ception Wit$ /eneration of an 05ception O&3ect
The s$nta/ is+
%A*S0 0_C0PT*1N T3P0 c/S!!! X0_P1%T*N( f
1
H a
1
f
4
H a
4
!!!Y!
This statement raises the e/ception lin-ed to e/ception class c/S!!! and generates a
corresponding e/ception ob2ect! The optional I,PO(-IN/parameters of the instance
constructor of the e/ception class can be supplied "ith the 0XPO(-IN/addition! This can fill the
attributes of the ob2ect "ith alues that a handler can access!
,or reasons of efficienc$# an e/ception ob2ect is onl$ actuall$ generated if the IN-O addition of
the CA-C+ statement is used for e/ception handling! ,or this reason# the constructor should not
contain an$ further functionalit$# e/cept for a function for initiali9ing the attributes# and cannot
be changed in global e/ception classes (onl$ the constructor of a local e/ception class can contain
further functionalit$)!
(aising an 05ception wit$ an 05isting 05ception O&3ect
The s$nta/ is+
%A*S0 0_C0PT*1N ref!
*n this case# the e/ception ob2ect must alread$ e/ist and the refreference ariable must point to
it! This ma$ be the case if the e/ception has alread$ been caught once but if the handler "ants
to raise it again (because it cannot be handled completel$# for e/ample) or if the e/ception ob2ect
"as generated preiousl$ b$ means of C(0A-0 OBY0C-!
05ample
report &0'1S%A*S0S0_C0PT*1NS!
data 1%0, t$pe ref to C_S%11T!
data T0_T t$pe ST%*N(!
tr$!
tr$!
raise e/ception t$pe C_S&0'1SC1NST%)CT1%
e/porting '3ST0_T H S3-%0P*&!
catch C_S&0'1SC1NST%)CT1% into 1%0,!
T0_T H 1%0,-G(0TST0_T( )!
"rite ; T0_T!
raise e/ception 1%0,!
endtr$!
catch C_S&0'1SC1NST%)CT1% into 1%0,!
T0_T H 1%0,-G(0TST0_T( )!
"rite ; T0_T!
endtr$!
This e/ample sho"s the t"o ariants of the (AIS0 0XC0P-ION statement! The first statement
remoes the self-defined e/ception of the class C_S&0'1SC1NST%)CT1% in the internal -(7
bloc-# generates the corresponding ob2ect# and transfers the program name to the instance
constructor! *n the internal CA-C+ bloc-# the e/ception is handled# the e/ception te/t is output#
and the e/ception is raised again "ithout generating a ne" ob2ect! The e/ternal CA-C+ bloc-
handles the e/ception again! The class C_S&0'1SC1NST%)CT1% is defined in such a "a$ that
the transferred program name appears in the e/ception te/t! The generated instance constructor
ta-es care of this!
Propagating 05ceptions
ABAP Programming (BC-ABA) E1
Class-based e/ceptions that occur in procedures (methods# function modules# subroutines) do not
necessaril$ hae to be handled here! The$ can be propagated to the caller of the procedure! *f
the caller is a procedure and the call ta-es place in a -(7 bloc-# the caller can handle the
e/ception or propagate it to its caller!
The highest leel to "hich e/ceptions can be propagated is processing bloc-s "ithout a local data
area# in other "ords# eent bloc-s or dialog modules! Both the e/ceptions for"arded from called
procedures and the e/ceptions that hae occurred in the indiidual coding must be handled here!
1ther"ise# a runtime error "ill occur!
A static constructor of a class cannot usuall$ propagate e/ceptions# since a user of a class does
not -no" "hether it is the first user and "hether or not it has to handle an$ e/ceptions that are
propagated b$ the static constructor!
.i-e"ise# eent handler methods cannot propagate e/ceptions# since this "ould be against the
eent concept! The handler of an eent is called up indirectl$ b$ the runtime enironment "hen an
eent ta-es place! *t is completel$ separate from the eent trigger and can# therefore# not
for"ard an$ e/ceptions to the trigger! Aice ersa# the eent trigger can neer -no" "hich
handlers react to the eent and can# therefore# not handle their e/ceptions!
&ue to the fact that e/ceptions are represented b$ transient ob2ects that are onl$ alie in the
internal mode of a program# e/ceptions cannot be propagated to the caller from "ithin programs
that "ere called "ith S)B'*T !!! AN& %0T)%N or CA.. T%ANSACT*1N!
-$e (AISIN/ Addition
To propagate e/ceptions from procedures# the (AISIN/addition must usuall$ be used for the
definition of the interface of a procedure (e/cept for static constructors and eent handlers)!
This ensures that the caller of a procedure -no"s "hich e/ceptions can occur in a procedure and
can handle the e/ceptions or for"ard them using the (AISIN/addition!
*n the (AISIN/ clause# the classes of all e/ception classes "hose e/ceptions can arise in the
procedure must be counted up (strictl$ spea-ing# this onl$ applies to e/ceptions that re8uire
declarations)! (,or more information# see belo"!) Superclasses can also be specified here to
combine groups of e/ceptions! The most general superclass# C_S%11T# and its direct subordinate
class# C_SN1SC60CU# ho"eer# cannot be specified (see belo")! Since the order of the CA-C+
bloc-s in e/ception handling is determined b$ the inheritance hierarch$ of the e/ception classes#
e/ception classes in the (AISIN/ clause also hae to be specified in this order! This enables the
caller of a procedure to list the CA-C+ bloc-s in the correct order 2ust based on its -no"ledge
of the procedure interface! *t does not need to loo- at the e/ception classes in the Class Builder!
This is handled as follo"s for the possible procedures+
,et$ods of ocal Classes
The (AISIN/ addition is specified in the declaration of a method+
'0T61&S meth !!! %A*S*N( c/S!!! c/S!!!
The e/ception classes "hose ob2ects are to be propagated are specified after (AISIN/# in the
order described aboe! Conentional e/ceptions "ith the 0XC0P-IONS addition cannot be
specified simultaneousl$!
,et$ods of /lo&al Classes
The (AISIN/ addition cannot be specified directl$ "ith the methods of global classes! *nstead#
the e/ception classes "hose ob2ects are to be propagated must be entered in the e/ception table
of the method in the Class Builder! The Class Builder sorts the specified e/ceptions in the order
described aboe and generates the corresponding (AISIN/ clause!
The 0/ception Class chec-bo/ has to be selected in the e/ception table of the Class Builder for
this purpose! 1ther"ise# the Class Builder ie"s the e/ceptions entered as conentional
e/ceptions and generates a corresponding 0XC0P-IONS clause` The tool does not allo" e/ception
classes and conentional e/ceptions to be used simultaneousl$!
*f an e/ception re8uiring a declaration has not been defined in the e/ception table (see belo")#
the s$nta/ chec- reports an error# since the (AISIN/ clause is incomplete!
2unction modules
*n the same "a$ as global methods in the Class Builder# e/ceptions in function modules are
propagated "hen the$ are specified in the ,unction Builder! The ,unction Builder has a
corresponding tab page that "or-s in the same "a$ as the e/ception table of a method in the
ABAP Programming (BC-ABA) E4
Class Builder! To propagate class-based e/ceptions# the corresponding chec-bo/ must also be
selected here! 1ther"ise# conentional e/ceptions are declared!
Su&routines
With subroutines# the (AISIN/ addition is specified in the definition of the subroutine!
,1%' form !!! %A*S*N( c/S!!! c/S!!!
The e/ception classes "hose ob2ects are to be propagated are specified after %A*S*N(! Class-
based e/ceptions are the onl$ e/ceptions that can be listed in the interface of a subroutine!
S%nta5 C$ec*
0/ceptions that occur in a procedure "ill usuall$ either be handled here or for"arded to a higher
leel "ith the (AISIN/ addition ia the interface of the procedure! This is supported b$ the
s$nta/ chec- (for methods) or the e/tended program chec- (for function modules or
subroutines)! ,or e/ample# the s$nta/ of the follo"ing subroutine is incorrect+
form T0ST!
raise e/ception t$pe C_S&0'1SC1NST%)CT1%!
endform!
The error can either be remoed b$ handling the e/ception in the subroutine+
form T0ST!
tr$!
raise e/ception t$pe C_S&0'1SC1NST%)CT1%!
catch C_S&0'1SC1NST%)CT1%!
!!!
endtr$!
endform!
1r b$ propagating the e/ception ia the (AISIN/ clause+
form T0ST raising C_S&0'1SC1NST%)CT1%!
raise e/ception t$pe C_S&0'1SC1NST%)CT1%!
endform!
This s$nta/ chec- and the resulting necessit$ to handle e/ceptions or for"ard them using a
declaration in the interface is suitable for most application-specific error situations! There ma$#
ho"eer# be e/ception situations to "hich this procedure is not suited# such as+
7 0/ceptions that can occur but that do not hae to be handled or declared!
*t is not "orth ma-ing it compulsor$ to handle or e/plicitl$ for"ard this -ind of e/ception#
since the user can establish b$ means of program logic that the e/ception "ill not occur!
7 %esource bottlenec-s
6andling or declaring all e/ceptions "ithout fail "ould mean haing to specif$ these
e/ceptions in almost eer$ interface! This "ould simpl$ ma-e the programs more illegible
rather than more WrobustW!
Three different t$pes of e/ception class hae been introduced to deal "ith this problem+
1! 0/ceptions re8uiring a declaration that either hae to be handled or propagated! This is the
standard case described preiousl$!
4! 0/ceptions that can be declared in the interface if desired!
:! 0/ceptions that must not be declared in the interface!
This is enabled b$ three direct subordinate classes of the superclass C_S%11T+
!!!
1! C_SSTAT*CSC60CU for e/ceptions that hae to be declared!
4! C_S&3NA'*CSC60CU for e/ceptions that do not hae to be declared!
:! C_SN1SC60CU for e/ceptions that must not be declared!
These three classes and their superclass# C_S%11T# are abstract! All other e/ception classes
are subordinate classes of these three classes! &epending on the superclass# each e/ception class
belongs to one of the three t$pes!
05ceptions t$at $ave to &e declared
The associated e/ception classes are subordinate classes of C_SSTAT*CSC60CU! ,or these
classes# a corresponding e/ception must either be handled or for"arded e/plicitl$ "ith the
(AISIN/ addition! This is chec-ed in the s$nta/ chec-! Proided that the messages output b$
the s$nta/ chec- or e/tended program chec- are considered# e/ceptions re8uiring declarations
can onl$ lead to runtime errors if the$ are not handled at the top call leel!
ABAP Programming (BC-ABA) E:
At present# onl$ self-defined e/ceptions for error situations in the application coding are
subordinate classes of C_SSTAT*CSC60CU! There are no predefined e/ceptions C_SS3S!!! for
error situations in the runtime enironment that are subordinate classes of C_SSTAT*CSC60CU!
05ceptions t$at do not $ave to &e declared
The associated e/ception classes are subordinate classes of C_S&3NA'*CSC60CU! *f this -ind
of e/ception occurs at runtime# it has to either be handled or e/plicitl$ for"arded "ith the
(AISIN/ addition# in the same "a$ as the subordinate classes of C_SSTAT*CSC60CU! This is#
ho"eer# not chec-ed in the s$nta/ chec-! *f this -ind of e/ception is neither handled nor
for"arded at runtime# a runtime error occurs!
This -ind of e/ception class is useful for potential error situations that do not hae to be handled
or for"arded# since the program logic can more or less e/clude them! 'ost of the predefined
e/ceptions C_SS3S!!! for error situations in the runtime enironment are subordinate classes of
C_S&3NA'*CSC60CU! A t$pical e/ample of this is class C_SS3ST0%1&*A*&0! The user of a
diision can aoid this e/ception b$ ensuring that the diisor is not F! A declaration re8uirement
for predefined e/ception classes of the runtime enironment "ould actuall$ be impossible# since
each potential e/ception of each ABAP statement of a procedure "ould hae to be handled or
propagated!
Since e/ceptions of the C_S&3NA'*CSC60CU categor$ do not hae to be declared in the
interface# the called procedure determines "hether the$ are preented or handled! The caller
cannot assume that this -ind of e/ception is for"arded!
05ceptions t$at must not &e declared
The associated e/ception classes are subordinate classes of C_SN1SC60CU! This -ind of
e/ception can be handled! 1ther"ise# it is for"arded automaticall%! The (AISIN/ clause
contains the addition C_SN1SC60CU implicitl$! This class and its subordinate classes do not need
to be and must not be specified! The s$nta/ chec-# therefore# neer finds an error here! All the
e/ceptions of the C_SN1SC60CU categor$ that are not handled in the call hierarch$ are
automaticall$ assigned to the highest call leel and result in a runtime error if the$ are not
caught here!
Some of the predefined e/ceptions C_SS3S!!! for error situations in the runtime enironment are
subordinate classes of C_SN1SC60CU! 1ne e/ample of this is the class
C_SS3S0_P1%TST1SB),,0%SN1S'0'1%3# "hich is responsible for a particular resource
bottlenec- but cannot usuall$ be handled there and then! The caller of a procedure must al"a$s
ta-e into account the fact that the procedure can propagate e/ceptions of the C_SN1SC60CU
categor$!
Summar% on )eclaring 05ception Classes
*n the (AISIN/ clause of the interface of a procedure# onl$ the e/ceptions that ma$ actuall$
pass the interface hae to be declared in terms of s$nta/! 0/ceptions that are alread$ handled in
the procedure are irreleant for the interface! The 8uantit$ of all e/ceptions that hae to be
declared in the interface can be determined as follo"s+
All the e/ceptions of the C_SSTAT*CSC60CU categor$ that ma$ occur outside of a -(7
construct in the procedure [ "hether as a result of an e/plicit (AIS0 0XC0P-ION or of a
procedure call [ that can raise these e/ceptions themseles according to their (AISIN/ clause!
All the e/ceptions of the C_SSTAT*CSC60CU categor$ that occur "ithin a -(7 construct in the
procedure and are not handled "ithin this -(7construct! These are all the e/ceptions that are
not caught b$ CA-C+ or e/ceptions that occur "ithin a CA-C+ bloc-!
These rules are to be used recursiel$ if -(7 constructs occur "ithin -(7 or CA-C+ bloc-s!
!iolation of t$e Interface
A iolation of the interface means that an unhandled e/ception in a procedure is not for"arded
using %A*S*N(! According to the e/planations aboe# this can onl$ occur for e/ceptions of the
categor$ C_S&3NA'*CSC60CU or C_SSTAT*CSC60CU# since e/ceptions of the C_SN1SC60CU
categor$ are al"a$s propagated implicitl$! ,or e/ceptions of the C_SSTAT*CSC60CU categor$#
iolations can onl$ occur if the s$nta/ error message is ignored!
*f the interface is iolated in this "a$# the program is not completed "ith a runtime error!
*nstead# a ne" e/ception of the predefined class C_SS3SN1S6AN&.0%# "hich inherits from
ABAP Programming (BC-ABA) E>
C_SN1SC60CU# is raised and a reference is defined to the original e/ception in its attribute
P%0A*1)S!
*f a C_SS3SN1S6AN&.0% e/ception occurs# this usuall$ means that the deeloper of a
procedure has forgotten to handle an e/ception of the C_S&3NA'*CSC60CU categor$ locall$ or
to preent this e/ception! *t does not mean that the deeloper has forgotten to e/tend the
(AISIN/ clause accordingl$! A handler for this -ind of e/ception cannot catch the original
e/ception! *t can onl$ indicate a programming error in the calling procedure!
Since the interfaces of eent handlers and static constructors cannot contain an$ e/plicit
(AISIN/ clauses# unhandled e/ceptions of the categories C_S&3NA'*CSC60CU or
C_SSTAT*CSC60CU usuall$ lead to the C_SS3SN1S6AN&.0% e/ception# "hich can be handled
in the program!
05ample
report &0'1SP%1PA(AT0S0_C0PT*1NS!
class ASC.ASS definition!
public section!
methods ,11 importing
P t$pe ST%*N(
raising
C_S&0'1SC1NST%)CT1%
C_S&0'1SABSST11S.A%(0!
endclass!
class BSC.ASS definition!
public section!
data A t$pe ref to ASC.ASS!
methods BA% raising C_S&0'1SC1NST%)CT1%!
endclass!
data B t$pe ref to BSC.ASS!
start-of-selection!
create ob2ect B!
tr$!
B-GBA%( )!
catch C_S&0'1SC1NST%)CT1%!
"rite ICatching C_S&0'1SC1NST%)CT1%I! We0C N1T0_T
endtr$!
class ASC.ASS implementation!
method ,11!
raise e/ception t$pe C_S&0'1SC1NST%)CT1%!
endmethod!
endclass!
class BSC.ASS implementation!
method BA%!
create ob2ect A!
tr$!
!!!
A-G,11( IS1'0T6*N(I )!
!!!
catch C_S&0'1SABSST11S.A%(0!
!!!
endtr$!
endmethod!
endclass!
This e/ample sho"s "hich e/ceptions in the (AISIN/ clause of the BA( method hae
to be declared!
The method does not contain a (AIS0 0XC0P-ION statement but the 2OO method
is called up! According to its interface description# the ,11 method can suppl$ the
e/ceptions C_S&0'1SC1NST%)CT1% and C_S&0'1SABSST11S.A%(0!
ABAP Programming (BC-ABA) E?
C_S&0'1SABSST11S.A%(0 is caught e/plicitl$ "ith CATC6# "hich means that
onl$ C_S&0'1SC1NST%)CT1% passes the interface! ,or this reason# this e/ception
must be declared in the (AISIN/ clause of BA(!
)efining 05ceptions
0/ceptions are represented b$ ob2ects that are instances of e/ception classes! &efining an
e/ception is# therefore# the same as creating an e/ception class!
All e/ception classes must inherit from the common superclass C_S%11T and one of its
subordinate classes+
7 C_SSTAT*CSC60CU
7 C_S&3NA'*CSC60CU
7 C_SN1SC60CU
! The assignment of e/ception classes to one of these three paths of the inheritance hierarch$
determines the "a$ in "hich the associated e/ceptions are propagated! There is a record of
predefined e/ception classes C_SS3S!!! "hose e/ceptions are raised in error situations in the
runtime enironment! These classes all inherit from C_S&3NA'*CSC60CU or C_SN1SC60CU
but not from C_SSTAT*CSC60CU (see hierarch$ in the ABAP -e$"ord documentation)!
All e/ception classes must begin "ith the prefi/ C_S! The$ are usuall$ defined globall$ "ith the
Class Builder of the ABAP Wor-bench! .ocal e/ception classes can# ho"eer# also be defined!
*ndiidual (abstract) e/ception classes that are used as the superclass of further e/ception
classes can be defined! The e/ceptions of the subordinate classes can be handled together using
a superclass!
0/ception classes hae the follo"ing features+
7 Constructor
The constructor must hae a predefined structure and a specific interface! With global classes#
the Class Builder generates the correct constructor and sets it to an unchangeable status! The
constructor has t"o I,PO(-IN/ parameters+
T0_T*& of the S1T%SC1NC t$pe
This parameter can be used to determine "hich of $our e/ception te/ts the e/ception "ill
use!
P%0A*1)S of the C_S%11T t$pe
This parameter can be used to assign the P%0A*1)S attribute a preious e/ception!
7 ,et$ods
*n e/ception classes# $ou can define $our o"n methods! The follo"ing t"o predefined methods are
inherited from the root class C_S%11T+
(0TST0_T
Sends bac- the e/ception te/ts of a class (controlled b$ the T0_T*& attribute) as a
string!
(0TSS1)%C0SP1S*T*1N
%eturns the program name# the name of a possible include program# and the line number of
the statement that raised the e/ception!
7 Attri&utes
The attributes of e/ception classes are used to transport additional information on an error
situation to the handler! The main piece of information is# ho"eer# al"a$s the fact that an
e/ception of a particular class has occurred! The follo"ing attributes are inherited from
C_S%11T+
T0_T*&
)sed to specif$ the e/ception of a class more precisel$ b$ using seeral e/ception te/ts!
*s ealuated in the (0TST0_T method!
P%0A*1)S
*f an e/ception is mapped to another e/ception# a reference to the original e/ception can
be defined in this attribute ia the 0XPO(-IN/addition of the (AIS0 0XC0P-ION
statement and b$ means of the I,PO(-IN/parameter of the constructor "ith the same
name! This can result in a chain of e/ception ob2ects! *n the eent of a runtime error# the
e/ception te/ts of all the e/ceptions in the chain are output! 'apping an e/ception to
another e/ception is onl$ beneficial if the conte/t in "hich the original e/ception occurred
is important for characteri9ing the error situation!
U0%N0.S0%%*&
ABAP Programming (BC-ABA) E@
The name of the associated runtime error is stored in this attribute if the e/ception "as
raised b$ the runtime enironment# for e/ample# C1'P)T0S*NTST0%1&*A*&0 "ith a
diision b$ 9ero! *f the e/ception is not handled# precisel$ this runtime error occurs!
Parameters cannot be transferred to the constructor for this attribute! *f the e/ception
is raised "ith (AIS0 0XC0P-ION# the attribute is set to initial!
/lo&al 05ception Classes
(lobal e/ception classes are defined and managed in the Class Builder! *f the correct naming
conention (prefi/ C_S) and the class t$pe 0/ception Class is chosen "hen a ne" class is created#
the Class Builder automaticall$ becomes the 0/ception Builder!
The 0/ception Builder offers precisel$ the functionalit$ re8uired to define e/ception classes and
generates independentl$-defined components that must not be changed! When classes are
created# the categor$ of the e/ception must be specified# in other "ords# "hether it is to inherit
from C_SSTAT*CSC60CU# C_S&3NA'*CSC60CU# or C_SN1C60CU!
-a& Pages of t$e 05ception Builder
The 0/ception Builder has the tab pages Properties# Attributes# 'ethods# and Te/ts!
7 The properties do not normall$ need to be changed!
7 0/cept for the four inherited attributes mentioned aboe# further public attributes can be
generated b$ the 0/ception Builder! The contents of these attributes specif$ the e/ception more
clearl$ and manage the e/ception te/ts!
7 All of the methods are inherited from C_S%11T! Ne" methods cannot be added! The
instance constructor is generated automaticall$! *t ensures that# "hen an e/ception is raised# the
attributes hae the right alues! *t also transfers the te/t of the superclass for an e/ception
class "hose e/ception te/t is not specified e/plicitl$!
The instance constructor is generated on the basis of the attributes# "hich are set up on the
basis of the e/ception te/ts! Changing the attributes in superclasses can# therefore# inalidate
the constructors of subordinate classes! The constructors of subordinate classes can be
regenerated under )tilities 7 Clean)p 7 Constructor!
7 Te/ts are a special feature of e/ception classes and the 0/ception Builder! ,or further
information# refer to 0/ception Te/ts!
ocal 05ception Classes
.ocal e/ception classes can be defined for specific e/ceptions that onl$ occur "ithin one single
ABAP program! The condition for a local e/ception class is that it inherits from one of the three
classes C_SSTAT*CSC60CU# C_S&3NA'*CSC60CU# or C_SN1SC60CU# or from their
subordinate classes! An indiidual constructor and indiidual attributes can be created! *ndiidual
methods should not be created# ho"eer# and the methods of superclasses should not be
redefined!
05amples of ocal 05ception Classes
report &0'1S.1CA.S0_C0PT*1NS1!
class C_S.1CA.S0_C0PT*1N definition
inheriting from C_SSTAT*CSC60CU!
endclass!
start-of-selection!
tr$!
raise e/ception t$pe C_S.1CA.S0_C0PT*1N!
catch C_S.1CA.S0_C0PT*1N!
message I.ocal 0/ception`I t$pe I*I!
endtr$!
This e/ample sho"s a minimal local e/ception class# "hich is simpl$ the local representation of one
of the three direct subordinate classes of C_S%11T! *t can be used in the program!
report &0'1S.1CA.S0_C0PT*1NS4!
class C_S.1CA.S0_C0PT*1N definition
inheriting from C_SSTAT*CSC60CU!
public section!
data .1CA.ST0_T t$pe ST%*N(!
ABAP Programming (BC-ABA) EB
methods C1NST%)CT1% importing T0_T t$pe ST%*N(!
endclass!
class C_S.1CA.S0_C0PT*1N implementation!
method C1NST%)CT1%!
S)P0%-GC1NST%)CT1%( )!
.1CA.ST0_T H T0_T!
endmethod!
endclass!
data 1%0, t$pe ref to C_S.1CA.S0_C0PT*1N!
start-of-selection!
tr$!
raise e/ception t$pe C_S.1CA.S0_C0PT*1N
e/porting T0_T H ^.ocal 0/ception^!
catch C_S.1CA.S0_C0PT*1N into 1%0,!
message 1%0,-G.1CA.ST0_T t$pe I*I!
endtr$!
*n this e/ample# the e/ception class from the preious e/ample is e/tended to include an
indiidual attribute and constructor! The I,PO(-IN/ parameter of the constructor must be
supplied "hen the e/ception is raised (it is re8uired here)! The attribute can be ealuated in the
handler of the e/ception!
report &0'1S.1CA.S0_C0PT*1NS:!
class C_S.1CA.S0_C0PT*1N definition
inheriting from C_SS3SA%*T6'0T*CS0%%1%!
public section!
methods C1NST%)CT1% importing S*T)AT*1N t$pe ST%*N(!
endclass!
class C_S.1CA.S0_C0PT*1N implementation!
method C1NST%)CT1%!
S)P0%-GC1NST%)CT1%( 1P0%AT*1N H S*T)AT*1N )!
endmethod!
endclass!
data 1%0, t$pe ref to C_S.1CA.S0_C0PT*1N!
data T0_T t$pe ST%*N(!
start-of-selection!
tr$!
raise e/ception t$pe C_S.1CA.S0_C0PT*1N
e/porting S*T)AT*1N H ^STA%T-1,-S0.0CT*1N^!
catch C_S.1CA.S0_C0PT*1N into 1%0,!
T0_T H 1%0,-G(0TST0_T( )!
message T0_T t$pe I*I!
endtr$!
*n this e/ample# an e/ception class is deried from one of the predefined e/ception classes for
error situations in the runtime enironment! An indiidual constructor is defined "ith an indiidual
I,PO(-IN/ parameter that supplies the superclass constructor "ith this parameter! When the
e/ception is handled# the e/ception te/t# as defined in the superclass# is read "ith (0TST0_T!
05ception -e5ts
The most important feature of a caught e/ception is the fact that it has occurred and that it is
handled in the program! *t is left to the handler to decide ho" the e/ception situation is dealt
"ith! *t is not up to the e/ception itself to interact "ith the program user!
Neertheless# an e/planator$ te/t is assigned to each e/ception! This te/t describes the
e/ception situation more precisel$ and is output as an error message if the e/ception is not
handled! *t should# ho"eer# onl$ be used sparingl$ during e/ception handling for communication
"ith the user! The e/ception te/t describes an error situation from a mostl$ technical ie"! *f an
e/ception is described to a user# it should be described from the userIs perspectie!
Attri&utes as Parameters in 05ception -e5ts
ABAP Programming (BC-ABA) ED
0/ception te/ts can contain parameters that enable an error situation to be described more
precisel$! 0lementar$ attributes of the e/ception class "hose content can be interpreted as te/t
are used here! 3ou can conert attributes into parameters of e/ception te/ts b$ displa$ing their
name using the character IfI in the e/ception te/t! *f the character IfI is to actuall$ appear in
the te/t# it has to be entered t"ice!
05ample
*f an e/ception ob2ect has the attributes .AW30% and PA%TN0% "ith the contents ISmithI and
IaonesI# the parameteri9ed e/ception te/t of the class+
Chambers fla"$erffffpartnerf
in this ob2ect status+
Chambers Smithfaones
(ules
The rules for setting parameters for e/ception te/ts using attributes are+
!!!
1! *f te/t parameters# "hich are not attributes in the class# appear in the message# the names
of the parameters remain unchanged in the te/t!
4! *f a te/t parameter# "hich is an attribute in the ob2ect but is not interpretable as a te/t#
appears in the message# the name of the parameter remains unchanged in the te/t and the
attribute t$pe is also specified!
:! *f the contents of an attribute to be substituted e/ceed a reasonable length# the$ can be
truncated (represented b$ I!!!I)!
,anaging 05ception -e5ts
The e/ception te/ts of global e/ception classes are stored "ith their arious translations in the
1T% (1pen Te/t %epositor$)! A te/t is assigned to an e/ception class ia the T0_T*& attribute
defined in the C_S%11T superclass! This attribute contains the globall$ uni8ue *& of the te/t
ob2ect in the 1T% in an e/ception ob2ect at runtime! The (0TST0_T method reads this te/t# ma$
substitute te/t parameters "ith the contents of the corresponding attributes# and returns the
te/t as a string!
The e/ception te/ts in the 1T% are in an$ language! As soon as (0TST0_T is called up# ho"eer#
the logon language must be set! ,or this reason# it al"a$s ma-es more sense to "or- "ith the
e/ception ob2ect itself "ithin an application# in other "ords# to for"ard or store the e/ception
rather than to "or- "ith the alue returned b$ (0TST0_T!
Creating 05ception -e5ts
The e/ception te/ts of global classes are defined on the Te/ts tab page of the 0/ception Builder!
The 0/ception Builder generates the corresponding entries in the 1T%!
Seeral te/ts "ith indiidual *&s can be assigned to a class! The 0/ception Builder generates a
standard te/t for each global class! The unchangeable name of this standard te/t is the same as
the class name! *ndiidual names must be assigned for further te/ts! ,or each te/t# the
0/ception Builder generates a static constant that contains the associated *& in the 1T%! The
names of e/ception te/ts are# therefore# in the same namespace as the attributes of the
e/ception class and are uni8ue for one path of the inheritance hierarch$! A te/t can be addressed
and identified b$ means of the static constant# "hich aoids haing to "or- directl$ "ith the 1T%
in the ABAP program!
05ample of 05ception -e5ts in t$e 05ception Builder
The predefined e/ception class C_SS3S,*.0S1P0NS'1&0 is used b$ the runtime enironment
to refer to e/ceptions during file access for "hich the file "as not opened or simpl$ not opened
in the correct mode! Apart from the standard te/t# the class contains three further te/ts called
%0A&S1N.3# N1TS1P0N and *NC1'PAT*B.0S'1&0# "hich enable the e/ception to be
handled more specificall$ "ithout further subordinate classes haing to be created immediatel$!
05ception -e5ts and Constructors
The e/ception te/t to be used can be determined "hen an e/ception is raised b$ transferring the
static constants mentioned aboe to the I,PO(-IN/parameter T0_T*& of the instance
constructor! *f this te/t is not defined# the standard te/t is used! The instance constructor must
be programmed accordingl$! With global e/ception classes# the 0/ception Builder generates the
ABAP Programming (BC-ABA) EE
instance constructor so that at least one te/t is aailable for each e/ception! 0en if a standard
te/t is not entered# the te/t of the ne/t possible superclass is used!
The 0/ception Builder also ensures that the instance constructor has I,PO(-IN/ parameters
"ith the same name for the attributes "ith "hich the parameters of the e/ception te/ts are
filled!
With local classes# $ou hae to ma-e these settings $ourself!
Outputting 05ception -e5ts
Although the e/ception te/ts are not primaril$ designed for interaction "ith the end user# it ma$#
in certain cases# be "orth outputting them as messages! ,or this purpose# the ,0SSA/0
statement has been e/tended to enable an$ strings to be output+
,0SSA/0 string -7P0 t%pe9
As "ell as the message string to be output# the re8uired t$pe must be specified in a t%pe field!
05ample
report )0,OE0XC0P-IONE-0X-9
data 1%0, t$pe ref to C_SS3S,*.0S1P0NS'1&0!
data T0_T t$pe ST%*N(!
tr$!
raise e/ception t$pe C_SS3S,*.0S1P0NS'1&0
e/porting T0_T*& H C_SS3S,*.0S1P0NS'1&0HG%0A&S1N.3
,*.0NA'0 H ^&)''3!&AT^!
catch C_SS3S,*.0S1P0NS'1&0 into 1%0,!
T0_T H 1%0,-G(0TST0_T( )!
message T0_T t$pe I*I!
endtr$!
tr$!
raise e/ception t$pe C_SS3S,*.0S1P0NS'1&0
e/porting T0_T*& H C_SS3S,*.0S1P0NS'1&0HGN1TS1P0N
,*.0NA'0 H ^&)''3!&AT^!
catch C_SS3S,*.0S1P0NS'1&0 into 1%0,!
T0_T H 1%0,-G(0TST0_T( )!
message T0_T t$pe I*I!
endtr$!
tr$!
raise e/ception t$pe C_SS3S,*.0S1P0NS'1&0
e/porting T0_T*& H C_SS3S,*.0S1P0NS'1&0HG*NC1'PAT*B.0S'1&0
,*.0NA'0 H ^&)''3!&AT^!
catch C_SS3S,*.0S1P0NS'1&0 into 1%0,!
T0_T H 1%0,-G(0TST0_T( )!
message T0_T t$pe I*I!
endtr$!
*n this e/ample# the predefined e/ception C_SS3S,*.0S1P0NS'1&0 is raised and caught three
times! The three e/ception te/ts of the class are used one after the other and their ,*.0NA'0
parameters supplied using arious parameter passings to the instance constructor!
Previous Concepts
Before discussing class-based e/ceptions for %elease @!1F# a distinction needs to be made
bet"een t"o different t$pes of e/ception! These e/ceptions and the mechanisms for handling
them are aailable in addition to the class-based e/ceptions both before and after this release
for reasons of do"n"ard compatibilit$! The t"o handling t$pes cannot be used in parallel "ithin
the same processing bloc-# ho"eer!
0/ceptions in ,unction 'odules and 'ethods
Catchable %untime 0rrors
05ceptions in 2unction ,odules and ,et$ods
To enable error situations in procedures to be handled b$ the caller# e/ceptions hae been
defined in the interface of function modules and methods! ,or global procedures# the e/ceptions
ABAP Programming (BC-ABA) 1FF
"ere defined in the ABAP Wor-bench! ,or local methods# the$ "ere defined "ith the
0XC0P-IONS addition of the ,0-+O)Sstatement! 0/ceptions defined in this "a$ can be raised
"ithin the procedure "ith the (AIS0statements and "ith the (AISIN/ addition of the
,0SSA/0statement!
0/ceptions that are defined li-e this in the interface are handled using the 0XC0P-IONS
additions of the corresponding CA statements! These e/ceptions cannot be for"arded in the
call hierarch$! Not handling them leads to a runtime error!
B$ using the predefined e/ception 0%%1%S'0SSA(0 after the 0XC0P-IONS addition of a
procedure call# messages of t$pe 0 and A sent "ith the ,0SSA/0 statement can also be handled
as e/ceptions!
The principle of these self-defined e/ceptions is e/plained in+
Creating ,unction 'odules
Calling ,unction 'odules
Since the class-based approach here is much more sophisticated and fle/ible# it is the preferred
approach for ne" deelopments! The 0XC0P-IONS and (AISIN/ additions are mutuall$
e/clusie in the interface of a procedure!

Catc$a&le (untime 0rrors
0rror situations in the runtime enironment that "ere handled in the program "ere handled as
catchable runtime errors up to %elease @!1F! Catachable runtime errors are assigned to certain
ABAP statements and are triggered b$ the runtime enironment if errors are detected in an
ABAP statement!
Catchable runtime errors are handled "ith CA-C+ S7S-0,-0XC0P-IONSusing the name of the
runtime error! To detect semanticall$ related runtime errors using a common name# the$ are
combined into e/ception groups!
3ou can handle catchable runtime errors in an ABAP program using the follo"ing control
statements+
CATC6 S3ST0'-0_C0PT*1NS e/c
1
H rc
1
!!! e/c
n
H rc
n
!
!!!
0N&CATC6!
The e/pressions e5c
8
\ e5c
n
indicate either a catchable runtime error or the name of an
e/ception class! The e/pressions rc
8
\ rc
n
are numeric literals! *f one of the specified runtime
errors occurs bet"eenCA-C+and 0N)CA-C+# the program does not terminate! *nstead# the
program 2umps straight to the 0N)CA-C+ statement! After 0N)CA-C+# the numeric literal rc
8

\ rc
n
that $ou assigned to the runtime error is contained in the return code field S7-S.B(C! The
contents of an$ fields that occur in the statement in "hich the error occurred cannot be
guaranteed after 0N)CA-C+!
CA-C+ control structures are li-e I2structures# that is# $ou can nest them to an$ depth# but
the$ must begin and end "ithin the same processing bloc-! ,urthermore# CA-C+ control
structures onl$ catch runtime errors at the current call leel# and not in an$ procedures that $ou
call from "ithin the CA-C+ Z 0N)CA-C+ bloc-!
Since as of %elease @!1F e/ceptions are generall$ handled based on classes# each detectable
runtime error is assigned to a predefined e/ception class! The e/ception groups "ere assigned to
abstract intermediate classes in the inheritance hierarch$ of the assigned e/ception classes! The
defined e/ception classes adhere to the naming conention C_SS3S !!!# for e/ample
C_SS3ST0%1&*A*&0! ,or an oerie" of the hierarch$ of the predefined e/ception classes# use
the ABAP -e$"ord documentation!
With the predefined e/ception classes# a catchable runtime error bet"een the T%3 !!! 0N)-(7
statements can be detected "ith the CA-C+statement# li-e all e/ceptions that can be handled!
This is the preferred method! Parallel handling "ith T%3 !!! 0N)-(7 and CA-C+ !!! 0N)CA-C+
is not allo"ed "ithin a processing bloc-! No ne" catchable runtime errors are planned for the
future! *nstead# it is e/ceptions in ABAP statements "ill onl$ be handled b$ assigning e/ception
classes!
%0P1%T demoScatchSendcatch!
&ATA+ result T3P0 p &0C*'A.S :#
number T3P0 i AA.)0 11!
CATC6 S3ST0'-0_C0PT*1NS arithmeticSerrors H ?!
&1!
ABAP Programming (BC-ABA) 1F1
number H number - 1!
result H 1 ; number!
W%*T0+ ; number# result!
0N&&1!
0N&CATC6!
SU*P!
*, s$-subrc H ?!
W%*T0 ; I&iision b$ 9ero`I!
0N&*,!
The program calculates the 8uotients tens time from 1 and num&er until the runtime error
BC&ST0%1&*A*&0 occurs! This belongs to the e/ception group A%*T6'0T*CS0%%1%S# and is
caught in the e/ample using this class!
B%te and C$aracter String Processing
The follo"ing sections+
Processing Character Strings
Processing B$te Strings
Processing Subfields
&etermining .ength
describe the statements that are intended for processing b$te and character strings in b$te-
t$pe and character-t$pe data ob2ects!
B$te-t$pe data ob2ects contain b$te strings (or b$te se8uences) and al"a$s hae the b$te-t$pe
data t$pe 5 or 5string!
Character-t$pe data ob2ects contains character strings (or strings)! A character-t$pe data
ob2ect has either a character-t$pe data t$pe c# d# n# t# string or it is a structure "ith purel$
character-t$pe components!
Note=
Since %elease @!1F# $ou can use an$ flat structures and b$te-t$pe data ob2ects as character
strings onl$ outside of )nicode programs! Before %elease @!1F# $ou could do this in all programs!
Processing C$aracter Strings
ABAP contains a series of statements for processing character fields of the t$pes c# d# n t and
string! *f $ou use flat structures or b$te strings at operand positions of these statements before
%elease @!1F# then the$ are treated as character strings# that means# an implicit casting is
carried out!
Since as of %elease @!1F an e/plicit b$te string processing is possible# the statements+ 2IN)#
(0PAC0# S+I2-# CONCA-0NA-0 and SPI-# "hich support b$te- and character string
processing# hae the optional addition
999 IN RB7-0OC+A(AC-0(S ,O)0 999
This addition specifies "hich processing t$pe is carried out! *f the addition is not specified#
string processing is performed!
The statements+ -(ANSA-0# CON!0(- -0X-# O!0(A7 and CON)0NS0 are onl$ capable of
character string processing!
3ou should no longer use these obsolete statements!
Searc$ing Wit$in C$aracter Strings
3ou can start a screen se8uence from an ABAP program using
2IN) PR2I(S- OCC.((0NC0SORA OCC.((0NC0SS O2Q pattern IN do&39
The internal table ita& is searched through ro"-b$-ro" according to the b$te or character string
defined b$ pattern! The addition OCC.((0NC0PSQdetermines if the first occurrence# or all
occurrences are searched! The search is terminated if the search pattern "as found for the first
time# or if all search patterns "ere found in the entire search area# or if the end of the search
area "as reached! The search result is communicated b$ setting s%-su&rc!
&uring string processing "ith data ob2ects do&3 of fi/ed length# the closing space is ta-en into
account!
(eplacements in C$aracter Strings
)sing the follo"ing ariants of the (0PAC0statement+
ABAP Programming (BC-ABA) 1F4
1! %0P.AC0 Xb,*%ST 1CC)%%0NC0cZbA.. 1CC)%%0NC0Sc 1,Y pattern
*N dob2 W*T6 ne"!
4! %0P.AC0 S0CT*1N X1,,S0T offY X.0N(T6 lenY 1, dob2 W*T6 ne"!
it is possible to replace characters or b$tes of the do&3ariable "ith characters or b$tes of the
new data ob2ect! 6ere "e distinguish bet"een sample-based (ariant 1) and position-based
(ariant 4) replacement!
When the replacement is e/ecuted# an interim result is implicitl$ created# "ithout an$ length
limit# and this interim result is passed to the do&3 data ob2ect! *f the length of the interim result
is longer than the length of do&3# data ob2ects of fi/ed length are truncated at the right! *f the
length of the interim result is shorter than the length of do&3# data ob2ects of fi/ed length are
filled "ith blan-s or he/adecimal F at the right! &ata ob2ects of ariable length are ad2usted
accordingl$! *f the interim result is truncated to the right# s%-su&rc is set to 4!
&uring string processing "ith do&3 data ob2ects of fi/ed length# the closing blan- is ta-en into
account# "hile "ith new it is not!
,oving 2ield Contents C$aracter &% C$aracter
3ou can shift the contents of a field using the follo"ing ariants of the S+I2- statement!
S+I2- moes field contents character b$ character!
S$ifting a C$aracter String &% a /iven Num&er of Positions
S6*,T c XB3 n P.AC0SY XmodeY!
This statement shifts the field c b$ npositions! *f $ou omit B7 n PAC0S# n is interpreted as one!
*f n is F or negatie# c remains unchanged! *f n e/ceeds the length of c# c is filled out "ith
blan-s! n can be ariable!
With the different mode options# $ou can shift the field c in the follo"ing "a$s+
mode is 02-+
Shifts the field contents n places to the left and adds n blan-s at the right-hand end of the field
(default)!
mode is (I/+-+
Shift n positions to the right and adds n blan-s at the left-hand end of the field!
mode is CI(C.A(+
Shifts the field content on a c$clical basis+ shifts content npositions to the left and shifts the n
characters on the left to the right!
&ATA+ t(1F) T3P0 c AA.)0 Iabcdefghi2I#
string .*U0 t!
string H t!
W%*T0 string!
S6*,T string!
W%*T0 ; string!
string H t!
S6*,T string B3 : P.AC0S .0,T!
W%*T0 ; string!
string H t!
S6*,T string B3 : P.AC0S %*(6T!
W%*T0 ; string!
string H t!
S6*,T string B3 : P.AC0S C*%C).A%!
W%*T0 ; string!
1utput+
abcdefghi2
bcdefghi2
defghi2
abcdefg
defghi2abc
S$ifting t$e 2ield Content up to a /iven C$aracter String
S6*,T c )P T1 str mode!
ABAP Programming (BC-ABA) 1F:
This statement searches the field contents of c until it finds the string str and shifts the field c
up to the edge of the field! The options mode are the same as aboe! str can be a ariable!
*f str is not found in c# s%-su&rc is set to > and c is not shifted! 1ther"ise# s%-su&rc is set to F!
&ATA+ t(1F) T3P0 c AA.)0 Iabcdefghi2I#
string .*U0 t#
str(4) T3P0 c AA.)0 IefI!
string H t!
W%*T0 string!
S6*,T string )P T1 str!
W%*T0 ; string!
ST%*N( H t!
S6*,T string )P T1 str .0,T!
W%*T0 ; string!
ST%*N( H t!
S6*,T string )P T1 str %*(6T!
W%*T0 ; string!
string H t!
S6*,T string )P T1 str C*%C).A%!
W%*T0 ; string!
1utput+
abcdefghi2
efghi2
efghi2
abcdef
efghi2abcd
S$ifting a C$aracter String According to t$e 2irst or ast C$aracter
S6*,T c .0,T &0.0T*N( .0A&*N( str!
S6*,T c %*(6T &0.0T*N( T%A*.*N( str!
This statement shifts the field c to the left or to the right# proided the first character on the
left or the last character on the right occur in str! The right or left of the field is then padded
"ith blan-s! str can be a ariable!
&ATA+ t(1>) T3P0 c AA.)0 I abcdefghi2I#
string .*U0 t#
str(@) AA.)0 Ighi2-lI!
string H t!
W%*T0 string!
S6*,T string .0,T &0.0T*N( .0A&*N( SPAC0!
W%*T0 ; string!
string H t!
S6*,T string %*(6T &0.0T*N( T%A*.*N( str!
W%*T0 ; string!
1utput+
abcdefghi2
abcdefghi2
abcdef
Concatenating C$aracter Strings
The C1NCAT0NAT0 statement combines t"o or more separate strings into one!
C1NCAT0NAT0 c1 !!! cn *NT1 c XS0PA%AT0& B3 sY!
This statement concatenates the character fields c1 to cn and assigns the result to c! The s$stem
ignores spaces at the end of the indiidual source strings!
The addition S0PA%AT0& B3 s allo"s $ou to specif$ a character field s "hich is placed in its
defined length bet"een the indiidual fields!
*f the result fits into c# s$-subrc is set to F! 6o"eer# if the result has to be truncated# s$-subrc
is set to >!
ABAP Programming (BC-ABA) 1F>
&ATA+ c1(1F) T3P0 c AA.)0 ISumI#
c4(:) T3P0 c AA.)0 ImerI#
c:(?) T3P0 c AA.)0 Iholi I#
c>(1F) T3P0 c AA.)0 Ida$I#
c1 (:F) T3P0 c#
sep(:) T3P0 c AA.)0 I - I!
C1NCAT0NAT0 c1 c4 c: c> *NT1 c?!
W%*T0 c?!
C1NCAT0NAT0 c1 c4 c: c> *NT1 c? S0PA%AT0& B3 sep!
W%*T0 ; c?!
The output loo-s li-e this+
Summerholida$
Sum - mer - holi - da$
*n c1 to c?# the trailing blan-s are ignored! The separator sep retains them!
Splitting C$aracter Strings
To split a character string into t"o or more smaller strings# use the SP.*T statement as follo"s+
SP.*T c AT del *NT1 c1 !!! cn!
The s$stem searches the field c for the separator del! The parts before and after the separator
are placed in the target fields c1 !!! cn!
To place all fragments in different target fields# $ou must specif$ enough target fields!
1ther"ise# the last target field is filled "ith the rest of the field c and still contains delimiters!
*f all target fields are long enough and no fragment has to be truncated# s$-subrc is set to F!
1ther"ise it is set to >!
&ATA+ string(@F) T3P0 c#
p1(4F) T3P0 c AA.)0 I55555555555555555555I#
p4(4F) T3P0 c AA.)0 I55555555555555555555I#
p:(4F) T3P0 c AA.)0 I55555555555555555555I#
p>(4F) T3P0 c AA.)0 I55555555555555555555I#
del(:) T3P0 c AA.)0 ILLLI!
string H I Part 1 LLL Part 4 LLL Part : LLL Part > LLL Part ?I!
W%*T0 string!
SP.*T string AT del *NT1 p1 p4 p: p>!
W%*T0 ; p1!
W%*T0 ; p4!
W%*T0 ; p:!
W%*T0 ; p>!
The output appears as follo"s+
Part 1 LLL Part 4 LLL Part : LLL Part > LLL Part ?
Part 1
Part 4
Part :
Part > LLL Part ?
Note that the contents of the fields p1 !!!p> are totall$ oer"ritten and that the$ are filled out
"ith trailing blan-s!
3ou can also split a string into the indiidual lines of an internal table as follo"s+
SP.*T c AT del *NT1 TAB.0 itab!
The s$stem adds a ne" line to the internal table itab for each part of the string!
Converting to .pper or ower Case or (eplacing C$aracters
The -(ANSA-0 statement conerts characters into upper or lo"er case# or uses substitution
rules to conert all occurrences of one character to another character!
Converting to .pper or ower Case
T%ANS.AT0 te/t T1 )PP0% CAS0!
T%ANS.AT0 te/t T1 .1W0% CAS0!
These statements conert all lo"er case letters in the field ]cG to upper case or ice ersa!
Su&stituting C$aracters
T%ANS.AT0 te/t )S*N( pattern!
ABAP Programming (BC-ABA) 1F?
This statement replaces all characters in the te5t field according to the substitution rule stored
in pattern! pattern contains letter pairs "here the first letter of each pair is replaced b$ the
second! pattern can be a ariable!
,or more ariants of the -(ANSA-0 statement "ith more comple/ substitution rules (obsolete
ariants`)# refer to the -e$"ord documentation!
&ATA+ t(1F) T3P0 c AA.)0 IAbCd0f(h*2I#
string .*U0 t#
rule(4F) T3P0 c AA.)0 IA/b_C$d309fTI!
string H t!
W%*T0 string!
T%ANS.AT0 string T1 )PP0% CAS0!
W%*T0 ; string!
string H t!
T%ANS.AT0 string T1 .1W0% CAS0!
W%*T0 ; string!
string H t!
T%ANS.AT0 string )S*N( rule!
W%*T0 ; string!
1utput+
AbCd0f(h*2
ABC&0,(6*a
abcdefghi2
/_$39T(h*2
Converting into a Sorta&le 2ormat
The CON!0(- -0X- statement conerts strings into a format that can be sorted alphabeticall$!
C1NA0%T T0_T c *NT1 S1%TAB.0 C1&0 sc!
This statement "rites a string c to a sortable target field sc! The field c must be of t$pe c and
the field sc must be of t$pe 5 "ith a minimum si9e of 1@ times the si9e of c!
The field sc can sere as an alphabetic sort -e$ for c! These sorts are applied to internal tables
and e/tract datasets! *f $ou sort unconerted character fields# the s$stem creates an order that
corresponds to the platform-specific internal coding of the indiidual letters! The conersion
CON!0(- -0X- creates target fields in such a "a$ that# after sorting the target fields# the
order of the corresponding character fields is alphabetical!
The method of conersion depends on the te/t enironment of the current ABAP program! The
te/t enironment is fi/ed in the user master record# but can also be set from a program using the
follo"ing ABAP statement+
S0T .1CA.0 .AN()A(0 lg XC1)NT%3 c$Y X'1&*,*0% mY!
This statement sets the te/t enironment in accordance "ith the language lg! With the
CO.N-(7 addition# $ou can specif$ the countr$ in addition to the language# proided there are
countr$-specific differences for languages! With the ,O)I2I0( addition# $ou can specif$
another identifier# proided there are differences in the language "ithin one countr$! ,or
e/ample# in (erman$# the order for sorting umlauts is different in a dictionar$ from the order
used in a telephone boo-!
The fields lg# c%# and m must be of t$pe c and must hae the same lengths as the -e$ fields of
table TCPFC! Table TCPFC is a table# in "hich the te/t enironment is maintained platform-
dependent! &uring the statement S0- OCA0# the s$stem sets the te/t enironment according
to the entries in TCPFC! With the e/ception of the platform identit$# "hich is transferred
internall$# the table -e$ is specified "ith the S0- statement! The platform identifier is passed
implicitl$! *f lg e8uals space# the s$stem sets the te/t enironment according to the user=s
master record! *f there is no entr$ in the table for the -e$ specified# the s$stem reacts "ith a
runtime error!
The te/t enironment influences all operations in ABAP that depend on the character set!
,or more information about this topic# see the -e$"ord documentation for CON!0(- -0X- and
S0- OCA0 AN/.A/0!
,or an e/ample of alphabetical sorting# see Sorting *nternal Tables!
Overla%ing C$aracter 2ields
The 1A0%.A3 statement oerla$s one string "ith another+
ABAP Programming (BC-ABA) 1F@
1A0%.A3 c1 W*T6 c4 X1N.3 strY!
This statement oerla$s all positions in field c8containing letters "hich occur in str "ith the
contents of cB! cBremains unchanged! *f $ou omit ON7 str # all positions of c8 containing spaces
are oer"ritten!
*f at least one character in c1 "as replaced# s%-su&rc is set to F! *n all other cases# s%-su&rc is
set to >! *f c8 is longer than cB# it is oerlaid onl$ in the length of cB!
&ATA+ t(1F) T3P0 c AA.)0 Ia c e g i I#
string .*U0 t#
oer(1F) T3P0 c AA.)0 IABC&0,(6*aI#
str(4) T3P0 c AA.)0 IaiI!
string H t!
W%*T0 string!
W%*T0 ; oer!
1A0%.A3 string W*T6 oer!
W%*T0 ; string!
string H t!
1A0%.A3 string W*T6 oer 1N.3 str!
W%*T0 ; string!
1utput+
a c e g i
ABC&0,(6*a
aBc&e,g6ia
A c e g *
Condensing 2ield Contents
The C1N&0NS0 statement deletes redundant spaces from a string+
C1N&0NS0 c XN1-(APSY!
This statement remoes an$ leading blan-s in the field c and replaces other se8uences of blan-s
b$ e/actl$ one blan-! The result is a left-2ustified se8uence of "ords# each separated b$ one
blan-! *f the addition N1-(APS is specified# all blan-s are remoed!
&ATA+ string(4?) T3P0 c AA.)0 I one t"o three fourI#
len T3P0 *!
len H strlen( string )!
W%*T0+ string# I`I!
W%*T0+ ; I.ength+ I# len!
C1N&0NS0 string!
len H strlen( string )!
W%*T0+ string# I`I!
W%*T0+ ; I.ength+ I# len!
C1N&0NS0 string N1-(APS!
len H strlen( string )!
W%*T0+ string# I`I!
W%*T0+ ; I.ength+ I# len!
1utput+
one t"o three four `
.ength+ 4?
one t"o three four `
.ength+ 1D
onet"othreefour `
.ength+ 1?
Note that the total length of the field string remains unchanged# but that the deleted blan-s
appear again on the right!
O&solete Statements for C$aracter Strings
The follo"ing statements are obsolete and are onl$ aailable to ensure compatibilit$ "ith
%eleases prior to >!@ and @!1F! The statements ma$ appear in older programs but should no longer
be used!
ABAP Programming (BC-ABA) 1FB
Searc$ .sing S0A(C+
The S0A(C+ statement is the predecessor of the 2IN) statement! *t e/ists since %elease @!1F!
S0A(C+ should be used in %eleases prior to B!F onl$ for functions that are not coered b$ the
2IN) statement! These include in particular searches "ith special characters!
Since %elease B!F# the S0A(C+ functions [ "ith the e/ception of selecting the sample found
(AN) ,A(" addition) hae been coered b$ the inclusion of standard e/pressions in the 2IN)
statement! *f re8uired# selecting a sample after it has been found can be programmed itself
through offset;length access!
*n contrast to 2IN) # S0A(C+ is not case-sensitie and is much slo"er "hen searching through
large te/ts!
&ecimal points and asteris-s are special samples "hose rules are described in the
-e$"ord documentation!
&ATA string(:F) T3P0 c AA.)0 IThis is a little sentence!I!
W%*T0+ ; ISearchedI# IS3-S)B%C I# IS3-,&P1SI!
).*N0 ;1(4@)!
S0A%C6 string ,1% I_I!
W%*T0+ ; I_I# s$-subrc )N&0% IS3-S)B%CI#
s$-fdpos )N&0% IS3-,&P1SI
S0A%C6 string ,1% Iitt I!
W%*T0+ ; Iitt I# s$-subrc )N&0% IS3-S)B%CI#
s$-fdpos )N&0% IS3-,&P1SI
S0A%C6 string ,1% I!e !I!
W%*T0+ ; I!e !I# s$-subrc )N&0% IS3-S)B%CI#
s$-fdpos )N&0% IS3-,&P1SI!
S0A%C6 string ,1% ILeI!
W%*T0+ ; ILe I# s$-subrc )N&0% IS3-S)B%CI#
s$-fdpos )N&0% IS3-,&P1SI!
S0A%C6 string ,1% IsLI!
W%*T0+ ; IsL I# s$-subrc )N&0% IS3-S)B%CI#
s$-fdpos )N&0% IS3-,&P1SI!
1utput+
S0A%C60& S3-S)B%C S3-,&P1S
_ > F
itt F 11
!e ! F 1?
Le F 1F
sL F 1B
&ATA+ T3P0 c (:F) T3P0 c AA.)0 IThis is a fast first e/ample!I#
pos T3P0 i#
off T3P0 i!
W%*T0 ; string!
S0A%C6 string ,1% IftI ABB%0A*AT0&!
W%*T0+ ; IS3-,&P1S+I# s$-fdpos!
pos H s$-fdpos 5 4!
S0A%C6 string ,1% IftI ABB%0A*AT0& STA%T*N( AT pos AN& 'A%U!
W%*T0 ; string!
W%*T0+ ; IS3-,&P1S+I# s$-fdpos!
off H pos 5 s$-fdpos -1!
W%*T0+ ; I1ff+I# off!
1utput+
This is a fast first e/ample!
S3-,&P1S+ 1F
This is a fast ,*%ST e/ample!
S3-,&P1S+ >
1ff+ 1?
ABAP Programming (BC-ABA) 1FD
Note that in order to find the second "ord containing IftI after finding the "ord IfastI# $ou hae
to add 4 to the offset s$-fdpos and start the search at the position pos! 1ther"ise# the "ord
IfastI "ould be found again! To obtain the offset of IfirstI in relation to the start of the field
string# it is calculated from pos and s$-fdpos!
Assigning Parts of C$aracter Strings .sing ,O!0 > P0(C0N-A/0
The follo"ing ariant of the '1A0statement "or-s onl$ "ith t$pe c fields+
'1A0 c1 T1 c4 P0%C0NTA(0 p X%*(6TY!
Copies the percentage p of the field c1 left-2ustified (or right-2ustified if specified "ith the
%*(6T option) to c4!
The alue of p can be a number bet"een F and 1FF! The length to be copied from f1 is rounded up
or do"n to the ne/t "hole number!
*f one of the arguments in the statement is not t$pe c# the parameter P0%C0NTA(0 is ignored!
&ATA c1(1F) T3P0 c AA.)0 IABC&0,(6*aI#
c4(1F) T3P0 c!
'1A0 c1 T1 c4 P0%C0NTA(0 >F!
W%*T0 c4!
'1A0 c1 T1 c4 P0%C0NTA(0 >F %*(6T!
W%*T0 ; c4!
1utput+
ABC&
ABC&
(eplacing 2ield Contents .sing (0PAC0 WI-+
To replace a string in a field "ith a different string# use the (0PAC0 statement!
%0P.AC0 str1 W*T6 str4 *NT1 c X.0N(T6 lenY!

(0PAC0 su&Estring WI-+ new IN-O do&3
PIN RB7-0OC+A(AC-0(S ,O)0Q
P0N/-+ lenQ9
The statement searches the field c for the first occurrence of the first len positions of the
pattern str8! *f no length is specified# it searches for the pattern str8 in its full length!
Then# the statement replaces the first occurrence of the pattern str8 in field c "ith the string
strB! *f a length len "as specified# onl$ the releant part of the pattern is replaced!
*f the return code alue of the s$stem field s%-su&rc is set to F# this indicates that str8 "as
found in c and replaced b$ strB! Another return alue sho"s that nothing "as replaced! str8#
strB# and len can be ariables!
&ATA+ t(1F) T3P0 c AA.)0 Iabcdefghi2I#
string .*U0 t#
str1(>) T3P0 c AA.)0 IcdefI#
str4(>) T3P0 c AA.)0 I-lmnI#
str:(4) T3P0 c AA.)0 I-lI#
str>(@) T3P0 c AA.)0 I-lmnopI#
len T3P0 i AA.)0 4!
string H t!
W%*T0 string!
%0P.AC0 str1 W*T6 str4 *NT1 string!
W%*T0 ; string!
string H t!
%0P.AC0 str1 W*T6 str4 *NT1 string .0N(T6 len!
W%*T0 ; string!
string H t!
%0P.AC0 str1 W*T6 str: *NT1 string!
W%*T0 ; string!
string H t!
%0P.AC0 str1 W*T6 str> *NT1 string!
W%*T0 ; string!
The output appears as follo"s+
ABAP Programming (BC-ABA) 1FE
abcdefghi2
ab-lmnghi2
ab-lmnefgh
ab-lghi2
ab-lmnopgh
*n the last line# the field string is truncated on the right! The search pattern IcdefI of length >
is replaced b$ I-lmnopI of length @! Then# the rest of the field string is filled up to the end of
the field!
Processing B%te Strings
Since release @!1F# ABAP has offered the IN B7-0 ,O)0 addition for the statements
CONCA-0NA-0# 2IN)# (0PAC0# S+I2-and SPI-! *t allo"s operands to be processed b$te b$
b$te! The functions of these statements remain the same as "hen the$ are used for character
strings# the onl$ difference being that in this case b$te-t$pe data ob2ects (data t$pe 5 and
5string)are being processed!
Single Bit Processing in +e5adecimal 2ields
*n a he/adecimal field (t$pe 5)# $ou can process the indiidual bits! ABAP interprets the contents
of he/ fields b$te b$ b$te! ,or e/ample# a he/adecimal field of length n is n b$tes long and has a
displa$ length in ABAP of 4/n! The decimal alues F-4?? are represented in he/adecimal b$ the
characters IFFI to I,,I!
The illustration sho"s ho" a b$te in a se8uence "ith the decimal alue 1D1 is represented in he/!
The first four bits hae the decimal alue 11# the second four bits hae the decimal alue ?! This
leads to the he/adecimal alue JB?= - 11/1@5? H 1D1!
ABAP contains statements that allo" $ou to read and set the indiidual bits in a t$pe 5 field!
There are also statements "hich allo" bit operations bet"een fields of t$pe 5! ,urthermore
there are special relational operands in logic e/pressions for bit patterns!
Bit se8uence processing allo"s $ou to process comple/ conditions and set operations more
efficientl$!
Setting and %eading Bits
Bit 1perations
Set 1perations "ith Bit Se8uences
Setting and (eading Bits
*n a he/adecimal field (t$pe 5)# $ou can set or read indiidual bits!
Setting Bits
To set an indiidual bit# use the statement
S0T B*T n 1, f XT1 bY!
This statement sets the bit at position n of the field f to 1# or to the alue of field &! The s$stem
must be able to interpret bit n as a positie "hole number! The field f must hae data t$pe 5! The
field & must contain the alue F or 1! *f the bit is set# s%-su&rc is set to F! *f n is greater than
the length of f# s%-su&rc is not e8ual to 9ero! *f n or & contain inalid alues# a runtime error
occurs!
)A-A $e5(C) -7P0 59
S0- BI-= @K O2 $e5 -O 84
8@ O2 $e5 -O @4
88 O2 $e5 -O 84
8B O2 $e5 -O 84
8C O2 $e5 -O @4
8D O2 $e5 -O 84
ABAP Programming (BC-ABA) 11F
8G O2 $e5 -O @4
8H O2 $e5 -O 89
W(I-0 $e59
The bits of the second b$te in the three-character he/adecimal field $e5 are set to J1F11F1F1=#
and the list output is as follo"s+
FFB?FF
The decimal alue of the second b$te is 1D1!
(eading Bits
To read an indiidual bit# use the statement
(0T B*T n 1, f *NT1 b!
This statement reads the bit at position n of the field f into field & !The s$stem must be able to
interpret bit n as a positie "hole number! The field f must hae data t$pe 5! *f the bit is read#
s%-su&rc is set to F! *f n is greater than the length of f# s%-su&rc is not e8ual to 9ero and & is
set to 9ero! *f n contains an inalid alue# a runtime error occurs!
)A-A= $e5(8) -7P0 5 !A.0 ?BG?4
&(8) -7P0 n9
)O J -I,0S9
/0- BI- s%-inde5 O2 $e5 IN-O &9
W(I-0 & NO-/AP9
0N))O9
6ere# the eight buts of the single-character he/adecimal field $e5 (alue JB?=) are read and
displa$ed as follo"s+
1F11F1F1
Bit Operations
Bit operations are e/ecuted in Bit e/pressions of the CO,P.-0statement!
XC1'P)T0Y / H bite/p!
&ite5p can be one of the follo"ing bit e/pressions+
Bit 0/pression 'eaning
BI--NO- % Negation
% BI--AN) : And
% BI--XO( : 0/clusie or
% BI--O( : 1r
As "ith mathematical e/pressions# $ou can use parentheses "ith bit e/pressions!
To find the meaning of the indiidual bit operators (BI--NO-# BI--AN)# BI--XO(# BI--O()#
refer to the ABAP -e$"ord documentation!
)A-A= $e58(8) -7P0 5 !A.0 ?BG?4
$e5B(8) -7P0 5 !A.0 ?GB?4
$e5C(8) -7P0 59
$e5C F BI--NO- ( $e58 BI--XO( $e5B )9
W(I-0 $e5C9
The list output is+
11
The bit operation is processed as displa$ed belo"+
ABAP Programming (BC-ABA) 111

Set Operations .sing Bit Se1uences
*f $ou hae a set of m elements# $ou can represent an$ subset as a se8uence of bits! *f the n
th

element of the set is present in a subset# the n
th
bit is set to 1# other"ise# it is set to F! The
uniersal set therefore contains no 9eros!
*n ABAP# $ou can represent a set of m elements using a field "ith t$pe X and length of at least
m;D! To include a member of the uniersal set in a set# use the S0- BI- statement! To chec-
"hich members of the uniersal set are included in a particular set# use the /0- BI- statement!
3ou can use bit operations for the follo"ing set operations+
Set operation Bit operation
*ntersection BI--AN)
)nion BI--O(
S$mmetrical difference BI--XO(
3ou can also use the O relational operator for bit se8uences (see -e$"ord documentation) to
determine "hether a particular set is a subset of another!
(0PO(- demoEdataE&it9
)A-A= fran*furt(D) -7P0 54
frisco(D) -7P0 54
intersect(D) -7P0 54
union(D) -7P0 54
&it -7P0 i9
)A-A= carrid -7P0 spfli-carrid4
carrier I"0 SO(-0) -AB0 O2 carrid
WI-+ .NIW.0 "07 ta&leEline9
)A-A wa -7P0 spfli9
S00C- carrid 2(O, scarr IN-O -AB0 carrier9
S00C- carrid cit%from 2(O, spfli
IN-O CO((0SPON)IN/ 2I0)S O2 wa9
W(I-0= A wa-carrid4 wa-cit%from9
(0A) -AB0 carrier 2(O, wa-carrid -(ANSPO(-IN/ NO 2I0)S9
CAS0 wa-cit%from9
W+0N ?2(AN"2.(-?9
S0- BI- s%-ta&i5 O2 fran*furt9
W+0N ?SAN 2(ANCISCO?9
S0- BI- s%-ta&i5 O2 frisco9
0N)CAS09
0N)S00C-9
ABAP Programming (BC-ABA) 114
intersect F fran*furt BI--AN) frisco9
union F fran*furt BI--O( frisco9
S"IP9
W(I-0 ?Airlines fl%ing from 2ran*furt and San 2rancisco=?9
)O CB -I,0S9
/0- BI- s%-inde5 O2 intersect IN-O &it9
I2 &it F 89
(0A) -AB0 carrier IN)0X s%-inde5 IN-O carrid9
W(I-0 carrid9
0N)I29
0N))O9
S"IP9
W(I-0 ?Airlines fl%ing from 2ran*furt or San 2rancisco=?9
)O CB -I,0S9
/0- BI- s%-inde5 O2 union IN-O &it9
I2 &it F 89
(0A) -AB0 carrier IN)0X s%-inde5 IN-O carrid9
W(I-0 carrid9
0N)I29
0N))O9

This produces the follo"ing output list+
The program uses four he/adecimal fields "ith length > - ,%ANU,)%T# ,%*SC1# *NT0%S0CT#
and )N*1N! 0ach of these fields can represent a set of up to :4 elements! The basic set is the
set of all airlines from database table SCA%%! 0ach bit of the corresponding bit se8uences
representes one airline! To proide an inde/# the e/ternal inde/ table CA%%*0% is created and
filled "ith the airline codes from table SCA%%! *t is then possible to identif$ an airline using the
internal inde/ of table CA%%*0%!
*n the S00C- loop for database table SP,.*# the corresponding bit for the airline is set either
in the ,%ANU,)%T field or the ,%*SC1 field# depending on the departure cit$! The line number
S7--ABIX is determined using a (0A)statement in "hich no fields are transported!
The intersection and union of ,%ANU,)%T and ,%*SC1 are constructed using the bit operations
BI--AN) and BI--O(!
The bits in *NT0%S0CT and )N*1N are read one b$ one and ealuated in t"o )Oloops! ,or each
position in the fields "ith the alue 1# a (0A)statement retriees the airline code from the table
CA%%*0%!
Processing Su&fields
3ou can address subfields in an$ statement in "hich non-numeric elementar$ ABAP t$pes (c# d# n#
t# 5) or structures that do not contain internal tables occur using the follo"ing s$nta/+
ABAP Programming (BC-ABA) 11:
fX5offYX(len)Y
B$ specif$ing an offset 5off and a length (len) directl$ after the field name f# $ou can address
the part of the field starting at position off51 "ith length len as though it "ere an independent
data o&3ect! *n all statements# offset off and length len can be staticall$ specified as number
literals "ithout a plus;minus sign or the$ can be specified d$namicall$ using ariables!
The data t$pe and length of the string section are as follo"s+
1riginal field Subfield
&ata t$pe &ata t$pe .ength
c c len
d n len
n n len
t n len
5 5 len
Structure c len
*f $ou do not specif$ the length len# $ou address the section of the subfield bet"een off and the
end of the field! *f the offset and length combination that $ou specif$ leads to an inalid section
of the field (for e/ample# e/ceeding the length of the original field)# a s$nta/ or runtime error
occurs! 3ou cannot use offset and length to address a literal or a te/t s$mbol!
3ou should ta-e particular care "hen addressing components of structures! To ensure the correct
platform-specific alignment of t$pe i and f components# the$ ma$ contain filler fields# "hose
lengths $ou need to consider "hen calculating the correct offset! ,urthermore# conersion of the
internal representation of character t$pes to )N*C1&0 is planned! 1ne character "ill no longer
occup$ one b$te# but t"o or four instead! Although offset and length specifications can "or- for
character fields (t$pes c# d# n# t) or for he/adecimal fields (t$pe 5)# incompatible changes ma$
occur in structures containing a mi5ture of numeric# character# and he/adecimal fields! SAP
therefore recommends that $ou do not use offset and length to address components of
structures!
&ATA time T3P0 t AA.)0 I1B4?>?I!
W%*T0 time!
W%*T0 ; time54(4)!
C.0A% time54(>)!
W%*T0 ; time!
The output appears as follo"s+
1B4?>?
4?
1BFFFF
,irst# the minutes are selected b$ specif$ing an offset in the W(I-0 statement! Then# the
minutes and seconds are set to their initial alues b$ specif$ing an offset in the C0A(
statement!
Offset and engt$ Specifications in t$e ,O!0 Statement
,or the ,O!0 statement# the s$nta/ for specif$ing offset and length is as follo"s+
'1A0 f1X5off1YX(len1)Y T1 f4X5off4YX(len4)Y!
1r# "hen $ou use the assignment operator+
f4X5off4YX(len4)Y H f1X5off1YX(len1)Y!
The contents of the part of the field f8 that begins at position off851 and has a length of len8
are assigned to field fB# "here the$ oer"rite the section that begins at position offB51 and has
a length of lenB!
SAP recommends that $ou assign alues "ith offset and length specifications onl$ bet"een non-
numeric fields! With numeric fields# the results can be meaningless!
&ATA+ f1(D) T3P0 c AA.)0 IABC&0,(6I#
f4(4F) T3P0 c AA.)0 I14:>?@BDEF14:>?@BDEFI!
f45@(?) H f15:(?)!
*n this e/ample# the assignment operator functions as follo"s+
ABAP Programming (BC-ABA) 11>
&ATA+ f1(D) T3P0 c AA.)0 IABC&0,(6I#
f4(D)! T3P0 c!
&ATA+ o T3P0 i AA.)0 4#
l T3P0 i AA.)0 >!
'1A0 f1 T1 f4! W%*T0 f4!
'1A0 f15o(l) T1 f4! W%*T0 ; f4!
'1A0 f1 T1 f45o(l)! W%*T0 ; f4!
C.0A% f4!
'1A0 f1 T1 f45o(l)! W%*T0 ; f4!
'1A0 f15o(l) T1 f45o(l)! W%*T0 ; f4!
This produces the follo"ing output+
ABC&0,(6
C&0,
C&ABC&
ABC&
C&0,
,irst# the contents of f8 are assigned to fB "ithout offset specifications! Then# the same
happens for f8 "ith offset and length specification! The ne/t three ,O!0 statements oer"rite
the contents of fB "ith offset 4! Note that fB is filled "ith spaces on the right# in accordance
"ith the conersion rule for source t$pe c9
Su&fields in t$e W(I-0 -O Statement
,or the W(I-0 -O statement# the s$nta/ for specif$ing offset and length is as follo"s+
W%*T0 f1X5off1YX(len1)Y T1 f4X5off4YX(len4)Y!
The contents of the subfield o f field f8 that begins at position off851 and has a length of len8
are assigned to field fB# "here the$ oer"rite the section that begins at position offB51 and has
a length of lenB!
&ATA+ string(4F) T3P0 c#
number(D) T3P0 c AA.)0 I14:>?@I#
offset T3P0 i AA.)0 D#
length T3P0 i AA.)0 14!
W%*T0 number(@) T1 string5offset(length) .0,T-a)ST*,*0&!
W%*T0+ ; string!
C.0A% string!
W%*T0 number(@) T1 string5offset(length) C0NT0%0&!
W%*T0+ ; string!
C.0A% string!
W%*T0 number T1 string5offset(length) %*(6T-a)ST*,*0&!
W%*T0+ ; string!
C.0A% string!
This produces the follo"ing output+
14:>?@
14:>?@
14:>?@
The first si/ characters of the field num&er are "ritten left-2ustified# centered# and right-
2ustified into the last 14 characters of the field string!
)etermining engt$
The built-in length functions ST%.0N and _ST%.0Ndetermine the length of a character string
up to the ne/t character that is not a space!
XC1'P)T0Y n H ST%.0N( c )!
ABAP Programming (BC-ABA) 11?
ST%.0Nprocesses an$ operand c as a character data t$pe# regardless of its real t$pe! There is no
t$pe conersion!
As "ith mathematical functions# the -e$"ord C1'P)T0 is optional!
,or more information# refer to the -e$"ord documentation!
&ATA+ int T3P0 i#
"ord1(4F) T3P0 c AA.)0 I14:>?I!
"ord4(4F) T3P0 c!
"ord:(4F) T3P0 c AA.)0 I > I!
int H strlen( "ord1 )!W%*T0 int!
int H strlen( "ord4 )!W%*T0 ; int!
int H strlen( "ord: )!W%*T0 ; int!
The results are ?# F# and >respectiel$!
2ield S%m&ols and )ata (eferences
,ield s$mbols and data references allo" $ou to access data ob2ects d$namicall$ in ABAP
programs! )nli-e static access to a data ob2ect# "here $ou need to specif$ the name of the
ob2ect# field s$mbols and data references allo" $ou to access and pass data ob2ects "hose name
and attributes $ou do not -no" until runtime!
3ou can regard a field s$mbol as a s$mbolic name for a data ob2ect! ,ield s$mbols use value
semantics! When $ou address a field s$mbol# the s$stem "or-s "ith the contents of the data
ob2ect assigned to it# and not "ith the contents of the field s$mbol itself!
&ata references are pointers to data ob2ects! &ata references use reference semantics! &ata
references are the contents of data reference ariables! When $ou access the reference
ariable# $ou are addressing the data reference itself! To access the contents of the data ob2ect
to "hich a data reference is pointing# $ou must dereference it!
2ield S%m&ols
,ield s$mbols are placeholders or s$mbolic names for other fields! The$ do not ph$sicall$ resere
space for a field# but point to its contents! A field s$mbol cam point to an$ data ob2ect! The data
ob2ect to "hich a field s$mbol points is assigned to it after it has been declared in the program!
Wheneer $ou address a field s$mbol in a program# $ou are addressing the field that is assigned
to the field s$mbol! After successful assignment# there is no difference in ABAP "hether $ou
reference the field s$mbol or the field itself! 3ou must assign a field to a field s$mbol before $ou
can address it in a program!
,ield s$mbols are similar to de-referenced pointers in the C programming language (that is#
pointers to "hich the content operator L is applied)! *n ABAP# data references represent a real
e8uialent to pointers in the sense of ariables that contain a memor$ address and can be used
"ithout the contents operator!
All operations programmed "ith field s$mbols are applied to the field assigned to it! A ,O!0
statement bet"een t"o field s$mbols# for e/ample# assigns the contents of the field assigned to
another source field s$mbol to the field assigned to the target field s$mbol! The field s$mbols
themseles point to the same fields after the ,O!0 statement as the$ did before the
,O!0statement!
3ou can create field s$mbols either "ithout or "ith t$pe specifications! *f $ou do not specif$ a
t$pe# the field s$mbol inherits all of the technical attributes of the field assigned to it! *f $ou do
specif$ a t$pe# the s$stem chec-s during the field assignment "hether the assigned field
matches the t$pe of field s$mbol!
,ield s$mbols proide greater fle/ibilit$ "hen $ou address data ob2ects+
7 3ou can assign one field s$mbol to another# "hich allo"s $ou to address subfields!
7 Assignments to field s$mbols ma$ e/tend be$ond field boundaries! This allo"s $ou to
address regular se8uences of fields in memor$ efficientl$!
7 3ou can also force a field s$mbol to ta-e different technical properties than those of the
field assigned to it (casting)!
The fle/ibilit$ of field s$mbols proides elegant solutions to certain problems! 1n the other hand#
it does mean that errors can easil$ occur! Since fields are not assigned to field s$mbols until
runtime# the effectieness of s$nta/ and securit$ chec-s is er$ limited for operations inoling
field s$mbols! This can lead to runtime errors or incorrect data assignments!
ABAP Programming (BC-ABA) 11@
While runtime errors indicate an obious problem# incorrect data assignments are dangerous
because the$ can be er$ difficult to detect! ,or this reason# $ou should onl$ use field s$mbols if
$ou cannot achiee the same result using other ABAP statements!
,or e/ample# $ou ma$ "ant to process part of a string "here the offset and length depend on the
contents of the field! 3ou could use field s$mbols in this case! The ,O!0 statement ("ith $our
o"n au/iliar$ ariables# if re8uired) is much safer than using field s$mbols# since it cannot
address memor$ be$ond the boundar$ of a field! 6o"eer# field s$mbols ma$ improe
performance in some cases!
&efining ,ield S$mbols
Assigning &ata 1b2ects to ,ield S$mbols
)eclaring 2ield S%m&ols
To declare a field s$mbol# use the statement
,*0.&-S3'B1.S ]fsG Xt$pingY!
,or field s$mbols# the angle brac-ets are part of the s$nta/! The$ identif$ field s$mbols in the
program code!
*f $ou do not specif$ an$ additions# the field s$mbol]fsN can hae data ob2ects of an$ t$pe
assigned to it! When $ou assign a data ob2ect# the field s$mbol inherits its technical attributes!
The data t$pe of the assigned data ob2ect becomes the actual data t$pe of the field s$mbol!
Note+ it is possible to assign reference ariables and structured data ob2ects to unt%ped field
s$mbols! 6o"eer# the static field s$mbol is onl$ a pointer to the field in memor$# and does not
hae the comple/ t$pe attributes of a reference or structured field until runtime! 3ou can onl$
use the field s$mbol to address the "hole field (for e/ample# in a ,O!0 statement)! Specific
statements such as C(0A-0 OBY0C- VfsN or OOP A- VfsN are not possible!
-%ping 2ield S%m&ols
The t%ping addition allo"s $ou to specif$ the t$pe of a field s$mbol! When $ou assign a data
ob2ect to a field s$mbol# the s$stem chec-s "hether the t$pe of the data ob2ect $ou are tr$ing
to assign is compatible "ith that of the field s$mbol! *f the t$pes are not compatible or
conertible# the s$stem reacts "ith a s$nta/ or runtime error! *f $ou "ish to perform casting of
data ob2ects using field s$mbols# $ou must do so e/plicitl$ using the ASSI/Nstatement! The
s$stem then treats the assigned data ob2ect as if it had the same t$pe as the field s$mbol!
3ou specif$ the t$pe of a field s$mbol using the same semantics as for t$ping formal parameters
in procedures! 3ou can specif$ the t$pe either genericall% or in full! *f $ou specif$ a generic t$pe#
the t$pe of the field s$mbol is either partiall$ specified or not specified at all! An$ attributes
that are not specified are inherited from the corresponding data ob2ect in the ASS*(N
statement! *f $ou specif$ the t$pe full$# all of the technical attributes of the field s$mbol are
determined "hen $ou define it! 3ou can then onl$ assign data ob2ects to it that hae e/actl$ the
same data t$pe!
3ou should alwa%s specif$ a t$pe for each field s$mbol! *f $ou cannot aoid defining a generic
field s$mbol# ma-e this clear b$ using an appropriate generic t$pe declaration!
,or more information on t$ping using the t%pingaddition# refer to the -e$"ord documentation!
/eneric -%pe Specification
The follo"ing t$pes allo" $ou more freedom "hen assigning data ob2ects! The data ob2ect onl$
needs to hae the specified attributes of the field s$mbol!
*f $ou specif$ a t$pe genericall$# remember that the attributes inherited from the data ob2ect
during assignment are not staticall$ -no"n in the program! 3ou can# at most# address them
d%namicall%!
-7P0S= B0/IN O2 line4
col8 -7P0 c4
colB -7P0 c4
0N) O2 line9
)A-A= wa -7P0 line4
ita& -7P0 +AS+0) -AB0 O2 line WI-+ .NIW.0 "07 col84
*e%(D) -7P0 c !A.0 ?CO8?9
2I0)-S7,BOS VfsN -7P0 AN7 -AB09
ASSI/N ita& -O VfsN9
(0A) -AB0 VfsN WI-+ -AB0 "07 (*e%) F ?X? IN-O wa9
ABAP Programming (BC-ABA) 11B
The internal table ita& is assigned to the generic field s$mbol ]fsG# after "hich it is possible to
address the table -e$ of the field s$mbol d$namicall$! 6o"eer# the static address
(0A) -AB0 VfsN WI-+ -AB0 "07 col8 F ?X? IN-O wa9
is not possible s$ntacticall$# since the field s$mbol does not adopt the -e$ of table ita& until
runtime! *n the program# the t$pe specification AN7 -AB0 onl$ indicates that ]fsG is a table! *f
the t$pe had been AN7 (or no t$pe had been specified at all)# een the specific internal table
statement (0A) -AB0 VfsN "ould not hae been possible from a s$nta/ point of ie"!
*f $ou adopt a structured t$pe genericall$ (a structure# or a table "ith structured line t$pe)# the
indiidual components cannot be addressed in the program either staticall$ or d$namicall$! *n this
case# $ou "ould hae to "or- "ith other field s$mbols and the method of assigning structures
component b$ component!
Specif%ing t$e -%pe 2ull%
*f $ou hae full t$pes specified# the technical attributes of the field s$mbols are determined!
The technical attributes of the assigned data ob2ects must match those of the field s$mbol!
When $ou use a field s$mbol that is full$ t$ped# $ou can address its attributes staticall$ in the
program# since the$ are recogni9ed in the source code! *f $ou full% specif$ the t$pe of a field
s$mbol as a reference or structured data ob2ect# $ou can address it as $ou "ould the data ob2ect
itself# once $ou hae assigned an ob2ect to it! So# for e/ample# $ou could address the components
of a structure# loop through an internal table# or create an ob2ect "ith reference to a field
s$mbol!
(0PO(- demoEfieldEs%m&olsEt%pe9
)A-A= B0/IN O2 line4
col8(8) -7P0 c4
colB(8) -7P0 c !A.0 ?X?4
0N) O2 line9
2I0)-S7,BOS VfsN I"0 line9
ASSI/N line -O VfsN9
,O!0 VfsN-colB -O VfsN-col89
The field s$mbol ]fsG is full$ t$ped as a structure# and $ou can address its components in the
program!
Assigning )ata O&3ects to 2ield S%m&ols
Before $ou can "or- "ith a field s$mbol# $ou must assign a data ob2ect to it! *f $ou attach a
structure to a field s$mbol# $ou assign a data ob2ect to it in the declaration! )nt$ped field
s$mbols point to the built in data ob2ect space once the program starts! space has t$pe c and
length 1! T$ped field s$mbols do not point to an$ field before a data ob2ect is assigned to them!
&uring a program# $ou can assign data ob2ects to field s$mbols at an$ time! 3ou can also assign a
series of different data ob2ects to the same field s$mbol during a program!
To assign a data ob2ect to a field s$mbol# use the ASSI/Nstatement! The ASSI/N statement
has seeral ariants and parameters!
The Basic ,orm of the ASS*(N Statement
Assigning Components of Structures to a ,ield S$mbol
Casting &ata 1b2ects
&ata Areas for ,ield S$mbols
3ou can assign single lines from internal tables to field s$mbols!
3ou can start a screen se8uence from an ABAP program using
)NASS*(N ]fsG!
"hich allo"s $ou to specif$ e/plicitl$ that a field s$mbol ]fsG s$ould not hae a data ob2ect
assigned to it! *f $ou tr$ to use an unassigned field s$mbol# a runtime error occurs! There is a
special logical e/pression that $ou can use to chec- "hether a data ob2ect is assigned to a field
s$mbol!
Basic 2orms of t$e ASSI/N Statement
The statement has the follo"ing basic forms+
Static ASSI/N
*f $ou alread$ -no" the name of the field that $ou "ant to assign to the field s$mbol "hen $ou
"rite a program# use the static ASSI/N statement+
ASS*(N dob2 T1 ]fsG!
ABAP Programming (BC-ABA) 11D
When $ou assign the data ob2ect# the s$stem chec-s "hether the technical attributes of the
data ob2ect do&3 correspond to the t$pe specifications for the field s$mbol ]fsG! The field
s$mbol adopts an$ generic attributes of do&3 that are not contained in its o"n t$pe specification!
After the assignment# it points to this field in the memor$!
(0PO(- demoEfieldEs%m&olsEstatEASSI/N 9
2I0)-S7,BOS= Vf8N -7P0 AN74 VfBN -7P0 i9
)A-A= te5t(B@) -7P0 c !A.0 ?+ello4 $ow are %ou[?4
num -7P0 i !A.0 G4
B0/IN O2 line84
col8 -7P0 f !A.0 ?898eT8@?4
colB -7P0 i !A.0 ?8BCD?4
0N) O2 line84
lineB I"0 line89
ASSI/N te5t -O Vf8N9
ASSI/N num -O VfBN9
)0SC(IB0 2I0) Vf8N 0N/-+ VfBN9
W(I-0= A Vf8N4 ?$as lengt$?4 num9
ASSI/N line8 -O Vf8N9
ASSI/N lineB-colB -O VfBN9
,O!0 Vf8N -O lineB9
ASSI/N ?IN0B-COB F? -O Vf8N9
W(I-0= A Vf8N4 VfBN9
The list output is+
6ello# ho" are $oug has length 4F
.*N0-C1.4 H 1#4:>
The e/ample declares t"o field s$mbols ]f8G and ]fBG! ]fBG ma$ onl$ hae fields of t$pe * since it
has been t$ped accordingl$! ]f8G and ]fBG both point to different fields during the program!
Static ASSI/N wit$ Offset Specification
*n a static ASSI/N statement# $ou can use positive offset and length specifications to assign a
subfield to a field s$mbol!
ASS*(N dob2X5offYX(len)Y T1 ]fsG!
When $ou assign parts of fields to a field s$mbol# the follo"ing special conditions appl$+
7 The s$stem does not chec- "hether the selected part lies inside the field do&3! Both
offset off and length len can be larger than the length of do&3! 3ou can address memor$ be$ond
the boundar$ of do&3# but not be$ond the data areas for field s$mbols!
7 *f $ou do not specif$ the length len# the s$stem automaticall$ uses the length of the field
do&3! *f off is greater than 9ero# ]fsG al"a$s points to an area be$ond the limits of do&3!
7 *f off is smaller than the length of do&34 $ou can enter an asteris- (L) for len to preent
]fsG from referring to an address be$ond the limits of do&3!
(0PO(- demoEfieldEs%m&olsEstatEasEoff 9
2I0)-S7,BOS VfsN -7P0 AN79
)A-A= B0/IN O2 line4
string8(8@) !A.0 ?@8BCDGHIJK?4
stringB(8@) !A.0 ?a&cdefg$i3?4
0N) O2 line9
W(I-0 A line-string8TG9
ASSI/N line-string8TG -O VfsN9
W(I-0 A VfsN9
ASSI/N line-string8TG(U) -O VfsN9
W(I-0 A VfsN9
The list output is+
?@BDE
?@BDEabcde
?@BDE
*n this e/ample# $ou can see the difference bet"een an offset specification in a W(I-0
statement and an offset specification in an ASSI/Nstatement! With W(I-0 # the output is
ABAP Programming (BC-ABA) 11E
truncated at the end of line-string8! Specif$ing an offset greater than E "ould lead to an error
during the s$nta/ chec-! *n the first ASSI/N statement# the memor$ area of length 1F
beginning "ith offset ? in line-string8 is assigned to the field s$mbol ]fsG! The output then ma-es
sense because the memor$ area behind line-string8 belongs to line-stringB! *n the second
ASSI/N statement# the length specification L preents the s$stem from addressing the memor$
area after line-string8!
(0PO(- demoEfieldEs%m&olsEstatEasEofB 9
2I0)-S7,BOS VfsN -7P0 AN79
)A-A= B0/IN O2 line4
a -7P0 c !A.0 ?8?4 & -7P0 c !A.0 ?B?4
c -7P0 c !A.0 ?C?4 d -7P0 c !A.0 ?D?4
e -7P0 c !A.0 ?G?4 f -7P0 c !A.0 ?H?4
g -7P0 c !A.0 ?I?4 $ -7P0 c !A.0 ?J?4
0N) O2 line4
off -7P0 i4
len -7P0 i !A.0 B9
)O B -I,0S9
off F s%-inde5 U C9
ASSI/N line-aToff(len) -O VfsN9
VfsN F ?XX?9
0N))O9
)O J -I,0S9
off F s%-inde5 - 89
ASSI/N line-aToff(8) -O VfsN9
W(I-0 VfsN9
0N))O9
The list output is+
1 4 : _ _ @ _ _
The e/ample sho" ho" field s$mbols can ma-e it easier to access and manipulate regular
structures! Note# ho"eer# that this fle/ible method of manipulating memor$ contents be$ond
field limits also has its dangers and ma$ lead to runtime errors!
)%namic ASSI/N
*f $ou do not -no" the name of the field that $ou "ant to assign to the field s$mbol "hen $ou
"rite a program# $ou can use a d$namic ASSI/Nstatement+
ASS*(N (dob2) T1 ]fsG!
This statement assigns the data ob2ect "hose name is contained in the do&3 field to the field
s$mbol ]fsG! 3ou cannot use subfields in a d$namic ASSI/N!
At runtime# the s$stem searches for the corresponding data ob2ect in the follo"ing order+
!!!
1! *f the ASS*(N statement is in a procedure# the s$stem searches first in its local data!
4! *f it cannot find the ob2ect in the local data (or if the ASS*(N statement is not in a
procedure)# it then loo-s in the local data of the program!
:! *f the field is not found in the global data of the program# the s$stem loo-s in the table
"or- areas declared "ith the -AB0S statement in the main program of the current program
group! A program group consists of a main program and all of the programs that are loaded into
the same internal session as a result of other program calls!
*f the search is successful and a field can be assigned to the field s$mbol# s%-su&rc is set to F!
1ther"ise# it is set to ># and the field s$mbol remains unchanged! ,or securit$ reasons# $ou
should al"a$s chec- the alue of s%-su&rc after a d$namic ASSI/N to preent the field s$mbol
pointing to the "rong area!
Searching for the field in this "a$ slo"s do"n the response time! 3ou should therefore onl$ use
the d$namic ASSI/Nstatement "here absolutel$ necessar$! *f $ou -no" "hen $ou create the
program that $ou "ant to assign a table "or- area to the field s$mbol# $ou can also use the
follo"ing ariant of the d$namic ASSI/Nstatement+
ASS*(N TAB.0 ,*0.& (dob2) T1 ]fsG!
ABAP Programming (BC-ABA) 14F
The s$stem then onl$ searches for the data ob2ect to be assigned "ithin the table "or- areas
declared using -AB0S in the main program of the current program group! This addition is
forbidden in ABAP 1b2ects# since the latter does not support table "or- areas!
Suppose "e hae three programs! The main program+
%0P1%T demoSfieldSs$mbolsSd$namiSasS1!
TAB.0S sboo-!
sboo--fldate H s$-datum!
P0%,1%' form1 *N P%1(%A' demoSform1!
The other t"o programs are+
%0P1%T demoSform1!
,1%' form1!
P0%,1%' form4 *N P%1(%A' demoSform4!
0N&,1%'!
and
%0P1%T demoSform4!
,1%' form4!
&ATA name(4F) T3P0 c AA.)0 ISB11U-,.&AT0I!
,*0.&-S3'B1.S ]fsG T3P0 AN3!
ASS*(N (name) T1 ]fsG!
*, s$-subrc 0C F!
W%*T0 ; ]fsG!
0N&*,!
0N&,1%'!
The output loo-s something li-e this+
F4!F@!1EED
The program group in the internal session no" consists of the programs &0'1# '3,1%'S1 and
'3,1%'S4! The field s$mbol ]fsG is defined in '3,1%'S4! After the d$namic ASSI/N
statement# it points to the component ,.&AT0 of the table "or- area SB11U declared in the
main program &0'1!
(0PO(- demoEfieldEs%m&olsEd%namiEasEB 9
-AB0S s&oo*9
)A-A= name8(B@) -7P0 c !A.0 ?SBOO"-2)A-0?4
nameB(B@) -7P0 c !A.0 ?NA,08?9
2I0)-S7,BOS VfsN -7P0 AN79
ASSI/N -AB0 2I0) (name8) -O VfsN9
W(I-0= A ?s%-su&rc=?4 s%-su&rc9
ASSI/N -AB0 2I0) (nameB) -O VfsN9
W(I-0= A ?s%-su&rc=?4 s%-su&rc9
The list output is+
s$-subrc+ F
s$-subrc+ >
*n the first ASSI/N statement# the s$stem finds the component ,.&AT0 of the table "or- area
SB11U# and s%-su&rc is set to F! *n the second ASSI/N statement# the s$stem does not find
the field name8 because it is declared b$ the )A-A statement and not b$ the -AB0S
statement! s%-su&rc is therefore set to >!
Assigning 2ield S%m&ols
*nstead of using the names of data ob2ects# $ou can also assign field s$mbols to field s$mbols in
all ariants of the ASSI/Nstatement!
ASS*(N ]fs1GX5offYX(len)Y T1 ]fs4G!
in a static ASSI/N and+
ASS*(N XTAB.0 ,*0.&Y (dob2) T1 ]fs4G!
in a d$namic ASSI/N# "here the field do&3contains the name of a field s$mbol ]fs1G! ]fs1G and
]fs4G ma$ be identical!
Note that the same code in )nicode s$stem "ill produce different results than in non-)nicode
s$stems+
ABAP Programming (BC-ABA) 141
(0PO(- demoEfieldEs%m&olsEd%namiEasEC 9
)A-A= B0/IN O2 s4
a -7P0 c !A.0 ?8?4
& -7P0 c !A.0 ?B?4
c -7P0 c !A.0 ?C?4
d -7P0 c !A.0 ?D?4
e -7P0 c !A.0 ?G?4
f -7P0 c !A.0 ?H?4
g -7P0 c !A.0 ?I?4
$ -7P0 c !A.0 ?J?4
0N) O2 s9
)A-A off -7P0 i9
2I0)-S7,BOS VfsN -7P0 AN79
ASSI/N s-a -O VfsN9
&1 > T*'0S!
off H s$-inde/ - 1!
*, ]fsG *S ASS*(N0&!
ASS*(N ]fsG5off(1) T1 ]fsG!
*, ]fsG *S ASS*(N0&!
W%*T0 ]fsG!
0N&*,!
0N&*,!
0N&&1!
*n non-)nicode s$stems# the output is as follo"s+
1 4 > B
The program declares a structure "ith eight components s-a to s-$# and fills them "ith the
digits 1 to D! These character strings are stored regularl$ in memor$! The component s-a is
assigned initiall$ to the field s$mbol ]fsG! The effect of the statements in the &1 loop is+
.oop pass 1+
]fsG points to s-a# off is 9ero# and s-a is assigned to ]fsG
.oop pass 4+
]fsG points to s-a# off is 9ero# and s-& is assigned to ]fsG
.oop pass :+
]fsG points to s-&# off is t"o# and s-d is assigned to ]fsG
.oop pass >+
]fsG points to s-d# off is three# and s-g is assigned to ]fsG
*n a )nicode enironment ("here the )nicode flag is set in the editor settings)# the output is
simpl$+
1
No data ob2ect is assigned to ]fsG from the second loop pass on"ards!
Assigning Components of Structures to a 2ield S%m&ol
,or a structured data ob2ect struc# $ou can use the statement
ASS*(N C1'P1N0NT comp 1, ST%)CT)%0 struc T1 ]fsG!
to assign one of its components comp to the field s$mbol VfsN! 3ou can specif$ the component
compeither as a literal or a ariable! *f comp is of t$pe c or a structure "hich has no internal
tables as components# it specifies the name of the component! *f comp has an$ other elementar$
data t$pe# it is conerted to t$pe i and specifies the number of the component! *f the assignment
is successful# s%-su&rc is set to F! 1ther"ise# it returns >!
This statement is particularl$ important for addressing components of structured data ob2ects
d%namicall%! *f $ou assign a data ob2ect to a field s$mbol genericall%# or using Casting# or pass it
genericall$ to the parameter interface of a procedure# $ou cannot address its components either
staticall$ or d$namicall$! *nstead# $ou must use the aboe statement! This allo"s indirect access
either using the component name or its inde/ number!
(0PO(- demoEfieldEs%m&olsEstatEassign 9
)A-A= B0/IN O2 line4
col8 -7P0 i !A.0 884
colB -7P0 i !A.0 BB4
ABAP Programming (BC-ABA) 144
colC -7P0 i !A.0 CC4
0N) O2 line9
)A-A comp(G) -7P0 c !A.0 ?COC?9
2I0)-S7,BOS= Vf8N -7P0 AN74 VfBN -7P0 AN74 VfCN -7P0 AN79
ASSI/N line -O Vf8N9
ASSI/N comp -O VfBN9
)O C -I,0S9
ASSI/N CO,PON0N- s%-inde5 O2 S-(.C-.(0 Vf8N -O VfCN9
W(I-0 VfCN9
0N))O9
ASSI/N CO,PON0N- VfBN O2 S-(.C-.(0 Vf8N -O VfCN9
W(I-0 A VfCN9
The list output is+
11 44 ::
::
The field s$mbol Vf8N points to the structure line# ]fBNpoints to the field comp! *n the &1 loop#
the components of line are specified b$ their numbers and assigned one b$ one to VfCN! After the
loop# the components colCare specified b$ their names and assigned to VfCN! Note that ASSI/N
CO,PON0N- is the onl$ possible method of addressing the components of Vf8N! 0/pressions
such as Vf8N-col8 are s$ntacticall$ incorrect!
Casting )ata O&3ects
When $ou assign a data ob2ect to a field s$mbol# $ou can cast to an$ data t$pe! This means that
an$ area of memor$ can be ie"ed as haing assumed a gien t$pe! 3ou can then address parts of
fields s$mbolicall$ "ithout haing to use offset;length addressing!
A cast is performed using the CAS-IN/addition of the ASSI/N statement! The
CAS-IN/addition allo"s $ou to assign a data ob2ect to a field s$mbol "here the t$pe of the data
ob2ect is incompatible "ith that of the field s$mbol! There are t"o t$pes of casting+ casting "ith
an implicit t$pe declaration and casting "ith an e5plicit t$pe declaration!
The CAS-IN/ addition replaces some obsolete additions of the ASSI/N statement that should
no longer be used!
Casting wit$ an Implicit -%pe )eclaration
Proided the field s$mbol is either full$ t$ped or has one of the generic built-in ABAP t$pes [ c#
n# p# or 5 [ $ou can use the follo"ing ASSI/Nstatement+
ASS*(N !!! T1 ]fsG CAST*N(!
When the s$stem accesses the field s$mbol# the content of the assigned data ob2ect is
interpreted as if it had the same t$pe as the field s$mbol! The length and alignment of the data
ob2ect must be compatible "ith the field s$mbol t$pe! 1ther"ise the s$stem returns a runtime
error! *f the t$pe of either the field s$mbol or the data ob2ect is [ or contains [ a string#
reference t$pe# or internal table# the t$pe and position of these components must match e/actl$!
1ther"ise# a runtime error occurs!
(0PO(- demoEfieldEs%m&olsEcasting9
-7P0S= B0/IN O2 tEdate4
%ear(D) -7P0 n4
mont$(B) -7P0 n4
da%(B) -7P0 n4
0N) O2 tEdate9
2I0)-S7,BOS VfsN -7P0 tEdate9
ASSI/N s%-datum -O VfsN CAS-IN/9
W(I-0 A s%-datum9
S"IP9
W(I-0= A VfsN-%ear 4 A VfsN-mont$4 A VfsN-da%9
The output loo-s something li-e this+
1EEE;F?;1E
1EEE
F?
1E
ABAP Programming (BC-ABA) 14:
*n this e/ample# the field s$mbol VfsN is full$ t$ped using the local program t$pe tEdate! The s%-
datum field can be treated li-e a structure as a result of the CAS-IN/addition of the ASSI/N
statement! This "ould not be possible "ithout the CAS-IN/ addition# since s%-datum is
incompatible "ith the field s$mbol t$pe!
Casting wit$ an 05plicit -%pe )eclaration
*f the field s$mbol is neither full$ t$ped nor genericall$ t$ped# use the follo"ing form of the
ASSI/N statement+
ASS*(N !!! T1 ]fsG CAST*N( bT3P0 t$pecZb.*U0 dob2c X&0C*'A.S decY!
When the s$stem accesses the field s$mbol# the content of the assigned data ob2ect is
interpreted as if it had the t$pe declared in the statement! After the -7P0 addition# $ou can
declare the name of a data ob2ect enclosed in parentheses! The content of this data ob2ect
indicates the data t$pe at runtime!
3ou cannot enter a t$pe unless an e/plicit cast to the data ob2ect is logical! ,or e/ample# there is
no point casting a standard table to a sorted table# or an ob2ect reference to a data reference!
Thus# $ou cannot declare table t$pes (such as SO(-0) -AB0) or reference t$pes (using (02
-O) after the -7P0addition! *f the data t$pe contains implicit string# reference t$pes# or
internal tables# these components must also occur in the assigned data ob2ect "ith their t$pe and
position!! 1ther"ise# the s$stem returns a s$nta/ or runtime error!
The data t$pe declared in the -7P0 or I"0addition must be compatible "ith the generic t$pe of
the field s$mbol! The generic t$pe can be left as it is or speciali9ed! 6o"eer# $ou cannot reset
-no"n technical attributes of the field s$mbol! ,or e/ample# if the field s$mbol has the
completel$ generic t$pe AN7 # $ou can declare another permitted generic t$pe! *f the field
s$mbol has the generic t$pe c# n# p# or 5# $ou can onl$ specif$ the length and the number of
decimal places! 3ou cannot ma-e an e/plicit t$pe declaration for a full$ t$ped field s$mbol# since#
if the field s$mbol is full$ t$ped alread$# $ou cannot speciali9e it further! *n an$ case# the s$stem
chec-s staticall$ for this at runtime# "here possible!
3ou should use the )0CI,AS addition if the content of the assigned data ob2ect can be
interpreted as a pac-ed number! The field s$mbol is then gien dec decimal places! )0CI,AS
can onl$ be used if no t$pe specification is made of if the t$pe p is specified after -7P0! *f
there is no t$pe specification# t$pe p is used implicitl$! 'oreoer# $ou cannot use the I"0 and
)0CI,AS additions together!
(0PO(- demoEfieldEs%m&olsEcastingEt%p9
-7P0S= B0/IN O2 tEdate4
%ear(D) -7P0 n4
mont$(B) -7P0 n4
da%(B) -7P0 n4
0N) O2 tEdate9
2I0)-S7,BOS= VfsN -7P0 AN74
VfN -7P0 n9
ASSI/N s%-datum -O VfsN CAS-IN/ -7P0 tEdate9
W(I-0 A s%-datum9
S"IP9
)O9
ASSI/N CO,PON0N- s%-inde5 O2 S-(.C-.(0 VfsN -O VfN9
I2 s%-su&rc VN @9
0XI-9
0N)I29
W(I-0 A VfN9
0N))O9
The output loo-s something li-e this+
1EEE;F?;1E
1EEE
F?
1E
*n this e/ample# the field s$mbol ]fsG is completel$ generic! A cast is performed on the field s%-
datum to the local program t$pe tEdate using the CAS-IN/ addition of the ASSI/N statement!
ABAP Programming (BC-ABA) 14>
The field s$mbol VfsN can no" be treated li-e a structure# but it does not -no" an$ components!
Therefore# it must be assigned [ component b$ component [ to another field s$mbol VfN!
O&solete Casting
The follo"ing additions to the ASSI/Nstatement are obsolete! 3ou should therefore no
longer use them! The$ hae been replaced b$ the CAS-IN/addition!

Cast wit$ &uilt-in data t%pes
To set the data t$pe of a field s$mbol independentl$ of the assigned ob2ect t$pe (prior to the
introduction of the CAS-IN/addition "as introduced)# it "as necessar$ to use the -7P0addition
directl$ in the ASSI/N statement+
ASS*(N !!! T1 ]fsG T3P0 dt$pe!
,or dt%pe# ho"eer# $ou could onl$ use the fi/ed-length elementar$ ABAP t$pes (c# d# f# i# n# p# t#
5)# Js= for t"o-b$te integers ("ith sign) and Jb= for one b$te integers ("ithout sign) as literals or
ariables! With the CAS-IN/addition# $ou can no" declare an$ data t$pe after the -7P0addition!
There are t"o different situations "here $ou could use a -7P0addition+
7 T$ped field s$mbols
3ou could use the -7P0 addition "ith a t$ped field s$mbol "heneer the assigned data ob2ect
t$pe "as incompatible "ith the field s$mbol t$pe# but $ou needed to aoid triggering an error
message! *n this case# the specified t$pe dt%pe must be compatible "ith the field s$mbol
t$pe! The field s$mbol then retains its data t$pe# regardless of the assigned data ob2ect! 3ou
should no" use casting "ith an implicit t$pe declaration in this situation!
7 )nt$ped field s$mbols
*f $ou use the -7P0 addition# an unt$ped field s$mbol VfsN adopt the data t$pe specified in
dt%pe instead of the data t$pe and output length of the data ob2ect assigned to it! *f the
field s$mbol is used in a program after a statement "ith the -7P0 addition# the content of
the data ob2ect is interpreted in the same "a$s as for a field of t$pe dt%pe! 3ou should no"
use casting "ith an e/plicit t$pe declaration in this situation!
%untime errors occur if the declared data t$pe is un-no"n< if the length of the declared data
t$pe does not match the t$pe of the assigned field and if the alignments are incompatible!
0/ample using the obsolete -7P0 addition+
&ATA t/t(D) AA.)0 I1EEDF@F@I!
&ATA m$t$pe(1) AA.)0 I_I!
,*0.&-S3'B1.S ]fsG!
ASS*(N t/t T1 ]fsG!
W%*T0 ; ]fsG!
ASS*(N t/t T1 ]fsG T3P0 I&I!
W%*T0 ; ]fsG!
ASS*(N t/t T1 ]fsG T3P0 '3T3P0!
W%*T0 ; ]fsG!
0/ample using the CAS-IN/ addition+
&ATA t/t(D) AA.)0 I1EEDF@F@I!
&ATA m$t$pe(1) AA.)0 I_I!
,*0.&-S3'B1.S ]fsG!
ASS*(N t/t T1 ]fsG!
W%*T0 ; ]fsG!
ASSI/N t5t -O VfsN CAS-IN/ -7P0 d9
W(I-0 A VfsN9
ASSI/N t5t -O VfsN CAS-IN/ -7P0 (m%t%pe)9
W(I-0 A VfsN9
*n both cases# the s$stem displa$s the follo"ing+
1EEDF@F@
F@F@1EED
:1:E:E:D:F:@:F:@
*n these e/amples# the string t5t is assigned to the field s$mbol VfsN three times+ once "ithout
casting# once cast to t$pe d# and once cast to t$pe 5! The format of the second line depends on
the settings in the user master record! The numbers in the last line are the he/adecimal codes of
the characters in t5t! The$ are platform-specific (in this case# ASC**)!
ABAP Programming (BC-ABA) 14?
Casting decimal places
To specif$ the number of decimal places in a field s$mbol "hen assigning it to a pac-ed number of
t$pe p (before the CAS-IN/ statement "as introduced)# $ou needed to use the )0CI,AS
addition in the ASSI/Nstatement+
ASS*(N !!! T1 ]fsG &0C*'A.S dec!
3ou can use the )0CI,AS addition in an$ ariant of the ASSI/Nstatement "here the data
ob2ect assigned to the field s$mbol has t$pe p! *n general# using the )0CI,AS addition
produces different numerical alues for the field s$mbol and the assigned field! 3ou can specif$
the number of decimal places dec as a literal or a ariable! *f dec is not bet"een F and 1># or the
data ob2ect assigned to the field s$mbol is not a t$pe p field# a runtime error occurs!
0/ample using the obsolete )0CI,AS addition+
)A-A= pac*8 -7P0 p )0CI,AS B !A.0 ?D@@?4
pac*B -7P0 p )0CI,AS B4
pac*C -7P0 p )0CI,AS B9
2I0)-S7,BOS= Vf8N -7P0 AN7 4
VfBN -7P0 AN79
W(I-0= A ?PAC"8?4 pac*89
ASSI/N pac*8 -O Vf8N )0CI,AS 89
W(I-0= A ?V28N ?4 Vf8N9
pac*B F Vf8N9
W(I-0= A ?PAC"B?4 pac*B9
ASSI/N pac*B -O VfBN )0CI,AS D9
W(I-0= A ?V2BN ?4 VfBN9
pac*C F Vf8N T VfBN9
W(I-0= A ?PAC"C?4 pac*C9
VfBN F ?8BCD9GHIJK?9
W(I-0= A ?V2BN ?4 VfBN9
W(I-0= A ?PAC"B?4 pac*B9
0/ample using the CAS-IN/ addition+
)A-A= pac*8 -7P0 p )0CI,AS B !A.0 ?D@@?4
pac*B -7P0 p )0CI,AS B4
pac*C -7P0 p )0CI,AS B9
2I0)-S7,BOS= Vf8N -7P0 AN7 4
VfBN -7P0 AN79
W(I-0= A ?PAC"8?4 pac*89
ASSI/N pac*8 -O Vf8N CAS-IN/ -7P0 p )0CI,AS 89
W(I-0= A ?V28N ?4 Vf8N9
pac*B F Vf8N9
W(I-0= A ?PAC"B?4 pac*B9
ASSI/N pac*B -O VfBN CAS-IN/ -7P0 p )0CI,AS D9
W(I-0= A ?V2BN ?4 VfBN9
pac*C F Vf8N T VfBN9
W(I-0= A ?PAC"C?4 pac*C9
VfBN F ?8BCD9GHIJK?9
W(I-0= A ?V2BN ?4 VfBN9
W(I-0= A ?PAC"B?4 pac*B9
*n both cases# the list appears as follo"s+
PACU1 >FF#FF
],1G >!FFF#F
PACU4 >#FFF#FF
],4G >F#FFFF
PACU: >!F>F#FF
],4G 1!4:>#?@BE
PACU4 14:!>?@#BE
0ach of the three t$pe p fields has t"o decimal places! The field s$mbols Vf8N and VfBN hae one
and four decimal places respectiel$! Note that the numeric alues are different for the field
s$mbols and for their assigned fields!
ABAP Programming (BC-ABA) 14@
)ata Areas for 2ield S%m&ols
3ou can onl$ assign data ob2ects from the data areas of the ABAP program to a field s$mbol!
When $ou assign a data ob2ect to a field s$mbol# the s$stem chec-s at runtime to ensure that no
data is lost due to the field s$mbol addressing memor$ outside the data area!
The data areas of an ABAP program are+
7 The table memor$ area for internal tables! The si9e of this storage area depends on the
number of table lines! This is not a fi/ed alue# it is determined d$namicall$ at runtime!
7 The )A-A storage area for other data ob2ects! The si9e of this storage area is fi/ed
during the data declaration!
,ield s$mbols cannot point to addresses outside these areas! *f $ou assign data ob2ects to a field
s$mbol and point to addresses outside these areas# a runtime error occurs!
Certain s$stem information# such as the control bloc-s of internal tables# is also stored in the
)A-A storage area! Therefore# despite the runtime chec-s# $ou ma$ unintentionall$ oer"rite
some of these fields and cause subse8uent errors (for e/ample# destruction of the table header)!
(0PO(- demoEfieldEs%m&olsEassignEerr9
)A-A= te5t8(8@) -7P0 c4 te5tB(8@) -7P0 c4 te5tC(G) -7P0 c9
2I0)-S7,BOS VfsN -7P0 AN79
)O 8@@ -I,0S9 ;(untime-0rror\
ASSI/N te5t8Ts%-inde5(8) -O VfsN9
0N))O9
After starting &0'1# a runtime error occurs! The short dump message begins as follo"s+
The )A-A memor% area is at least 4? b$tes "ide (it can be e/panded due to alignment of the
data areas in memor$)! &uring one of the loop passes# the program tries to access an address
outside this area! The termination message also contains the contents of the field s%-inde5#
"hich ma$ ar$ from case to case! )p to the 4>th loop pass# no error occurs! *f $ou replace te5t8
"ith te5tBin the ASSI/N statement# the error occurs ten loop passes earlier!
)ata (eferences
&ata references are pointers to data ob2ects! The$ occur in ABAP as the contents of data
reference ariables! 3ou can use data references to create data ob2ects d$namicall$! 3ou can also
create references to e/isting data ob2ects! 3ou can onl$ dereference a data reference using a
special assignment to a field s$mbol!

%eference ariable
Creating &ata 1b2ects &$namicall$
(etting %eferences to &ata 1b2ects
&ereferencing &ata %eferences
0/ample of &ata %eferences
(eference !aria&le
%eference ariables contain references! The actual contents of a reference ariable# namel$ the
alue of a reference# is not isible in an ABAP program! ABAP contains data references and ob2ect
references! Conse8uentl$# there are t"o -inds of data reference ariables - data reference
ariables and ob2ect reference ariables!
3ou create the data t$pe of a data reference ariable using+
T3P0S tSdref T3P0 %0, T1 &ATA!
3ou can create a data reference ariable either b$ referring to the aboe data t$pe or using+
&ATA dref T3P0 %0, T1 &ATA!
ABAP Programming (BC-ABA) 14B
%eference ariables are handled in ABAP li-e other data ob2ects "ith an elementar$ data t$pe!
This means that a reference ariable can be defined as a component of a comple/ data ob2ect
such as a structure or internal table as "ell as a single field!
%eference ariables are initial "hen $ou declare them! The$ do not point to an ob2ect! 3ou cannot
dereference an initial reference ariable! A data reference ariable can point to a data ob2ect if
$ou
7 )se it to create a data ob2ect d$namicall$!
7 )se it to get a reference to a data ob2ect!
7 Assign an e/isting data reference to it from another data reference ariable!
3ou can assign references bet"een data reference ariables using the ,O!0 statement or the
assignment operator (H)# and also "hen $ou fill an internal table or pass interface parameters to a
procedure! *f $ou assign references in this "a$# the operands must be t$ped as data reference
ariables! 3ou cannot assign to ob2ect reference ariables or other ariables! After the
assignment# the reference in the target ariable points to the same data ob2ect as the reference
in the source ariable!
Creating )ata O&3ects )%namicall%
All of the data ob2ects that $ou define in the declaration part of a program using statements
such as )A-A are created staticall$# and alread$ e/ist "hen $ou start the program! To create a
data ob2ect d$namicall$ during a program# $ou need a data reference ariable and the follo"ing
statement+
C%0AT0 &ATA dref bT3P0 t$pecZb.*U0 dob2c!
This statement creates a data ob2ect in the internal session of the current ABAP program! After
the statement# the data reference in the data reference ariable dref points to the ob2ect! The
data ob2ect that $ou create does not hae its o"n name! 3ou can onl$ address it using a data
reference ariable! To access the contents of the data ob2ect# $ou must dereference the data
reference!
3ou must specif$ the data t$pe of the ob2ect using the -7P0or I"0 addition! *n contrast to the
use of the -7P0addition in other ABAP statements# $ou can use the C(0A-0 )A-A addition to
d%namicall% specif$ the data t$pe as the contents of a field!
C%0AT0 &ATA dref T3P0 (name)!
6ere# name is the name of a field that contains the name of the re8uired data t$pe!
/etting (eferences to )ata O&3ects
The follo"ing statements allo" $ou to place a data reference to an e/isting data ob2ect in a
reference ariable+
(0T %0,0%0NC0 1, dob2 *NT1 dref!
do&3 can be a staticall$-declared data ob2ect# or a field s$mbol pointing to an$ ob2ect (including a
d$namic ob2ect)! *f $ou specif$ a field s$mbol to "hich no ob2ects hae $et been assigned# a
runtime error occurs!
*f $ou place a reference to a local field in a procedure in a global reference ariable# the
reference "ill become inalid "hen $ou leae the procedure! 3ou cannot then dereference the
reference ariable!
)ereferencing )ata (eferences
To access the contents of the data ob2ect to "hich a data reference is pointing# $ou must
dereference it!
ASS*(N dref-GL T1 ]fsG XCAST*N( !!!Y!
This statement assigns the data ob2ect to the field s$mbol VfsN "hich the data reference in the
reference ariable VdrefN points to! *f the assignment is successful# s%-su&rc is set to 9ero!
*f the field s$mbol is full$ generic# it adopts the data t$pe of the data ob2ect! *f the field
s$mbol is partiall$ or full$ t$ped# the s$stem chec-s the data t$pes for compatibilit$! Casting is
also possible for the assigned data ob2ect!
*f the data reference in ]drefG is initial or inalid# $ou cannot dereference it! The field s$mbol
remains unchanged# and s%-su&rc is set to >!
*f $ou create a data ob2ect d$namicall$# the onl$ "a$ to access its contents is to use
dereferencing!
)ata (eferences= 05ample
(0PO(- demoEdataEreference9
ABAP Programming (BC-ABA) 14D
-7P0S= B0/IN O2 tEstruct4
col8 -7P0 i4
colB -7P0 i4
0N) O2 tEstruct9
)A-A= dref8 -7P0 (02 -O data4
drefB -7P0 (02 -O data9
2I0)-S7,BOS= Vfs8N -7P0 tEstruct4
VfsBN -7P0 i9
C(0A-0 )A-A dref8 -7P0 tEstruct9
ASSI/N dref8-NU -O Vfs8N9
Vfs8N-col8 F 89
Vfs8N-colB F B9
drefB F dref89
ASSI/N drefB-NU -O VfsBN CAS-IN/9
W(I-0 A VfsBN9
/0- (020(0NC0 O2 Vfs8N-colB IN-O drefB9
ASSI/N drefB-NU -O VfsBN9
W(I-0 A VfsBN9
The list output is+
1
4
This e/ample declares t"o data reference ariables dref8 and drefB! dref8is used to create a
structured d$namic data ob2ect! This is dereferenced "ith the field s$mbol ]fs8G# and alues are
then assigned to it! dref8 is assigned to drefB! drefBthen points to the structured data ob2ect!
When drefB is dereferenced# it is cast to the elementar$ t$pe i of field s$mbol ]fsBG! *ts first
component is assigned to the field s$mbol! /0- (020(0NC0 is then used to get a reference to
the second component not the structured data ob2ect in drefB! *t is dereferenced "ithout
casting!
Internal -a&les and 05tracts
There are t"o "a$s of processing large 8uantities of data in ABAP - either using internal tables
or e/tract datasets!
An internal table is a d$namic se8uential dataset in "hich all records hae the same structure and
a -e$! The$ are part of the ABAP t$pe concept! 3ou can access indiidual records in an internal
table using either the inde/ or the -e$!
0/tracts are d$namic se8uential datasets in "hich different lines can hae different structures!
0ach ABAP program ma$ currentl$ onl$ hae a single e/tract dataset! 3ou cannot access the
indiidual records in an e/tract using -e$ or inde/! *nstead# $ou al"a$s process them using a loop!
*nternal Tables
0/tracts
The follo"ing section contains e/amples of ho" to process large datasets for displa$ in a list+
,ormatting &ata
Internal -a&les
*nternal tables proide a means of ta-ing data from a fi/ed structure and storing it in "or-ing
memor$ in ABAP! The data is stored line b$ line in memor$# and each line has the same structure!
*n ABAP# internal tables fulfill the function of arra$s! Since the$ are d$namic data ob2ects# the$
sae the programmer the tas- of d$namic memor$ management in his or her programs! 3ou should
use internal tables "heneer $ou "ant to process a dataset "ith a fi/ed structure "ithin a
program! A particularl$ important use for internal tables is for storing and formatting data from
a database table "ithin a program! The$ are also a good "a$ of including er$ complicated data
structures in an ABAP program!
)ata -%pe of an Internal -a&le
The data t$pe of an internal table is full$ specified b$ its line t$pe# -e$# and table t$pe!
ine -%pe
The line t$pe of an internal table can be an$ data t$pe! The data t$pe of an internal table is
normall$ a structure! 0ach component of the structure is a column in the internal table! 6o"eer#
the line t$pe ma$ also be elementar$ or another internal table!
"e%
The -e$ identifies table ro"s! There are t"o -inds of -e$ for internal tables - the standard -e$
and a user-defined -e$! 3ou can specif$ "hether the -e$ should be .NIW.0 or NON-.NIW.0!
ABAP Programming (BC-ABA) 14E
*nternal tables "ith a uni8ue -e$ cannot contain duplicate entries! The uni8ueness depends on the
table access method!
At tables "ith structured ro" t$pe# the standard -e$ is formed from all character-t$pe columns
of the internal table! *f a table has an elementar$ line t$pe# the default -e$ is the entire line!
The default -e$ of an internal table "hose line t$pe is an internal table# the default -e$ is empt$!
At tables "ith non-structured ro" t$pe# the standard *e% consists of the entire ro"! *f the ro"
t$pe is also a table# an empt$ -e$ is defined!
The user-defined *e% can contain an$ columns of the internal table that are no internal table
themseles# and do not contain internal tables! %eferences are allo"ed as table -e$s! *nternal
tables "ith a user-defined -e$ are called -e$ tables! When $ou define the -e$# the se8uence of
the -e$ fields is significant! 3ou should remember this# for e/ample# if $ou intend to sort the
table according to the -e$!
-a&le t%pe
The table t$pe determines ho" ABAP "ill access indiidual table entries! *nternal tables can be
diided into three t$pes+
Standard ta&les hae an internal linear inde/! ,rom a particular si9e up"ards# the inde/es of
internal tables are administered as trees! *n this case# the inde/ administration oerhead
increases in logarithmic and not linear relation to the number of lines! The s$stem can access
records either b$ using the table inde/ or the -e$! The response time for -e$ access is
proportional to the number of entries in the table! The -e$ of a standard table is al"a$s non-
uni8ue! 3ou cannot specif$ a uni8ue -e$! This means that standard tables can al"a$s be filled er$
8uic-l$# since the s$stem does not hae to chec- "hether there are alread$ e/isting entries!
Sorted ta&les are al"a$s saed sorted b$ the -e$! The$ also hae an internal inde/! The s$stem
can access records either b$ using the table inde/ or the -e$! The response time for -e$ access
is logarithmicall$ proportional to the number of table entries# since the s$stem uses a binar$
search! The -e$ of a sorted table can be either uni8ue or non-uni8ue! When $ou define the table#
$ou must specif$ "hether the -e$ is to be .NIW.0 or NON-.NIW.0! Standard tables and
sorted tables are -no"n genericall$ as inde/ tables!
+as$ed ta&les hae no linear inde/! 3ou can onl$ access a hashed table using its -e$! The
response time is independent of the number of table entries# and is constant# since the s$stem
access the table entries using a hash algorithm! The -e$ of a hashed table must be uni8ue! When
$ou define the table# $ou must specif$ the -e$ as .NIW.0!
/eneric Internal -a&les
)nli-e other local data t$pes in programs# $ou do not hae to specif$ the data t$pe of an internal
table full$! *nstead# $ou can specif$ a generic construction# that is# the -e$ or -e$ and line t$pe
of an internal table data t$pe ma$ remain unspecified! 3ou can use generic internal tables to
specif$ the t$pes of field s$mbols and the interface parameters of procedures ! 3ou cannot use
them to declare data ob2ects!
Internal -a&les as )%namic )ata O&3ects
*nternal tables are al"a$s completel$ specified regarding ro" t$pe# -e$ and access t$pe!
6o"eer# the number of lines is not fi/ed! Thus internal tables are d$namic data ob2ects# since
the$ can contain an$ number of lines of a particular t$pe! The onl$ restriction on the number of
lines an internal table ma$ contain are the limits of $our s$stem installation! The ma/imum
memor$ that can be occupied b$ an internal table (including its internal administration) is 4
gigab$tes! A more realistic figure is up to ?FF megab$tes! An additional restriction for hashed
tables is that the$ ma$ not contain more than 4 million entries! The line t$pes of internal tables
can be an$ ABAP data t$pes - elementar$# structured# or internal tables! The indiidual lines of an
internal table are called table lines or table entries! 0ach component of a structured line is called
a column in the internal table!
C$oosing a -a&le -%pe
The table t$pe (and particularl$ the access method) that $ou "ill use depends on ho" the t$pical
internal table operations "ill be most fre8uentl$ e/ecuted!
Standard ta&les
This is the most appropriate t$pe if $ou are going to address the indiidual table entries using the
inde/! *nde/ access is the 8uic-est possible access! 3ou should fill a standard table b$ appending
lines (ABAP APP0N)statement)# and read# modif$ and delete entries b$ specif$ing the inde/
(IN)0X option "ith the releant ABAP command)! The access time for a standard table increases
in a linear relationship "ith the number of table entries! *f $ou need -e$ access# standard tables
are particularl$ useful if $ou can fill and process the table in separate steps! ,or e/ample# $ou
ABAP Programming (BC-ABA) 1:F
could fill the table b$ appending entries# and then sort it! *f $ou use the binar$ search option
(BINA(7) "ith -e$ access# the response time is logarithmicall$ proportional to the number of
table entries!
Sorted ta&les
This is the most appropriate t$pe if $ou need a table "hich is sorted as $ou fill it! 3ou fill sorted
tables using the INS0(-statement! 0ntries are inserted according to the sort se8uence defined
through the table -e$! An$ illegal entries are recogni9ed as soon as $ou tr$ to add them to the
table! The response time for -e$ access is logarithmicall$ proportional to the number of table
entries# since the s$stem al"a$s uses a binar$ search! Sorted tables are particularl$ useful for
partiall$ se8uential processing in a OOP if $ou specif$ the beginning of the table -e$ in the
W+0(0condition!
+as$ed ta&les
This is the most appropriate t$pe for an$ table "here the main operation is -e$ access! 3ou
cannot access a hashed table using its inde/! The response time for -e$ access remains constant#
regardless of the number of table entries! .i-e database tables# hashed tables al"a$s hae a
uni8ue -e$! 6ashed tables are useful if $ou "ant to construct and use an internal table "hich
resembles a database table or for processing large amounts of data!

Creating *nternal Tables
Processing *nternal Tables
Creating Internal -a&les
3ou define internal tables first as an abstract data t$pe in the program or ABAP &ictionar$# and
then as a data ob2ect based on that# or the$ are declared directl$ as a full$ specified data
ob2ect! When $ou create an internal table as a data ob2ect# $ou should ensure that onl$ the
administration entr$ "hich belongs to an internal table is declared staticall$! The si9e of table
headers for initial tables is currentl$ D b$tes! This should be heeded "heneer internal tables
occur as components of comple/ data ob2ects! Also# empt$ tables can use up a relatiel$ high
amount of storage space as components of tables! The si9e of the entire storage space re8uired
for an internal table is not defined in the declaration [ as is the case for data ob2ects of the t$pe
string or 5string! Table ro"s are added to and deleted from the table d$namicall$ at runtime b$
the arious statements for adding and deleting records!

Table T$pes
*nternal Tables
Special Aspects of Standard Tables
-a&le t%pes
This section describes ho" to define internal tables locall$ in a program! 3ou can also define
internal tables globall$ as data t$pes in the ABAP &ictionar$!
.i-e all local data t$pes in programs # $ou define internal tables using the -7P0S statement! *f
$ou do not refer to an e/isting table t$pe using the -7P0 or I"0 addition# $ou can use the
-7P0S statement to construct a ne" local internal table in $our program!
T3P0S t$pe T3P0Z.*U0 tab-ind 1, linet$pe XW*T6 -e$Y
X*N*T*A. S*T0 nY!
After -7P0 or I"04 there is no reference to an e/isting data t$pe! *nstead# the t$pe
constructor occurs+
tab-ind 1, linet$pe XW*T6 -e$Y
The t$pe constructor defines the table t$pe ta&*ind# the line t$pe linet%pe# and the -e$ *e% of
the internal table t%pe!
3ou can# if $ou "ish# allocate an initial amount of memor$ to the internal table using the INI-IA
SI60 addition!
-a&le t%pe
3ou can specif$ the table t$pe ta&*ind as follo"s+
ABAP Programming (BC-ABA) 1:1
/eneric ta&le t%pes
*N&0_ TAB.0
,or creating a generic table t$pe "ith inde/ access!
AN3 TAB.0
,or creating a full$-generic table t$pe!
&ata t$pes defined using generic t$pes can currentl$ onl$ be used for field s$mbols and for
interface parameters in procedures ! The generic t$pe IN)0X -AB0includes standard tables
and sorted tables! These are the t"o table t$pes for "hich inde/ access is allo"ed! 3ou cannot
pass hashed tables to field s$mbols or interface parameters defined in this "a$! The generic t$pe
AN7 -AB0 can represent an$ table! 3ou can pass tables of all three t$pes to field s$mbols and
interface parameters defined in this "a$! 6o"eer# these field s$mbols and parameters "ill then
onl$ allo" operations that are possible for all tables# that is# inde/ operations are not allo"ed!
2ull%-Specified -a&le -%pes
STAN&A%& TAB.0 or TAB.0
,or creating standard tables!
S1%T0& TAB.0
,or creating sorted tables!
6AS60& TAB.0
,or creating hashed tables!
,ull$-specified table t$pes determine ho" the s$stem "ill access the entries in the table in -e$
operations! *t uses a linear search for standard tables# a binar$ search for sorted tables# and a
search using a hash algorithm for hashed tables!
ine -%pe
,or the line t$pe linet%pe# $ou can specif$+
7 An$ data t$pe if $ou are using the -7P0 addition! This can be a predefined ABAP t$pe# a
local t$pe in the program# or a data t$pe from the ABAP &ictionar$! *f $ou specif$ an$ of the
generic elementar$ t$pes c# n# p and / # an$ attributes that $ou fail to specif$ (field length#
number of decimal places) are automaticall$ filled "ith the default alues! 3ou cannot specif$ an$
other generic t$pes!
7 An$ data ob2ect recogni9ed "ithin the program at that point if $ou are using the I"0
addition! The line t$pe adopts the full$-specified data t$pe of the data ob2ect to "hich $ou refer!
0/cept for "ithin classes# $ou can still use the I"0 addition to refer to database tables and
structures in the ABAP &ictionar$ (for compatibilit$ reasons)!
All of the lines in the internal table hae the full$-specified technical attributes of the specified
data t$pe!
"e%
3ou can specif$ the -e$ *e% of an internal table as follo"s+
X)N*C)0ZN1N-)N*C)0Y U03 col
1
!!! col
n
*n tables "ith a structured line t$pe# all of the components col
1
\ col
n
belong to the -e$ as
long as the$ are not internal tables or references# and do not contain internal tables or
references! Ue$ fields can be nested structures! The substructures are e/panded component
b$ component "hen $ou access the table using the -e$! The s$stem follo"s the se8uence of
the -e$ fields!
ABAP Programming (BC-ABA) 1:4
X)N*C)0ZN1N-)N*C)0Y U03 tableSline
*f a table has an elementar% line t$pe (c# d# f# i# n# p# t# 5)# $ou can define the entire line as
the -e$! *f $ou tr$ this for a table "hose line t$pe is itself a table# a s$nta/ error occurs! *f a
table has a structured line t$pe# it is possible to specif$ the entire line as the -e$! 6o"eer#
$ou should remember that this is often not suitable!
X)N*C)0ZN1N-)N*C)0Y &0,A).T U03
This declares the fields of the default -e$ as the -e$ fields! *f $ou hae a structured line
t$pe# the standard -e$ is build from all columns of the internal table that hae a character-
t$pe t$pe (c# d# t# n# 5# string# 5string)! *nternal tables "ith a nested ro" structure hae a
standard -e$ built b$ lineari9ation of the ro" structure! At elementar$ ro" t$pes# the
standard -e$ is the ro" itself! 0lementar$ tables "ith an internal table as ro" t$pe hae an
empt$ standard -e$!
Specif$ing a -e$ is optional! *f $ou do not specif$ a -e$# the s$stem defines a table t$pe "ith an
arbitrar$ -e$! 3ou can onl$ use this to define the t$pes of field s$mbols and the interface
parameters of procedures ! ,or e/ceptions# refer to Special ,eatures of Standard Tables)!
The optional additions .NIW.0 or NON-.NIW.0 determine "hether the -e$ is to be uni8ue or
non-uni8ue# that is# "hether the table can accept duplicate entries! *f $ou do not specif$
.NIW.0 or NON-.NIW.0 for the -e$# the table t$pe is generic in this respect! As such# it can
onl$ be used for specif$ing t$pes! When $ou specif$ the table t$pe simultaneousl$# $ou must note
the follo"ing restrictions+
7 3ou cannot use the .NIW.0 addition for standard tables! The s$stem al"a$s generates
the NON-.NIW.0 addition automaticall$!
7 3ou must al"a$s specif$ the .NIW.0 option "hen $ou create a hashed table!
Initial ,emor% (e1uirement
3ou can specif$ the initial amount of main memor$ assigned to an internal table ob2ect "hen $ou
define the data t$pe using the follo"ing addition+
*N*T*A. S*T0 n
! This si9e does not belong to the data t$pe of the internal table# and does not affect the t$pe
chec-! 3ou can use the aboe addition to resere memor$ space for n table lines "hen $ou declare
the table ob2ect!
When this initial area is full# the s$stem ma-es t"ice as much e/tra space aailable up to a limit
of DUB! ,urther memor$ areas of 14UB each are then allocated!
3ou can usuall$ leae it to the s$stem to "or- out the initial memor$ re8uirement! The first time
$ou fill the table# little memor$ is used! The space occupied# depending on the line "idth# is 1@ ]H
n]H 1FF!
*t onl$ ma-es sense to specif$ a concrete alue of nif $ou can specif$ a precise number of table
entries "hen $ou create the table and need to allocate e/actl$ that amount of memor$
(e/ception+ Appending table lines to ran-ed lists)! This can be particularl$ important for deep-
structured internal tables "here the inner table onl$ has a fe" entries (less than ?# for e/ample)!
To aoid e/cessie memor$ re8uests# large alues for nare treated as follo"s+ The possible
ma/imum alue for n results from D -ilob$te diided b$ the ro" length! *f $ou specif$ a larger
alue of n# the s$stem calculates a ne" alue so that ntimes the line "idth is around 14UB!
T3P0S+ B0(*N 1, line#
column1 T3P0 i#
column4 T3P0 i#
column: T3P0 i#
0N& 1, .*N0!
T3P0S itab T3P0 S1%T0& TAB.0 1, line W*T6 )N*C)0 U03 column1!
The program defines a table t$pe itab! *t is a sorted table# "ith line t$pe of the structure line
and a uni8ue -e$ of the component column1!
T3P0S ector T3P0 6AS60& TAB.0 1, i W*T6 )N*C)0 U03 tableSline!
T3P0S+ B0(*N 1, line#
column1 T3P0 i#
column4 T3P0 i#
column: T3P0 i#
0N& 1, line!
ABAP Programming (BC-ABA) 1::
T3P0S itab T3P0 S1%T0& TAB.0 1, line W*T6 )N*C)0 U03 column1!
T3P0S+ B0(*N 1, deepline#
field T3P0 c#
table1 T3P0 ector#
table4 T3P0 itab#
0N& 1, deepline!
T3P0S deeptable T3P0 STAN&A%& TAB.0 1, deepline
W*T6 &0,A).T U03!
The program defines a table t$pe ector "ith t$pe hashed table# the elementar$ line t$pe i and a
uni8ue -e$ of the entire table line! The second table t$pe is the same as in the preious e/ample!
The structure deepline contains the internal table as a component! The table t$pe deeptable has
the ro" t$pe deepline! Therefore# the elements of this internal table are themseles internal
tables! The -e$ is the default -e$ - in this case the column field! The -e$ is non-uni8ue# since the
table is a standard table!
Internal -a&les
*nternal tables are d$namic ariable data ob2ects! .i-e all ariables# $ou declare them using the
)A-A statement!
3ou can also declare static internal tables in procedures using the S-A-ICSstatement# and static
internal tables in classes using the CASS-)A-Astatement!
This description is restricted to the )A-Astatement! 6o"eer# it applies e8uall$ to the
S-A-ICS and CASS-)A-A statements!
(eferring to "nown -a&le -%pes
.i-e all other data ob2ects# $ou can declare internal tables using the I"0 or -7P0 addition of the
)A-A statement!
&ATA itab T3P0 t$peZ.*U0 ob2 XW*T6 60A&0% .*N0Y!
6ere# the I"0 addition refers to an e/isting table ob2ect in the same program! The -7P0
addition can refer to an internal t$pe in the program declared using the -7P0S statement# or a
table t$pe in the ABAP &ictionar$!
3ou must ensure that $ou onl$ refer to tables that are full$ t$ped! %eferring to generic table
t$pes (AN7 -AB04 IN)0X -AB0) or not specif$ing the -e$ full$ is not allo"ed (for
e/ceptions# refer to Special ,eatures of Standard Tables)!

The WI-+ +0A)0( IN0 addition is obsolete< $ou should no longer use it! Also see the
-e$"ord documentation!

The optional addition WI-+ +0A)0( IN0 declares an e5tra data o&3ect "ith the same name
and line t%pe as the internal table! This data ob2ect is -no"n as the $eader line of the internal
table! 3ou use it as a "or- area "hen "or-ing "ith the internal table (see )sing the 6eader .ine
as a Wor- Area)! When $ou use internal tables "ith header lines# $ou must remember that the
header line and the bod$ of the table hae the same name! *f $ou hae an internal table "ith
header line and $ou "ant to address the bod$ of the table# $ou must indicate this b$ placing
brac-ets after the table name (ita&PQ)! 1ther"ise# ABAP interprets the name as the name of the
header line and not of the bod$ of the table! 3ou can aoid this potential confusion b$ using
internal tables "ithout header lines! *n particular# internal tables nested in structures or other
internal tables must not hae a header line# since this can lead to ambiguous e/pressions!
T3P0S ector T3P0 S1%T0& TAB.0 1, i W*T6 )N*C)0 U03 tableSline!
&ATA+ itab T3P0 ector#
2tab .*U0 itab W*T6 60A&0% .*N0!
L '1A0 itab T1 2tab! ]- S$nta/ error`
'1A0 itab T1 2tabXY!
The table ob2ect ita& is created "ith reference to the table t$pe vector! The table ob2ect 3ta&
has the same data t$pe as ita&! 3ta& also has a header line! *n the first ,O!0 statement# 3ta&
addresses the header line! Since this has the data t$pe *# and the table t$pe of ita& cannot be
conerted into an elementar$ t$pe# the ,O!0 statement causes a s$nta/ error! The second
,O!0 statement is correct# since both operands are table ob2ects!
)eclaring New Internal -a&les
ABAP Programming (BC-ABA) 1:>
3ou can use the )A-A statement to construct ne" internal tables as "ell as using the I"0 or
-7P0addition to refer to e/isting t$pes or ob2ects! The table t$pe that $ou construct does not
e/ist in its o"n right< instead# it is onl$ an attribute of the table ob2ect! 3ou can refer to it using
the I"0 addition# but not using -7P0! The s$nta/ for constructing a table ob2ect in the &ATA
statement is similar to that for defining a table t$pe in the -7P0Sstatement!
&ATA itab T3P0Z.*U0 tab-ind 1, linet$pe W*T6 -e$
X*N*T*A. S*T0 nY
XW*T6 60A&0% .*N0Y!
As illustrated "hen $ou define a table t$pe $ourself# the t$pe constructor
tab-ind 1, linet$pe W*T6 -e$
defines the table t$pe ta&*ind# the line t$pe linet%pe# and the -e$ *e% of the internal table ita&!
Since the technical attributes of data ob2ects are al"a$s full$ specified# the table must be full$
specified in the )A-Astatement! 3ou cannot create generic table t$pes (AN7 -AB0# IN)0X
-AB0)# onl$ full$-t$ped tables (S-AN)A() -AB0 and -AB0# SO(-0) -AB0# +AS+0)
-AB0)! 3ou must also specif$ the -e$ and "hether it is to be uni8ue (for e/ceptions# refer to
Special ,eatures of Standard Tables)!
As in the -7P0S statement# $ou can# if $ou "ish# allocate an initial amount of memor$ to the
internal table using the INI-IA SI60addition! 3ou can create an internal table "ith a header
line using the WI-+ +0A)0( IN0 addition! The header line is created under the same
conditions as appl$ "hen $ou refer to an e/isting table t$pe!
&ATA itab T3P0 6AS60& TAB.0 1, spfli
W*T6 )N*C)0 U03 carrid connid!
The table ob2ect ita& has the t$pe hashed table# a line t$pe corresponding to the flat structure
SP,.* from the ABAP &ictionar$# and a uni8ue -e$ "ith the -e$ fields CA%%*& and C1NN*&! The
internal table ita& can be regarded as an internal template for the database table SP,.*! *t is
therefore particularl$ suitable for "or-ing "ith data from this database table as long as $ou onl$
access it using the -e$!
Special 2eatures of Standard -a&les
)nli-e sorted tables# hashed tables# and -e$ access to internal tables# "hich "ere onl$ introduced
in %elease >!F# standard tables alread$ e/isted seeral releases preiousl$! &efining a line t$pe#
table t$pe# and tables "ithout a header line hae onl$ been possible since %elease :!F! ,or this
reason# there are certain features of standard tables that still e/ist for compatibilit$ reasons!
Standard -a&les Before (elease C9@
Before %elease :!F# internal tables all had header lines and a flat-structured line t$pe! There
"ere no independent table t$pes! 3ou could onl$ create a table ob2ect using the OCC.(S addition
in the &ATA statement# follo"ed b$ a declaration of a flat structure+
&ATA+ B0(*N 1, itab 1CC)%S n#
!!!
f
1
!!!#
f
4
!!!#
!!!
0N& 1, itab!
This statement declared an internal table ita&"ith the line t$pe defined follo"ing the OCC.(S
addition! ,urthermore# all internal tables had header lines!
The number n in the OCC.(S addition had the same meaning as in the INI-IA SI60 addition
from %elease >!F! 0ntering JF= had the same effect as omitting the INI-IA SI60 addition! *n
this case# the initial si9e of the table is determined b$ the s$stem!
The aboe statement is still possible in %elease >!F# and has roughl$ the same function as the
follo"ing statements+
T3P0S+ B0(*N 1, itab#
!!!
f
1
!!!#
f
4
!!!#
!!!
0N& 1, itab!
&ATA itab T3P0 STAN&A%& TAB.0 1, itab
W*T6 N1N-)N*C)0 &0,A).T U03
ABAP Programming (BC-ABA) 1:?
*N*T*A. S*T0 n
W*T6 60A&0% .*N0!
*n the original statement# no independent data t$pe ita&is created! *nstead# the line t$pe onl$
e/ists as an attribute of the data ob2ect ita&!
Standard -a&les 2rom (elease C9@
Since %elease :!F# it has been possible to create table t$pes using
T3P0S t$pe T3P0Z.*U0 linet$pe 1CC)%S n!
and table ob2ects using
&ATA itab T3P0Z.*U0 linet$pe 1CC)%S n XW*T6 60A&0% .*N0Y!
statement! The effect of the OCC.(S addition is to construct a standard table "ith the data
t$pe linet%pe! The line t$pe can be an$ data t$pe! The number n in the OCC.(S addition has the
same meaning as before %elease :!F! Before %elease >!F# the -e$ of an internal table "as al"a$s
the default -e$# that is# all non-numeric fields that "ere not themseles internal tables!
The aboe statements are still possible in %elease >!F# and hae the same function as the
follo"ing statements+
T3P0SZ&ATA itab T3P0Z.*U0 STAN&A%& TAB.0 1, linet$pe
W*T6 N1N-)N*C)0 &0,A).T U03
*N*T*A. S*T0 n
XW*T6 60A&0% .*N0Y!
The$ can also be replaced b$ the follo"ing statements+
Standard -a&les 2rom (elease D9@
When $ou create a standard table# $ou can use the follo"ing forms of the -7P0S and
)A-Astatements! The addition INI-IA SI60 is also possible in all of the statements! The
addition WI-+ +0A)0( IN0 is possible in the )A-A statement!
Standard -a&le -%pes
/eneric Standard -a&le -%pe=
T3P0S itab T3P0Z.*U0 XSTAN&A%&Y TAB.0 1, linet$pe!
The table -e$ is not defined!
2ull%-Specified Standard -a&le -%pe=
T3P0S itab T3P0Z.*U0 XSTAN&A%&Y TAB.0 1, linet$pe
W*T6 XN1N-)N*C)0Y -e$!
The -e$ of a full$-specified standard table is al"a$s non-uni8ue!
Standard -a&le O&3ects
S$ort 2orms of t$e )A-A Statement
&ATA itab T3P0Z.*U0 XSTAN&A%&Y TAB.0 1, linet$pe!
&ATA itab T3P0Z.*U0 XSTAN&A%&Y TAB.0 1, linet$pe
W*T6 &0,A).T U03!
Both of these )A-A statements are automaticall$ completed b$ the s$stem as follo"s+
&ATA itab T3P0Z.*U0 STAN&A%& TAB.0 1, linet$pe
W*T6 N1N-)N*C)0 &0,A).T U03!
The purpose of the shortened forms of the )A-Astatement is to -eep the declaration of
standard tables# "hich are compatible "ith internal tables from preious releases# as simple as
possible! When $ou declare a standard table "ith reference to the aboe t$pe# the s$stem
automaticall$ adopts the default -e$ as the table -e$!
2ull%-Specified Standard -a&les=
&ATA itab T3P0Z.*U0 XSTAN&A%&Y TAB.0 1, linet$pe
W*T6 XN1N-)N*C)0Y -e$!
The -e$ of a standard table is al"a$s non-uni8ue!
Processing Internal -a&les

When $ou process an internal table ob2ect# $ou must distinguish bet"een the follo"ing t"o cases+
1perations on 0ntire *nternal Tables
1perations on *ndiidual .ines
Operations on 0ntire Internal -a&les
When $ou access the entire internal table# $ou address the bod$ of the table as a single data
ob2ect! The follo"ing operations on the bod$ of an internal table are releant+
Assigning *nternal Tables
*nitiali9e *nternal Tables
Compare *nternal Tables
ABAP Programming (BC-ABA) 1:@
Sort *nternal Tables
*nternal Tables as *nterface Parameters
&etermining the Attributes of *nternal Tables
3ou can also address internal tables in 1pen SC. statements - either to fill an internal table
from a database table or the other "a$ round!
Assigning Internal -a&les
.i-e other data ob2ects# $ou can use internal tables as operands in a '1A0 statement
'1A0 itab1 T1 itab4!
or the e8uialent statement
itab4 H itab1!
Both operands must either be compatible or conertible internal tables! These statements assign
the entire contents of table ita&8 to table ita&B# including the data in an$ nested internal tables!
The original contents of the target table are oer"ritten!
*f $ou are using internal tables "ith header lines# remember that the header line and the bod$ of
the table hae the same name! *f $ou "ant to address the bod$ of the table in an assignment# $ou
must place t"o brac-ets (PQ) after the table name!
)A-A= B0/IN O2 line4
col8(8) -7P0 c4
colB(8) -7P0 c4
0N) O2 line9
)A-A= eta& I"0 -AB0 O2 line WI-+ +0A)0( IN04
fta& I"0 -AB0 O2 line9
line-col8 F ?A?9 line-colB F ?B?9
APP0N) line -O eta&9
,O!0 eta&PQ -O fta&9
OOP A- fta& IN-O line9
W(I-0= A line-col84 line-colB9
0N)OOP9
The list output is+
A B
The e/ample creates t"o standard tables eta&and fta& "ith the line t$pe of the structure IN0!
After filling eta& line b$ line using the APP0N) statement# its entire contents are assigned to
fta&! Note the brac-ets in the statement!
)A-A= fta& -7P0 SO(-0) -AB0 O2 f
WI-+ NON-.NIW.0 "07 ta&leEline4
ita& -7P0 +AS+0) -AB0 O2 i
WI-+ .NIW.0 "07 ta&leEline4
fl -7P0 f9
)O C -I,0S9
INS0(- s%-inde5 IN-O -AB0 ita&9
0N))O9
fta& F ita&9
OOP A- fta& IN-O fl9
W(I-0= A fl9
0N)OOP9
The list output is+
1!FFFFFFFFFFFFFFF05FF
4!FFFFFFFFFFFFFFF05FF
:!FFFFFFFFFFFFFFF05FF
fta& is a sorted table "ith the line t$pe f and a non-uni8ue -e$! ita& is a hashed table "ith the
line t$pe i and a uni8ue -e$! The line t$pes# and therefore all the tables# are conertible! *t is
therefore possible to assign the contents of ita& to fta&! When $ou assign the unsorted table
ita& to the sorted table fta&# the contents are automaticall$ sorted b$ the -e$ of fta&!
*n )nicode s$stems# the follo"ing conersion is not allo"ed+
ABAP Programming (BC-ABA) 1:B
)A-A= B0/IN O2 iline4
num -7P0 i4
0N) O2 iline4
B0/IN O2 fline4
num -7P0 f4
0N) O2 fline4
ita& I"0 -AB0 O2 iline4
fta& I"0 -AB0 O2 fline9
)O C -I,0S9
iline-num F s%-inde59
APP0N) iline-num -O ita&9
0N))O9
fta& F ita&9
loop A- fta& IN-O fline9
W(I-0= A fline-num9
0N)OOP9
*n a non-)nicode s$stem# the output ma$ loo- li-e this+
@!F:D4:>F:DE?D1:0-1?>
@!F:E@EFB>@1:41E0-1?>
@!F>11>B>?::F@4@0-1?>
6ere# the line t$pes of the internal tables ita&und fta& are structures each "ith one component
of t$pe i or f! The line t$pes are conertible# but not compatible! Therefore# "hen assigning ita&
to fta&# the contents of Table ita&are conerted to t$pe C fields and then "ritten to fta&! The
ABAP s$stem interprets the transferred data as t$pe f fields# so that the results are
meaningless! *n )nicode s$stems# $ou can not conert numeric fields to fields of t$pe c!
Initiali:ing Internal -a&les
.i-e all data ob2ects# $ou can initiali9e internal tables "ith the
C.0A% itab!
The memor$ space re8uired for the table is released# e/cept for the initial memor$ re8uirement!
*f $ou are using internal tables "ith header lines# remember that the header line and the bod$ of
the table hae the same name! *f $ou "ant to address the bod$ of the table itself# not the
header line# during initiali9ation using C0A(# $ou must place t"o s8uare brac-ets (PQ) after the
table name!
C.0A% itabXY!
To ensure that the table itself has been initiali9ed# $ou can use the statement
%0,%0S6 itab!
This al"a$s applies to the bod$ of the table! With (02(0S+# too# the initial memor$ re8uirement
fort he table remains resered! To release this memor$ space# use the statement
,%00 itab!
3ou can use 2(00 to directl$ initiali9e an internal table and to release its entire memor$ space#
including the initial memor$ re8uirement# "ithout first using the (02(0S+ or C0A( statements!
.i-e (02(0S+# 2(00accesses the table bod$# not the table "or- area! After a 2(00statement#
the internal table still e/ists! *t still occupies the amount of memor$ re8uired for its header
(currentl$ 4?@ b$tes)! When $ou refill the table# the s$stem has to allocate ne" memor$ space to
the lines!
(0PO(- demoEintEta&lesEclear9
)A-A= B0/IN O2 line4
col8(8) -7P0 c4
colB(8) -7P0 c4
0N) O2 line9
)A-A ita& I"0 -AB0 O2 line9
line-col8 F ?A?9 line-colB F ?B?9
APP0N) line -O ita&9
(02(0S+ ita&9
I2 ita& IS INI-IA9
W(I-0 ?ita& is empt%?9
ABAP Programming (BC-ABA) 1:D
2(00 ita&9
0N)I29
The list output is+
itab is empt$!
An internal table ita& is filled and then initiali9ed "ith (02(0S+! The I2 statement uses the
e/pression ita& IS INI-IA to find out "hether ita& is empt$! *f so# the memor$ is released!
Comparing Internal -a&les
.i-e other data ob2ects# $ou can use internal tables as operands in logical e/pressions!
*f $ou are using internal tables "ith header lines# remember that the header line and the bod$ of
the table hae the same name! *f $ou "ant to address the bod$ of the table in a comparison# $ou
must place t"o brac-ets (X Y) after the table name!
(0PO(- demoEintEta&lesEcompare9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A= ita& I"0 -AB0 O2 line4
3ta& I"0 -AB0 O2 line9
)O C -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
0N))O9
,O!0 ita& -O 3ta&9
line-col8 F 8@9 line-colB F B@9
APP0N) line -O ita&9
I2 ita& /- 3ta&9
W(I-0 A ?I-AB /- Y-AB?9
0N)I29
APP0N) line -O 3ta&9
I2 ita& 0W 3ta&9
W(I-0 A ?I-AB 0W Y-AB?9
0N)I29
line-col8 F C@9 line-colB F J@9
APP0N) line -O ita&9
I2 3ta& 0 ita&9
W(I-0 A ?Y-AB 0 I-AB?9
0N)I29
line-col8 F G@9 line-colB F H@9
APP0N) line -O 3ta&9
I2 ita& N0 3ta&9
W(I-0 A ?I-AB N0 Y-AB?9
0N)I29
I2 ita& - 3ta&9
W(I-0 A ?I-AB - Y-AB?9
0N)I29
The list output is+
*TAB (T aTAB
*TAB 0C aTAB
aTAB .0 *TAB
*TAB N0 aTAB
*TAB .T aTAB
T"o tables ita& and 3ta&are created! ita& is then filled "ith : lines and assigned to 3ta&! Another
line is added to ita&and the first logical e/pression returns the result that ita& is bigger than
3ta&! After appending the same line to 3ta&# the second logical e/pression tests "hether both
tables are e8ual! Then another line is appended to ita& and the third logical e/pressions tests
"hether 3ta& is less than or e8ual to ita&! Ne/t# another line is appended to 3ta&! *ts contents
ABAP Programming (BC-ABA) 1:E
are different to the contents of the last line of ita&! The ne/t logical e/pressions test "hether
ita& is not e8ual to 3ta&! The first table field "hose contents are different in ita& and 3ta&is col8
in the last line of the table+ :F in ita& and ?F in 3ta&! Therefore# in the last logical e/pression#
ita& is less than 3ta&!
Sorting Internal -a&les
3ou can sort a standard or hashed table in a program! To sort a table b$ its -e$# use the
statement
S1%T itab XASC0N&*N(Z&0SC0N&*N(Y XAS te/tY XSTAB.0Y!
The statement sorts the internal table ita& in ascending order b$ its -e$! The statement al"a$s
applies to the table itself# not to the header line! The sort order depends on the se8uence of the
standard -e$ fields in the internal table! The default -e$ is made up of the non-numeric fields of
the table line in the order in "hich the$ occur!
3ou can specif$ the direction of the sort using the additions ASC0N)IN/ and )0SC0N)IN/!
The default is ascending order!
The larger the sort -e$# the more time the s$stem needs to sort the table! *f the sort -e$
contains an internal table# the sorting process ma$ be slo"ed do"n considerabl$!
3ou cannot sort a sorted table using the SO(- statement! The s$stem al"a$s maintains these
tables automaticall$ b$ their sort order! *f an internal table is staticall$ recogni9able as a sorted
table# the SO(- statement causes a s$nta/ error! *f the table is a generic sorted table# the
SO(- statement causes a runtime error if the sort -e$ is not the same as an e/tract of the
beginning of the table -e$# $ou sort in descending order# or use the AS te5taddition! *n other
"ords# the SO(- statement is onl$ allo"ed for generic internal tables# if it does not iolate the
internal sort order!
Sorting &% Anot$er Sort "e%
*f $ou hae an internal table "ith a structured line t$pe that $ou "ant sort b$ a different -e$#
$ou can specif$ the -e$ in the SO(- statement+
S1%T itab XASC0N&*N(Z&0SC0N&*N(Y XAS te/tY XSTAB.0Y
B3 f
1
XASC0N&*N(Z&0SC0N&*N(Y XAS te/tY
!!!
f
n
XASC0N&*N(Z&0SC0N&*N(Y XAS te/tY!
The table is no" sorted b$ the specified components f
1
!!! f
n
instead of b$ the table -e$! The
number of sort fields is limited to 4?F! The sort order depends on the se8uence of the fields f
1
!!!
f
n
! The sort se8uence specified before B3 applies to all fields! The sort se8uence after a field
applies onl$ to that column of the table!
3ou can specif$ a sort field d$namicall$ b$ specif$ing (f) instead of f
1
!!! f
n
! The contents of the
field f determines the name of the sort field! *f f is empt$ "hen the statement is e/ecuted# the
field is ignored in the sort! *f it contains an inalid component name# a runtime error occurs!
*f the line t$pe of the internal table contains ob2ect reference ariables as component ]compN or
if the entire line t$pe is a reference ariable# the attributes of the ]attrN ob2ect to "hich the
respectie line reference points can be specified as -e$ alues using ]comp-Nattr or ta&leEline-
NattrN!
Sorting alp$a&eticall%
As "ell as the ASC0N)IN/ or )0SC0N)IN/ addition# $ou can also specif$ that the entire sort
or each sort field should be alphabetical!
S1%T itab!!! AS te/t!!!!
This addition affects the sort method for strings! Without the addition# strings are sorted
according to the se8uence specified b$ the hard"are platform! With the option AS te5t# the
s$stem sorts character fields alphabeticall$ according to the current te/t enironment! B$
default# the te/t enironment is set in the user=s master record! 6o"eer# $ou can also set it
specificall$ using the statement
S0T .1CA.0 .AN()A(0
! The AS te5taddition saes $ou haing to conert strings into a sortable format! Such a
conersion is onl$ necessar$ if $ou "ant to
7 Sort an internal table alphabeticall$ and then use a binar$ search
7 resort an internal table "ith character fields as its -e$ seeral times# since onl$ one
conersion is then re8uired
7 Construct an alphabetical inde/ for database tables in $our program
*f the AS te5taddition is applied to the entire sort# it onl$ affects sort fields "ith t$pe c! *f $ou
appl$ the AS te5t addition to a single sort field# it must hae t$pe c!
ABAP Programming (BC-ABA) 1>F
Sta&le sort
The option
S1%T itab!!! STAB.0!
allo"s $ou to perform a stable sort# that is# the relatie se8uence of lines that are unchanged b$
the sort is not changed! *f $ou do not use the S-AB0 option# the sort se8uence is not presered!
*f $ou sort a table seeral times b$ the same -e$# the se8uence of the table entries "ill change in
each sort! 6o"eer# a stable sort ta-es longer than an unstable sort!
(0PO(- demoEintEta&lesEsortEsta&le9
)A-A= B0/IN O2 line4
land(C) -7P0 c4
name(8@) -7P0 c4
age -7P0 i4
weig$t -7P0 p )0CI,AS B4
0N) O2 line9
)A-A ita& I"0 S-AN)A() -AB0 O2 line WI-+ NON-.NIW.0 "07 land9
line-land F ?/?9 line-name F ?+ans?9
line-age F B@9 line-weig$t F ?J@9@@?9
APP0N) line -O ita&9
line-land F ?.SA?9 line-name F ?Nanc%?9
line-age F CG9 line-weig$t F ?DG9@@?9
APP0N) line -O ita&9
line-land F ?.SA?9 line-name F ?+oward?9
line-age F D@9 line-weig$t F ?KG9@@?9
APP0N) line -O ita&9
line-land F ?/B?9 line-name F ?Yenn%?9
line-age F 8J9 line-weig$t F ?G@9@@?9
APP0N) line -O ita&9
line-land F ?2?9 line-name F ?,ic$ele?9
line-age F C@9 line-weig$t F ?H@9@@?9
APP0N) line -O ita&9
line-land F ?/?9 line-name F ?"arl?9
line-age F H@9 line-weig$t F ?IG9@@?9
APP0N) line -O ita&9
P0(2O(, loopEatEita&9
SO(- ita&9
P0(2O(, loopEatEita&9
SO(- ita&9
P0(2O(, loopEatEita&9
SO(- ita& S-AB09
P0(2O(, loopEatEita&9
SO(- ita& )0SC0N)IN/ B7 land weig$t ASC0N)IN/9
P0(2O(, loopEatEita&9
2O(, loopEatEita&9
OOP A- ita& IN-O line9
W(I-0= A line-land4 line-name4 line-age4 line-weig$t9
0N)OOP9
S"IP9
0N)2O(,9
The list output is+
( 6ans 4F DF!FF
)SA Nanc$ :? >?!FF
)SA 6o"ard >F E?!FF
(B aenn$ 1D ?F!FF
, 'ichele :F @F!FF
( Uarl @F B?!FF
, 'ichele :F @F!FF
( 6ans 4F DF!FF
ABAP Programming (BC-ABA) 1>1
( Uarl @F B?!FF
(B aenn$ 1D ?F!FF
)SA 6o"ard >F E?!FF
)SA Nanc$ :? >?!FF
, 'ichele :F @F!FF
( Uarl @F B?!FF
( 6ans 4F DF!FF
(B aenn$ 1D ?F!FF
)SA 6o"ard >F E?!FF
)SA Nanc$ :? >?!FF
, 'ichele :F @F!FF
( Uarl @F B?!FF
( 6ans 4F DF!FF
(B aenn$ 1D ?F!FF
)SA 6o"ard >F E?!FF
)SA Nanc$ :? >?!FF
)SA Nanc$ :? >?!FF
)SA 6o"ard >F E?!FF
(B aenn$ 1D ?F!FF
( Uarl @F B?!FF
( 6ans 4F DF!FF
, 'ichele :F @F!FF
The program sorts a standard table "ith one -e$ field four times! ,irst# the table is sorted t"ice
b$ the -e$ field (land) "ithout the S-AB0 addition! The sort is unstable! The se8uence of the
second and third lines changes! The same sort is then performed using the S-AB0 addition! The
sort is stable! The lines remain in the same se8uence! Then# it is sorted b$ a sort -e$ defined as
land and weig$t! The general sort order is defined as descending# but for weig$t it is defined as
ascending!
(0PO(- demoEintEta&lesEsortEte5t9
)A-A= B0/IN O2 line4
te5t(H) -7P0 c4
5te5t(8H@) -7P0 54
0N) O2 line9
)A-A ita& I"0 +AS+0) -AB0 O2 line WI-+ .NIW.0 "07 te5t9
line-te5t F ?,uller?9
CON!0(- te5t line-te5t IN-O SO(-AB0 CO)0 line-5te5t9
INS0(- line IN-O -AB0 ita&9
line-te5t F ?,]ller?9
CON!0(- te5t line-te5t IN-O SO(-AB0 CO)0 line-5te5t9
INS0(- line IN-O -AB0 ita&9
line-te5t F ?,oller?9
CON!0(- te5t line-te5t IN-O SO(-AB0 CO)0 line-5te5t9
INS0(- line IN-O -AB0 ita&9
line-te5t F ?,iller?9
CON!0(- te5t line-te5t IN-O SO(-AB0 CO)0 line-5te5t9
INS0(- line IN-O -AB0 ita&9
SO(- ita&9
P0(2O(, loopEatEita&9
SO(- ita& B7 5te5t9
P0(2O(, loopEatEita&9
SO(- ita& AS te5t9
P0(2O(, loopEatEita&9
2O(, loopEatEita&9
OOP A- ita& IN-O line9
W(I-0 A line-te5t9
0N)OOP9
ABAP Programming (BC-ABA) 1>4
S"IP9
0N)2O(,9
This e/ample demonstrates alphabetical sorting of character fields! The internal table
ita&contains a column "ith character fields and a column "ith corresponding binar$ codes that
are alphabeticall$ sortable! The binar$ codes are created "ith the C1NA0%T statement (see
Conerting to a Sortable ,ormat)! The table is sorted three times! ,irst# it is sorted binaril$ b$
the te5t field! Second# it is sorted binaril$ b$ the 5te5t field! Third# it is sorted alphabeticall$ b$
the te5t field! Since there is no directl$ corresponding case in 0nglish# "e hae ta-en the results
from a (erman te/t enironment+
'iller
'oller
'uller
'hller
'iller
'oller
'hller
'uller
'iller
'oller
'hller
'uller
After the first sorting# I'hllerI follo"s behind I'ullerI since the internal code for the letter IhI
comes after the code for IuI! The other t"o sorts are alphabetical! The binar$ sort b$ 5te5thas
the same result as the alphabetical sorting b$ the field te5t!
Internal -a&les as Interface Parameters
.i-e other data ob2ects# $ou can pass internal tables b$ alue or reference to the parameter
interface of procedures! *f an internal table has a header line# $ou must indicate that $ou "ant
to address the bod$ of the table b$ placing t"o s8uare brac-ets (PQ) after the table name!
3ou can define the formal parameters of the parameter interfaces of procedures as internal
tables! ,or t$ping purposes# the generic table t$pes can also be used# in addition to the generic
data t$pes proided!
To ensure compatibilit$ "ith preious releases# $ou can also specif$ formal parameters in
subroutines and function modules as -AB0Sparameters! This defines a formal parameter as a
standard table "ith default -e$ and header line! Wheneer $ou pass a table "ithout a header line
as an actual parameter to a formal parameter "ith a header line (TAB.0S)# the s$stem
automaticall$ creates the corresponding header line in the routine!

)etermining t$e Attri&utes of Internal -a&les
To find out the attributes of an internal table at runtime that "ere not aailable staticall$# use
the statement+
&0SC%*B0 TAB.0 itab X.*N0S linY X1CC)%S nY XU*N& -ndY!
*f $ou use the IN0S parameter# the number of filled lines is "ritten to the ariable lin! *f $ou
use the OCC.(S parameter# the alue of the INI-IA SI60of the table is returned to the
ariable n! *f $ou use the "IN) parameter# the table t$pe is returned to the ariable *nd+ JT= for
standard table# JS= for sorted table# and J6= for hashed table!
(0PO(- demoEintEta&lesEdescri&eEta&le 9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 +AS+0) -AB0 O2 line WI-+ .NIW.0 "07 col8
INI-IA SI60 8@9
)A-A= lin -7P0 i4
ini -7P0 i4
*nd(8) -7P0 c9
)0SC(IB0 -AB0 ita& IN0S lin OCC.(S ini "IN) *nd9
W(I-0= A lin4 ini4 *nd9
ABAP Programming (BC-ABA) 1>:
)O 8@@@ -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
)0SC(IB0 -AB0 ita& IN0S lin OCC.(S ini "IN) *nd9
W(I-0= A lin4 ini4 *nd9
The list output is+
F 1F 6
1#FFF 1F 6
6ere# a hashed table ita& is created and filled! The )0SC(IB0 -AB0 statement is processed
before and after the table is filled! The current number of lines changes# but the number of
initial lines cannot change!
Operations on Individual ines
Influence of t$e -a&le -%pe
When "or-ing "ith single table lines# "e must distinguish bet"een the operators that are possible
for all table t$pes# and those that are onl$ possible "ith inde/ tables! *nde/ tables (standard and
sorted tables) hae an internal inde/# ma-ing inde/ access possible! 6ashed tables hae no linear
inde/! Conse8uentl$# onl$ -e$ access is possible! The operations that are permitted for all table
t$pes do not use inde/es! The$ can also be used in procedures or "ith field s$mbols# "here the
internal table t$pe is not defined "ith a certain t$pe! These operations are -no"n as generic
operations!
The statements used to access lines of an$ t$pe of table differ from those used to access inde/
tables ("ith fe" e/ceptions) mainl$ through the -AB0 addition follo"ing the corresponding
-e$"ord! ,or e/ample# $ou "ould use ,O)I27 -AB0 to change lines in an$ table# but ,O)I27
to change lines in inde/ tables onl$!
Inde5 Access and "e% Access
Ue$ access addresses lines through the table -e$ and is possible for all table t$pes! *nde/ access
addresses lines through the internal inde/ and is therefore onl$ possible for standard tables and
sorted tables! After accessing an inde/ table# the s$stem field s%-ta&i5 is al"a$s filled "ith the
inde/ of the addressed line! As "ith all successful accesses to lines of internal tables# the s$stem
field s%-su&rc is filled "ith the alue 9ero< other"ise# it is filled "ith a alue not e8ual to 9ero!
The follo"ing table proides a summar$ of the access options for indiidual tables t$pes++

Standard
Table
Sorted Table 6ash Table
*nde/ Access 3es 3es No
Ue$ Access 3es 3es 3es
Ue$ Aalues Not uni8ue )ni8ue or
not uni8ue
)ni8ue
Preferred
Access
'ainl$
inde/
'ainl$
-e$
Ue$
onl$

*n the last line of the table# a preferred access t$pe for the different table t$pes is specified!
This recommendation results from the fact that "or-ing "ith internal table mostl$ means "or-ing
"ith large data 8uantities! 1ne of the standard applications of internal tables is to load large data
8uantities from the database into the main memor$ in order to process the data there more
8uic-l$ and more efficientl$! *n such cases# it is imperatie that $ou ie" the time re8uired for
each indiidual access t$pe!
The inde/ access is usuall$ the 8uic-est access t$pe for an internal table line since there is a
direct internal reference! 6o"eer# it is often not the most suitable access t$pe for "or-ing "ith
data from database tables! *n the case of inde/ access# the program must -no" the assignment
bet"een the inde/ and the content of the table line "hile# "ith -e$ access# the content of the
table line itself is ealuated! Ue$ access is therefore more suitable for man$ applications# but it is
also slo"er!
Access -%pe
The time re8uired for -e$ access strongl$ depends on the table t$pe!
ABAP Programming (BC-ABA) 1>>
With standard tables# all the lines are searched [ at each -e$ access [ in a linear fashion for the
-e$ alue! The aerage search effort is therefore directl$ proportional to the number of lines!
*n the case of sorted tables# the runtime enironment automaticall$ e/ecutes [ for a -e$ access [
a binar$ search (interal search) for the -e$ alue! The aerage search effort is proportional to
log
4
of the number of lines!
*n the case of hashed tables# the runtime enironment calculates the position of the line using a
hash function from the -e$ alue! The search effort is independent of the number of lines!
(untime ,easurement
The follo"ing figure sho"s a t$pical measurement for the aerage runtime for -e$ accesses to
different table t$pes# depending on the number of lines! The times "ere measured for each of
the three table t$pes on the basis of a -e$ access to all the lines! The aerage alue "as
determined! ,rom appro/imatel$ ?F lines on"ards# the cures go up"ards as predicted! Note the
logarithmic measure for the displa$! At 1F#FFF lines# access to a hashed table is t"ice as fast as
access to a sorted table# and the latter is 1BF times faster than access to a standard table!
&epending on the use of an internal table in the program (number of lines# access fre8uenc$)# $ou
should b$ all means use the suitable table t$pes! *n the case of small tables up to appro/imatel$
1FF lines or tables "here there are no or onl$ fe" -e$ accesses# standard tables can be used!
.arge tables that do not hae duplicate entries and are not accessed through the -e$ should
al"a$s be created as hashed tables! Sorted tables are al"a$s appropriate if a table must be
aailable in sorted form during the entire runtime!
Operations for all -a&le -%pes
3ou should use these operations onl$ if the$ are the onl$ possibilit$ for the table t$pe# or "hen
the table t$pe is not -no"n "hen $ou "rite the program (for e/ample# generic formal parameters
in procedures)!
*f $ou -no" the table t$pe# $ou should# for performance reasons# use the corresponding specific
operation! ,or e/ample# $ou should use the APP0N) Z -O statement to fill inde/ tables# but
INS0(- Z IN-O -AB0 to fill hashed or generic tables!
Operations for Inde5 -a&les
Some operations are onl$ permitted for inde/ tables (sorted and standard tables)! Some of them
are restricted to standard tables! Since it is 8uic-er to access a table b$ inde/ than b$ -e$# $ou
should al"a$s use specific inde/ operations "hen $ou -no" that a particular internal table is an
inde/ table!
*n particular# the 8uic-est "a$ to fill a table line b$ line is to append lines to a standard table#
since a standard table cannot hae a uni8ue -e$ and therefore appends the lines "ithout haing to
chec- the e/isting lines in the table! *f $ou can either accommodate duplicate entries in a table
or e/clude them in a different "a$# it can be 8uic-er to fill a standard table first and then sort it
or assign it to a sorted table [ proided the data does not hae to be inserted into the table in
the correct sort se8uence!
,urthermore# the performance of operations that change the internal linear inde/ has been
improed in %elease >!?A! Preiousl$# inde/ manipulation costs for inserting and deleting liens in
standard tables and sorted tables increased in linear relation to the number of lines! ,rom
ABAP Programming (BC-ABA) 1>?
%elease >!?A# the inde/ manipulation costs onl$ increase logarithmicall$ "ith the number of lines#
since the table inde/es are no" maintained as a tree structure! This ma-es insertion and deletion
operations efficient# een in er$ large standard and sorted tables!

,or more information# refer to the follo"ing chapters+
Access 'ethods for *ndiidual Table 0ntries
,illing *nternal Tables .ine b$ .ine
%eading Table .ines
Processing Table .ines in .oops
Changing Table .ines
&eleting Table .ines
Searching Through *nternal Tables .ine b$ .ine
1bsolete Statements for *nternal Tables
Access ,et$ods to Individual -a&le 0ntries
There are three "a$s to access a single table entr$+
Access .sing a Wor* Area
When $ou access indiidual table entries using a "or- area# $ou are not "or-ing directl$ "ith the
data in the table! *nstead# $ou "or- "ith another data ob2ect as a "or- area! The "or- area is an
interface to the entries in the internal table# and must be conertible into the line t$pe of the
internal table! The most efficient "or-ing method is to use a "or- area compatible "ith the line
t$pe of the internal table! When $ou read data from a table record# the data $ou are reading
oer"rites the current contents of the "or- area! 3ou can then use this data in the program!
When $ou "rite data to the internal table# this must first be placed in the "or- area! The s$stem
then transfers it from the "or- area to the appropriate table entr$! &ata transfer follo"s the
rules of assigning data using '1A0!
*f the internal table has a header line# $ou can use it as the "or- area! The ABAP statements
that $ou use to access indiidual table entries can use the header line implicitl$ as a "or- area!
Access .sing 2ield S%m&ols
*f $ou access an internal table using a field s$mbol # $ou do not need to cop$ the data into a "or-
area! 3ou can assign a line of an internal table to a field s$mbol! *deall$# the field s$mbol "ill hae
the same t$pe as the line t$pe of the internal table! 1nce $ou hae assigned the entr$ to the field
s$mbol# "or-ing "ith the field s$mbol has e/actl$ the same effect as accessing the corresponding
line directl$!
ABAP Programming (BC-ABA) 1>@
Access via )ata (eferences
*f $ou access an internal table using a data reference# $ou do not need to cop$ the data into a
"or- area! 3ou can assign a line of an internal table to a data reference! *deall$# the data
reference "ill hae the same t$pe as the line t$pe of the internal table! 1nce $ou hae assigned
the entr$ to the field s$mbol# "or-ing "ith the dereferenced data reference has e/actl$ the
same effect as accessing the corresponding line directl$!
Access .sing 2ield S%m&ols
When $ou read table entries using (0A) or in a OOP# $ou can assign them to a field s$mbol using
the addition
!!! ASS*(N*N( ]fsG
The field s$mbol ]fsG points directl$ to the assigned line in memor$! )nli-e "or- areas# in "hich
the contents of the line are onl$ aailable indirectl$ using the IN-Oaddition# field s$mbols allo"
$ou to read and change table entries directl$!
%emember "hen $ou access internal tables using field s$mbols that $ou must not change the
contents of the -e$ fields of sorted or hashed tables! *f $ou tr$ to assign a ne" alue to a -e$
field using a field s$mbol# a runtime error occurs! Note that $ou cannot use the S.,statement
"ith field s$mbols# since the statement is al"a$s applied to "or- areas!
Advantages of 2ield S%m&ols
When $ou read from an internal table# there are no oerheads for cop$ing the table line to the
"or- area! When $ou change an internal table "ith the ,O)I27 statement# $ou must first fill a
"or- area "ith alues# and then assign them to the internal table! *f $ou "or- "ith field s$mbols
instead# $ou do not hae this oerhead! This can improe performance if $ou hae large or
comple/ internal tables! *t also ma-es it easier to process nested internal tables!
Over$eads of (0A)
Note that internal oerheads arise "hen $ou access internal tables using field s$mbols! After a
(0A) statement "ith a field s$mbol# the s$stem has to register the assignment! When $ou delete
a table line to "hich a field s$mbol is pointing# the s$stem also has to unassign the field s$mbol to
preent it from pointing to an undefined area!
When $ou read indiidual table lines# it is "orth using field s$mbols "ith the (0A) statement for
tables "ith a line "idth of 1FFF b$tes or more! *f $ou also change the line using the
,O)I27statement# using field s$mbols is "orth"hile from a line "idth of 1FF b$tes on"ards!
Over$eads of OOP
To minimi9e the oerheads incurred b$ using field s$mbols in loop processing# the s$stem does not
register the assignment of each current line to the field s$mbol! *nstead# it registers a general
assignment bet"een a line of the table and the field s$mbol! When the loop is finished# the line
processed in the last loop pass is assigned to the field s$mbol!
Conse8uentl$# it is "orth using field s$mbols in a .11P "hen the internal table has as fe" as 1F
lines! 6o"eer# it is not possible to reassign the field s$mbol to another field or unassign it
altogether "ithin the loop! *f $ou include the statements ASSI/N# )NASSI(N# or the
ASSI/NIN/ addition for the same field s$mbol "ithin the loop bloc-# a runtime error occurs!
&ATA+ B0(*N 1, line#
col1 T3P0 i#
col4 T3P0 i#
0N& 1, line!
&ATA itab .*U0 S1%T0& TAB.0 1, line W*T6 )N*C)0 U03 col1!
,*0.&-S3'B1.S ]fsG .*U0 .*N0 1, itab!
&1 > T*'0S!
line-col1 H s$-inde/!
line-col4 H s$-inde/ LL 4!
ABAP Programming (BC-ABA) 1>B
APP0N& line T1 itab!
0N&&1!
%0A& TAB.0 itab W*T6 TAB.0 U03 col1 H 4 ASS*(N*N( ]fsG!
]fsG-col4 H 1FF!
%0A& TAB.0 itab W*T6 TAB.0 U03 col1 H : ASS*(N*N( ]fsG!
&0.0T0 itab *N&0_ :!
*, ]fsG *S ASS*(N0&!
W%*T0 I]fsG is assigned`I!
0N&*,!
.11P AT itab ASS*(N*N( ]fsG!
W%*T0+ ; ]fsG-col1# ]fsG-col4!
0N&.11P!
The list output is+
1 1
4 1FF
> 1@
The e/ample fills a sorted table I-AB "ith four lines! The second line is assigned to the field
s$mbol ]fsG ("hich has the same t$pe)# and modified using it! The third line is assigned to ]fsG and
then deleted! Conse8uentl$# the logical e/pression in the I2 statement is untrue! ]fsG is used to
displa$ the table lines in the OOP! After"ards# ]fsG points to the third line of the table!
2illing Internal -a&les ine B% ine
The statements for filling internal tables are on principle distinguished from one another b$ the
fact# "hether the indiidual ro"s should be inserted at a specific position (INS0(-) #or "hether
the$ should be appended to the internal table (APP0N))! *f $ou "ant to create uni8ue or
aggregated internal tables# use the statement CO0C-!
Inserting ines into -a&les
3ou can insert one or seeral lines into internal tables using the *NS0%T statement!
Inserting a Single ine
To add a line to an internal table# use the statement+
*NS0%T line *NT1 TAB.0 itab!
line is either a "or- area that is compati&le "ith the line t$pe# or the e/pression INI-IA IN0!
The "or- area must be compatible because the fields in the table -e$ must be filled from fields
of the correct t$pe! INI-IA IN0 inserts an initiali9ed blan- line suitable for the t$pe!
*f the internal table has a uni8ue -e$# lines "hose -e$ alread$ e/ists in the table "ill not be
inserted and s%-su&rc is set to >! When the s$stem successfull$ adds a line to the table# s%-
su&rc is set to F!
.ines are added to internal tables as follo"s+
7 Standard tables
The line is appended to the end of the internal table! The statement "or-s in the same "a$ as
the specific statement APP0N& for appending lines!
7 Sorted tables
The line is inserted into the table according to the table -e$! *f the -e$ is non-uni8ue#
duplicates are inserted aboe the e/isting entr$ "ith the same -e$! The runtime for the
operation increases logarithmicall$ "ith the number of e/isting table entries!
7 6ashed tables
The table is inserted into the internal hash administration according to the table -e$!
Inserting Several ines
To add seeral lines to an internal table# use the statement+
*NS0%T .*N0S 1, itab1 X,%1' n1Y XT1 n4Y *NT1 TAB.0 itab4!
ita&8 and ita&B are tables "ith a compati&le line t$pe! The s$stem inserts the lines of table ita&8
one b$ one into table ita&B using the same rules as for single lines!
*f ita&8 is an inde/ table# $ou can specif$ the first and last lines of ita&8 that $ou "ant to
append in n8 and nB!
&epending on the si9e of the tables and "here the$ are inserted# this method of inserting lines of
one table into another can be up to 4F times faster than inserting them line b$ line in a loop!
05amples
*nserting a Single .ine
ABAP Programming (BC-ABA) 1>D
(0PO(- demoEintEta&lesEinsert9
)A-A= B0/IN O2 line4
land(C) -7P0 c4
name(8@) -7P0 c4
age -7P0 i4
weig$t -7P0 p )0CI,AS B4
0N) O2 line9
)A-A ita& I"0 SO(-0) -AB0 O2 line
WI-+ NON-.NIW.0 "07 land name age weig$t9
line-land F ?/?9 line-name F ?+ans?9
line-age F B@9 line-weig$t F ?J@9@@?9
INS0(- line IN-O -AB0 ita&9
line-land F ?.SA?9 line-name F ?Nanc%?9
line-age F CG9 line-weig$t F ?DG9@@?9
INS0(- line IN-O -AB0 ita&9
line-land F ?.SA?9 line-name F ?+oward?9
line-age F D@9 line-weig$t F ?KG9@@?9
INS0(- line IN-O -AB0 ita&9
line-land F ?/B?9 line-name F ?Yenn%?9
line-age F 8J9 line-weig$t F ?G@9@@?9
INS0(- line IN-O -AB0 ita&9
line-land F ?2?9 line-name F ?,ic$ele?9
line-age F C@9 line-weig$t F ?H@9@@?9
INS0(- line IN-O -AB0 ita&9
line-land F ?/?9 line-name F ?"arl?9
line-age F H@9 line-weig$t F ?IG9@@?9
INS0(- line IN-O -AB0 ita&9
OOP A- ita& IN-O line9
W(I-0= A line-land4 line-name4 line-age4 line-weig$t9
0N)OOP9
The list output is+
, 'ichele :F @F#FF
( 6ans 4F DF#FF
( Uarl @F B?#FF
(B aenn$ 1D ?F#FF
)SA 6o"ard >F E?#FF
)SA Nanc$ :? >?#FF
Single lines are inserted into a sorted internal table!
*nserting Seeral .ines
%0P1%T demoSintStablesSinsertSlines!
&ATA+ B0(*N 1, line#
col1 T3P0 i#
col4 T3P0 i#
0N& 1, line!
&ATA+ itab .*U0 STAN&A%& TAB.0 1, line#
2tab .*U0 S1%T0& TAB.0 1, line
W*T6 N1N-)N*C)0 U03 col1 col4!
&1 : T*'0S!
line-col1 H s$-inde/! line-col4 H s$-inde/ LL 4!
APP0N& line T1 itab!
line-col1 H s$-inde/! line-col4 H s$-inde/ LL :!
APP0N& line T1 2tab!
0N&&1!
*NS0%T .*N0S 1, itab *NT1 TAB.0 2tab!
.11P AT 2tab *NT1 line!
W%*T0+ ; s$-tabi/# line-col1# line-col4!
0N&.11P!
ABAP Programming (BC-ABA) 1>E
The list output is+
1 1 1
4 1 1
: 4 >
> 4 D
? : E
@ : 4B
The e/ample creates t"o internal tables "ith the same line t$pe but different table t$pes! 0ach
is filled "ith three lines! Then# the entire table itab is sorted into the sorted table 2tab!
Inserting ines .sing t$e Inde5
The INS0(- statement allo"s $ou not onl$ to insert lines in an$ t$pe of internal table# but also to
change them using a line inde/! 3ou can insert either a single line or a group of lines into inde/
tables using the inde/!
Inserting a Single ine
To insert a line into an inde/ table# use the statement+
*NS0%T line *NT1 itab X*N&0_ id/Y!
line is either a "or- area wa that is converti&le to the line t$pe# or the e/pression INI-IA
IN0! *f $ou use wa# the s$stem adds a ne" line to the internal table ita& and fills it "ith the
contents of the "or- area! INI-IA IN0 inserts an initiali9ed blan- line suitable for the t$pe!
*f $ou use the IN)0X option# the ne" line is inserted before the line that has the inde/ id5!
After the insertion# the ne" entr$ has the inde/ id5 and the inde/ of the follo"ing lines is
incremented b$ 1! *f the table contains id5 -1 lines# the ne" line is added after the last line! *f
the table has less than id5 - 1 lines# the ne" line cannot be inserted# and s%-su&rc is set to >!
When the s$stem successfull$ adds a line to the table# s%-su&rc is set to F!
Without the IN)0X addition# $ou can onl$ use the aboe statement "ithin a OOP! Then the ne"
line is inserted before the current line< id5 is implicitl$ set to s%-ta&i5!
Appending lines to standard tables and sorted tables "ith a non-uni8ue -e$ "or-s regardless of
"hether lines "ith the same -e$ alread$ e/ist in the table! &uplicate entries ma$ occur! A
runtime error occurs if $ou attempt to add a duplicate entr$ to a sorted table "ith a uni8ue -e$!
08uall$# a runtime error occurs if $ou iolate the sort order of a sorted table b$ appending to it!
Inserting Several ines
To add seeral lines to an internal table# use the statement+
*NS0%T .*N0S 1, itab1 *NT1 itab4 X*N&0_ id/Y!
The s$stem inserts the lines of the entire table ita&8 one b$ one into ita&B using the same rules
as for single lines! ita&8 can be an$ t$pe of table! The line t$pe of ita&8 must be conertible into
the line t$pe of ita&B!
When $ou append an inde/ table to another inde/ table# $ou can specif$ the lines to be appended
as follo"s+
*NS0%T .*N0S 1, itab1 X,%1' n
1
Y XT1 n
4
Y *NT1 itab4
X*N&0_ id/Y!
n
1
and n
4
specif$ the inde/es of the first and last lines of ita&8!
&epending on the si9e of the tables and "here the$ are inserted# this method of inserting lines of
one table into another can be up to 4F times faster than inserting them line b$ line in a loop!
(0PO(- demoEintEta&lesEinsertEindE89
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 -AB0 O2 line9
)O B -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
0N))O9
line-col8 F 889 line-colB F BB9
INS0(- line IN-O ita& IN)0X B9
INS0(- INI-IA IN0 IN-O ita& IN)0X 89
ABAP Programming (BC-ABA) 1?F
OOP A- ita& IN-O line9
W(I-0= A s%-ta&i54 line-col84 line-colB9
0N)OOP9
The list output is+
1 F F
4 1 1
: 11 44
> 4 >
The e/ample creates an internal table ita& and fills it "ith t"o lines! A ne" line containing alues
is inserted before the second line! Then# an initiali9ed line is inserted before the first line!
*nserting Seeral .ines Through *nde/
(0PO(- demoEintEta&lesEinsertEindEB9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 -AB0 O2 line9
)O B -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
0N))O9
OOP A- ita& IN-O line9
line-col8 F C U s%-ta&i59 line-colB F G U s%-ta&i59
INS0(- line IN-O ita&9
0N)OOP9
OOP A- ita& IN-O line9
W(I-0= A s%-ta&i54 line-col84 line-colB9
0N)OOP9
The list output is+
1 : ?
4 1 1
: E 1?
> 4 >
The e/ample creates an internal table ita& and fills it "ith t"o lines! )sing a OOP construction#
the program inserts a ne" line before each e/isting line!
(0PO(- demoEintEta&lesEinsertEindEC9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A= ita& I"0 -AB0 O2 line4
3ta& I"0 ita&9
)O C -I,0S9
line-col8 F s%-inde59 line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
line-col8 F s%-inde59 line-colB F s%-inde5 UU C9
APP0N) line -O 3ta&9
0N))O9
INS0(- IN0S O2 ita& IN-O 3ta& IN)0X 89
OOP A- 3ta& IN-O line9
W(I-0= A s%-ta&i54 line-col84 line-colB9
0N)OOP9
The list output is+
1 1 1
4 4 >
: : E
ABAP Programming (BC-ABA) 1?1
> 1 1
? 4 D
@ : 4B
The e/ample creates t"o internal tables of the same t$pe! 0ach is filled "ith three lines! Then#
the entire table ita& is inserted before the first line of 3ta&!
Appending Summari:ed ines
The follo"ing special statement allo"s $ou to summate entries in an internal table+
C1..0CT "a *NT1 itab!
ita& must hae a flat line t$pe# and all of the fields that are not part of the table -e$ must hae a
numeric t%pe (f# i# p)! 3ou specif$ the line wathat $ou "ant to add as a "or- area that is
compatible "ith the line t$pe of itab!
When the line is inserted# the s$stem chec-s "hether there is alread$ a table entr$ that matches
the -e$! *f there is no corresponding entr$ alread$ in the table# the CO0C- statement has the
same effect as inserting the ne" line! *f an entr$ "ith the same -e$ alread$ e/ists# the CO0C-
statement does not append a ne" line# but adds the contents of the numeric fields in the "or-
area to the contents of the numeric fields in the e/isting entr$!
(0PO(- demoEintEta&lesECO0C- 9
)A-A= B0/IN O2 line4
col8(C) -7P0 c4
colB(B) -7P0 n4
colC -7P0 i4
0N) O2 line9
)A-A ita& I"0 SO(-0) -AB0 O2 line
WI-+ NON-.NIW.0 "07 col8 colB9
line-col8 F ?a&c?9 line-colB F ?8B?9 line-colC F C9
CO0C- line IN-O ita&9
W(I-0 A s%-ta&i59
line-col8 F ?def?9 line-colB F ?CD?9 line-colC F G9
CO0C- line IN-O ita&9
W(I-0 A s%-ta&i59
line-col8 F ?a&c?9 line-colB F ?8B?9 line-colC F I9
CO0C- line IN-O ita&9
W(I-0 A s%-ta&i59
OOP A- ita& IN-O line9
W(I-0= A line-col84 line-colB4 line-colC9
0N)OOP9
The list output is+
1
4
1
abc 14 1F
def :> ?
The e/ample fills a sorted table! The first t"o CO0C- statements "or- li-e normal insertion
statements! *n the third CO0C-statement# the first line of ita& is modified! The follo"ing
diagram sho"s the three steps+
ABAP Programming (BC-ABA) 1?4
Appending -a&le ines
There are seeral "a$s of adding lines to inde/ tables! The follo"ing statements hae no
e8uialent that applies to all internal tables!
Appending a Single ine
To add a line to an inde/ table# use the statement+
APP0N& line T1 itab!
line is either a "or- area wa that is converti&le to the line t$pe# or the e/pression INI-IA
IN0! *f $ou use wa# the s$stem adds a ne" line to the internal table ita& and fills it "ith the
contents of the "or- area! INI-IA IN0 appends a blan- line containing the correct initial
alue for each field of the structure! After each APP0N) statement# the s$stem field s%-ta&i5
contains the inde/ of the appended line!
Appending lines to standard tables and sorted tables "ith a non-uni8ue -e$ "or-s regardless of
"hether lines "ith the same -e$ alread$ e/ist in the table! &uplicate entries ma$ occur! A
runtime error occurs if $ou attempt to add a duplicate entr$ to a sorted table "ith a uni8ue -e$!
08uall$# a runtime error occurs if $ou iolate the sort order of a sorted table b$ appending to it!
Appending Several ines
3ou can also append internal tables to inde/ tables using the follo"ing statement+
APP0N& .*N0S 1, itab1 T1 itab4!
This statement appends the "hole of ita&8 to ita&B! ita&8can be an$ t$pe of table! The line t$pe
of ita&8 must be conertible into the line t$pe of ita&B!
When $ou append an inde/ table to another inde/ table# $ou can specif$ the lines to be appended
as follo"s+
APP0N& .*N0S 1, itab1 X,%1' n
1
Y XT1 n
4
Y T1 itab4!
n
1
and n
4
specif$ the inde/es of the first and last lines of ita&8 that $ou "ant to append to ita&B!
This method of appending lines of one table to another is about : to > times faster than
appending them line b$ line in a loop! After the APP0N) statement# the s$stem field s%-ta&i5
contains the inde/ of the last line appended! When $ou append seeral lines to a sorted table# $ou
must respect the uni8ue -e$ (if defined)# and not iolate the sort order! 1ther"ise# a runtime
error "ill occur!
(an*ed ists
3ou can use the APP0N) statement to create ran-ed lists in standard tables! To do this# create
an empt$ table# and then use the statement+
APP0N& "a T1 itab S1%T0& B3 f!
The ne" line is not added to the end of the internal table ita&! *nstead# the table is sorted b$
field f in descending order! The "or- area wamust be compatible "ith the line t$pe of the
internal table! 3ou cannot use the SO(-0) B7 addition "ith sorted tables!
When $ou use this techni8ue# the internal table ma$ onl$ contain as man$ entries as $ou specified
in the INI-IA SI60 parameter of the table declaration! This is an e/ception to the general
rule# "here internal tables can be e/tended d$namicall$! *f $ou add more lines than specified# the
last line is discarded! This is useful for creating ran-ed lists of limited length (for e/ample WTop
TenW)! 3ou can use the APP0N) statement to generate ran-ed lists containing up to 1FF entries!
When dealing "ith larger lists# it is adisable to sort tables normall$ for performance reasons!
ABAP Programming (BC-ABA) 1?:
)A-A= B0/IN O2 wa4
col8(8) -7P0 c4
colB -7P0 i4
0N) O2 wa9
)A-A ita& I"0 -AB0 O2 wa9
)O C -I,0S9
APP0N) INI-IA IN0 -O ita&9
wa-col8 F s%-inde59 wa-colB F s%-inde5 UU B9
APP0N) wa -O ita&9
0N))O9
OOP A- ita& IN-O wa9
W(I-0= A wa-col84 wa-colB9
0N)OOP9
The list output is+
F
1 1
F
4 >
F
: E
This e/ample creates an internal table ita& "ith t"o columns that is filled in the )O loop! 0ach
time the processing passes through the loop# an initiali9ed line is appended and then the table
"or- area is filled "ith the loop inde/ and the s8uare root of the loop inde/ and appended!
)A-A= B0/IN O2 line84
col8(C) -7P0 c4
colB(B) -7P0 n4
colC -7P0 i4
0N) O2 line84
ta&8 I"0 -AB0 O2 line89
)A-A= B0/IN O2 lineB4
field8(8) -7P0 c4
fieldB I"0 ta&84
0N) O2 lineB4
ta&B I"0 -AB0 O2 lineB9
line8-col8 F ?a&c?9 line8-colB F ?8B?9 line8-colC F C9
APP0N) line8 -O ta&89
line8-col8 F ?def?9 line8-colB F ?CD?9 line8-colC F G9
APP0N) line8 -O ta&89
lineB-field8 F ?A?9 lineB-fieldB F ta&89
APP0N) lineB -O ta&B9
(02(0S+ ta&89
line8-col8 F ?g$i?9 line8-colB F ?GH?9 line8-colC F I9
APP0N) line8 -O ta&89
line8-col8 F ?3*l?9 line8-colB F ?IJ?9 line8-colC F K9
APP0N) line8 -O ta&89
lineB-field8 F ?B?9 lineB-fieldB F ta&89
APP0N) lineB -O ta&B9
OOP A- ta&B IN-O lineB9
W(I-0= A lineB-field89
OOP A- lineB-fieldB IN-O line89
W(I-0= A line8-col84 line8-colB4 line8-colC9
0N)OOP9
0N)OOP9
The list output is+
A
abc 14 :
def :> ?
ABAP Programming (BC-ABA) 1?>
B
ghi ?@ B
2-l BD E
The e/ample creates t"o internal tables ta&8 and ta&B! ta&B has a deep structure because the
second component of lineB has the data t$pe of internal table ta&8! line8 is filled and appended
to ta&8! Then# lineB is filled and appended to ta&B! After clearing ta&8 "ith the (02(0S+
statement# the same procedure is repeated!
)A-A= B0/IN O2 line4
col8(8) -7P0 c4
colB -7P0 i4
0N) O2 line9
)A-A= ita&8 I"0 -AB0 O2 line4
3ta& I"0 ita&9
)O C -I,0S9
line-col8 F s%-inde59 line-colB F s%-inde5 UU B9
APP0N) line -O ita&89
line-col8 F s%-inde59 line-colB F s%-inde5 UU C9
APP0N) line -O 3ta&9
0N))O9
APP0N) IN0S O2 3ta& 2(O, B -O C -O ita&89
OOP A- ita&8 IN-O line9
W(I-0= A line-col84 line-colB9
0N)OOP9
The list output is+
1 1
4 >
: E
4 D
: 4B
This e/ample creates t"o internal tables of the same t$pe# ita& and 3ta&! *n the )O loop# ita& is
filled "ith a list of s8uare numbers# and 3ta& "ith a list of cube numbers! Then# the last t"o lines
of 3ta& are appended to ita&!
)A-A= B0/IN O2 lineC4
col8 -7P0 i4
colB -7P0 i4
colC -7P0 i4
0N) O2 lineC9
)A-A ita&B I"0 -AB0 O2 lineC INI-IA SI60 B9
lineC-col8 F 89 lineC-colB F B9 lineC-colC F C9
APP0N) lineC -O ita&B SO(-0) B7 colB9
lineC-col8 F D9 lineC-colB F G9 lineC-colC F H9
APP0N) lineC -O ita&B SO(-0) B7 colB9
lineC-col8 F I9 lineC-colB F J9 lineC-colC F K9
APP0N) lineC -O ita&B SO(-0) B7 colB9
OOP A- ita&B IN-O lineC9
W(I-0= A lineC-colB9
0N)OOP9
The list output is+
D
?
The program inserts three lines into the internal table ita& using the APP0N) statement and the
SO(-0) B7 addition! The line "ith the smallest alue for the field C1.4 is deleted from the
table# since the number of lines that can be appended is fi/ed to 4 through the *NI-IA SI60
addition!
(eading ines of -a&les
To read a single line of an$ table# use the statement+
ABAP Programming (BC-ABA) 1??
%0A& TAB.0 itab -e$ result!
,or the statement to be alid for an$ -ind of table# $ou must specif$ the entr$ using the -e$ and
not the inde/! 3ou specif$ the -e$ in the *e% part of the statement! The result part can specif$ a
further processing option for the line that is retrieed!
*f the s$stem finds an entr$# it sets s%-su&rc to 9ero# if not# it ta-es the alue ># as long as it is
not influenced b$ one of the possible additions! *f the internal table is an inde/ table# s%-ta&i5 is
set to the inde/ of the line retrieed! *f the table has a non-uni8ue -e$ and there are duplicate
entries# the first entr$ is read!
Specif%ing t$e Searc$ "e%
The search -e$ ma$ be either the table -e$ or another -e$!
*f $ou read entries from standard tables using a -e$ other than the default -e$# $ou can use a
binar$ search instead of the normal linear search!
.sing t$e -a&le "e%
To use the table -e$ of ita& as a search -e$# enter *e% as follo"s+
%0A& TAB.0 itab ,%1' "a result!
or as follo"s
%0A& TAB.0 itab W*T6 TAB.0 U03 -
1
H f
1
!!! -
n
H f
n
result!
*n the first case# wa must be a "or- area compati&le "ith the line t$pe of ita&! The alues of the
-e$ fields are ta-en from the corresponding components of the "or- area!
*n the second case# $ou hae to suppl$ the alues of each -e$ field e/plicitl$! *t is not allo"ed to
specif$ the same -e$ specifications seeral times! *f $ou do not -no" the name of one of the -e$
fields until runtime# $ou can specif$ it d$namicall$ as the content of a field n
8
!!! n
n
using (n
8
) F f
8

(n
B
) F f
B
*f the data t$pes of f
8
!!! f
n
are not compatible "ith the -e$ fields# the s$stem
conerts them! *f the ro" t$pe of the internal table is not structured# $ou can specif$ a
comparison "ith the pseudo-component tableSline!
%0A& TAB.0 itab W*T6 TAB.0 U03 tableSline H f result!
The contents of the entire table line are compared "ith the contents of field f! *f f is not
compatible "ith the line t$pe of the table# the alue is conerted into the line t$pe! The search
-e$ allo"s $ou to find entries in internal tables that do not hae a structured line t$pe# that is#
"here the line is a single field or an internal table t$pe!
*f the line t$pe of the internal table contains ob2ect reference ariables as component comp or if
the entire line t$pe is a reference ariable# the attributes of the attr ob2ect to "hich the
respectie line reference points can be specified as -e$ alues using comp-Nattr or ta&leEline-
Nattr!
The s$stem searches for the releant table t$pes as follo"s+
7 Standard tables
.inear search# "here the runtime is in linear relation to the number of table entries!
7 Sorted tables
Binar$ search# "here the runtime is in logarithmic relation to the number of table entries!
7 6ashed tables
The entr$ is found using the hash algorithm of the internal table! The runtime is independent
of the number of table entries!
.sing a )ifferent Searc$ "e%
%0A& TAB.0 itab W*T6 U03 -
1
H f
1
!!! -
n
H f
n
result!
The search -e$ consists of arbitrar$ table fields *
8
!!! *
n
! *f $ou do not -no" the name of a
component until runtime# $ou can specif$ it d$namicall$ as the content of a field n
8
!!! n
n
using (n
8
)
F f
8
(n
B
) F f
B
*f n
8
!!! n
n
is empt$ "hen the statement is e/ecuted# the search field is ignored! *f
the data t$pes of f
8
!!! f
n
are not compatible "ith the components# the s$stem conerts them! 3ou
can restrict the search to partial fields b$ specif$ing offset and length!
*f the ro" t$pe of the internal table is not structured# $ou can specif$ a comparison "ith the
pseudo-component tableSline! 3ou can also specif$ the attributes of ob2ects as -e$s!
The search is linear for all ta&le t%pes! The runtime is in linear relation to the number of table
lines!
Specif%ing t$e 05tra Processing Option
3ou can specif$ an option that specifies "hat the s$stem does "ith the table entr$ that it finds!
.sing a Wor* Area
3ou can "rite the table entr$ read from the table into a "or- area b$ specif$ing result as
follo"s+
ABAP Programming (BC-ABA) 1?@
%0A& TAB.0 itab -e$ *NT1 "a XC1'PA%*N( f
1
f
4
!!! ZA.. ,*0.&SY
XT%ANSP1%T*N( f
1
f
4
!!! ZA.. ,*0.&S
ZN1 ,*0.&SY!
*f $ou do not use the additions CO,PA(IN/ or -(ANSPO(-IN/# the contents of the table line
must be conertible into the data t$pe of the "or- area wa! *f $ou specif$ CO,PA(IN/ or
-(ANSPO(-IN/# the line t$pe and "or- area must be compatible! 3ou should al"a$s use a "or-
area that is compatible "ith the line t$pe of the releant internal table!
*f $ou use the CO,PA(IN/ addition# the specified table fields f
8
!!! f
n
of the structured line
t$pe are compared "ith the corresponding fields of the "or- area &efore being transported! *f
$ou use the A 2I0)S option# the s$stem compares all components! *f the s$stem finds an
entr$ "ith the specified -e$ *e% and if the contents of the compared fields are the same# s%-
su&rc is set to F! *f the contents of the compared fields are not the same# s%-su&rc returns the
alue 4! *f the s$stem cannot find an entr$# s%-su&rc is set to >! *f the s$stem finds an entr$# it
copies it into the target "or- area regardless of the result of the comparison!
*f $ou use the -(ANSPO(-IN/ addition# $ou can specif$ the table fields f
8
!!! f
n
of the
structured line t$pe that $ou "ant to transport into the "or- area! *f $ou specif$ A 2I0)S
"ithout -(ANSPO(-IN/# the contents of all of the fields are transported! *f $ou specif$ NO
2I0)S# no fields are transported! *n the latter case# the (0A) statement onl$ fills the s$stem
fields s%-su&rc and s%-ta&i5! Specif$ing the "or- area wa "ith -(ANSPO(-IN/ NO 2I0)S is
unnecessar$# and should be omitted!
*n both additions# $ou can also specif$ the fields f
8
!!! f
n
\ d$namicall$ using (n
8
) (n
B
)Z as the
contents of a field n
8
!!! n
n
! *f n
8
!!! n
n
is empt$ "hen the statement is e/ecuted# it is ignored! 3ou
can also restrict all fields f
8
!!! f
n
to subfields b$ specif$ing offset and length!
.sing a 2ield S%m&ol
3ou can assign the table entr$ read from the table to a field s$mbol b$ specif$ing result as
follo"s+
%0A& TAB.0 itab -e$ ASS*(N*N( ]fsG!
After the (0A) statement# the field s$mbol points to the table line! *f the line t$pe is
structured# $ou should specif$ the same t$pe for the field s$mbol "hen $ou declare it! This
allo"s $ou to address the components of the field s$mbol! *f $ou cannot specif$ the t$pe
staticall$# $ou must use further field s$mbols and the techni8ue of assigning components of
structures to address the components of the structure!
,or further information about assigning table lines to field s$mbols# refer to Access )sing ,ield
S$mbols!
(0PO(- demoEintEta&lesEreadEcomparing9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 +AS+0) -AB0 O2 line WI-+ .NIW.0 "07 col89
)O D -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
line-col8 F B9
line-colB F C9
(0A) -AB0 ita& 2(O, line IN-O line CO,PA(IN/ colB9
W(I-0= ?s%-su&rc F?4 s%-su&rc9
S"IP9
W(I-0= A line-col84 line-colB9
The list output is+
s%-su&rc H 4
4 >
The program fills a hashed table "ith a list of s8uare numbers! The "or- area IN0# "hich is
compatible "ith the line t$pe# is filled "ith the numbers 4 and :! The (0A)statement reads the
line of the table in "hich the -e$ field col8has the same alue as in the "or- area and copies it
ABAP Programming (BC-ABA) 1?B
into the "or- area! s%-su&rce8uals 4# because different numbers are found "hen compared to the
field colB!
(0PO(- demoEintEta&lesEreadEtransport 9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 SO(-0) -AB0 O2 line WI-+ .NIW.0 "07 col89
)O D -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
C0A( line9
(0A) -AB0 ita& WI-+ -AB0 "07 col8 F C
IN-O line -(ANSPO(-IN/ colB9
W(I-0= ?s%-su&rc F?4 s%-su&rc4
A ?s%-ta&i5 F?4 s%-ta&i59
S"IP9
W(I-0= A line-col84 line-colB9
The list output is+
s%-su&rcH F
s%-ta&i5 H :
F E
The program fills a sorted table "ith a list of s8uare numbers! The %0A& statement reads the
line of the table in "hich the -e$ field col8 has the alue :! 1nl$ the content of colBis copied to
the "or- area IN0! s%-su&rc has the alue 9ero and s%-ta&i5 has the alue :# because ita&is an
inde/ table!
(0PO(- demoEintEta&lesEreadEtranspEno 9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 SO(-0) -AB0 O2 line WI-+ .NIW.0 "07 col89
)O D -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
(0A) -AB0 ita& WI-+ "07 colB F 8H -(ANSPO(-IN/ NO 2I0)S9
W(I-0= ?s%-su&rc F?4 s%-su&rc4
A ?s%-ta&i5 F?4 s%-ta&i59
The list output is+
s%-su&rc H F
s%-ta&i5 H >
The program fills a sorted table "ith a list of s8uare numbers! The (0A) statement reads the
line of the table in "hich the -e$ field colB has the alue 1@! *t does not use the table -e$! No
fields are copied to a "or- area or assigned to a field s$mbol! s%-su&rcis 9ero# since a line "as
found# and s%-ta&i5 is four!
(0PO(- demoEintEta&lesEreadEassigning 9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 +AS+0) -AB0 O2 line WI-+ .NIW.0 "07 col89
ABAP Programming (BC-ABA) 1?D
2I0)-S7,BOS VfsN I"0 IN0 O2 ita&9
)O D -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
(0A) -AB0 ita& WI-+ -AB0 "07 col8 F B ASSI/NIN/ VfsN9
VfsN-colB F 8@@9
OOP A- ita& IN-O line9
W(I-0= A line-col84 line-colB9
0N)OOP9
The list output is+
1 1
4 1FF
: E
> 1@
The program fills a hashed table "ith a list of s8uare numbers! The (0A) statement reads the
line of the table in "hich the -e$ field col8 has the alue 4 and assigns it to the field s$mbol VfsN
! The program then assigns the alue 1FF to component colB of VfsN ! This also changes the
corresponding table field!

(eading ines .sing t$e Inde5
3ou can use the (0A) statement to read lines in tables using their inde/! To read a single line of
an inde/ table# use the statement+
%0A& TAB.0 itab *N&0_ id/ result!
The s$stem reads the line "ith the inde/ id5 from the table ita&! This is 8uic-er than searching
using the -e$! The result part can specif$ a further processing option for the line that is
retrieed!
*f an entr$ "ith the specified inde/ "as found# the s$stem field s%-su&rc is set to F and s%-
ta&i5contains the inde/ of that line! 1ther"ise# s%-su&rc is set to a alue other than F!
*f id5 is less than or e8ual to F# a runtime error occurs! *f id5 is greater than the number of lines
in the table# s%-su&rc is set to >!
(0PO(- demoEintEta&lesEreadEinde59
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 SO(-0) -AB0 O2 line WI-+ .NIW.0 "07 col89
2I0)-S7,BOS VfsN I"0 IN0 O2 ita&9
)O B@ -I,0S9
line-col8 F s%-inde59
line-colB F B U s%-inde59
APP0N) line -O ita&9
0N))O9
(0A) -AB0 ita& ASSI/NIN/ VfsN IN)0X I9
W(I-0= s%-su&rc4 s%-ta&i59
W(I-0= A VfsN-col84 VfsN-colB9
The list output is+
F B
B 1>
The e/ample creates a sorted table ita&and fills it "ith 4F lines! The line "ith inde/ B is read and
assigned to the field s$mbol VfsN!
Binar% Searc$ in Standard -a&les
*f $ou read entries from standard tables using a -e$ other than the default -e$# $ou can use a
binar$ search instead of the normal linear search! To do this# include the addition BINA(7
S0A(C+ in the corresponding (0A)statements!
ABAP Programming (BC-ABA) 1?E
%0A& TAB.0 itab W*T6 U03 -1 H f1 !!! -n H fn result
B*NA%3 S0A%C6!
The standard table must be sorted in ascending order b$ the specified search -e$! The B*NA%3
S0A%C6 addition means that $ou can access an entr$ in a standard table b$ its -e$ as 8uic-l$ as
$ou "ould be able to in a sorted table!
(0PO(- demoEintEta&lesEreadEinde5E&in9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 S-AN)A() -AB0 O2 line9
)O D -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
0N))O9
SO(- ita& B7 colB9
(0A) -AB0 ita& WI-+ "07 colB F 8H IN-O line BINA(7 S0A(C+9
W(I-0= ?S7-S.B(C F?4 s%-su&rc9
The list output is+
S3-S)B%C H F
The program fills a standard table "ith a list of s8uare numbers and sorts them into ascending
order b$ field colB ! The (0A) statement uses a binar$ search to loo- for and find the line in the
table "here colB has the alue 1@!
Processing -a&le 0ntries in oops
3ou can use the OOP statement to process special loops for an$ internal table!
.11P AT itab result condition!
statement bloc-
0N&.11P!
This reads the lines of the table one b$ one as specified in the result part of the .11P
statement! 3ou can then process them in the statements "ithin the OOP - 0N)OOP control
structure! 3ou can either run the loop for all entries in the internal table# or restrict the number
of lines read b$ specif$ing a condition! Control leel processing is allo"ed "ithin the loop!
The se8uence in "hich the lines are processed depends on the table t$pe+
7 Standard tables and sorted tables
The lines are processed according to the linear inde/! Within the processing bloc-# the s$stem
field s%-ta&i5 contains the inde/ of the current line!
7 6ashed tables
As long as the table has not been sorted# the lines are processed in the order in "hich $ou
added them to the table! Within the processing bloc-# the s$stem field s%-ta&i5 is al"a$s F!
3ou can nest OOP bloc-s! When $ou leae the loop# s%-ta&i5 has the same alue as "hen $ou
entered it! After the 0N)OOP statement# s%-su&rc is 9ero if at least one table entr$ "as
processed! 1ther"ise# it is >!
The loop ma$ not contain an$ operations on entire internal tables that change the table! 6o"eer#
$ou should remember that een saing a global internal table "ith the .1CA. statement in a
procedure is a change operation on the entire table# since it e/changes the table contents! When
$ou call procedures "ithin loops# $ou should therefore chec- that it does not change the entire
internal table! *f $ou change the table# the loop can no longer "or- properl$!
*f $ou insert or delete a table entr$ "ithin a loop pass# it is ta-en into account in subse8uent loop
passes as follo"s+
7 *f $ou insert a line after the current line# it "ill be processed in a subse8uent loop pass!
7 *f $ou delete a line after the current line# it "ill not be processed in a subse8uent loop
pass!
7 *f $ou insert a line before or at the current line# the internal loop counter "ill be increased
accordingl$!
7 *f $ou delete a line before or at the current line# the internal loop counter "ill be
decreased accordingl$!
ABAP Programming (BC-ABA) 1@F
Specif%ing t$e 05tra Processing Option
The processing option specifies ho" a table line is aailable in the statement bloc- of the list!
.sing a Wor* Area
To place the current loop line into a "or- area# specif$ result as follo"s+
.11P AT itab *NT1 "a bedingung!
The contents of the table lines must be conertible into the data t$pe of the "or- area wa! *n
each loop pass# one line of the table is copied into the "or- area! The end of the loop does not
affect the "or- area# that is# the contents of wa are the same after the 0N)OOP statement as
the$ "ere in the final loop pass! *f no table entries are processed in the loop# because the table is
entr$# or no line meets the condition cond# the "or- area is not changed!
.sing a 2ield S%m&ol
To assign the contents of the current loop line to a field s$mbol# specif$ result as follo"s+
.11P AT itab ASS*(N*N( ]fsG condition!
*n each loop pass# the field s$mbol VfsN points to the table entr$ read in that pass! *f the line
t$pe is structured# $ou should specif$ the same t$pe for the field s$mbol "hen $ou declare it!
This allo"s $ou to address the components of the field s$mbol! *f $ou cannot specif$ the t$pe
staticall$# $ou must use further field s$mbols and the techni8ue of assigning components of
structures to address the components of the structure!
The end of the loop does not affect the field s$mbol# that is# after 0N)OOP it is still assigned
to the same line as in the final loop pass! *f no table entries are processed in the loop# because
the table is entr$# or no line meets the condition cond# the field s$mbol is not changed!
,or further information about assigning table lines to field s$mbols# refer to Access )sing ,ield
S$mbols!
Suppressing t$e Assignment of ines
*f $ou do not need to transfer the contents of the current table line to a "or- area or assign
them to a field s$mbol# $ou can use the follo"ing statement+
.11P AT itab T%ANSP1%T*N( N1 ,*0.&S condition!
This form of the .11P statement is useful if $ou "ant to find the inde/ of a particular internal
table in the s$stem field s%-ta&i5# or the number of ro"s in a table that meet a particular
condition!
0nter conditions
To aoid reading all of the lines in an internal table# $ou can specif$ a condition for the line
selection as follo"s+
.11P AT itab result W60%0 cond!
This processes all of the lines that meet the logical condition cond! The logical e/pression cond
can consist of more than one comparison! *n each comparison# the first operand must be a
component of the line structure! *f the table lines are not structured# the first operand can also
be the e/pression ta&leEline! The comparison then applies to the entire line!
*f the line t$pe of the internal table contains ob2ect reference ariables as component comp or if
the entire line t$pe is a reference ariable# the attributes of the attr ob2ect to "hich the
respectie line reference points# can be specified as first field of a comparison using comp-Nattr
or ta&leEline-Nattr!
Control level processing
Control leel processing is allo"ed "ithin a OOP oer an internal table! This means that $ou can
diide se8uences of entries into groups based on the contents of certain fields!
*nternal tables are diided into groups according to the se8uence of the fields in the line
structure! The first column defines the highest control leel and so on! The control leel
hierarch$ must be -no"n "hen $ou create the internal table!
The control leels are formed b$ sorting the internal table in the se8uence of its structure# that
is# b$ the first field first# then b$ the second field# and so on! Tables in "hich the table -e$
occurs at the start of the table are particularl$ suitable for control leel processing!
The follo"ing diagram illustrates control leel processing in a sorted table# "here different field
contents in the first three fields are indicated b$ different colors+
ABAP Programming (BC-ABA) 1@1
0ach change of color in a column indicates a control leel change in the corresponding hierarch$
leel! Within the processing bloc- of a loop# $ou can use the control leel statement A- to react
to a control leel change! This enables $ou to restrict statements to a certain set of lines! 3ou
can thus use the S.,statement to calculate totals from subsets of all lines!
The A- statement introduces a statement bloc- that $ou end "ith the 0N)A- statement!
AT leel!
statement bloc-
0N&AT!
3ou can react to the follo"ing control leel changes+
leel 'eaning
,*%ST ,irst line of the internal table
.AST .ast line of the internal table
N0W f Beginning of a group of lines "ith the same contents in the
field f and in the fields left of f
0N& 1f f 0nd of a group of lines "ith the same contents in the field f
and in the fields left of f
3ou can use control leel statements to react to control brea-s in internal tables instead of
programming them $ourself "ith logical e/pressions! Within the loop# $ou must order the A--
0N)A-statement bloc-s according to the hierarch$ of the control leels! *f the internal table
ita& has the columns f
8
# f
B
#!!!! and if it is sorted b$ these columns# $ou must program the loop as
follo"s+
.11P AT itab!
AT ,*%ST!!!! 0N&AT!
AT N0W f
8
9999999 0N&AT!
AT N0W f
B
9999999 0N&AT!
!!!!!!!
single record processing
!!!!!!!
AT 0N& 1, f
B
9999 0N&AT!
AT 0N& 1, f
8
9999 0N&AT!
AT .AST!!!!! 0N&AT!
0N&.11P!
The innermost hierarch$ leel single line processing processes the table lines that do not
correspond to a control leel change! 3ou do not hae to use all control leel statements! But $ou
must place the ones that $ou use in the aboe se8uence! 3ou should not use control leel
ABAP Programming (BC-ABA) 1@4
statements in loops "here the line selection is restricted b$ W+0(0 or 2(O, and -O! Neither
should the table be modified during the loop!
*f a control leel field f
8
# f
B
#!!!! is not -no"n until runtime# $ou can specif$ it d$namicall$ as (n
8
)#
(n
B
)# \ "here n
8
# n
B
#!!!! contains the field of f
8
# f
B
#!!!! ! *f n
8
# n
B
#!!!! is empt$ at runtime# the criterion
for changing the control leel is ignored! 3ou can further restrict the group leel fields f
8
# f
B
#!!!!
to partial fields b$ specif$ing offset and length!
*f $ou are "or-ing "ith a "or- area wa# it does not contain the current line in the A--
0N)A-statement bloc-! All character fields to the right of the current group -e$ are filled "ith
asteris-s (L)! All other fields to the right of the current group -e$ contain their initial alue!
Within an A--0N)A- bloc-# $ou can calculate the contents of the numeric fields of the
corresponding control leel using the S.,statement!
!
3ou can onl$ use this statement "ithin a OOP! *f $ou use S)' in an A--0N)A- bloc-# the
s$stem calculates totals for the numeric fields of all lines in the current line group and "rites
them to the corresponding fields in the "or- area (see e/ample in )! *f $ou use the S)'
statement outside an A--0N)A- bloc- (single entr$ processing)# the s$stem calculates totals for
the numeric fields of all lines of the internal table in eac$ loop pass and "rites them to the
corresponding fields of the "or- area! *t therefore onl$ ma-es sense to use the S., statement
in A--0N)A- bloc-s!
*f the table contains a nested table# $ou cannot use the S.,statement! Neither can $ou use it if
$ou are using a field s$mbol instead of a "or- area in the OOP statement!
(0PO(- demoEintEta&lesEatE89
)A-A= B0/IN O2 line4
col8(8) -7P0 c4
colB -7P0 i4
colC -7P0 i4
0N) O2 line9
)A-A ita& I"0 +AS+0) -AB0 O2 line
WI-+ .NIW.0 "07 col8 colB9
line-col8 F ?A?9
)O C -I,0S9
line-colB F s%-inde59
line-colC F s%-inde5 UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
line-col8 F ?B?9
)O C -I,0S9
line-colB F B U s%-inde59
line-colC F ( B U s%-inde5 ) UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
SO(- ita&9
OOP A- ita& IN-O line9
W(I-0= A line-col84 line-colB4 line-colC9
A- 0N) O2 col89
S.,9
.IN09
W(I-0= A line-col84 line-colB4 line-colC9
S"IP9
0N)A-9
A- AS-9
S.,9
.IN09
W(I-0= A line-col84 line-colB4 line-colC9
0N)A-9
0N)OOP9
The list output is+
ABAP Programming (BC-ABA) 1@:
A 1 1
A 4 >
A : E
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
A @ 1>
B 4 >
B > 1@
B @ :@
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
B 14 ?@
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
L 1D BF
The program creates a hashed table ita&# fills it "ith si/ lines# and sorts it! *n the OOP -
0N)OOP bloc-# the "or- area IN0 is output for each loop pass! The first field of the table
-e$# col8# is used for control leel processing! The total for all numeric fields is al"a$s calculated
"hen the contents of col8 change and "hen the s$stem is in the last loop pass!
(0PO(- demoEintEta&lesEatEB9
)A-A= B0/IN O2 line4
carrid -7P0 s&oo*-carrid4
connid -7P0 s&oo*-connid4
fldate -7P0 s&oo*-fldate4
custt%pe -7P0 s&oo*-custt%pe4
class -7P0 s&oo*-class4
&oo*id -7P0 s&oo*-&oo*id4
0N) O2 line9
)A-A ita& I"0 SO(-0) -AB0 O2 line WI-+ .NIW.0 "07 ta&leEline9
S00C- carrid connid fldate custt%pe class &oo*id
2(O, s&oo* IN-O CO((0SPON)IN/ 2I0)S O2 -AB0 ita&9
OOP A- ita& IN-O line9
A- 2I(S-9
W(I-0 A ?ist of Boo*ings?9
.IN09
0N)A-9
A- N0W carrid9
W(I-0= A ?Carrid=?4 line-carrid9
0N)A-9
A- N0W connid9
W(I-0= A ?Connid=?4 line-connid9
0N)A-9
A- N0W fldate9
W(I-0= A ?2ldate=?4 line-fldate9
0N)A-9
A- N0W custt%pe9
W(I-0= A ?Custt%pe=?4 line-custt%pe9
0N)A-9
W(I-0= A line-&oo*id4 line-class9
A- 0N) O2 class9
.IN09
0N)A-9
0N)OOP9
*n this e/ample# the sorted internal table ita& is filled "ith data from the database table SB11U
using the 1pen SC. statement S00C-! The se8uence of the columns in the internal table
defines the control leel hierarch$! Since the table -e$ is the entire line# the sort se8uence and
the control leel hierarch$ are the same! The se8uence of the AT-0N&AT bloc-s "ithin the OOP
- 0N)OOP statements is important!
The output loo-s something li-e this+
ABAP Programming (BC-ABA) 1@>
.ist of Boo-ings
Carrid+ AA
Connid+ FF1B
,ldate+ 1EED;11;44
Custt$pe+ B
FFF@:?FE C
FFF@:?1B C
!!!
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
FFF@:?:4 ,
FFF@:?:? ,
!!!
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
Custt$pe+ P
FFF@:@?: C
FFF@:@?> C
!!!
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
FFF@:@@D ,
FFF@:@BF ,
!!!
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
,ldate+ 1EED;4E;11
Custt$pe+ B
FFF@>14F C
FFF@>141 C
!!!
and so on!
Specif%ing t$e Inde5 in oops
When $ou process an internal table in a loop# $ou can specif$ the inde/ of an inde/ table to
restrict the number of entries that are read+
.11P AT itab result X,%1' n
1
Y XT1 n
4
Y condition!
statement bloc-
0N&.11P!
The loop is processed li-e an$ internal table! Within the processing bloc-# the s$stem field s%-
ta&i5 contains the inde/ of the current line!
3ou can use the additions 2(O, and -O to specif$ the inde/es n
8
and n
B
of the first and last
entries that $ou "ant to read! The 2(O, and -O options restrict the number of lines "hich the
s$stem has to read! The W+0(0 addition in the condition onl$ preents the result from being
processed! 6o"eer# all of the table lines are read! To improe performance# $ou should use the
2(O, and -O options as much as possible! *t can be also beneficial under certain conditions to
leae the loop "ith the CON-IN.0 or 0XI- statement!
(0PO(- demoEintEta&lesEloopEind9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 SO(-0) -AB0 O2 line WI-+ .NIW.0 "07 ta&leEline9
)O C@ -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
0N))O9
OOP A- ita& IN-O line 2(O, 8@ -O BG W+0(0 colB N D@@9
W(I-0= A s%-ta&i54 line-colB9
0N)OOP9
The list output is+
ABAP Programming (BC-ABA) 1@?
41 >>1
44 >D>
4: ?4E
4> ?B@
4? @4?
The e/ample fills a sorted table ita& "ith four lines! *n the loop# onl$ the lines 1F to 4? are read!
There is also a condition that the contents of colB must be more than >FF!
C$anging ines
To change a single line of an$ internal table# use the ,O)I27statement! 3ou can either use the
table -e$ to find and change a single line using its -e$# or find and change a set of lines that meet
a certain condition! *f the table has a non-uni8ue -e$ and there are duplicate entries# the first
entr$ is changed!
C$anging a ine .sing t$e -a&le "e%
To change a single line# use the follo"ing statement+
'1&*,3 TAB.0 itab ,%1' "a XT%ANSP1%T*N( f
1
f
4
!!!Y!
The "or- area wa# "hich must be compatible "ith the line t$pe of the internal table# pla$s a
double role in this statement! Not onl$ it is used to find the line that $ou "ant to change# but it
also contains the ne" contents! The s$stem searches the internal table for the line "hose table
-e$ corresponds to the -e$ fields in wa!
The s$stem searches for the releant table t$pes as follo"s+
7 Standard tables
.inear search# "here the runtime is in linear relation to the number of table entries! The first
entr$ found is changed!
7 Sorted tables
Binar$ search# "here the runtime is in logarithmic relation to the number of table entries! The
first entr$ found is changed!
7 6ashed tables
The entr$ is found using the hash algorithm of the internal table! The runtime is independent
of the number of table entries!
*f a line is found# the contents of the non--e$ fields of the "or- area are copied into the
corresponding fields of the line# and s%-su&rc is set to F! 1ther"ise# s%-su&rc is set to >! *f the
table has a non-uni8ue -e$ and the s$stem finds duplicate entries# it changes the first entr$!
3ou can specif$ the non--e$ fields that $ou "ant to assign to the table line in the
-(ANSPO(-IN/ addition! 3ou can also specif$ the fields f
1
f
4
\ d$namicall$ using (n
1
) (n
4
) \ as
the contents of a field n
1
n
4
\! *f ]n
i
G is empt$ "hen the statement is e/ecuted# it is ignored! 3ou
can also restrict all fields f
1
f
4
\ to subfields b$ specif$ing offset and length!
,or tables "ith a comple/ line structure# the use of the -(ANSPO(-IN/addition results in
better performance# proided the s$stem does not hae to transport unnecessar$ table-li-e
components!
C$anging Several ines .sing a Condition
To change one or more lines using a condition# use the follo"ing statement+
'1&*,3 itab ,%1' "a T%ANSP1%T*N( f
1
f
4
!!! W60%0 cond!
This processes all of the lines that meet the logical condition cond! The logical e/pression cond
can consist of more than one comparison! *n each comparison# the first operand must be a
component of the line structure! *f the table lines are not structured# the first operand can also
be the e/pression -AB0EIN0! The comparison then applies to the entire line! *f the line t$pe
of the internal table contains ob2ect reference ariables as component comp or if the entire line
t$pe is a reference ariable# the attributes of the attr ob2ect to "hich the respectie line
reference points can be specified as comparison alues using comp-Nattr or ta&leEline-Nattr!
The "or- area wa# "hich must be compatible "ith the line t$pe of the internal table# contains the
ne" contents# "hich in turn "ill be assigned to the releant table line using the -(ANSPO(-IN/
addition! )nli-e the aboe ,O)I27statement# the -(ANSPO(-IN/ addition is not optional here!
,urthermore# $ou can onl$ modif$ the -e$ fields of the internal table if it is a standard table! *f
at least one line is changed# the s$stem sets s%-su&rc to F# other"ise to >!
(0PO(- demoEintEta&lesEmodif% 9
)A-A= B0/IN O2 line4
col8 -7P0 i4
ABAP Programming (BC-ABA) 1@@
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 +AS+0) -AB0 O2 line WI-+ .NIW.0 "07 col89
)O D -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
line-col8 F B9
line-colB F 8@@9
,O)I27 -AB0 ita& 2(O, line9
OOP A- ita& IN-O line9
W(I-0= A line-col84 line-colB9
0N)OOP9
The list output is+
1 1
4 1FF
: E
> 1@
The program fills a hashed table "ith a list of s8uare numbers! The ,O)I27 statement changes
the line of the table in "hich the -e$ field col8 has the alue 4!
(0PO(- demoEintEta&lesEmodif%Etransp9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 +AS+0) -AB0 O2 line WI-+ .NIW.0 "07 col89
)O D -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
line-colB F 8@@9
,O)I27 ita& 2(O, line -(ANSPO(-IN/ colB
W+0(0 ( colB N 8 ) AN) ( col8 V D )9
OOP A- ita& IN-O line9
W(I-0= A line-col84 line-colB9
0N)OOP9
The list output is+
1 1
4 1FF
: 1FF
> 1@
The program fills a hashed table "ith a list of s8uare numbers! The ,O)I27 statement changes
the lines of the table "here the content of field colB is greater than 1 and the content of field
col8 is less than >!
C$anging -a&le ines .sing t$e Inde5
3ou can use the ,O)I27 statement to change lines in tables using their inde/! There is also an
obsolete ariant of the W(I-0 -Ostatement that $ou can use to modif$ lines in standard tables!
C$anging Single ines using ,O)I27
To change a line using its inde/# use the follo"ing statement+
'1&*,3 itab ,%1' "a X*N&0_ id/Y XT%ANSP1%T*N( f
1
f
4
!!! Y!
The "or- area wa specified in the 2(O, addition replaces the addressed line in the ita& table!
The "or- area must be conertible into the line t$pe of the internal table!
*f $ou use the IN)0X option# the contents of the "or- area oer"rite the contents of the line
"ith the inde/ id5! *f the operation is successful# s%-su&rc is set to F! *f the internal table
contains fe"er lines than id5# no line is changed and s%-su&rc is set to >!
ABAP Programming (BC-ABA) 1@B
Without the IN)0X addition# $ou can onl$ use the aboe statement "ithin a OOP! *n this case#
$ou delete the current line! id5 is implicitl$ set to s%-ta&i5 !
When $ou change lines in sorted tables# remember that $ou must not change the contents of -e$
fields# and that a runtime error "ill occur if $ou tr$ to replace the contents of a -e$ field "ith
another alue! 6o"eer# $ou can assign the same alue!
The -(ANSPO(-IN/ addition allo"s $ou to specif$ the fields that $ou "ant to change e/plicitl$
in a list! *f $ou change a sorted table# $ou ma$ onl$ specif$ non--e$ fields!
(0PO(- demoEintEta&lesEmodif%Eind9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 -AB0 O2 line9
)O C -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
0N))O9
OOP A- ita& IN-O line9
I2 s%-ta&i5 F B9
line-col8 F s%-ta&i5 U 8@9
line-colB F ( s%-ta&i5 U 8@ ) UU B9
,O)I27 ita& 2(O, line9
0N)I29
0N)OOP9
OOP A- ita& IN-O line9
W(I-0= A s%-ta&i54 line-col84 line-colB9
0N)OOP9
This produces the follo"ing output+
1 1 1
4 4F >FF
: : E
6ere# a sorted table ita& is created and filled "ith three lines! The second line is replaced b$ the
contents of the "or- area line!
(0PO(- demoEintEta&lesEmodif%EindEind9
)A-A name(D) -7P0 c !A.0 ?colB?9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 SO(-0) -AB0 O2 line WI-+ .NIW.0 "07 col89
)O D -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
0N))O9
line-colB F BBB9
,O)I27 ita& 2(O, line IN)0X B -(ANSPO(-IN/ (name)9
line-col8 F C9
line-colB F CCC9
,O)I27 ita& 2(O, line IN)0X C9
OOP A- ita& IN-O line9
W(I-0= A s%-ta&i54 line-col84 line-colB9
0N)OOP9
The list output is+
ABAP Programming (BC-ABA) 1@D
1 1 1
4 4 444
: : :::
> > 1@
The e/ample fills a sorted table "ith four lines! *n the second and third lines# the component colB
is modified! *f the third line "ere to be changed so that the alue of line-col8 "as no longer :# a
runtime error "ould occur# since the -e$ fields of sorted tables ma$ not be changed!
)eleting ines
To delete a single line of an$ internal table# use the )00-0statement! 3ou can either use the
table -e$ to find and delete a single line using its -e$# delete a set of lines that meet a condition#
or find and delete neighboring duplicate entries! *f the table has a non-uni8ue -e$ and there are
duplicate entries# the first entr$ is deleted!
)eleting a ine .sing t$e -a&le "e%
To use the table -e$ of table ita& as a search -e$# use one of the follo"ing statements+
&0.0T0 TAB.0 itab ,%1' "a!
or
&0.0T0 TAB.0 itab W*T6 TAB.0 U03 -
1
H f
1
!!! -
n
H f
n
!
*n the first case# wa must be a "or- area compati&le "ith the line t$pe of ita&! The alues of the
-e$ fields are ta-en from the corresponding components of the "or- area! To delete tables "ith
the elementar$ line t$pe and the ta&leEline -e$ using the table -e$s# $ou can use either the first
ariant or the ta&leEline pseudo component as an operand in the second ariant!
*n the second case# $ou hae to suppl$ the alues of each -e$ field e/plicitl$! *f $ou do not -no"
the name of one of the -e$ fields until runtime# $ou can specif$ it d$namicall$ as the content of a
field *
8
*
B
using (*
8
) H f
8
(*
B
) H f
B
*f the data t$pes of f
8
\ f
n
are not compatible "ith the -e$
fields# the s$stem conerts them!
The s$stem searches for the releant table t$pes as follo"s+
7 Standard tables
.inear search# "here the runtime is in linear relation to the number of table entries!
7 Sorted tables
Binar$ search# "here the runtime is in logarithmic relation to the number of table entries!
7 6ashed tables
The entr$ is found using the hash algorithm of the internal table! The runtime is independent
of the number of table entries!
*f the s$stem finds a line# it deletes it from the table and sets s%-su&rc to 9ero! 1ther"ise# s%-
su&rc is set to >! *f the table has a non-uni8ue -e$ and the s$stem finds duplicate entries# it
deletes the first entr$!
)eleting Several ines .sing a Condition
To delete more than one line using a condition# use the follo"ing statement+
&0.0T0 itab W60%0 cond!
This processes all of the lines that meet the logical e/pression cond! The logical e/pression cond
can consist of more than one comparison! *n each comparison# the first operand must be a
component of the line structure! *f the table lines are not structured# the first operand can also
be the e/pression ta&leEline! The comparison then applies to the entire line! *f at least one line is
deleted# the s$stem sets s%-su&rc to F# other"ise to >!
*f the line t$pe of the internal table contains ob2ect reference ariables as component comp or if
the entire line t$pe is a reference ariable# the attributes of the attr ob2ect to "hich the
respectie line reference points can be specified as comparison alues using comp-Nattr or
ta&leEline-Nattr!
)eleting Ad3acent )uplicate 0ntries
To delete ad2acent duplicate entries use the follo"ing statement+
&0.0T0 A&aAC0NT &)P.*CAT0 0NT%*0S ,%1' itab
XC1'PA%*N( f
1
f
4
!!! ZA.. ,*0.&SY!
The s$stem deletes all ad2acent duplicate entries from the internal table ita&! 0ntries are
duplicate if the$ fulfill one of the follo"ing compare criteria+
7 Without the CO,PA(IN/addition# the contents of the -e$ fields of the table must be
identical in both lines!
7 *f $ou use the addition CO,PA(IN/ f
8
f
B
!!! the contents of the specified fields f
8
f
B
!!!
must be identical in both lines! 3ou can also specif$ the fields f
8
f
B
\ d$namicall$ using (n
8
) (n
B
) \
ABAP Programming (BC-ABA) 1@E
as the contents of a field n
8
n
B
! *f n
8
n
B
is empt$ "hen the statement is e/ecuted# it is ignored!
3ou can also restrict all fields f
8
f
B
\ to subfields b$ specif$ing offset and length!
7 *f $ou use the addition CO,PA(IN/ A 2I0)S the contents of all fields of both lines
must be identical!
3ou can use this statement to delete all duplicate entries from an internal table if the table is
sorted b$ the specified compare criterion!
*f at least one line is deleted# the s$stem sets s%-su&rc to F# other"ise to >!
(0PO(- demoEintEta&lesE)00-0Efrom 9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 +AS+0) -AB0 O2 line WI-+ .NIW.0 "07 col89
)O D -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
line-col8 F 89
)00-0 -AB0 ita&= 2(O, line4
WI-+ -AB0 "07 col8 F C9
OOP A- ita& IN-O line9
W(I-0= A line-col84 line-colB9
0N)OOP9
The list output is+
4 >
> 1@
The program fills a hashed table "ith a list of s8uare numbers! The )00-0 statements delete
lines from the table "here the -e$ field col8 has the contents 1 or :!
(0PO(- demoEintEta&lesE)00-0Ew$ere9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 +AS+0) -AB0 O2 line WI-+ .NIW.0 "07 col89
)O D -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
INS0(- line IN-O -AB0 ita&9
0N))O9
)00-0 ita& W+0(0 ( colB N 8 ) AN) ( col8 V D )9
OOP A- ita& IN-O line9
W(I-0= A line-col84 line-colB9
0N)OOP9
The list output is+
1 1
> 1@
The program fills a hashed table "ith a list of s8uare numbers! The )00-0 statement deletes
the lines of the table "here the content of field colB is greater than 1 and the content of field
col8 is less than >!
(0PO(- demoEintEta&lesE)00-0Ead3acen9
)A-A off -7P0 i9
)A-A= B0/IN O2 line4
col8 -7P0 i4
ABAP Programming (BC-ABA) 1BF
colB(8) -7P0 c4
0N) O2 line9
)A-A ita& I"0 S-AN)A() -AB0 O2 line
WI-+ NON-.NIW.0 "07 colB9
line-col8 F 89 line-colB F ?A?9 APP0N) line -O ita&9
line-col8 F 89 line-colB F ?A?9 APP0N) line -O ita&9
line-col8 F 89 line-colB F ?B?9 APP0N) line -O ita&9
line-col8 F B9 line-colB F ?B?9 APP0N) line -O ita&9
line-col8 F C9 line-colB F ?B?9 APP0N) line -O ita&9
line-col8 F D9 line-colB F ?B?9 APP0N) line -O ita&9
line-col8 F G9 line-colB F ?A?9 APP0N) line -O ita&9
off F @9 P0(2O(, list9
)00-0 A)YAC0N- ).PICA-0S 2(O, ita& CO,PA(IN/ A 2I0)S9
off F 8D9 P0(2O(, list9
)00-0 A)YAC0N- ).PICA-0S 2(O, ita& CO,PA(IN/ col89
off F BJ9 P0(2O(, list9
)00-0 A)YAC0N- ).PICA-0S 2(O, ita&9
off F DB9 P0(2O(, list9
2O(, list9
S"IP -O IN0 C9
OOP A- ita& IN-O line9
W(I-0= A- Aoff line-col84 line-colB9
0N)OOP9
0N)2O(,9
The list output is+
1 A 1 A 1 A 1 A
1 A 1 B 4 B 4 B
1 B 4 B : B ? A
4 B : B > B
: B > B ? A
> B ? A
? A
The e/ample creates and fills a standard table! 6ere# the first )00-0 statement deletes the
second line# as the second line has the same contents as the first line! The second )00-0
statement deletes the second line from the remaining table because the contents of the field
col8 is the same as in the first line! The third )00-0 statement deletes the third and fourth
line from the remaining table because the contents of the default -e$ field colB are the same as
on the second line! Although the contents of the default -e$ are the same for the first and the
fifth line# the fifth line is not deleted because it is not ad2acent to the first line!
)eleting ines .sing t$e Inde5
3ou can use the )00-0 statement to delete lines in tables using their inde/! 3ou can insert one
or seeral lines into internal tables ia the inde/+
)eleting a Single ine
To delete a line using its inde/# use the follo"ing statement+
)00-0 ita& PIN)0X id5Q9
*f $ou use the IN)0X addition# the s$stem deletes the line "ith the inde/ id5 from table ita&#
reduces the inde/ of the subse8uent lines b$ 1# and sets s%-su&rc to 9ero! 1ther"ise# if no line
"ith inde/ id5 e/ists# s%-&u&rc is set to >!
Without the IN)0X addition# $ou can onl$ use the aboe statement "ithin a OOP! *n this case#
$ou delete the current line! id5 is implicitl$ set to s%-ta&i5 !
)eleting Several ines
To delete more than one line using the inde/# use the follo"ing statement+
)00-0 P2(O, n8Q P-O nBQ PW+0(0 conditionQ9
6ere# $ou must specif$ at least one of the additions! The W+0(0 addition "or- in the same "a$
as an$ other tables! As "ell as the W+0(0addition# $ou can specif$ the lines that $ou "ant to
delete b$ their inde/ using 2(O, and -O! The s$stem deletes all of the lines of ita& "hose inde/
lies bet"een n
1
und n
4
! *f $ou do not specif$ a 2(O, addition# the s$stem deletes lines from the
first line on"ards! *f $ou do not specif$ a -O addition# the s$stem deletes lines up to the last
line!
ABAP Programming (BC-ABA) 1B1
*f at least one line is deleted# the s$stem sets s%-su&rc to F# other"ise to >!
(0PO(- demoEintEta&lesEdeleteEindE89
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 SO(-0) -AB0 O2 line WI-+ .NIW.0 "07 col89
)O G -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
0N))O9
)00-0 ita& IN)0X= B4 C4 D9
W(I-0= ?s%-su&rc F?4s%-su&rc9
S"IP9
OOP A- ita& IN-O line9
W(I-0= A s%-ta&i54 line-col84 line-colB9
0N)OOP9
The list output is+
s%-su&rc >
1 1 1
4 : E
: ? 4?
The e/ample fills a sorted table ita& "ith fie lines! Then it deletes the three lines "ith the
inde/es 4# :# and >! After deleting the line "ith inde/ 4# the inde/ of the follo"ing lines is
decremented b$ one! Therefore# the ne/t deletion remoes the line "ith an inde/ "hich "as
initiall$ >! The third delete operation fails# since the table no" onl$ has three lines!
(0PO(- demoEintEta&lesEdeleteEindEB9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 -AB0 O2 line9
)O C@ -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
0N))O9
OOP A- ita& IN-O line9
I2 line-col8 V BJ9
)00-0 ita&9
0N)I29
0N)OOP9
OOP A- ita& IN-O line9
W(I-0= A s%-ta&i54 line-col84 line-colB9
0N)OOP9
The list output is+
1 4D BD>
4 4E D>1
: :F EFF
A standard table I-AB is filled "ith :F lines! )sing a OOP construction# the program deletes all
of the lines in the table "ith a alue of less than 4D in field col8!
(0PO(- demoEintEta&lesEdeleteEindEC9
)A-A= B0/IN O2 line4
col8 -7P0 i4
ABAP Programming (BC-ABA) 1B4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 -AB0 O2 line9
)O D@ -I,0S9
line-col8 F s%-inde59
line-colB F s%-inde5 UU B9
APP0N) line -O ita&9
0N))O9
)00-0 ita& 2(O, C -O CJ W+0(0 colB N B@9
OOP A- ita& IN-O line9
W(I-0= A line-col84 line-colB9
0N)OOP9
The list output is+
1 1
4 >
: E
> 1@
:E 1!?41
>F 1!@FF
The program deletes all entries from the standard table ita& "ith an inde/ bet"een : and :E
"here the alue in colB is greater than 4F!
Searc$ing -$roug$ Internal -a&les ine B% ine
*ndiidual lines of an internal table can be searched for certain patterns similar to the function
of the statement 2IN) for b$te and character string processing! &epending on "hat $ou are
loo-ing for or "hat $ou "ish to hae replaced# $ou can choose bet"een the follo"ing t"o
statements+
7 2IN) IN -AB0
7 (0PAC0 IN -AB0
Searc$ing t$roug$ -a&le (ows
)sing the statement+
2IN) PR2I(S- OCC.((0NC0SORA OCC.((0NC0SS O2Q pattern
IN -AB0 ita& 999 PIN RB7-0OC+A(AC-0(S ,O)0Q 999
the internal table ita& is searched through ro"-b$-ro" according to the b$te or character string
defined b$ pattern! ,or ita&# a standard table has to be specified! The ro" t$pe in the table must
be either b$te or character# depending on "hich of the additions B7-0 and C+A(AC-0( ,O)0
has been selected! B$te or character strings that coer seeral table ro"s are not found! The
optional addition R2I(S- OCC.((0NC0SORA OCC.((0NC0SS O2 defines "hether all or onl$
the first occurrence of the search pattern is searched!
,or further details and additions to the statement# see the -e$"ord documentation!

Searc$ing -$roug$ and (eplacing -a&le (ows
)sing the statement+
(0PAC0 PR2I(S- OCC.((0NC0SORA OCC.((0NC0SS O2Q pattern
IN -AB0 ita& 999 WI-+ new PIN RB7-0OC+A(AC-0(S ,O)0Q 999
the internal table ita& is searched through# ro" b$ ro"# for the b$te or character strings
determined b$ pattern! The found location(s) is (are) replaced b$ the content of the new data
ob2ect [ depending on "hether the first or all occurrences of the search pattern are searched
for (optional addition R2I(S- OCC.((0NC0SORA OCC.((0NC0SS O2)! ,or ita&# a standard
table has to be specified! The ro" t$pe in the table must be either b$te or character# depending
on "hich of the additions B7-0 and C+A(AC-0( ,O)0 has been selected! B$te or character
strings that coer seeral table ro"s are not found!
,or further details and additions to the statement# refer to the -e$"ord documentation!
O&solete Statements for Internal -a&les
The follo"ing statements are obsolete and are onl$ aailable to ensure compatibilit$ "ith
%eleases prior to >!@ and @!1F! The statements ma$ appear in older programs but should no longer
be used!
2inding C$aracter Strings in Internal -a&les
To find a character string in a line of an inde/ table# use the follo"ing statement+
ABAP Programming (BC-ABA) 1B:
S0A%C6 itab ,1% str options!
This statement chec-s the lines of internal table ita&for the character string str! *f the search
is successful s%-su&rc is set to F and s%-ta&i5 is set to the inde/ of the table line "here the
character string "as found! s%-fdpos contains the offset position of the character string in the
table line! 1ther"ise# s%-su&rc is set to >!
*n a )nicode s$stem# the line t$pe of the internal table must hae a character t$pe! *n a non-
)nicode s$stem# the line can also contain numeric or he/adecimal components!
The statement treats all table lines as t$pe cfields# regardless of their actual line t$pe! There is
no conersion! The search string str can hae the same form as for a normal S0A(C+ in a field!
The different options (options) for the search in an internal table ita& are+
7 ABB%0A*AT0&
The table ita& is searched for a "ord containing the character string str! The characters can
be separated b$ other characters! The first letter of the "ord and the string strmust be the
same!
7 STA%T*N( AT lin
1
This searches table ita& for str# starting at line lin
8
!lin
8
can be a ariable!
7 0N&*N( AT lin
4
This searches table ita& for str# ending at line lin
B
!lin
B
can be a ariable!
7 AN& 'A%U
*f the search string is found# all the characters in the search string (and all the characters in
bet"een "hen using ABB(0!IA-0)) are conerted to upper case!
This statement onl$ "or-s "ith inde/ tables! There is no corresponding statement for hashed
tables!
(0PO(- demoEintEta&lesEsearc$Einde59
)A-A= B0/IN O2 line4
inde5(D) -7P0 c4
te5t(J) -7P0 c4
0N) O2 line9
)A-A ita& I"0 SO(-0) -AB0 O2 line WI-+ .NIW.0 "07 inde59
)A-A num(B) -7P0 n9
)O 8@ -I,0S9
line-inde5 F s%-inde59
num F s%-inde59
CONCA-0NA-0 ?string? num IN-O line-te5t9
APP0N) line -O ita&9
0N))O9
S0A(C+ ita& 2O( ?string@G? AN) ,A("9
W(I-0= A ???string@G?? found at line?4 (8) s%-ta&i54
?wit$ offset?4 (8) s%-fdpos9
S"IP9
(0A) -AB0 ita& IN-O line IN)0X s%-ta&i59
W(I-0= A line-inde54 line-te5t9
The list output is+
IstringF?I found at line ? "ith offset >
? ST%*N(F?
The offset of the string found in the table is determined b$ the "idth of the first table column#
"hich has t$pe i and length >! The option AN) ,A(" changes the table contents in the
corresponding line!
C$anging ines .sing W(I-0 -O
3ou can change the lines of standard tables using the follo"ing statement+
W%*T0 f T1 itab *N&0_ id/!
This ariant of the W(I-0 -O (see -e$"ord documentation) statement conerts the contents of
field f to t$pe c and then transfers the resulting character string into the line "ith inde/ id5! *f
the operation is successful# s%-su&rc is set to F! *f the internal table contains fe"er lines than
id5# no line is changed and s%-su&rc is set to >!
The data t$pe of f must be conertible into a character field< if it is not# a s$nta/ or runtime
error occurs! The line is al"a$s interpreted as a character string# regardless of its actual line
ABAP Programming (BC-ABA) 1B>
t$pe! 3ou can process sub-fields in the same "a$ as in the normal W%*T0 T1 statement! 3ou
should onl$ use this statement for structured line t$pes if $ou "ant to change a single character
"hose e/act position $ou alread$ -no"! Another possibilit$ is to use internal tables "hose
structure is made up of a single character field! Tables of this -ind are often used in d$namic
programming!
(0PO(- demoEintEta&lesEwriteEind9
)A-A te5t(IB) -7P0 c9
)A-A code I"0 -AB0 O2 te5t9
te5t F ?-$is is t$e first line9?9
APP0N) te5t -O code9
te5t F ?-$is is t$e second line9 It is ugl%9?9
APP0N) te5t -O code9
te5t F ?-$is is t$e t$ird and final line9?9
APP0N) te5t -O code9
W(I-0 ?nice9? -O codeTC8 IN)0X B9
OOP A- code IN-O te5t9
W(I-0 A te5t9
0N)OOP9
This produces the follo"ing output+
This is the first line!
This is the second line! *t is nice!
This is the third and final line!
6ere# an internal table code is defined "ith an elementar$ t$pe c field "hich is B4 characters
long! After filling the table "ith three lines# the second line is changed b$ using the W(I-0 -O
statement! The "ord Wugl$W is replaced b$ the "ord WniceW!
.sing +eader ines as Wor* Areas
*t is not allo"ed to "or- "ith header lines in internal tables in classes! This statement is
obsolete and is onl$ aailable to ensure compatibilit$ "ith %eleases prior to >!@ and @!1F! The
addition ma$ appear in the statements listed belo" in older programs but should no longer be
used!

When $ou create an internal table $ou can also declare a header line "ith the same name! 3ou can
use the header line as a "or- area "hen $ou process the internal table! The ABAP statements
that $ou use "ith internal tables hae short forms that $ou can use if $our internal table has a
header line! These statements automaticall$ assume the header line as an implicit "or- area! The
follo"ing table sho"s the statements that $ou must use for internal tables "ithout a header line#
and the e8uialent statements that $ou can use for internal tables "ith a header line+
1perations "ithout header line 1perations "ith header line
1perations for all Table T$pes
*NS0%T "a *NT1 TAB.0 itab! *NS0%T TAB.0 *TAB!
C1..0CT "a *NT1 itab! C1..0CT itab!
%0A& TAB.0 itab!!! *NT1 "a! %0A& TAB.0 itab!!!
'1&*,3 TAB.0 itab ,%1' "a!!! '1&*,3 TAB.0 itab!!!
'1&*,3 itab ,%1' "a!!!W60%0!!! '1&*,3 itab!!! W60%0!!!
&0.0T0 TAB.0 itab ,%1' "a! &0.0T0 TAB.0 itab!
.11P AT *TAB *NT1 "a!!! .11P AT *TAB!!!
1perations for *nde/ Tables
APP0N& "a T1 itab! APP0N& itab!
*NS0%T "a *NT1 itab!!! *NS0%T itab!!!
'1&*,3 itab ,%1' "a!!! '1&*,3 itab!!!
)sing the header line as a "or- area means that $ou can use shorter statements< ho"eer# the$
are not necessaril$ easier to understand# since $ou cannot immediatel$ recogni9e the origin and
target of the assignment! ,urthermore# the fact that the table and its header line hae the same
name can cause confusion in operations "ith entire internal tables! To aoid confusion# $ou should
use internal tables "ith differentl$-named "or- areas!
ABAP Programming (BC-ABA) 1B?
The follo"ing e/ample sho"s t"o programs "ith the same function! 1ne uses a header line# the
other does not!
With header line+
T3P0S+ B0(*N 1, line#
col1 T3P0 i#
col4 T3P0 i#
0N& 1, line!
&ATA itab T3P0 6AS60& TAB.0 1, line W*T6 )N*C)0 U03 col1
W*T6 60A&0% .*N0!
&1 > T*'0S!
itab-col1 H s$-inde/!
itab-col4 H s$-inde/ LL 4!
*NS0%T TAB.0 itab!
0N&&1!
itab-col1 H 4!
%0A& TAB.0 itab ,%1' itab!
itab-col4 H 1FF!
'1&*,3 TAB.0 itab!
itab-col1 H >!
&0.0T0 TAB.0 itab!
.11P AT itab!
W%*T0+ ; itab-col1# itab-col4!
0N&.11P!
Bearbeitung ohne Uopf9eile+
T3P0S+ B0(*N 1, line#
col1 T3P0 i#
col4 T3P0 i#
0N& 1, line!
&ATA+ itab T3P0 6AS60& TAB.0 1, line W*T6 )N*C)0 U03 col1#
"a .*U0 .*N0 1, itab!
&1 > T*'0S!
"a-col1 H s$-inde/!
"a-col4 H s$-inde/ LL 4!
*NS0%T "a *NT1 TAB.0 itab!
0N&&1!
"a-col1 H 4!
%0A& TAB.0 itab ,%1' "a *NT1 "a!
"a-col4 H 1FF!
'1&*,3 TAB.0 itab ,%1' "a!
"a-col1 H >!
&0.0T0 TAB.0 itab ,%1' "a!
.11P AT itab *NT1 "a!
W%*T0+ ; "a-col1# "a-col4!
0N&.11P!
*n both cases# the list appears as follo"s+
1 1
4 1FF
: E
The statements in the program that does not use a header line are easier to understand! As a
further measure# $ou could hae a further "or- area 2ust to specif$ the -e$ of the internal table#
but to "hich no other alues from the table are assigned!
05tracts
Since internal tables hae fi/ed line structures# the$ are not suited to handle data sets "ith
ar$ing structures! ,or this purpose# ABAP offers the possibilit$ to create so-called e/tract
datasets (e/tracts# for short)!
An e/tract is a se8uential dataset in the memor$ area of the program! 3ou can onl$ address the
entries in the dataset "ithin a special loop! The inde/ or -e$ access permitted "ith internal
tables is not allo"ed! 3ou ma$ onl$ create one e/tract in an$ ABAP program! The si9e of an
e/tract dataset is# in principle# unlimited! 0/tracts larger than ?FF UB are stored in operating
ABAP Programming (BC-ABA) 1B@
s$stem files! The practical si9e of an e/tract is up to 4 (B# as long as there is enough space in the
file s$stem!
An e/tract dataset consists of a se8uence of records of a predefined structure! 6o"eer# the
structure need not be identical for all records! *n one e/tract dataset# $ou can store records of
different length and structure one after the other! 3ou need not create an indiidual dataset for
each different structure $ou "ant to store! This fact reduces the maintenance effort
considerabl$!
*n contrast to internal tables# the s$stem partl$ compresses e/tract datasets "hen storing them!
This reduces the storage space re8uired! *n addition# $ou need not specif$ the structure of an
e/tract dataset at the beginning of the program# but $ou can determine it d$namicall$ during the
flo" of the program!
3ou can use control leel processing "ith e/tracts 2ust as $ou can "ith internal tables! The
internal administration for e/tract datasets is optimi9ed so that it is 8uic-er to use an e/tract
for control leel processing than an internal table!
Procedure for creating an e/tract+
!!!
1! &efine the record t$pes that $ou "ant to use in $our e/tract dataset b$ declaring them as
field groups! The structure is defined b$ including fields in each field group!
&efining an 0/tract
4! ,ill the e/tract dataset line b$ line b$ e/tracting the re8uired data!
,illing an 0/tract "ith &ata
:! 1nce $ou hae filled the e/tract# $ou can sort it and process it in a loop! At this stage# $ou
can no longer change the contents of the e/tract!
Processing 0/tracts
)efining an 05tract
The ob2ect is defined in t"o steps! ,irst# the indiidual records must be declared and then their
structure defined!
)eclaring 05tract (ecords as 2ield /roups
An e/tract dataset consists of a se8uence of records! These records ma$ hae different
structures! All records "ith the same structure form a record t$pe! 3ou must define each record
t$pe of an e/tract dataset as a field group# using the 2I0)-/(O.PS statement!
,*0.&-(%1)PS fg!
This statement defines a field group fg! A field group combines seeral fields under one name!
,or clarit$# $ou should declare $our field groups at the end of the declaration part of $our
program!
A field group does not resere storage space for the fields# but contains pointers to e/isting
fields! When filling the e/tract dataset "ith records# these pointers determine the contents of
the stored records!
3ou can also define a special field group called $eader+
,*0.&-(%1)PS $eader9
This group is automaticall$ placed before an$ other field groups "hen $ou fill the e/tract! This
means that a record of a field group fg al"a$s contains the fields of the field group $eader!
When sorting the e/tract dataset# the s$stem uses these fields as the default sort *e%!
)efining t$e Structure of a 2ield /roup
To define the structure of a record# use the follo"ing statement to add the re8uired fields to a
field group+
*NS0%T f
1
!!! f
n
*NT1 fg!
This statement defines the fields of field group fg! Before $ou can assign fields to a field group#
$ou must define the field group fg using the 2I0)-/(O.PSstatement! 1nl$ globall$ isible data
ob2ects of the ABAP program can be used as fields f
1
!!! f
n
! 3ou cannot assign a local data ob2ect
defined in a procedure to a field group!
The INS0(- statement# 2ust as the 2I0)-/(O.PSstatement# neither reseres storage space
nor transfers alues! 3ou use the INS0(-statement to create pointers to the fields f
1
!!! f
n
in the
field group fg# thus defining the structures of the e/tract records!
When $ou run the program# $ou can assign fields to a field group up to the point "hen $ou use this
field group for the first time to fill an e/tract record! ,rom this point on# the structure of the
record is fi/ed and ma$ no longer be changed! *n short# as long as $ou hae not used a field group
$et# $ou can still e/tend it d$namicall$!
ABAP Programming (BC-ABA) 1BB
The special field group $eader is part of ever% e/tract record! Conse8uentl$# $ou ma$ not change
the structure of the $eader field group after $ou hae filled the first e/tract record!
A field ma$ occur in seeral field groups< ho"eer# this means unnecessar$ data redundanc$
"ithin the e/tract dataset! 3ou do not need to define the structure of a field group e/plicitl$
"ith INS0(-! *f the field group $eader is defined# an undefined field group consists implicitl$ of
the fields in the field group $eader^other"ise# it is empt$!
(0PO(- demoEe5tractEfieldEgroups9
NO)0S= spfli4 sflig$t9
2I0)-/(O.PS= $eader4 flig$tEinfo4 flig$tEdate9
INS0(-= spfli-carrid spfli-connid sflig$t-fldate
IN-O $eader4
spfli-cit%from spfli-cit%to
IN-O flig$tEinfo9
The program is lin-ed to the logical database ,1S! The NO)0S statement declares the
corresponding interface "or- areas!
There are three field groups! The INS0(- statement assigns fields to t"o of the field groups!
2illing an 05tract wit$ )ata
1nce $ou hae declared the possible record t$pes as field groups and defined their structure# $ou
can fill the e/tract dataset using the follo"ing statements+
0_T%ACT fg!
When the first 0X-(AC- statement occurs in a program# the s$stem creates the e/tract
dataset and adds the first e/tract record to it! *n each subse8uent 0X-(AC- statement# the
ne" e/tract record is added to the dataset!
0ach e/tract record contains e/actl$ those fields that are contained in the fg field group# plus
perhaps the fields of the $eader field group! The fields occur as a sort -e$ at the beginning! *f
$ou do not e/plicitl$ specif$ an fg field group# the
0_T%ACT
statement is a shortened form of the statement
0_T%ACT header!
When $ou e/tract the data# the record is filled "ith the current alues of the corresponding
fields!
As soon as the s$stem has processed the first 0X-(AC-statement for an fg field group# the
structure of the corresponding e/tract record in the e/tract dataset is fi/ed! 3ou can no longer
insert ne" fields into the fg and $eader field groups! *f $ou tr$ to modif$ one of the field groups
after"ards and use it in another 0X-(AC-statement# a runtime error occurs!
B$ processing 0X-(AC- statements seeral times using different field groups# $ou fill the
e/tract dataset "ith records of different length and structure! Since $ou can modif$ field
groups d$namicall$ up to their first usage in an 0X-(AC- statement# e/tract datasets proide
the adantage that $ou need not determine the structure at the beginning of the program!
Assume the follo"ing program is lin-ed to the logical database ,1S!
(0PO(- demoEe5tractEe5tract9
NO)0S= spfli4 sflig$t9
2I0)-/(O.PS= $eader4 flig$tEinfo4 flig$tEdate9
INS0(-= spfli-carrid spfli-connid sflig$t-fldate
IN-O $eader4
spfli-cit%from spfli-cit%to
IN-O flig$tEinfo9
S-A(--O2-S00C-ION9
/0- spfli9
0X-(AC- flig$tEinfo9
/0- sflig$t9
0X-(AC- flig$tEdate9
There are three field groups! The INS0(- statement assigns fields to t"o of the field groups!
&uring the (0T eents# the s$stem fills the e/tract dataset "ith t"o different record t$pes!
The records of the field group flig$tEinfo consist of fie fields+ spfli-carrid# spfli-connid#
sflig$t-fldate# spfli-cit%from# and spfli-cit%to!
ABAP Programming (BC-ABA) 1BD
The first three fields belong to the prefi/ed field group $eader! The records of the field group
flig$tEdate consist onl$ of the three fields of the $eader field group! The follo"ing figure sho"s
the structure of the e/tract dataset+

Processing 05tracts
1nce an e/tract dataset contains all of the re8uired data# $ou can process it! When $ou hae
started processing a dataset# $ou can no longer e/tract data into it!
%eading 0/tracts
Sorting 0/tracts
Control .eel Processing
Calculating Numbers and Totalsn
(eading an 05tract
.i-e internal tables# $ou can read the data in an e/tract dataset using a loop!
.11P!
!!!
XAT ,*%ST Z A- fg
i
XW*T6 fg
2
Q O A- AS-9
!!!
0N&AT!Y
!!!
0N&.11P!
When the .11Pstatement occurs# the s$stem stops creating the e/tract dataset# and starts a
loop through all entries contained in it! 1ne record from the e/tract dataset is read in each loop
pass! The alues of the e/tracted fields are placed in the corresponding output fields "ithin the
loop! 3ou can e/ecute seeral loops in succession! The loop around an e/tract dataset cannot be
nested! *t is also no longer possible to use further 0X-(AC- statements "ithin or after the loop!
*n both cases# a runtime error occurs!
*n contrast to internal tables# e/tract datasets do not re8uire a special "or- area or field s$mbol
as an interface! *nstead# $ou can process each record of the dataset "ithin the loop using its
original field names!
oop control
*f $ou "ant to e/ecute some statements for certain records of the dataset onl$# use the control
statements AT and 0N)A-!
The s$stem processes the statement bloc-s bet"een the control statements for the different
arguments of A- as follo"s+
ABAP Programming (BC-ABA) 1BE
7 A- 2I(S-
The s$stem e/ecutes the statement bloc- once for the first record of the dataset!
7 A- fg
i
XW*T6 fg
2
Q The s$stem processes the statement bloc- if the record t$pe of the
currentl$ read e/tract record "as defined using the field group fg
i
! When using the WI-+
fg
3
addition# in the e/tract dataset# the currentl$ rea14Dd record of field group fg
i
must be
immediatel$ follo"ed b$ a record of field group fg
3
!
7 A- AS-
The s$stem e/ecutes the statement bloc- once for the last record of the dataset!
3ou can also use the AT and 0N&ATstatements for control leel processing!
Assume the follo"ing program is lin-ed to the logical database ,1S!
(0PO(- demoEe5tractEloop9
NO)0S= spfli4 sflig$t9
2I0)-/(O.PS= $eader4 flig$tEinfo4 flig$tEdate9
INS0(-= spfli-carrid spfli-connid sflig$t-fldate
IN-O $eader4
spfli-cit%from spfli-cit%to
IN-O flig$tEinfo9
S-A(--O2-S00C-ION9
/0- spfli9
0X-(AC- flig$tEinfo9
/0- sflig$t9
0X-(AC- flig$tEdate9
0N)-O2-S00C-ION9
OOP9
A- 2I(S-9
W(I-0 A ?Start of OOP?9
.IN09
0N)A-9
A- flig$tEinfo WI-+ flig$tEdate9
W(I-0= A ?Info=?4
spfli-carrid 4 spfli-connid4 sflig$t-fldate4
spfli-cit%from4 spfli-cit%to9
0N)A-9
A- flig$tEdate9
W(I-0= A ?)ate=?4
spfli-carrid 4 spfli-connid4 sflig$t-fldate9
0N)A-9
A- AS-9
.IN09
W(I-0 A ?0nd of OOP?9
0N)A-9
0N)OOP9
The e/tract dataset is created and filled in the same "a$ as sho"n in the e/ample for ,illing an
0/tract "ith &ata! The data retrieal ends before the 0N&-1,-S0.0CT*1N eent# in "hich the
dataset is read once using a .11P!
The control statements A- 2I(S- and A- AS- instruct the s$stem to "rite one line and one
underscore line in the list# once at the beginning of the loop and once at the end!
The control statement A- fg
i
tells the s$stem to output the fields corresponding to each of the
t"o record t$pes! The WI-+ flig$tEdate addition means that the s$stem onl$ displa$s the
records of field group flig$tEinfo if at least one record of field group flig$tEdatefollo"s< that is#
if the logical database passed at least one date for a flight!
The beginning of the output list loo-s li-e this+
ABAP Programming (BC-ABA) 1DF
The contents of the field sflig$t-fldate in the header part of record t$pe flig$tEinfo are
displa$ed as hash signs (e)! This is because the logical database fills all of the fields at that
hierarch$ leel "ith the alue 60_ FF "hen it finishes processing that leel! This feature is
important for sorting and for processing control leels in e/tract datasets!
Sorting an 05tract
3ou can sort an e/tract dataset in much the same "a$ as an internal table b$ using the follo"ing
statement+
S1%T XASC0N&*N(Z&0SC0N&*N(Y XAS T0_TY XSTAB.0Y
B3 f
1
XASC0N&*N(Z&0SC0N&*N(Y XAS T0_TY
!!!
f
n
XASC0N&*N(Z&0SC0N&*N(Y XAS T0_TY!
The SO(- statement terminates the creation of the e/tract dataset of a program and# at the
same time# sorts its records! Without the B7 option# the s$stem sorts the dataset b$ the -e$
specified in the $eader field group!
3ou can sort an e/tract dataset as often as $ou li-e in a program# using an$ number of different
-e$s! The onl$ prere8uisite is that all fields b$ "hich $ou "ant to sort are contained in the $eader
during the e/traction process! 3ou must not use the SO(- statement bet"een OOP and
0N)OOP! 6o"eer# $ou can sort and read the e/tract dataset in an$ se8uence! After the SO(-
statement has been e/ecuted $ou can not use an$ further 0X-(AC- statements! 1ther"ise# a
runtime error occurs!
3ou can define a different sort -e$ b$ using the B7addition! The s$stem then sorts the dataset
according to the specified components f
1
999 f
n
! These components must either be fields of the
$eaderfield group or field groups containing onl$ fields from the $eader field group! The number
of -e$ fields is limited to ?F! The se8uence of the components f
1
999 f
n
determines the sort order!
The s$stem uses the options $ou specif$ before B7 as a default for all fields specified after B7!
The options that $ou specif$ after indiidual fields oer"rite for these fields the options
specified before B7!
3ou can define the sort direction using the )0SC0N)IN/ or ASC0N)IN/ additions! The default
is ascending order! ,or character strings# $ou can use the AS -0X- addition to define the sort
method! This forces an alphabetical sort# as "ith internal tables! *f $ou "ant to sort an e/tract
dataset alphabeticall$ more than once# $ou should include a field "hich can be sorted
alphabeticall$ in the sort -e$ instead of the te/t field for performance reasons! To fill this field#
use the C1NA0%T statement!
ABAP Programming (BC-ABA) 1D1
*f $ou put AS -0X- before B7# the addition onl$ applies to t$pe c fields in the sort -e$! *f $ou
place AS -0X- after a field# the field must be of t$pe c! *f $ou place AS -0X- after a field
group# the option onl$ applies to the t$pe c fields "ithin the group!
This sorting process is not stable# that is# the old se8uence of records "ith the same sort -e$
must not necessaril$ be -ept! To force a stable sort# use the S-AB0addition!
*f there is not enough main memor$ aailable to sort the data# the s$stem "rites data to an
e/ternal au/iliar$ file during the sorting process! The name of the file is determined b$ the SAP
profile parameter &*%SS1%TT'P!
The SO(- statement sorts b$ all of the fields in the sort -e$ "ith the contents 60_ FF &efore
all of the other entries! This is significant "hen $ou use logical databases! When a logical
database has finished reading a hierarch$ leel# it fills all of the fields at that leel "ith the
alue 60_ FF! 08uall$# if $ou use a field list in the (0T statement (2I0)S addition)# the logical
database fills all of the fields not in the field list "ith 60_ FF!
0ach sorting process e/ecuted on the e/tract dataset using the SO(- statement defines a
control leel! This is re8uired for subse8uent control leel processing!
Assume the follo"ing program is lin-ed to the logical database ,1S!
(0PO(- demoEe5tractEsort9
NO)0S= spfli4 sflig$t9
2I0)-/(O.PS= $eader4 flig$tEinfo4 flig$tEdate9
INS0(-= spfli-carrid spfli-connid sflig$t-fldate
IN-O $eader4
spfli-cit%from spfli-cit%to
IN-O flig$tEinfo9
S-A(--O2-S00C-ION9
/0- spfli9
0X-(AC- flig$tEinfo9
/0- sflig$t9
0X-(AC- flig$tEdate9
0N)-O2-S00C-ION9
SO(- )0SC0N)IN/9
OOP9
A- 2I(S-9
W(I-0 A ?Start of OOP?9
.IN09
0N)A-9
A- flig$tEinfo WI-+ flig$tEdate9
W(I-0= A ?Info=?4
spfli-carrid 4 spfli-connid4 sflig$t-fldate4
spfli-cit%from4 spfli-cit%to9
0N)A-9
A- flig$tEdate9
W(I-0= A ?)ate=?4
spfli-carrid 4 spfli-connid4 sflig$t-fldate9
0N)A-9
A- AS-9
.IN09
W(I-0 A ?0nd of OOP?9
0N)A-9
0N)OOP9
This e/ample is identical "ith the e/ample in the section %eading an 0/tract# apart from the
SO(- )0SC0N)IN/ statement! The SO(- statement tells the s$stem to sort the e/tract
dataset in descending order b$ the three fields of the $eader field group# before reading it using
OOP - 0N)OOP! The end of the list loo-s li-e this+
ABAP Programming (BC-ABA) 1D4
*t is "orth noting that the records "ith the alue 60_ FF in the field sflig$t-fldate (undefined
characters in the list) are sorted before the remaining records! This is done to presere the
hierarch$ of the data from the logical database# independent of the sort se8uence!
Control evel Processing
When $ou perform a sort using the SO(-statement# control leels are defined in the e/tract
dataset! ,or general information about control leels# refer to Processing *nternal Tables in
.oops The control leel hierarch$ of an e/tract dataset corresponds to the se8uence of the
fields in the $eader field group! After sorting# $ou can use the A-statement "ithin a OOP loop
to program statement bloc-s that the s$stem processes onl$ "hen the control leel changes!
AT N0W f Z AT 0N& 1, f!
!!!
0N&AT!
A control brea- occurs "hen the alue of the field f or a superior field in the current record has
a different alue from the preious record (A- N0W) or the subse8uent record (A- 0N))! ,ield
f must be part of the $eader field group!
*f the e/tract dataset is not sorted# the A- - 0N)A- bloc- is neer e/ecuted! ,urthermore# all
e/tract records "ith the alue 60_ null in the field f are ignored "hen the control brea-s are
determined!
The A-999 0N)A- bloc-s in a loop are processed in the order in "hich the$ occur! This se8uence
should be the same as the sort se8uence! This se8uence must not necessaril$ be the se8uence of
the fields in the $eader field group# but can also be the one determined in the SO(- statement!
*f $ou hae sorted an e/tract dataset b$ the fields f
8
# f
B
# \# the processing of the control leels
should be "ritten bet"een the other control statements in the OOP loop as follo"s+
.11P!
AT ,*%ST!!!! 0N&AT!
AT N0W f
1
!!!!!!! 0N&AT!
AT N0W f
4
!!!!!!! 0N&AT!
!!!
AT fg
i
!!!!! 0N&AT!
Single record processing "ithout control statement
!!!
AT 0N& 1, f
4
!!!! 0N&AT!
AT 0N& 1, f
1
!!!! 0N&AT!
ABAP Programming (BC-ABA) 1D:
AT .AST!!!!! 0N&AT!
0N&.11P!
3ou do not hae to use all of the statement bloc-s listed here# but onl$ the ones $ou re8uire!
(0PO(- demoEe5tractEatEnew9
)A-A= t8(D) -7P0 c4 tB -7P0 i9
2I0)-/(O.PS= $eader9
INS0(- tB t8 IN-O $eader9
t8 F?AABB?9 tB F 89 0X-(AC- $eader9
t8 F?BBCC?9 tB F B9 0X-(AC- $eader9
t8 F?AAAA?9 tB F B9 0X-(AC- $eader9
t8 F?AABB?9 tB F 89 0X-(AC- $eader9
t8 F?BBBB?9 tB F B9 0X-(AC- $eader9
t8 F?BBCC?9 tB F B9 0X-(AC- $eader9
t8 F?AAAA?9 tB F 89 0X-(AC- $eader9
t8 F?BBBB?9 tB F 89 0X-(AC- $eader9
t8 F?AAAA?9 tB F C9 0X-(AC- $eader9
t8 F?AABB?9 tB F 89 0X-(AC- $eader9
SO(- B7 t8 tB9
OOP9
A- 2I(S-9
W(I-0 ?Start of OOP?9
.IN09
0N)A-9
A- N0W t89
W(I-0 A ? New -8=?9
0N)A-9
A- N0W tB9
W(I-0 A ? New -B=?9
0N)A-9
W(I-0= A8D t84 tB9
A- 0N) O2 tB9
W(I-0 A ?0nd of -B?9
0N)A-9
A- 0N) O2 t89
W(I-0 A ?0nd of -8?9
0N)A-9
A- AS-9
.IN09
0N)A-9
0N)OOP9
This program creates a sample e/tract# containing the fields of the $eader field group onl$!
After the sorting process# the e/tract dataset has seeral control brea-s for the control leels
T1 and T4# "hich are indicated in the follo"ing figure+
ABAP Programming (BC-ABA) 1D>
*n the OOP loop# the s$stem displa$s the contents of the dataset and the control brea-s it
recogni9ed as follo"s+

Calculating Num&ers and -otals
When $ou read a sorted e/tract dataset using OOP# $ou can access t"o automaticall$-generated
fields cnt(f) and sum(g)! These fields contain the number of different alues and the sums of the
numeric fields respectiel$! The s$stem fills these fields at the end of a control leel and after
reading the last record of the dataset as follo"s+
7 cnt(f)
*f f is a non-numeric field of the $eader field group and the s$stem sorted the e/tract
dataset b$ f# cnt(f) contains the number of different alues f assumed "ithin the control
leel or entire dataset respectiel$!
7 sum(g)
*f g is a numeric field of the e/tract dataset# sum(g)contains the total of the alues of g
"ithin the control leel or entire dataset# respectiel$!
3ou can access these fields either "ithin the processing bloc-s follo"ing A- 0N) O2 or in the
processing bloc- follo"ing A- AS-# after reading the entire dataset! *f $ou tr$ to access the
fields cnt(f) and sum(g) "ithout first sorting the dataset# a runtime error ma$ occur!
(0PO(- demoEe5tractEcntEsum9
)A-A= t8(D) -7P0 c4 tB -7P0 i9
2I0)-/(O.PS= $eader4 test9
INS0(- tB t8 IN-O $eader9
t8 F?AABB?9 tB F 89 0X-(AC- test9
t8 F?BBCC?9 tB F B9 0X-(AC- test9
t8 F?AAAA?9 tB F B9 0X-(AC- test9
t8 F?AABB?9 tB F 89 0X-(AC- test9
t8 F?BBBB?9 tB F B9 0X-(AC- test9
t8 F?BBCC?9 tB F B9 0X-(AC- test9
t8 F?AAAA?9 tB F 89 0X-(AC- test9
t8 F?BBBB?9 tB F 89 0X-(AC- test9
ABAP Programming (BC-ABA) 1D?
t8 F?AAAA?9 tB F C9 0X-(AC- test9
t8 F?AABB?9 tB F 89 0X-(AC- test9
SO(- B7 t8 tB9
OOP9
W(I-0= AB@ t84 tB9
A- 0N) O2 tB9
.IN09
W(I-0= ?Sum=?4 B@ sum(tB)9
.IN09
0N)A-9
A- 0N) O2 t89
W(I-0= ?)ifferent values=?4 (H) cnt(t8)9
.IN09
0N)A-9
A- AS-9
.IN09
W(I-0= ?Sum=?4 B@ sum(tB)4
A ?)ifferent values=?4 (H) cnt(t8)9
0N)A-9
0N)OOP9
This program creates a sample e/tract# containing the fields of the $eader field group onl$!
After sorting# the s$stem outputs the contents of the dataset# the number of the different t8
fields# and the totals of the tB fields at the end of each control leel and at the end of the loop+
2ormatting data
ABAP Programming (BC-ABA) 1D@
This section sho"s ho" $ou can use internal tables and e/tracts# using an e/ample of ho" to
format data for displa$ as a list! The data that $ou format is usuall$ read from database tables
or from an e/ternal file# or $ou can create $our o"n generic data in the program! ,ormatting data
for a list usuall$ means sorting it# calculating sums# finding out the number of items# and so on!
The e/ample of formatted data sho"s a list "hose output data has been processed li-e this!
There are t"o "a$s of formatting data - during and after data retrieal!
2ormatting )ata )uring (etrieval
When $ou create $our o"n datasets or read data from the database using 1pen SC. statements#
the data ma$ alread$ be sufficientl$ formatted "hen $ou read it!
2ormatting )ata After (etrieval
When using logical databases to access database tables# "hen reading data from se8uential files#
or if the options of 1pen SC. are not comprehensie enough# the retrieed data often appears in
a se8uence and structure $ou need to refine! To refine this data later on# $ou need to store it in a
temporar$ dataset! The formatting process is independent of the process of retrieing data! The
flo" of a program that can be directl$ e/ecuted is adapted to this procedure!
ABAP allo"s $ou to use internal tables and e/tracts to sae temporar$ datasets!
Internal -a&les
*t ma-es sense to use internal tables "heneer the dataset has the same structure as the
underl$ing data structure# and "hen $ou "ant to access indiidual entries indiiduall$!
05tract )atasets
*t ma-es sense to use an e/tract dataset "heneer $ou "ant to process large amounts of data
entirel$ and repeatedl$!

,ormatting &ata &uring %eading
,ormatting &ata )sing *nternal Tables
,ormatting &ata )sing 0/tracts
0/ample of ,ormatted &ata
,or man$ report ealuations# the se8uence in "hich $ou "ant to process data ma$ differ from the
se8uence in "hich it is stored! Since the results of read operations generall$ reflect the
se8uence in "hich data is stored# $ou must resort all of the data $ou selected into the desired
se8uence!
A t$pical result of formatting data in the conte/t of a flight reseration application is creating a
list that is designed to contain each flight number! The possible connections are to be sorted b$
departure cit$# the flights b$ date# and the customer data b$ class and smo-er;non-smo-er! ,or
each flight# the total number of passengers and the oerall luggage "eight need to be displa$ed!
A section of the resulting list should loo- li-e this+
ABAP Programming (BC-ABA) 1DB
2ormatting )ata )uring (eading
The most direct method of formatting data is to use the corresponding options of the S00C-
statement! With this method# $ou must program the database access $ourself! *n addition# $ou
must program a selection screen to offer the user the possibilit$ of restricting the set of data to
be read! Note that using nested S00C- loops is e/ceedingl$ inefficient! 3ou should therefore
place $our data in bloc-s into internal tables or e/tracts# and process it from there!
(0PO(- demoEdataEprocessEread9
)A-A= sum -7P0 i4 cnt -7P0 i4
waEspfli -7P0 spfli4
waEsflig$t -7P0 sflig$t4
waEs&oo* -7P0 s&oo*9
S00C- U 2(O, spfli IN-O waEspfli
O()0( B7 cit%from cit%to connid9
S"IP9
W(I-0= A waEspfli-carrid4
waEspfli-connid4
?from?4 (8G) waEspfli-cit%from4
?to?4 (8G) waEspfli-cit%to9
.IN09
S00C- U 2(O, sflig$t IN-O waEsflig$t
W+0(0 carrid F waEspfli-carrid
ABAP Programming (BC-ABA) 1DD
AN) connid F waEspfli-connid
O()0( B7 fldate9
S"IP9
W(I-0= A ?)ate=?4 waEsflig$t-fldate9
W(I-0= B@ ?Boo*-I)?4 D@ ?Smo*er?4 G@ ?Class?9
.IN09
sum F @9
cnt F @9
S00C- U 2(O, s&oo* IN-O waEs&oo*
W+0(0 carrid F waEsflig$t-carrid
AN) connid F waEsflig$t-connid
AN) fldate F waEsflig$t-fldate
O()0( B7 class smo*er &oo*id9
W(I-0= A waEs&oo*-&oo*id .N)0( ?Boo*-I)?4
waEs&oo*-smo*er .N)0( ?Smo*er?4
waEs&oo*-class .N)0( ?Class?9
sum F sum T waEs&oo*-luggweig$t9
cnt F cnt T 89
0N)S00C-9
.IN09
W(I-0= ?Num&er of &oo*ings= ?4 (C) cnt4
A ?-otal luggage weig$t=?4 (C) sum4 waEs&oo*-wunit9
0N)S00C-9

0N)S00C-9
This program creates the same list as in the 0/ample of ,ormatted &ata! *t uses the O()0( B7
addition in the S00C- statement to sort the data!
(efining )ata .sing Internal -a&les
When storing data in internal tables# $ou often use one internal table for each database $ou read!
0ach one contains some or all columns of the releant database table! *t is up to $ou "hether $ou
create an internal table "ith a flat structure for each database table or if $ou create# for
e/ample# internal tables "ith nested structures! *f $ou hae seeral tables# each one "ith a flat
structure# $ou hae to "or- "ith redundant -e$ fields to lin- the tables! *f# on the other hand#
$ou use nested internal tables# $ou can store the data from the database tables hierarchicall$!
Saing and processing er$ large amounts of data in internal tables has disadantages! *f $ou
diide up the data into different internal tables# processing it can be er$ runtime-intensie#
since the tables hae to be processed indiiduall$! ,urthermore# it re8uires a lot of storage space#
since internal tables are not stored in compressed form! The s$stem ma$ een need to store the
dataset outside of its "or-ing memor$! This means that processing it ta-es een longer!
Processing )ata .sing 2lat Internal -a&les
Assume the follo"ing program is lin-ed to the logical database ,1S!
(0PO(- )0,O9
)A-A= S., -7P0 I4 CN- -7P0 I9
NO)0S= SP2I4 S2I/+-4 SBOO"9
)A-A= -ABESP2I -7P0 -AB0 O2 SP2I4
-ABES2I/+- -7P0 -AB0 O2 S2I/+-4
-ABESBOO" -7P0 -AB0 O2 SBOO"9
)A-A= WAESP2I I"0 IN0 O2 -ABESP2I4
WAES2I/+- I"0 IN0 O2 -ABES2I/+-4
WAESBOO" I"0 IN0 O2 -ABESBOO"9
S-A(--O2-S00C-ION9
/0- SP2I9
APP0N) SP2I -O -ABESP2I9
/0- S2I/+-9
APP0N) S2I/+- -O -ABES2I/+-9
/0- SBOO"9
APP0N) SBOO" -O -ABESBOO"9
ABAP Programming (BC-ABA) 1DE
0N)-O2-S00C-ION9
SO(-= -ABESP2I B7 CI-72(O, CI-7-O CONNI)4
-ABES2I/+- B7 2)A-04
-ABESBOO" B7 CASS S,O"0( BOO"I)9
OOP A- -ABESP2I IN-O WAESP2I9
S"IP9
W(I-0= A WAESP2I-CA((I)4
WAESP2I-CONNI)4
?from?4 (8G) WAESP2I-CI-72(O,4
?to?4 (8G) WAESP2I-CI-7-O9
.IN09
OOP A- -ABES2I/+- IN-O WAES2I/+-
W+0(0 CA((I) F WAESP2I-CA((I)
AN) CONNI) F WAESP2I-CONNI)9
S"IP9
W(I-0= A ?)ate=?4 WAES2I/+--2)A-09
W(I-0= B@ ?Boo*-I)?4 D@ ?Smo*er?4 G@ ?Class?9
.IN09
S., F @9
CN- F @9
OOP A- -ABESBOO" IN-O WAESBOO"
W+0(0 CA((I) F WAES2I/+--CA((I)
AN) CONNI) F WAES2I/+--CONNI)
AN) 2)A-0 F WAES2I/+--2)A-09
W(I-0= A WAESBOO"-BOO"I) .N)0( ?Boo*-I)?4
WAESBOO"-S,O"0( .N)0( ?Smo*er?4
WAESBOO"-CASS .N)0( ?Class?9
S., F S., T WAESBOO"-.//W0I/+-9
CN- F CN- T 89
0N)OOP9
.IN09
W(I-0= ?Num&er of &oo*ings= ?4 (C) CN-4
A ?-otal luggage weig$t=?4
(C) S.,4 WAESBOO"-W.NI-9
0N)OOP9
0N)OOP9
This program creates the same list as in the 0/ample of ,ormatted &ata!
The (0T eents that retriee the data are clearl$ separated from the sorting
process! The three internal tables hae e/actl$ the same structure and contents as
the corresponding database tables! The data is sorted and then displa$ed! The loop
structure is e/actl$ the same as that of the S0.0CT loops in the e/ample from the
,ormatting &ata &uring %eading section!
2ormatting )ata .sing Nested Internal -a&les
Assume the follo"ing program is lin-ed to the logical database ,1S!
(0PO(- )0,O9
)A-A= S., -7P0 I4 CN- -7P0 I9
NO)0S= SP2I4 S2I/+-4 SBOO"9
)A-A= B0/IN O2 WAESBOO"4
BOO"I) -7P0 SBOO"-BOO"I)4
S,O"0( -7P0 SBOO"-S,O"0(4
CASS -7P0 SBOO"-CASS4
.//W0I/+- -7P0 SBOO"-.//W0I/+-4
W.NI- -7P0 SBOO"-W.NI-4
0N) O2 WAESBOO"9
)A-A= B0/IN O2 WAES2I/+-4
2)A-0 -7P0 S2I/+--2)A-04
ABAP Programming (BC-ABA) 1EF
SBOO" I"0 -AB0 O2 WAESBOO" 4
0N) O2 WAES2I/+-9
)A-A= B0/IN O2 WAESP2I4
CA((I) -7P0 SP2I-CA((I)4
CONNI) -7P0 SP2I-CONNI)4
CI-72(O, -7P0 SP2I-CI-72(O,4
CI-7-O -7P0 SP2I-CI-7-O4
S2I/+- I"0 -AB0 O2 WAES2I/+- 4
0N) O2 WAESP2I9
)A-A -ABESP2I I"0 -AB0 O2 WAESP2I 9
S-A(--O2-S00C-ION9
/0- SP2I9
(02(0S+ WAESP2I-S2I/+-9
/0- S2I/+-9
(02(0S+ WAES2I/+--SBOO"9
/0- SBOO"9
,O!0-CO((0SPON)IN/ SBOO" -O WAESBOO"9
APP0N) WAESBOO" -O WAES2I/+--SBOO"9
/0- S2I/+- A-09
,O!0-CO((0SPON)IN/ S2I/+- -O WAES2I/+-9
APP0N) WAES2I/+- -O WAESP2I-S2I/+-9
/0- SP2I A-09
,O!0-CO((0SPON)IN/ SP2I -O WAESP2I9
APP0N) WAESP2I -O -ABESP2I9
0N)-O2-S00C-ION9
SO(- -ABESP2I B7 CI-72(O, CI-7-O CONNI)9
OOP A- -ABESP2I IN-O WAESP2I9
S"IP9
W(I-0= A WAESP2I-CA((I)4
WAESP2I-CONNI)4
?from?4 (8G) WAESP2I-CI-72(O,4
?to?4 (8G) WAESP2I-CI-7-O9
.IN09
SO(- WAESP2I-S2I/+- B7 2)A-09
OOP A- WAESP2I-S2I/+- IN-O WAES2I/+-9
S"IP9
W(I-0= A ?)ate=?4 WAES2I/+--2)A-09
W(I-0= B@ ?Boo*-I)?4 D@ ?Smo*er?4 G@ ?Class?9
.IN09
SO(- WAES2I/+--SBOO" B7 CASS S,O"0( BOO"I)9
S., F @9
CN- F @9
OOP A- WAES2I/+--SBOO" IN-O WAESBOO"9
W(I-0= A WAESBOO"-BOO"I) .N)0( ?Boo*-I)?4
WAESBOO"-S,O"0( .N)0( ?Smo*er?4
WAESBOO"-CASS .N)0( ?Class?9
S., F S., T WAESBOO"-.//W0I/+-9
CN- F CN- T 89
0N)OOP9
.IN09
W(I-0= ?Num&er of &oo*ings= ?4 (C) CN-4
A ?-otal luggage weig$t=?4
(C) S.,4 WAESBOO"-W.NI-9
0N)OOP9
0N)OOP9
This program creates the same list as in the 0/ample of ,ormatted &ata!
&uring the (0T eents# the s$stem reads the data into the three-leel internal
table S1%TSSP,.* "hich contains the substructure S,.*(6T and its substructure
SB11U! The sorting process ta-es place on the indiidual nesting leels!
ABAP Programming (BC-ABA) 1E1
This "a$ of programming does not re8uire -e$ relations bet"een the internal tables
(no W60%0 conditions)# but it is more comple/ than using flat internal tables! And
the increased internal administration effort has a negatie effect on the storage
space re8uired as "ell as on the runtime!
,ormatting &ata )sing 0/tracts
3ou can use a single e/tract to store entries from more than one database table# since the
records in an e/tract can hae different structures!
Assume the follo"ing program is lin-ed to the logical database ,1S!
(0PO(- demoEdataEprocessEe5tract9
NO)0S= spfli4 sflig$t4 s&oo*9
2I0)-/(O.PS= $eader4 flig$tEinfo4 flig$tE&oo*ing9
INS0(-=
spfli-cit%from spfli-cit%to
spfli-connid sflig$t-fldate
s&oo*-class s&oo*-smo*er s&oo*-&oo*id IN-O $eader4
spfli-carrid IN-O flig$tEinfo4
s&oo*-luggweig$t s&oo*-wunit IN-O flig$tE&oo*ing9
S-A(--O2-S00C-ION9
/0- spfli9
0X-(AC- flig$tEinfo9
/0- sflig$t9
/0- s&oo*9
0X-(AC- flig$tE&oo*ing9
0N)-O2-S00C-ION9
SO(-9
OOP9
A- flig$tEinfo9
S"IP9
W(I-0= A spfli-carrid4
spfli-connid4
?from?4 (8G) spfli-cit%from4
?to?4 (8G) spfli-cit%to9
.IN09
0N)A-9
A- N0W sflig$t-fldate9
S"IP9
W(I-0= A ?)ate=?4 sflig$t-fldate9
W(I-0= B@ ?Boo*-I)?4 D@ ?Smo*er?4 G@ ?Class?9
.IN09
0N)A-9
A- flig$tE&oo*ing9
W(I-0= A s&oo*-&oo*id .N)0( ?Boo*-I)?4
s&oo*-smo*er .N)0( ?Smo*er?4
s&oo*-class .N)0( ?Class?9
0N)A-9
A- 0N) O2 sflig$t-fldate9
.IN09
W(I-0= ?Num&er of &oo*ings= ?4 (C) cnt(s&oo*-&oo*id)4
A ?-otal luggage weig$t=?4
sum(s&oo*-luggweig$t)4 s&oo*-wunit9
0N)A-9
0N)OOP9
This program creates the same list as in the 0/ample of ,ormatted &ata!
The s$stem creates three field groups and fills them "ith seeral fields! The e/tract dataset is
filled through 0X-(AC-statements during the (0T eents! There is no 0X-(AC- statement for
/0- sflig$t# since the re8uired field sflig$t-fldate is part of the $eader field group and thus
automaticall$ e/tracted for each subordinate eent /0- s&oo*!
ABAP Programming (BC-ABA) 1E4
After retrieing the data# the s$stem completes the creation of the dataset "hen the SO(-
statement occurs# and sorts the dataset b$ the $eader sort -e$! *n the OOP [ 0N)OOP bloc-#
it "rites the sorted e/tract dataset to the output list# using arious A- [ 0N)A- bloc-s and the
fields cnt(999) and sum(999)!
Saving )ata 05ternall%
This section describes the processing of persistent data# that means the data that can be stored
outside of an ABAP program! There are three "a$s $ou can do this!
&atabase Access# &ata *nterfaces and &ata Cluster!
The data stored in database tables and files using ABAP programs can be accessed and ealuated
independentl$ of the SAP s$stem ia the programming interface of the database s$stem and the
respectie operating s$stem! &ata cluster represent a specific ABAP format# "hich is e/clusiel$
understood b$ ABAP programs!
When e/ternal data is changed b$ application programs# $ou hae to ma-e sure that a consistent
state still e/ists after the changes! This applies especiall$ for editing data on the database!
)ata&ase Accesses

This section describes ho" ABAP programs communicate "ith the central database of NetWeaer
AS ABAP!

&atabase Accesses of NetWeaer AS ABAP
1pen SC.
Natie SC.
)ata&ase Accesses of t$e NetWeaver AS ABAP
The NetWeaer AS ABAP stores long-term data in a central relational database table! *n a
relational database model# the real "orld is represented b$ tables! A table is a t"o-dimensional
matri/# consisting of lines and columns (fields)! The smallest possible combination of fields that
can uni8uel$ identif$ each line of the table is called the -e$! 0ach table must hae at least one
-e$# and each table has one -e$ that is defined as its primar$ -e$! %elationships bet"een tables
are represented b$ foreign -e$s!
Standard SW
SC. (Structured Cuer$ .anguage) is a largel$ standardi9ed language for accessing relational
databases! *t can be diided into three areas+
7 &ata 'anipulation .anguage (&'.)
Statements for reading and changing data in data&ase ta&les9
7 &ata &efinition .anguage (&&.)
Statements for creating and administering database tables!
7 &ata Control .anguage (&C.)
Statements for authori9ation and consistenc$ chec-s!
0ach database has a programming interface that allo"s $ou to access the database tables using
SC. statements! The SC. statements in these programming interfaces are not full$
ABAP Programming (BC-ABA) 1E:
standardi9ed! To access a specific database s$stem# $ou must refer to the documentation of that
s$stem for a list of the SC. statements aailable and their correct s$nta/!
-$e )ata&ase Interface
To aoid incompatible situations bet"een different database tables and to ma-e the NetWeaer
AS ABAP s$stem independent of the database s$stem in use# each "or- process on an ABAP
application serer contains a database interface! The NW AS communicates "ith the database
solel$ through the database interface! The database interface conerts all of the database
re8uests from the NW AS into the correct Standard SC. statements for the database s$stem
in use! To do this# it uses a database-specific component that shields the differences bet"een
database s$stems from the rest of the database interface! 3ou choose the this component "hen
$ou install NetWeaer AS ABAP in accordance "ith the database in use!
ABAP programs hae t"o options for accessing the database interface+ 1pen SC. and Natie
SC.!
Open SW
1pen SC. statements are a full$ integrated subset of Standard SC. "ithin ABAP! The$ enable
the ABAP programs to access data irrespectie of the database s$stem installed! 1pen SC.
consists of the &ata 'anipulation .anguage (&'.) part of Standard SC.< in other "ords# it
allo"s $ou to read (S00C-) and change (INS0(-# .P)A-0# )00-0) data!
1pen SC. also goes be$ond Standard SC. to proide statements that# in con2unction "ith other
ABAP constructions# can simplif$ or speed up database access! *t also allo"s $ou to buffer
certain tables on the application serer# saing e/cessie database access! *n this case# the
database interface is responsible for comparing the buffer "ith the database! Buffers are partl$
stored in the "or-ing memor$ of the current "or- process# and partl$ in the shared memor$ for
all "or- processes on an application serer! *n SAP s$stems that are distributed across more than
one application serer# the data in the arious buffers is s$nchroni9ed at set interals b$ buffer
management! When buffering the database# $ou must remember that data in the buffer is not
al"a$s up to date! ,or this reason# $ou should onl$ use the buffer for data "hich does not often
change! 3ou specif$ "hether a table can be buffered in its definition in the ABAP &ictionar$!
Native SW
Natie SC. is onl$ loosel$ integrated into ABAP# and allo"s access to all of the functions
contained in the programming interface of the respectie database s$stem! )nli-e 1pen SC.
statements# Natie SC. statements are not chec-ed and conerted# but instead are sent directl$
to the database s$stem! When $ou use Natie SC.# the function of the database-dependent la$er
is minimal! Programs that use Natie SC. are specific to the database s$stem for "hich the$
"ere "ritten! When deeloping generall$ alid ABAP applications# $ou should [ as far as possible [
ABAP Programming (BC-ABA) 1E>
aoid using Natie SC.! *n some components of the SAP S$stem# Natie SC. is used [ for
e/ample# in the ABAP &ictionar$ for creating or changing tables!
-$e ABAP )ictionar%
The ABAP &ictionar$# part of the ABAP Wor-bench# allo"s $ou to create and administer database
tables! 1pen SC. contains no statements from the &&. part of Standard SC.! Normal
application programs should not create or change their o"n database tables!
The ABAP &ictionar$ uses the &&. part of 1pen SC. to create and change database tables! *t
also administers the ABAP &ictionar$ in the database! The ABAP &ictionar$ contains meta
descriptions of all database tables in the NetWeaer AS ABAP s$stem! 1nl$ database tables that
$ou create using the ABAP &ictionar$ appear in the &ictionar$! 1pen SC. statements can onl$
access tables that e/ist in the ABAP &ictionar$!
Aut$ori:ation and Consistenc% C$ec*s
The &C. part of Standard SC. is not important in ABAP programs! The "or- processes "ithin
the ABAP application serer are logged on to the database s$stem as users "ith full
authori9ation! The authori9ations of programs or program users to read or change database
tables is managed b$ the authori9ation concept! 08uall$# transactions must ensure their o"n data
consistenc$ in the database using the SAP loc-ing concept! ,or more information# refer to the
chapter &ata Consistenc$!
Open SW
1pen SC. consists of a set of ABAP statements that perform operations on the central database
in the SAP Web AS ABAP! The results of the operations and an$ error messages are independent
of the database s$stem in use! 1pen SC. thus proides a uniform s$nta/ and semantics for all of
the database s$stems supported b$ SAP! ABAP programs that onl$ use 1pen SC. statements "ill
"or- in an$ SAP s$stem# regardless of the database s$stem in use! 1pen SC. statements can onl$
"or- "ith database tables that hae been created in the ABAP &ictionar$!
*n the ABAP &ictionar$# $ou can combine columns of different database tables to a database ie"
(or ie" for short)! *n 1pen SC. statements# ie"s are handled in e/actl$ the same "a$ as
database tables! An$ references to database tables in the follo"ing sections can e8uall$ appl$ to
ie"s!
Overview
1pen SC. contains the follo"ing -e$"ords+
Ue$"ord ,unction
S0.0CT %eads data from database tables
*NS0%T Adds lines to database tables
)P&AT0 Changes the contents of lines of database tables
'1&*,3 *nserts lines into database tables or changes the contents
of e/isting lines
&0.0T0 &eleting .ines from &atabase Tables
1P0N C)%S1%#
,0TC6#
C.1S0 C)%S1%
%eads lines of database tables using the cursor
(eturn Codes
All 1pen SC. statements fill the follo"ing t"o s$stem fields "ith return codes+
7 s%-su&rc
After ever% 1pen SC. statement# the s$stem field s%-su&rc contains the alue F if the
operation "as successful# a alue other than F if not!
7 s%-d&cnt
After an open SC. statement# the s$stem field s%-d&cnt contains the number of database
lines processed!
Client +andling
A single SAP s$stem can manage the application data for seeral separate areas of a business (for
e/ample# branches)! 0ach of these commerciall$ separate areas in the SAP s$stem is called a
client# and has a number! When a user logs onto the SAP Web AS ABAP# the$ specif$ a client! The
first column in the structure of eer$ database table containing application data is the client
field ('AN&T# from the (erman "ord for client)! *t is also the first field of the table -e$! 1nl$
uniersal s$stem tables are client-independent# and do not contain a client name!
B$ default# 1pen SC. statements use automatic client handling! Statements that access client-
dependent application tables onl$ use the data from the current client! 3ou cannot specif$ a
ABAP Programming (BC-ABA) 1E?
condition for the client field in the W+0(0 clause of an 1pen SC. statement! *f $ou do so# the
s$stem "ill either return an error during the s$nta/ chec- or a runtime error "ill occur! 3ou
cannot oer"rite the 'AN&T field of a database using 1pen SC. statements! *f $ou specif$ a
different client in a "or- area# the ABAP runtime enironment automaticall$ oer"rites it "ith
the current one before processing the 1pen SC. statement further!
Should $ou need to specif$ the client specificall$ in an 1pen SC. statement# use the addition
!!! C.*0NT SP0C*,*0& !!!!
directl$ after the name of the database table! This addition disables the automatic client
handling and $ou can use the field 'AN&T both in the W+0(0 clause and in a table "or- area!
%eading data
Changing data
Performance Notes
(eading )ata
The 1pen SC. statement for reading data from database tables is+
S0.0CT result
*NT1 target
,%1' source
XW60%0 conditionY
X(%1)P B3 fieldsY
X6AA*N( condY
X1%&0% B3 fieldsY!
The S0.0CT statement is diided into a series of simple clauses# each of "hich has a different
part to pla$ in selecting# placing# and arranging the data from the database!

Clause &escription
S00C- result The S00C- clause result defines the structure of
the data $ou "ant to read# that is# "hether one line
or seeral# "hich columns $ou "ant to read# and
"hether identical entries are acceptable or not!
IN-O target The IN-O clause determines the target area target
ABAP Programming (BC-ABA) 1E@
into "hich the selected data is to be read!
2(O, source The 2(O, clause specifies the database table or
ie" the source from "hich the data is to be
selected! *t can also be placed before the IN-O
clause!
W+0(0 cond The W+0(0 clause specifies "hich lines are to be
read b$ specif$ing conditions for the selection!
/(O.P B7 fields The /(O.P-B7 clause produces a single line of
results from groups of seeral lines! A group is a set
of lines "ith identical alues for each column listed in
fields!
+A!IN/ cond The +A!IN/ clause sets logical conditions for the
lines combined using /(O.P B7!
O()0( B7 fields The O()0(-B7 clause defines a se8uence fields for
the lines resulting from the selection!
The indiidual clauses and the "a$s in "hich the$ combine are all er$ important factors in the
S00C- statement! Although it is a single statement li-e an$ other# beginning "ith the S00C-
-e$"ord and ending "ith a period# its diision into clauses# and the "a$s in "hich the$ combine#
ma-e it more po"erful than other statements! A single S00C- statement can perform functions
ranging from simpl$ reading a single line to e/ecuting a er$ complicated database 8uer$!
3ou can use S00C- statements in the W+0(0 and +A!IN/clauses! These are called sub8ueries!
3ou can decouple the IN-O clause from the S00C- statement b$ reading from the database
using a cursor!
1n certain database s$stems# this can result in loc- conflicts# een "ith pure read access< these
can be preented b$ using database commits!
)efining a Selection
The S00C- clause defines the structure of the result set (selection) that $ou "ant to read
from the database!
The selection can be flat (one line) or tabular (seeral lines)! 3ou can specif$ "hether to accept
or e/clude duplicate entries! The S00C- clause also specifies the names of the columns to be
read! 3ou can replace the names of the database fields "ith alternatie names! Aggregate
functions can be applied to indiidual columns!
The S00C- clause can be diided into t"o parts for lines and columns+
S0.0CT lines cols !!!
*n lines $ou specifi$ "hether an indiidual line is read using S0.0CT S*N(.0 cols
or "hether lines are read using S0.0CT X&*ST*NCTY cols!
*f $ou do not use )IS-INC- (lines is then empt$)# the s$stem reads all of the lines that satisf$
the W+0(0 condition! *f $ou use )IS-INC-# the s$stem e/cludes duplicate entries!
cols defines the column selection!
(eading All Columns
To read all of the columns in the database table# use the follo"ing for cols+
S0.0CT lines L!!!
This reads all columns for the specified lines! %eading indiidual columns can be considerabl$ more
efficient than reading all of the columns in a table! 3ou should therefore onl$ read the columns
that $ou need in $our program!
ABAP Programming (BC-ABA) 1EB
(eading Single Columns
To read single columns from the database table# use the follo"ing for cols+
S0.0CT lines s
1
XAS a
1
Y s
4
XAS a
4
Y !!!
7 "here s
1
s
4
\ are single columns! )sing the ASaddition# an alternatie column name a
1
a
4
\
can be defined for each column s
1
s
4
\! The alias column name is used instead of the real name in
the IN-O and O()0(-B7clauses! This allo"s $ou# for e/ample# to read the contents of a column
s
1
into a component a
1
of a structure "hen $ou use the IN-O CO((0SPON)IN/ 2I0)S ariant
of the IN-O condition!
(eading Aggregate )ata for Columns
To read aggregate data for a column in the database# use the follo"ing for cols+
S0.0CT lines agg( X&*ST*NCTY s
1
) XAS a
1
Y
agg( X&*ST*NCTY s
4
) XAS a
4
Y !!!
"here s
1
s
4
\ are single columns! The e/pression agg represents one of the follo"ing aggregate
functions+
7 ,AX+ supplies the ma/imum alue of the column
7 ,IN+ supplies the minimum alue of the column
7 A!/+ supplies the aerage alue of the column
7 S.,+ supplies the total o the column
7 CO.N-+ counts the alues or lines as follo"s+
7 C1)NT( &*ST*NCT s ) returns the number of different alues in the column s!
7 C1)NT( L ) or count(L) returns the total number of lines in the selection!
3ou can e/clude duplicate alues from the calculation using the )IS-INC- option! *n the
ASaddition# $ou can define an alternatie column name a
1
a
4
\ for each aggregate e/pression!
Specif%ing Columns )%namicall%
3ou can also specif$ cols d$namicall$ as follo"s+
S0.0CT lines (itab)!!!
The parentheses must include the name of an internal table ita& that is either empt$ or contains
s
1
s
4
\ !!! to specif$ the columns or aggregate e/pressions to be read! *f the internal table is
empt$# the s$stem reads all columns!
%eading certain columns of a single line+
(0PO(- demoEselectEsingle9
)A-A wa -7P0 spfli9
S00C- SIN/0 carrid connid cit%from cit%to
IN-O CO((0SPON)IN/ 2I0)S O2 wa
2(O, spfli
W+0(0 carrid 0W ?+? AN) connid 0W ?@D@@?9
I2 s%-su&rc 0W @9
W(I-0= A wa-carrid4 wa-connid4 wa-cit%from4 wa-cit%to9
0N)I29
The list output is+
SIN/0 in the S00C-clause means that the statement reads a single entr$ from the database
table SP,.* "here the primar$ -e$ fields CA%%*& and C1NN*& hae the alues specified in the
W+0(0 clause! The columns specified in the S00C- clause are transferred to the identicall$-
named components of the structure wa!
%eading particular columns of more than one line+
(0PO(- demoEselectEsomeEcolumns9
)A-A= ita& -7P0 S-AN)A() -AB0 O2 spfli4
wa I"0 IN0 O2 ita&9
S00C- carrid connid cit%from cit%to
IN-O CO((0SPON)IN/ 2I0)S O2 -AB0 ita&
2(O, spfli
W+0(0 carrid 0W ?+?9
I2 s%-su&rc 0W @9
OOP A- ita& IN-O wa9
W(I-0= A wa-carrid4 wa-connid4 wa-cit%from4 wa-cit%to9
ABAP Programming (BC-ABA) 1ED
0N)OOP9
0N)I29
The list output is+
Since there are no lines specified in the S00C- clause# the statement reads all of the lines from
the database table SP,.* that satisf$ the condition in the W+0(0clause! The columns specified
in the S00C-clause are transferred to the identicall$-named components of the internal table
ita&!
%eading all columns of more than one line+
(0PO(- demoEselectEallEcolumns9
)A-A wa -7P0 spfli9
S00C- U
IN-O CO((0SPON)IN/ 2I0)S O2 wa
2(O, spfli
W+0(0 carrid 0W ?+?9
W(I-0= A s%-d&cnt4
wa-carrid4 wa-connid4 wa-cit%from4 wa-cit%to9
0N)S00C-9
The list output is+
Since there are no lines specified in the S00C- clause# the statement reads all of the lines from
the database table SP,.* that satisf$ the condition in the W+0(0clause! All of the columns in
the table are transferred to the identicall$-named components of the flat structure WA! This is
"h$ $ou must conclude the S00C- loop "ith the 0N)S00C-statement!
Aggregate functions
Suppose a database table T0ST# consisting of t"o columns and 1F lines+
C1.S1 C1.S4
1 :
4 1
: ?
> B
? 4
@ :
B 1
D E
E >
1F :
The follo"ing coding demonstrates the aggregate functions+
&ATA %0S).T T3P0 P &0C*'A.S 4!
S0.0CT agg( X&*ST*NCTY C1.S4)
*NT1 %0S).T
,%1' T0ST!
W%*T0 %0S).T!
The follo"ing table sho"s the results of this program e/tract according to different
combinations of aggregate e/pressions agg and the )IS-INC-addition!
Aggregate
0/pression
&*ST*NCT %esult
'A_ nein E!FF
'A_ 2a E!FF
'*N nein 1!FF
'*N 2a 1!FF
ABAP Programming (BC-ABA) 1EE
AA( nein :!DF
AA( 2a >!>:
S)' nein :D!FF
S)' 2a :1!FF
C1)NT 2a B!FF
C1)NT( L ) --- 1F!FF
Specif$ing Columns &$namicall$
(0PO(- demoEselectEd%namicEcolumns9
)A-A= ita& -7P0 S-AN)A() -AB0 O2 spfli4
wa I"0 IN0 O2 ita&9
)A-A= line(IB) -7P0 c4
list I"0 -AB0 O2 line(IB)9
line F ? CI-72(O, CI-7-O ?9
APP0N) line -O list9
S00C- )IS-INC- (list)
IN-O CO((0SPON)IN/ 2I0)S O2 -AB0 ita&
2(O, spfli9
I2 s%-su&rc 0W @9
OOP A- ita& IN-O wa9
W(I-0= A wa-cit%from4 wa-cit%to9
0N)OOP9
0N)I29
The list output is+
The internal table ita&contains the columns of the database table SP,.* to be read! The
)IS-INC-addition in the S00C- clause means that the statement onl$ reads those lines that
hae different contents in both of these columns! The result is a list of possible routes!
Specif%ing a -arget Area
The IN-O clause defines the target area into "hich the selection from the S00C- clause is
"ritten! Suitable target areas are ariables "hose data t$pe is compatible "ith or conertible
into that of the selection in the S00C- clause!
The S00C- clause determines the data t$pe of the target area as follo"s+
7 The linesspecification in the S00C- clause determines the depth of the target area# that
is# "hether it is a flat or a tabular structure!
7 The colsspecification in the S00C- clause determines the structure (line t$pe) of the
target area!
ABAP Programming (BC-ABA) 4FF
*f $ou select a single line# the target area must be flat! *f $ou select more than one line# the
target area ma$ be either tabular or flat! *f the target area is flat# $ou need to use a S00C-
loop!
When $ou select all of the columns# the target area must either be a structure or conertible into
one! When $ou select indiidual columns# the target area can be a component of a structure or a
single field!
The elementar$ data t$pes in the selection in the S00C- clause are &ictionar$ t$pes! These
&ictionar$ t$pes must be able to be conerted into the ABAP data t$pes of the corresponding
elementar$ components of the target area! ,or a table of data t$pes# refer to &ata T$pes in the
ABAP &ictionar$!
Specif%ing a 2lat Wor* Area
To read data into one# use the follo"ing in the IN-O clause+
S0.0CT !!! *NT1 XC1%%0SP1N&*N( ,*0.&S 1,Y "a !!!
The target area wa must be at least as large as the line to be read into it! When $ou read the
data into wa# its preious contents are oer"ritten! 6o"eer# the components of wa that are not
affected b$ the S00C-statement retain their preious alues!
*f the "or- area is structured# $ou can use the CO((0SPON)IN/ 2I0)S addition! This
transfers onl$ the contents of fields "hose names are identical in the database table and the
"or- area! This includes an$ alias column names that $ou specified in the selection!
Specif%ing Internal -a&les
To do this# use the follo"ing in the IN-O clause+
S0.0CT !!! *NT1ZAPP0N&*N( XC1%%0SP1N&*N( ,*0.&S 1,Y TAB.0 itab
XPACUA(0 S*T0 nY !!!
The internal table is filled "ith all of the lines of the selection! When $ou use IN-O# all e/isting
lines in the table are deleted! When $ou use APP0N)IN/< the ne" lines are added to the e/isting
internal table ]itabG!
*f $ou use the PAC"A/0 SI60 addition# the lines of the selection are not "ritten into the
internal table at once# but in pac-ets! 3ou can define pac-ets of n lines that are "ritten one after
the other into the internal table!
Specif%ing Single 2ields
*f $ou specif$ single columns of the database table or aggregate e/pressions in the S00C-
clause# $ou can read the data into single fields for a single entr$ or for multiple entries in a
S00C- loop! To read data into single fields# use the follo"ing in the IN-O clause+
S0.0CT !!! *NT1 (f
1
# f
4
# !!!) !!!
3ou must specif$ as man$ indiidual fields f
1
# f
4
# \ as are specified in the field list of the
S00C- clause! The fields in the S00C- clause are assigned# from left to right# to the fields in
the list in the IN-O clause!
,lat structure as target area
&ATA "a T3P0 spfli!
ABAP Programming (BC-ABA) 4F1
S0.0CT L
*NT1 "a
,%1' spfli!
W%*T0+ ; "a-carrid!!!
0N&S0.0CT!
This e/ample uses a flat structure "ith the same data t$pe as the database table SP,.* as the
target area in a S00C- loop! Within the loop# it is possible to address the contents of the
indiidual columns!
&ATA spfli T3P0 spfli!
S0.0CT L
,%1' spfli!
W%*T0+ ; spfli-carrid!!!
0N&S0.0CT!
This e/ample declares a structure spfli "ith the same name as the database table $ou "ant to
read! This structure is used implicitl$ as the target area in the S00C- loop! Since the names are
the same# it is possible to oerloo- the fact that $ou are "or-ing "ith an ABAP data ob2ect here
and not the database table itself!
*nternal table as target area
(0PO(- demoEselectEintoEta&le9
)A-A= B0/IN O2 wa4
carrid -7P0 spfli-carrid4
connid -7P0 spfli-connid4
cit%from -7P0 spfli-cit%from4
cit%to -7P0 spfli-cit%to4
0N) O2 wa4
ita& I"0 SO(-0) -AB0 O2 wa
WI-+ NON-.NIW.0 "07 cit%from cit%to9
S00C- carrid connid cit%from cit%to
IN-O CO((0SPON)IN/ 2I0)S O2 -AB0 ita&
2(O, spfli9
I2 s%-su&rc 0W @9
W(I-0= A s%-d&cnt4 ?Connections?9
S"IP9
OOP A- ita& IN-O wa9
W(I-0= A wa-carrid4 wa-connid4 wa-cit%from4 wa-cit%to9
0N)OOP9
0N)I29
The list output is+
The e/ample uses a sorted table ita& as a target area! This table has four fields "ith the same
name and data t$pe as the database table SP,.*! The program uses the CO((0SPON)IN/
2I0)S addition to place the columns from the S00C- clause into the corresponding fields of
the internal table! Because ita& is a sorted table# the data is inserted into the table sorted b$
the table -e$ of ita&!
%eading pac-ets into an internal table
ABAP Programming (BC-ABA) 4F4
(0PO(- demoEselectEintoEpac*age9
)A-A= wa -7P0 spfli4
ita& -7P0 SO(-0) -AB0 O2 spfli
WI-+ .NIW.0 "07 carrid connid9
S00C- carrid connid
2(O, spfli
IN-O CO((0SPON)IN/ 2I0)S O2 -AB0 ita&
PAC"A/0 SI60 C9
OOP A- ita& IN-O wa9
W(I-0= A wa-carrid4 wa-connid9
0N)OOP9
S"IP 89
0N)S00C-9
The list output is+
The e/ample reads pac-ets of three lines each into the sorted table ita&! *n each pass of the
S00C- loop# the internal table has a different sorted content!
*f $ou "ere to use APP0N)IN/ instead of IN-O# the list "ould loo- li-e this+
*n each loop pass# a ne" pac-et is sorted into the internal table!
Single fields as target area+
(0PO(- demoEselectEsingleEfields9
ABAP Programming (BC-ABA) 4F:
)A-A= average -7P0 p )0CI,AS B4
sum -7P0 p )0CI,AS B9
S00C- A!/( luggweig$t ) S.,( luggweig$t )
IN-O (average4 sum)
2(O, s&oo*9
W(I-0= A ?Average=?4 average4
A ?Sum =?4 sum9
The list output is+
The S00C- clause contains t"o aggregate e/pressions for calculating the aerage and sum of
the field .)((W0*(6T from database table SB11U! The target fields are called average and
sum!
)sing aliases+
(0PO(- demoEselectEas9
)A-A= B0/IN O2 luggage4
average -7P0 p )0CI,AS B4
sum -7P0 p )0CI,AS B4
0N) O2 luggage9
S00C- A!/( luggweig$t ) AS average S.,( luggweig$t ) AS sum
IN-O CO((0SPON)IN/ 2I0)S O2 luggage
2(O, s&oo*9
W(I-0= A ?Average=?4 luggage-average4
A ?Sum =?4 luggage-sum9
The list output is+
This e/ample has the same effect as the preious one! The onl$ difference is that a structure is
used as the target area instead of indiidual fields# and that the names of the structure
components are used as aliases in the S00C- clause!
Specif%ing )ata&ase -a&les
The 2(O, clause determines the database tables from "hich the data specified in the S00C-
clause is read! 3ou can specif$ either a single table or more than one table# lin-ed using inner or
outer 2oins! The names of database tables ma$ be specified staticall$ or d$namicall$# and $ou can
use alias names! 3ou can also use the 2(O, clause to b$pass the SAP buffer and restrict the
number of lines to be read from the database!
ABAP Programming (BC-ABA) 4F>
K&atabase tablei can e8uall$ mean an ABAP &ictionar$ ie"! A ie" lin-s t"o or more database
tables in the ABAP &ictionar$# proiding a static 2oin that is aailable across the s$stem! 3ou can
specif$ the name of a ie" "hereer the name of a database table ma$ occur in the 2(O, clause!
The 2(O, clause has t"o parts# one for specif$ing database tables# and one for other additions
that control database access+
S0.0CT !!! ,%1' tables options !!!
*n ta&les# $ou specif$ the names of database tables and define 2oins!
*n options# $ou can specif$ the follo"ing+
7 C.*0NT SP0C*,*0& to disable automatic client handling
7 B3PASS*N( B),,0% to disable data buffering
7 )P T1 n %1WS to restrict the absolute number of ro"s in the selection to n
7 ,or more details about these additions# refer to the -e$"ord documentation!
Specif%ing )ata&ase -a&les Staticall%
To specif$ the name of a database table staticall$# use the follo"ing for ta&les+
S0.0CT !!! ,%1' dbtab XAS tabaliasY options !!!
The database table d&ta& must e/ist in the ABAP &ictionar$! The ASaddition allo"s $ou to
specif$ an alternatie name ta&alias that $ou can then use in the S00C-< 2(O,# W+0(0# and
/(O.P B7clauses!
Specif%ing )ata&ase -a&les )%namicall%
To specif$ the name of a database table d$namicall$# use the follo"ing for ta&les+
S0.0CT !!! ,%1' (name) options !!!
The field name must contain the name of a database table in the ABAP &ictionar$! The table
name must be "ritten in uppercase! When $ou specif$ the name of a database table d$namicall$#
$ou cannot use an empt$ IN-O clause to read all of the columns into the "or- area d&ta&! *t is
also not possible to use alternatie table names!
Specif%ing -wo or ,ore )ata&ase -a&les as an Inner Yoin
3ou can read from more than one table in a single S00C-statement# such that the data in the
tables all has to meet the same conditions# using the follo"ing 2oin e/pression+
S0.0CT !!!
!!!
,%1' tab X*NN0%Y a1*N dbtab XAS aliasY 1N cond options
!!!
"here d&ta& is a single database table and ta& is either a table or another 2oin e/pression! The
database tables can be specified staticall$ or d$namicall$! 3ou ma$ also use aliases! A 2oin
e/pression lin-s each line of ta& "ith the lines in d&ta& that meet the condition cond! This means
that there is al"a$s one or more lines from the right-hand table that is lin-ed to each line from
the left-hand table b$ the 2oin! *f d&ta& does not contain an$ lines that meet the condition cond#
the line from ta& is not included in the selection!
Specif%ing -wo or ,ore )ata&ase -a&les as a eft Outer Yoin
*n an inner 2oin# a line from the left-hand database table or 2oin is onl$ included in the selection if
there is one or more lines in the right-hand database table that meet the ON condition cond! The
ABAP Programming (BC-ABA) 4F?
left outer 2oin# on the other hand# reads lines from the left-hand database table or 2oin een if
there is no corresponding line in the right-hand table!
S0.0CT!!!
!!!
,%1' tab .0,T X1)T0%Y a1*N dbtab XAS aliasY 1N cond
options
!!!
05amples
Specif$ing a database table staticall$+
(0PO(- demoEselectEstaticEdata&ase9
)A-A wa -7P0 scarr9
S00C- U
IN-O wa
2(O, scarr .P -O D (OWS9
W(I-0= A wa-carrid4 wa-carrname9
0N)S00C-9
The list output is+
The s$stem reads four lines from the database table SCA%%!
Specif$ing a database table d$namicall$+
(0PO(- demoEselectEd%namicEdata&ase9
)A-A wa -7P0 scarr9
)A-A name(8@) -7P0 c !A.0 ?SCA((?9
S00C- U
IN-O wa
2(O, (name) CI0N- SP0CI2I0)
W+0(0 mandt F ?@@@?9
W(I-0= A wa-carrid4 wa-carrname9
0N)S00C-9
A condition for the 'AN&T field is allo"ed# since the e/ample uses the CI0N- SP0CI2I0)
option! *f name had contained the alue Jscarr= instead of JSCA%%=# a runtime error "ould hae
occurred!
*nner 2oin+
(0PO(- demoEselectEinnerE3oin9
)A-A= B0/IN O2 wa4
carrid -7P0 spfli-carrid4
connid -7P0 spfli-connid4
fldate -7P0 sflig$t-fldate4
&oo*id -7P0 s&oo*-&oo*id4
0N) O2 wa4
ita& I"0 SO(-0) -AB0 O2 wa
WI-+ .NIW.0 "07 carrid connid fldate &oo*id9
S00C- p_carrid p_connid f_fldate &_&oo*id
IN-O CO((0SPON)IN/ 2I0)S O2 -AB0 ita&
2(O, ( ( spfli AS p
INN0( YOIN sflig$t AS f ON p_carrid F f_carrid AN)
p_connid F f_connid )
INN0( YOIN s&oo* AS & ON &_carrid F f_carrid AN)
&_connid F f_connid AN)
&_fldate F f_fldate )
W+0(0 p_cit%from F ?2(AN"2.(-? AN)
p_cit%to F ?N0W 7O("? AN)
f_seatsma5 N f_seatsocc9
ABAP Programming (BC-ABA) 4F@
OOP A- ita& IN-O wa9
A- N0W fldate9
W(I-0= A wa-carrid4 wa-connid4 wa-fldate9
0N)A-9
W(I-0 A wa-&oo*id9
0N)OOP9
This e/ample lin-s the columns CA%%*&# C1NN*&# ,.&AT0# and B11U*& of the table SP,.*#
S,.*(6T# and SB11U# and creates a list of boo-ing numbers for all flights from ,ran-furt to
Ne" 3or- that are not full$ boo-ed! An alias name is assigned to each table!
.eft outer 2oin+
(0PO(- demoEselectEleftEouterE3oin9
)A-A= B0/IN O2 wa4
carrid -7P0 scarr-carrid4
carrname -7P0 scarr-carrname4
connid -7P0 spfli-connid4
0N) O2 wa4
ita& I"0 SO(-0) -AB0 O2 wa
WI-+ NON-.NIW.0 "07 carrid9
S00C- s_carrid s_carrname p_connid
IN-O CO((0SPON)IN/ 2I0)S O2 -AB0 ita&
2(O, scarr AS s
02- O.-0( YOIN spfli AS p ON s_carrid F p_carrid AN)
p_cit%from F ?2(AN"2.(-?9
OOP A- ita& IN-O wa9
W(I-0= A wa-carrid4 wa-carrname4 wa-connid9
0N)OOP9
The output might loo- li-e this+
The e/ample lin-s the columns CA%%*&# CA%%NA'0# and C1NN*& of the tables SCA%% and
SP,.* using the condition in the left outer 2oin that the airline must fl$ from ,ran-furt! All other
airlines hae a null alue in the C1NN*& column in the selection!
*f the left outer 2oin is replaced "ith an inner 2oin# the list loo-s li-e this+
1nl$ lines that fulfill the ON condition are included in the selection!
Selecting ines
The W+0(0 clause restricts the number of lines selected b$ specif$ing conditions that must be
met!
ABAP Programming (BC-ABA) 4FB
As "ell as in the S00C- statement# the W+0(0 clause is also used in the OP0N C.(SO(4
.P)A-0# and )00-0 statements! The general form of the W+0(0 clause is+
S0.0CT!!! W60%0 cond!!!
The cond conditions in the W+0(0 clause can be comparisons or a series of other special
e/pressions! 3ou can combine a series of conditions into a single condition in the W+0(0 clause!
Conditions ma$ also be programmed d$namicall$!
The conditions cond in the W+0(0 clause are often li-e logical e/pressions# but not identical#
since the s$nta/ and semantics follo" that of Standard SC.! *n the conditions in the W+0(0
clause# $ou name columns using a field name as in the S00C- clause! *n the follo"ing
descriptions# s al"a$s represents a column of one of the database tables named in the 2(O,
clause! The result of a condition ma$ be true# false# or un-no"n! A line is onl$ selected if the
condition is true for it! A condition is un-no"n if one of the columns inoled contains a null alue!
Comparisons for All -%pes
To compare the alue of a column of an$ data t$pe "ith another alue# use the follo"ing+
S0.0CT!!! W60%0 s operator f!!!
f can be another column in a database table from the 2(O, clause# a data ob2ect# or a scalar
sub8uer$!
3ou can use the follo"ing e/pressions for the relational operator+
operator 'eaning
0W 08uals
F 08uals
N0 &oes not e8ual
VN &oes not e8ual
NV &oes not e8ual
- less than
V less than
0 .ess than or e8ual to
VF .ess than or e8ual to
/- greater than
N greater than
/0 (reater than or e8ual to
NF (reater than or e8ual to
The alues of the operands are conerted if necessar$! The conersion ma$ be dependent on the
platform and codepage!
!alues in Intervals
To find out "hether the alue of a column lies "ithin a particular interal# use+
S0.0CT!!! W60%0 s N1T B0TW00N f
1
AN& f
4
!!!
The condition is true if the alue of column s is XnotY bet"een the alues of the data ob2ects f
8

and f
B
! 3ou cannot use B0TW00N in the ONcondition of the 2(O, clause!
Comparing Strings
To find out "hether the alue of a column matches a pattern# use+
ABAP Programming (BC-ABA) 4FD
S0.0CT!!! W60%0 s N1T .*U0 f X0SCAP0 hY! !!
The condition is true if the alue of the column s matches Xdoes not matchY the pattern in the
data ob2ect f! 3ou can onl$ use this test for te/t fields! The data t$pe of the column must be
alphanumeric! f must hae data t$pe c!
3ou can use the follo"ing "ildcard characters in f+
7 R for a se8uence of an$ characters (including spaces)!
7 S for a single character!
,or e/ample# ABCS0,(R matches the strings ABC/0,(/$9 and ABC/0,(# but not ABC0,(/$9! *f
$ou "ant to use the t"o "ildcard characters e/plicitl$ in the comparison# use the 0SCAP0 option!
0SCAP0 $ specifies an escape s$mbol $! *f preceded b$ $# the "ildcards and the escape s$mbol
itself lose their usual function "ithin the pattern f! The use of S and R corresponds to Standard
SC. usage! .ogical e/pressions else"here in ABAP use other "ildcard characters (5 and L)!
3ou cannot use I"0 in the ON condition of the 2(O, clause!
C$ec*ing ists of !alues
To find out "hether the alue of a column is contained in a list of alues# use+
S0.0CT!!! W60%0 s N1T *N (f
1
#!!!!!!# f
n
)!!!
The condition is true if the alue of column s is XnotY in the list f
8
\ f
n
!
C$ec*ing Su&1ueries
To find out "hether the alue of a column is contained in a scalar sub8uer$# use+
S0.0CT!!! W60%0 s N1T *N sub8uer$! !!
The condition is true if the alue of ]sG is XnotY contained in the results set of the scalar sub8uer$
su&1uer%!
To find out "hether the selection of a sub8uer$ contains lines at all# use+
S0.0CT!!! W60%0 N1T 0_*STS sub8uer$! !!
This condition is true if the result set of the sub8uer$ su&1uer%contains at least one XnoY line!
The sub8uer$ does not hae to be scalar!
3ou cannot chec- a sub8uer$ in the ONcondition of the 2(O, clause!
C$ec*ing Selection -a&les
To find out "hether the alue of a column satisfies the conditions in a selection table# use+
S0.0CT!!! W60%0 s N1T *N seltab! !!
The condition is true if the alue of s Xdoes notY satisf$ the conditions stored in selta&! selta&
can be either a real selection table or a (AN/0S table! 3ou cannot chec- a selection table in the
ON condition of the 2(O, clause!
C$ec*ing for Null !alues
To find out "hether the alue of a column is null# use+
S0.0CT!!! W60%0 s *S N1T N)..! !!
The condition is true if the alue of s is XnotY null!
Negating Conditions
To negate the result of a condition# use+
S0.0CT!!! W60%0 N1T cond!!!
The condition is true if cond is false# and false if cond is true! The result of an un-no"n condition
remains un-no"n "hen negated!
in*ing Conditions
3ou can combine t"o conditions into one using the AN) and O(operators+
S0.0CT!!! W60%0 cond
1
AN& cond
4
!!!
This condition is true if ]cond
8
G and ]cond
B
G are true!
S0.0CT!!! W60%0 cond
1
1% cond
4
!!!
This condition is true if one or both of ]cond
8
G and ]cond
B
G are true!
N1T ta-es priorit$ oer AN)# and AN) ta-es priorit$ oer O(! 6o"eer# $ou can also control the
processing se8uence using parentheses!
)%namic Conditions
To specif$ a condition d$namicall$# use+
S0.0CT!!! W60%0 (itab)!!!
"here ita& is an internal table "ith line t$pe c and ma/imum length B4 characters! All of the
conditions listed aboe e/cept for selection tables# can be "ritten into the lines of ita&! 6o"eer#
$ou ma$ onl$ use literals# and not the names of data ob2ects! The internal table ita& can also be
left empt$!
*f $ou onl$ "ant to specif$ a part of the condition d$namicall$# use+
S0.0CT!!! W60%0 cond AN& (itab)!!!
ABAP Programming (BC-ABA) 4FE
3ou cannot lin- a static and a d$namic condition using O(!
3ou ma$ onl$ use d$namic conditions in the W+0(0 clause of the S00C- statement!
-a&ular Conditions
The W+0(0 clause of the S00C- statement has a special ariant that allo"s $ou to derie
conditions from the lines and columns of an internal table+ This ariant is as follo"s+
S0.0CT!!! ,1% A.. 0NT%*0S *N itab W60%0 cond!!!
cond ma$ be formulated as described aboe! *f $ou specif$ a field of the internal table ita& as an
operand in a condition# $ou address all lines of the internal table! The comparison is then
performed for each line of the internal table! ,or each line# the s$stem selects the lines from the
database table that satisf$ the condition! The result set of the S00C- statement is the union
of the indiidual selections for each line of the internal table! &uplicate lines are automaticall$
eliminated from the result set! *f ita& is empt$# the addition 2O( A 0N-(I0S is disregarded#
and all entries are read!
The internal table ita& must hae a structured line t$pe# and each field that occurs in the
condition cond must be compatible "ith the column of the database "ith "hich it is compared! &o
not use the operators I"0# B0-W00N andIN in comparisons using internal table fields! 3ou ma$
not use the O()0( B7 clause in the same S0.0CT statement!
3ou can use the option 2O( A 0N-(I0Sto replace nested select loops b$ operations on
internal tables! This can significantl$ improe the performance for large sets of selected data!
Conditions in the W+0(0 clause+
!!! W60%0 carrid H I)AI!
This condition is true if the column CA%%*& has the contents )A!
!!! W60%0 num (0 1?!
This condition is true if the column N)' contains numbers greater than or e8ual to 1?!
!!! W60%0 cit$from N0 I,%ANU,)%TI!
This condition is true if the column C*T3,%1' does not contain the string ,%ANU,)%T!
!!! W60%0 num B0TW00N 1? AN& >?!
This condition is true if the column N)' contains numbers bet"een 1? and >?!
!!! W60%0 num N1T B0TW00N 1 AN& EE!
This condition is true if the column N)' contains numbers not bet"een 1 and EE!
!!! W60%0 name N1T B0TW00N IAI AN& I6I!
This condition is true if the column NA'0 is one character long and its contents are not bet"een
A and 6!
!!! W60%0 cit$ .*U0 IRto"nRI!
This condition is true if the column C*T3 contains a string containing the pattern Jto"n=!
!!! W60%0 name N1T .*U0 ISnRI!
This condition is true if the column NA'0 contains a alue "hose second character is not Jn=!
!!! W60%0 funcname .*U0 I0&*TeSRI 0SCAP0 IeI!
This condition is true if the contents of the column ,)NCNA'0 begin "ith 0&*TS!
!!! W60%0 cit$ *N (IB0%.*NI# IN0W 31%UI# I.1N&1NI)!
This condition is true if the column C*T3 contains one of the alues B0%.*N# N0W 31%U# or
.1N&1N!
!!! W60%0 cit$ N1T *N (I,%ANU,)%TI# I%1'I)!
This condition is true if the column C*T3 does not contain the alues ,%ANU,)%T or %1'0!
!!! !!!!!!!W60%0 ( N)'B0% H IFFF1I 1% N)'B0% H IFFF4I ) AN&
This condition is true if the column N)'B0% contains the alue FFF1 or FFF4 and the column
C1)NT%3 contains neither , nor )SA!
&$namic conditions
(0PO(- demoEselectEd%namicEconditions9
)A-A= cond(IB) -7P0 c4
ita& I"0 -AB0 O2 cond9
PA(A,0-0(S= cit%8(8@) -7P0 c4 cit%B(8@) -7P0 c9
)A-A wa -7P0 spfli-cit%from9
CONCA-0NA-0 ?CI-72(O, F ??? cit%8 ???? IN-O cond9
APP0N) cond -O ita&9
CONCA-0NA-0 ?O( CI-72(O, F ??? cit%B ???? IN-O cond9
ABAP Programming (BC-ABA) 41F
APP0N) cond -O ita&9
CONCA-0NA-0 ?O( CI-72(O, F ??? ?B0(IN? ???? IN-O cond9
APP0N) cond -O ita&9
OOP A- ita& IN-O cond9
W(I-0 cond9
0N)OOP9
S"IP9
S00C- cit%from
IN-O wa
2(O, spfli
W+0(0 (ita&)9
W(I-0 A wa9
0N)S00C-9
*f the user enters ,%ANU,)%T and B0%.*N for the parameters cit%8 and cit%B on the selection
screen# the list displa$ is as follo"s+
The first three lines sho" the contents of the internal table ita&! 0/actl$ the corresponding
table lines are selected!
Tabular conditions
(0PO(- demoEselectEforEallEentriesE89
)A-A= B0/IN O2 line4
carrid -7P0 spfli-carrid4
connid -7P0 spfli-connid4
cit%from -7P0 spfli-cit%from4
cit%to -7P0 spfli-cit%to4
0N) O2 line4
ita& I"0 -AB0 O2 line9
line-cit%from F ?2(AN"2.(-?9
line-cit%to F ?B0(IN?9
APP0N) line -O ita&9
line-cit%from F ?N0W 7O("?9
line-cit%to F ?SAN 2(ANCISCO?9
APP0N) line -O ita&9
S00C- carrid connid cit%from cit%to
IN-O CO((0SPON)IN/ 2I0)S O2 line
2(O, spfli
2O( A 0N-(I0S IN ita&
W+0(0 cit%from F ita&-cit%from AN) cit%to F ita&-cit%to9
W(I-0= A line-carrid4 line-connid4 line-cit%from4 line-cit%to9
0N)S00C-9
The output loo-s something li-e this+
This e/ample selects all lines in "hich the follo"ing conditions are fulfilled+
7 The C*T3,%1' column contains ,%ANU,)%T and the C*T3T1 column contains
B0%.*N!
ABAP Programming (BC-ABA) 411
7 The C*T3,%1' column contains N0W 31%U and the C*T3T1 column contains
SAN ,%ANC*SC1!
Tabular conditions
(0PO(- demoEselectEforEallEentriesEB9
)A-A= ta&Espfli -7P0 -AB0 O2 spfli4
ta&Esflig$t -7P0 SO(-0) -AB0 O2 sflig$t
WI-+ .NIW.0 "07 ta&leEline4
wa I"0 IN0 O2 ta&Esflig$t9
S00C- carrid connid
IN-O CO((0SPON)IN/ 2I0)S O2 -AB0 ta&Espfli
2(O, spfli
W+0(0 cit%from F ?N0W 7O("?9
S00C- carrid connid fldate
IN-O CO((0SPON)IN/ 2I0)S O2 -AB0 ta&Esflig$t
2(O, sflig$t
2O( A 0N-(I0S IN ta&Espfli
W+0(0 carrid F ta&Espfli-carrid AN)
connid F ta&Espfli-connid9
OOP A- ta&Esflig$t IN-O wa9
A- N0W connid9
W(I-0= A wa-carrid4 wa-connid9
0N)A-9
W(I-0= A wa-fldate9
0N)OOP9
The output loo-s something li-e this+
This e/ample selects flight data from S,.*(6T for all connections for "hich the column
C*T3,%1' in table SP,.* has the alue N0W 31%U! 3ou could also use a 2oin in the 2(O,clause
to select the same data in a single S00C-statement!
/rouping ines
The /(O.P-B7 clause summari9es seeral lines from the database table into a single line of the
selection!
ABAP Programming (BC-ABA) 414
The /(O.P-B7 clause allo"s $ou to summari9e lines that hae the same content in particular
columns! Aggregate functions are applied to the other columns! 3ou can specif$ the columns in the
/(O.P-B7 clause either staticall$ or d$namicall$!
Specif%ing Columns Staticall%
To specif$ the columns in the /(O.P-B7 clause staticall$# use+
S0.0CT lines s
1
XAS a
1
Y s
4
XAS a
4
Y!!!
agg s
m
XAS a
m
Y agg s
n
XAS a
n
Y!!!
!!!
(%1)P B3 s
1
s
4
!!!!
To use the /(O.P-B7 clause# $ou must specif$ all of the releant columns in the S00C- clause!
*n the /(O.P-B7 clause# $ou list the field names of the columns "hose contents must be the
same! 3ou can onl$ use the field names as the$ appear in the database table! The alternatie
column names a
1
a
4
\ from the S00C- clause are not allo"ed!
All columns of the S00C- clause that are not listed in the /(O.P-B7 clause must be included in
aggregate functions! This defines ho" the contents of these columns is calculated "hen the lines
are summari9ed!
Specif%ing Columns )%namicall%
To specif$ the columns in the /(O.P-B7 clause d$namicall$# use+
!!! (%1)P B3 (itab)!!!
"here ita& is an internal table "ith line t$pe c and ma/imum length B4 characters containing the
column names ]s
1
s
4
!!!
ABAP Programming (BC-ABA) 41:
(0PO(- demoEselectEgroupE&%9
)A-A= carrid -7P0 sflig$t-carrid4
minimum -7P0 p )0CI,AS B4
ma5imum -7P0 p )0CI,AS B9
S00C- carrid ,IN( price ) ,AX( price )
IN-O (carrid4 minimum4 ma5imum)
2(O, sflig$t
/(O.P B7 carrid9
W(I-0= A carrid4 minimum4 ma5imum9
0N)S00C-9
The output loo-s something li-e this+
The lines in the database table S,.*(6T that hae the same alue in the column CA%%*& are
summari9ed! The smallest and largest alues of P%*C0 are determined for each group and placed
in the summari9ed line!
Selecting /roups of ines
The +A!IN/ clause uses conditions to restrict the number of groups selected!
3ou can onl$ use the +A!IN/ clause in con2unction "ith the /(O.P-B7clause!
To select line groups# use+
S0.0CT lines s
1
XAS a
1
Y s
4
XAS a
4
Y!!!
agg s
m
XAS a
m
Y agg s
n
XAS a
n
Y!!!
!!!
(%1)P B3 s
1
s
4
!!!!
6AA*N( cond!
The conditions cond that $ou can use in the +A!IN/ clause are the same as those in the S0.0CT
clause# "ith the restrictions that $ou can onl$ use columns from the S00C- clause# and not all of
the columns from the database tables in the 2(O,clause! *f $ou use an inalid column# a runtime
error results!
1n the other hand# $ou can enter aggregate e/pressions for all columns read from the database
table that do not appear in the /(O.P-B7 clause! This means that $ou can use aggregate
e/pressions# een if the$ do not appear in the S00C- clause! 3ou cannot use aggregate
e/pressions in the conditions in the W+0(0 clause!
As in the W+0(0 clause# $ou can specif$ the conditions in the +A!IN/ clause as the contents of
an internal table "ith line t$pe c and length B4!
ABAP Programming (BC-ABA) 41>
(0PO(- demoEselectEgroupE&%E$aving9
)A-A wa -7P0 sflig$t9
S00C- connid
IN-O wa-connid
2(O, sflig$t
W+0(0 carrid F ?+?
/(O.P B7 connid
+A!IN/ S.,( seatsocc ) N C@@9
W(I-0= A wa-carrid4 wa-connid9
0N)S00C-9
This e/ample selects groups of lines from database table S,.*(6T "ith the alue J.6= for
CA%%*& and identical alues of C1NN*&! The groups are then restricted further b$ the
condition that the sum of the contents of the column S0ATS1CC for a group must be greater
than :FF!
Specif%ing a Sort Order
The O()0( B7 clause sorts the lines in the selection according to the contents of their columns!
*f $ou do not use the O()0( B7 clause# the se8uence of the lines in the selection is
indeterminate# and can ar$ each time the S00C-statement is e/ecuted! 3ou can sort the
selection b$ an$ column (not necessaril$ those of the primar$ -e$)# and specif$ the columns either
staticall$ or d$namicall$!
Sorting &% t$e Primar% "e%
To sort the selection set in ascending order b$ the primar$ -e$# use the follo"ing+
S0.0CT lines L
!!!
1%&0% B3 P%*'A%3 U03!
This sorting method is onl$ possible if $ou use an asteris- (U) in the S00C- clause to select all
columns! ,urthermore# it onl$ "or-s if $ou specif$ a single database table in the 2(O, clause!
3ou cannot use ie"s or 2oins# since neither has a defined primar$ -e$!
Sorting &% an% Columns
To sort the lines in the selection set b$ an$ columns# use the follo"ing+
S0.0CT!!!
!!!
1%&0% B3 s
8
PASC0N)IN/O)0SC0N)IN/Q
s
B
PASC0N)IN/O)0SC0N)IN/Q999
The lines are sorted b$ the columns s
8
# s
B
# !!! 3ou determine the direction of the sort using one of
the additions ASC0N)IN/ or )0SC0N)IN/! The default is ascending order! The sort order
depends on the se8uence in "hich $ou list the columns!
3ou can use either the names of the columns as specified in the S00C- clause or their alias
names! 3ou ma$ onl$ use columns that occur in the S00C- clause! B$ using alias names for
aggregate e/pressions# $ou can use them as sort fields!
Specif%ing t$e Columns )%namicall%
To specif$ the columns in the O()0( B7 clause d$namicall$# use+
ABAP Programming (BC-ABA) 41?
S0.0CT!!!
!!!
1%&0% B3 (itab)!
"here ita& is an internal table "ith line t$pe c and ma/imum length B4 characters containing the
column names s
8
s
B
!!!!!
(0PO(- demoEselectEorderE&%9
)A-A= B0/IN O2 wa4
carrid -7P0 sflig$t-carrid4
connid -7P0 sflig$t-connid4
min -7P0 i4
0N) O2 wa9
S00C- carrid connid ,AX( seatsocc ) AS min
IN-O CO((0SPON)IN/ 2I0)S O2 wa
2(O, sflig$t
/(O.P B7 carrid connid
O()0( B7 carrid min )0SC0N)IN/9
W(I-0= A wa-carrid4 wa-connid4 wa-min9
0N)S00C-9
The output loo-s something li-e this+
The lines of the database table S,.*(6T are grouped according to the columns CA%%*& and
C1NN*&# and the s$stem finds the minimum alue of the column S0ATS1CC for each group! The
selection is sorted in ascending order according to CA%%*& and in descending order according to
this minimum alue! 6ere# the alternatie name min is used for the aggregate e/pression!
Su&1ueries
A sub8uer$ is a special S00C- statement containing a sub8uer$ "ithin particular conditions of
the W+0(0 or +A!IN/ clauses! 3ou cannot use them in the ONcondition of the 2(O, clause!
Their s$nta/ is+
( S00C- result
2(O, source
PW+0(0 conditionQ
P/(O.P B7 fieldsQ
P+A!IN/ condQ )
As $ou can see# this s$nta/ is restricted in comparison "ith the full S00C- statement# since it
contains no IN-O or O()0( B7 clause!
3ou can nest sub8ueries# that is# the W+0(0 and +A!IN/ clauses of sub8ueries can themseles
contain a sub8uer$! When a nested sub8uer$ in the W+0(0 clause uses fields from the preious
8uer$# it is -no"n as a correlated 8uer$! The sub8uer$ is then processed for each line of the
database table that satisfies the preious condition!
Scalar su&1ueries
*n a scalar sub8uer$# the selection in the S00C- clause is restricted to one column or aggregate
e/pression! The e/pression result of the S00C- clause is+
ABAP Programming (BC-ABA) 41@
999 line PaggQ s
3ou can onl$ enter a single field in the S00C- clause!
Su&1ueries in Conditions
A non-scalar sub8uer$ can onl$ hae a W+0(0 or +A!IN/ clause in the PNO-Q 0XIS-S
Vsu&1uer%N condition!
This condition is true if the result set of the sub8uer$ contains at least one XnoY line!
Scalar Su&1ueries in Conditions
As "ell as in the aboe condition# $ou can also use scalar sub8ueries in further conditions!
C$ec*ing a !alue of t$e Su&1uer%
The follo"ing is a possible condition "ith scalar sub8ueries+
999 s NO- IN su&1uer%999
The condition is true if the alue of ]sG is XnotY contained in the results set of the scalar sub8uer$
su&1uer%!
Scalar Su&1ueries in Comparisons
The other conditions can all be comparisons "hose operators are contained in the table for
comparisons "ith all t$pes in the W60%0 clause! There is a difference# depending on "hether the
sub8uer$ selection contains one or more lines!
Single-ine Su&1uer%
*f the selection in the sub8uer$ onl$ contains one line# use the follo"ing for the comparison+
999 s operator su&1uer%999
The alue of s is compared "ith the alue in the selection from the sub8uer$! The condition is
either true of false!
The sub8uer$ ma$ onl$ contain one line# other"ise a runtime error occurs! 3ou can generate a
single-line sub8uer$ b$ specif$ing the complete -e$ in the W+0(0 clause!
,ultiple-ine Su&1uer%
*f the selection from the sub8uer$ returns more than one line# $ou must "rite the comparison as
follo"s+
999 s operator AOAN7OSO,0 su&1uer%999
*f $ou use the A prefi/# the condition is onl$ true if the comparison is true for all lines in the
sub8uer$! *f $ou use the AN7 or SO,0 prefi/# the condition is onl$ true if the comparison is true
for at least one line of the sub8uer$! The e8ualit$ operator (F or 0W) in con2unction "ith AN7 or
SO,0 has the same effect as the INoperator for chec-ing a alue!
*f the selection from the sub8uer$ contains seeral lines and $ou do not use the A# AN7# or
SO,0 e/pression# a runtime error occurs!
Correlated# non-scalar sub8uer$+
(0PO(- demoEselectEsu&1uer%E89
)A-A= nameEta& -7P0 -AB0 O2 scarr-carrname4
name I"0 IN0 O2 nameEta&9
S00C- carrname
IN-O -AB0 nameEta&
2(O, scarr
W+0(0 0XIS-S ( select U
2(O, spfli
W+0(0 carrid F scarr_carrid AN)
cit%from F ?N0W 7O("? )9
OOP A- nameEta& IN-O name9
W(I-0= A name9
0N)OOP9
This e/ample selects all lines from database table SCA%% for airlines that fl$ from Ne" 3or-!
Scalar sub8uer$+
(0PO(- demoEselectEsu&1uer%EB9
)A-A= carrEid -7P0 spfli-carrid !A.0 ?+?4
connEid -7P0 spfli-connid !A.0 ?@D@@?9
)A-A= cit% -7P0 sgeocit%-cit%4
lati -7P0 p )0CI,AS B4
longi -7P0 p )0CI,AS B9
ABAP Programming (BC-ABA) 41B
S00C- SIN/0 cit% latitude longitude
IN-O (cit%4 lati4 longi)
2(O, sgeocit%
W+0(0 cit% IN ( select cit%from
2(O, spfli
W+0(0 carrid F carrEid AN)
connid F connEid )9
W(I-0= cit%4 lati4 longi9
This e/ample reads the latitude and longitude of the departure cit$ of flight .6 >F4 from
database table S(01C*T3!
Scalar sub8uer$+
(0PO(- demoEselectEsu&1uer%EC9
)A-A= wa -7P0 sflig$t4
plane I"0 wa-planet%pe4
seats I"0 wa-seatsma59
S00C- carrid connid planet%pe seatsma5 ,AX( seatsocc )
IN-O (wa-carrid4 wa-connid4 wa-planet%pe4
wa-seatsma54 wa-seatsocc)
2(O, sflig$t
/(O.P B7 carrid connid planet%pe seatsma5
O()0( B7 carrid connid9
W(I-0= A wa-carrid4
wa-connid4
wa-planet%pe4
wa-seatsma54
wa-seatsocc9
+I)0= wa-carrid4 wa-connid4 wa-seatsma59
0N)S00C-9
A- IN0-S00C-ION9
WIN)OW S-A(-IN/ A- DG C 0N)IN/ A- JG 8C9
W(I-0= ?Alternative Plane -%pes?4
?for?4 wa-carrid4 wa-connid9
.IN09
S00C- planet%pe seatsma5
IN-O (plane4 seats)
2(O, saplane AS plane
W+0(0 seatsma5 V wa-seatsma5 AN)
seatsma5 NF A ( select seatsocc
2(O, sflig$t
W+0(0 carrid F wa-carrid AN)
connid F wa-connid )
O()0( B7 seatsma59
W(I-0= A plane4 seats9
0N)S00C-9
The list output# after double-clic-ing a line# loo-s li-e this+
ABAP Programming (BC-ABA) 41D
The detail list displa$s all aircraft t$pes that hae fe"er seats than the currentl$-allocated
aircraft t$pe# but enough to carr$ all of the passengers currentl$ boo-ed on the flight!
.sing a Cursor to (ead )ata
*n the normal S00C- statement# the data from the selection is al"a$s read directl$ into the
target area specified in the IN-O clause during the S00C- statement! When $ou use a cursor
to read data# $ou decouple the process from the S00C- statement! To do this# $ou must open a
cursor for a S00C- statement! After"ards# $ou can place the lines from the selection into a flat
target area!
Opening and Closing Cursors
To open a cursor for a S00C- statement# use the follo"ing+
1P0N C)%S1% XW*T6 61.&Y c ,1% S0.0CT result
,%1' source
XW60%0 conditionY
X(%1)P B3 fieldsY
X6AA*N( condY
X1%&0% B3 fieldsY!
3ou must first hae declared the cursor c using the )A-Astatement and the special data t$pe
C)%S1%! 3ou can use all clauses of the S00C-statement apart from the IN-O clause!
,urthermore# $ou can onl$ formulate the S0.0CT clause so that the selection consists of more
than one line! This means that $ou ma$ not use the SIN/0 addition# and that the column
selection ma$ not contain onl$ aggregate e/pressions!
An open cursor points to an internal handler# similarl$ to a reference ariable pointing to an
ob2ect! 3ou can reassign cursors so that more than one points to the same handler! *n a
,O!0statement# the target cursor adopts all of the attributes of the source cursor# namel$ its
position# and all of the clauses in the 1P0N C)%S1% statement!
3ou can also open more than one cursor in parallel for a single database table! *f a cursor is
alread$ open# $ou cannot reopen it! To close a cursor e/plicitl$# use the follo"ing statement+
C.1S0 C)%S1% c!
3ou should use this statement to close all cursors that $ou no longer re8uire# since onl$ a limited
number of cursors ma$ be open simultaneousl$! With one e/ception# a database .)W is concluded
"hen $ou close a cursor either e/plicitl$ or implicitl$! The WI-+ +O)addition in the OP0N
C.(SO( statement allo"s $ou to preent a cursor from being closed "hen a database commit
occurs in Natie SC.!
(eading )ata
An open cursor is lin-ed to a multiple-line selection in the database table! To read the data into a
target area in the ABAP program# use the follo"ing+
,0TC6 N0_T C)%S1% c *NT1 target!
This "rites one line of the selection into the target area target# and the cursor moes one line
further in the selection set! The 20-C+statement decouples the *NT1 clause from the other
clauses in the S00C- statement! 3ou can use all IN-O clauses of the S00C-statement! The
statement reads the re8uired lines to fill the target area of the IN-O clause and moes the
cursor to the ne/t line!
ABAP Programming (BC-ABA) 41E
*f not all lines in the selection hae been read# s%-su&rc is set to F< other"ise# it is set to >!
After a 20-C+ statement# the s$stem field s%-d&cntcontains the number of lines read for the
corresponding cursor!
(0PO(- demoEselectEcursorE89
)A-A= c8 -7P0 cursor4
cB -7P0 cursor9
)A-A= wa8 -7P0 spfli4
waB -7P0 spfli9
)A-A= flag8(8) -7P0 c4
flagB(8) -7P0 c9
OP0N C.(SO(= c8 2O( S00C- carrid connid
2(O, spfli
W+0(0 carrid F ?+?4
cB 2O( S00C- carrid connid cit%from cit%to
2(O, spfli
W+0(0 carrid F ?A6?9
)O9
I2 flag8 N0 ?X?9
20-C+ N0X- C.(SO( c8 IN-O CO((0SPON)IN/ 2I0)S O2 wa89
I2 s%-su&rc VN @9
COS0 C.(SO( c89
flag8 F ?X?9
0S09
W(I-0= A wa8-carrid4 wa8-connid9
0N)I29
0N)I29
I2 flagB N0 ?X?9
20-C+ N0X- C.(SO( cB IN-O CO((0SPON)IN/ 2I0)S O2 waB9
I2 s%-su&rc VN @9
COS0 C.(SO( cB9
flagB F ?X?9
0S09
W(I-0= A waB-carrid4 waB-connid4
waB-cit%from4 waB-cit%to9
0N)I29
0N)I29
I2 flag8 F ?X? AN) flagB F ?X?9
0XI-9
0N)I29
0N))O9
The output loo-s something li-e this+
The database table SP,.* is read using t"o cursors# each "ith different conditions!! The
selected lines are read alternatel$ in a )O loop!
(0PO(- demoEselectEcursorEB9
)A-A c -7P0 cursor9
)A-A wa -7P0 s&oo*9
ABAP Programming (BC-ABA) 44F
OP0N C.(SO( c 2O( S00C- carrid connid fldate &oo*id smo*er
2(O, s&oo*
O()0( B7 carrid connid fldate smo*er &oo*id9
20-C+ N0X- C.(SO( c IN-O CO((0SPON)IN/ 2I0)S O2 wa9
W+I0 s%-su&rc F @9
I2 wa-smo*er F ? ?9
P0(2O(, nonsmo*er .SIN/ c9
0S0I2 wa-smo*er F ?X?9
P0(2O(, smo*er .SIN/ c9
S"IP9
0S09
0XI-9
0N)I29
0N)W+I09
2O(, nonsmo*er .SIN/ nEcur -7P0 cursor9
W+I0 wa-smo*er F ? ? AN) s%-su&rc F @9
2O(,A- COO( F G9
W(I-0= A wa-carrid4 wa-connid4 wa-fldate4 wa-&oo*id9
20-C+ N0X- C.(SO( nEcur IN-O CO((0SPON)IN/ 2I0)S O2 wa9
0N)W+I09
0N)2O(,9
2O(, smo*er .SIN/ sEcur -7P0 cursor9
W+I0 wa-smo*er F ?X? AN) s%-su&rc F @9
2O(,A- COO( F H9
W(I-0= A wa-carrid4 wa-connid4 wa-fldate4 wa-&oo*id9
20-C+ N0X- C.(SO( sEcur IN-O CO((0SPON)IN/ 2I0)S O2 wa9
0N)W+I09
0N)2O(,9
The follo"ing is an e/tract from the list displa$+
The program opens a cursor for the database table SB11U! After the first 20-C+ statement# a
subroutine is called# "hich is dependent on the contents of the S'1U0% column! The cursor is
ABAP Programming (BC-ABA) 441
passed to an interface parameter in the subroutine! The subroutines read further lines until the
contents of the S'1U0% column change! The subroutines perform different tas-s using the lines
read b$ the cursor!
(0PO(- demoEselectEcursorEC9
)A-A= waEspfli -7P0 spfli4
waEsflig$t -7P0 sflig$t4
waEsflig$tE&ac* -7P0 sflig$t9
)A-A= c8 -7P0 cursor4
cB -7P0 cursor9
OP0N C.(SO( c8 2O( S00C- U
2(O, spfli
O()0( B7 P(I,A(7 "079
OP0N C.(SO( cB 2O( S00C- U
2(O, sflig$t
O()0( B7 P(I,A(7 "079
)O9
20-C+ N0X- C.(SO( c8 IN-O waEspfli9
I2 s%-su&rc N0 @9
0XI-9
0N)I29
W(I-0= A waEspfli-carrid4 waEspfli-connid9
)O9
I2 NO- waEsflig$tE&ac* IS INI-IA9
waEsflig$t F waEsflig$tE&ac*9
C0A( waEsflig$tE&ac*9
0S09
20-C+ N0X- C.(SO( cB IN-O waEsflig$t9
I2 s%-su&rc VN @9
0XI-9
0S0I2 waEsflig$t-carrid VN waEspfli-carrid
O( waEsflig$t-connid VN waEspfli-connid9
waEsflig$tE&ac* F waEsflig$t9
0XI-9
0N)I29
0N)I29
W(I-0= A waEsflig$t-carrid4 waEsflig$t-connid4
waEsflig$t-fldate9
0N))O9
0N))O9
The output is as follo"s+
ABAP Programming (BC-ABA) 444
The program opens a cursor for each of the table SP,.* and S,.*(6T! Since both tables are
lin-ed b$ a foreign -e$ relationship# it is possible to program a nested loop b$ sorting the
selection b$ its primar$ -e$# so that the data read in the inner loop depends on the data in the
outer loop! This programming method is 8uic-er than using nested S00C- statements# since the
cursor for the inner loop does not continuall$ hae to be reopened! *f there is a control leel
change in the inner loop# the read data is buffered until the ne/t loop pass# since the cursor
cannot be reset!
Possi&le Conflicting oc*s
*f $ou are using the database s$stem &B4 for 1S;:EF# commits must ta-e place at least once a
minute# een if $ou are carr$ing out read onl$ operations# in order to release an$ loc-s on the
database that hae occurred!
.oc-s occur here not onl$ "hen using modif$ing transactions but also "ith consistent reading
from buffered# cluster and pooled tables! The database s$stem uses the isolation leel %ead
Stabilit$# "hich# "ith the help of Shared .oc-s# stops the table contents being changed "hile it is
being read!
Conflicting loc-s can# li-e Time outs and &eadloc-s# cause errors "ith &&. (&ata &efinition
.anguage) statements# for e/ample C%0AT0# A.T0% and &%1P! The$ can also slo" do"n online
reorgani9ation!
*f $ou need to -eep the position of a cursor past the commit time then $ou can use the option
WI-+ +O) of the OP0N C.(SO( statement!
The commits must be e/ecuted as database commits! 3ou can use the follo"ing Natie SC. for
this!
*, s$-dbs$s H I&B4I!
0_0C SC.!
C1''*T W1%U
0N&0_0C!
0N&*,!
*t is a good idea to build database commits li-e this into all programs "ith long read operations!
C$anging )ata
1pen SC. contains a set of statements that allo" $ou to change data in the database! 3ou can
insert# change and delete entries in database tables! 6o"eer# $ou must remember that 1pen
SC. statements do not chec- authori9ation or the consistenc$ of data in the database! The
follo"ing statements are purel$ technical means of programming database updates! The$ are to
be used "ith care# and# outside the SAP transaction concept# onl$ to be used in e/ceptional cases!
The SAP transaction concept addresses the 8uestion of database update programming in the SAP
S$stem! *t discusses the difference bet"een a database .)W and an SAP .)W# and e/plains
about SAP transactions and the SAP loc-ing concept!

*nserting .ines
Changing .ines
&eleting .ines
*nserting or Changing .ines
C1''*T W1%U and %1..BACU W1%U

Inserting ines into -a&les
The 1pen SC. statement for inserting data into a database table is+
*NS0%T *NT1 target lines!
*t allo"s $ou to insert one or more lines into the database table target! 3ou ma$ specif$ the
database table targeteither staticall$ or d$namicall$!
Specif%ing a )ata&ase -a&le
To specif$ the database table staticall$# enter the follo"ing for target+
*NS0%T *NT1 dbtab XC.*0NT SP0C*,*0&Y lines!
"here d&ta& is the name of a database table defined in the ABAP &ictionar$!
To specif$ the database table d$namicall$# enter the follo"ing for target+
*NS0%T *NT1 (name) XC.*0NT SP0C*,*0&Y lines!
"here the field name contains the name of a database table defined in the ABAP &ictionar$!
3ou can use the CI0N- SP0CI2I0) addition to disable automatic client handling!
Inserting a Single ine
To insert a single line into a database table# use the follo"ing+
ABAP Programming (BC-ABA) 44:
*NS0%T *NT1 target AA.)0S "a!
The contents of the "or- area wa are "ritten to the database table d&ta&! *t is a good idea to
define the "or- area "ith reference to the structure of the database table!
3ou can also insert single lines using the follo"ing shortened form of the INS0(- statement+
*NS0%T target ,%1' "a!
)sing 2(O, instead of !A.0 allo"s $ou to omit the IN-Oclause! Shorter still is+
*NS0%T dbtab!
*n this case# the contents of the table "or- area d&ta& are inserted into the database table "ith
the same name! 3ou must declare this table "or- area using the -AB0S statement! *n this case#
it is not possible to specif$ the name of the database table d$namicall$! Table "or- areas "ith
the same name as the database table (necessar$ before %elease >!F) should no longer be used for
the sa-e of clarit$!
Inserting Several ines
To insert seeral lines into a database table# use the follo"ing+
*NS0%T target ,%1' TAB.0 itab XACC0PT*N( &)P.*CAT0 U03SY!
This "rites all lines of the internal table ita&to the database table in one single operation! *f one
or more lines cannot be inserted because the database alread$ contains a line "ith the same
primar$ -e$# a runtime error occurs! 3ou can preent the runtime error occurring b$ using the
addition ACC0P-IN/ ).PICA-0 "07S!
Wheneer $ou "ant to insert more than one line into a database table# it is more efficient to "or-
"ith an internal table than to insert the lines one b$ one!
05amples
Adding single lines
-AB0S spfli9
)A-A wa -7P0 spfli9
wa-carrid F ?+?9
wa-cit%from F ?WAS+IN/-ON?9
999
INS0(- IN-O spfli !A.0S wa9
wa-carrid F ?.A?9
wa-cit%from F ?ON)ON?9
999
INS0(- spfli 2(O, wa9
spfli-carrid F ?+?9
spfli-cit%from F ?B0(IN?9
999
INS0(- spfli9
This program inserts a single line into the database table SP,.* using each of the three possible
ariants of the INS0(-statement!
*nstead of
*NS0%T spfli!
in the last line# $ou could also use the longer forms
*NS0%T spfli ,%1' spfli
or
*NS0%T *NT1 spfli AA.)0S spfli
here! The name SP,.* is therefore not uni8ue!
These ariations of the INS0(- addition onl$ "or- "ith table "or- areas that hae been
declared using -AB0Sand should therefore no longer be used!
)A-A= ita& -7P0 +AS+0) -AB0 O2 spfli
WI-+ .NIW.0 "07 carrid connid4
wa I"0 IN0 O2 ita&9
wa-carrid F ?.A?9 wa-connid F ?@@88?9 wa-cit%from F 999
INS0(- wa IN-O -AB0 ita&9
wa-carrid F ?+?9 wa-connid F ?8BDG?9 wa-cit%from F 999
INS0(- wa IN-O -AB0 ita&9
ABAP Programming (BC-ABA) 44>
wa-carrid F ?AA?9 wa-connid F ?DGID?9 wa-cit%from F 999
INS0(- wa IN-O -AB0 ita&9
999
INS0(- spfli 2(O, -AB0 ita& ACC0P-IN/ ).PICA-0 "07S9
I2 s%-su&rc F @9
999
0S0I2 s%-su&rc F D9
999
0N)I29
This e/ample fills a hashed table ita&and inserts its contents into the database table SP,.*! The
program e/amines the contents of s%-su&rc to see if the operation "as successful!
C$anging ines
The 1pen SC. statement for changing data in a database table is+
)P&AT0 target lines!
This statement allo"s $ou to change one or more lines in the database table target! As described
in the section *nserting Table .ines# the database table target can be specified staticall$ and
d$namicall$!
C$anging ines Column &% Column
To change certain columns in the database table# use the follo"ing for lines+
)P&AT0 target S0T set
1
set
4
!!! XW60%0 condY!
The W60%0 clause determines the lines that are to be changed! *f $ou do not specif$ a W+0(0
clause# all lines "ill be changed! The e/pressions set
8
set
B
\ are three different S0-statements
that determine the columns (set
8
changes column s
1
) to be changed# and ho" the$ are to be
changed+
7 s
1
H f
The alue in column s
1
is set to the alue f for all lines selected!
7 s
1
H s
1
5 f
The alue in column s
1
is increased b$ the alue f for all lines selected!
7 s
1
H s
1
- f
The alue in column s
1
is decreased b$ the alue f for all lines selected!
f can be a data ob2ect or a column of the database table! 3ou address the columns using their
direct names!
*f at least one line has been changed# s%-su&rc is set to F [ other"ise to >! s%-d&cnt is set to
the number of changed lines!
*f $ou use S0- statements# $ou cannot specif$ the database table d$namicall$!
Overwriting Individual ines wit$ Wor* Areas
To oer"rite a single line in a database table "ith the contents of a "or- area# use the follo"ing
for lines+
)P&AT0 target ,%1' "a!
The contents of the "or- area waoer"rite the line in the database table d&ta& that has the
same primar$ -e$! The "or- area wa must be a data ob2ect "ith at least the same length and
alignment as the line structure of the database table! The data is placed in the database table
according to the line structure of the table# and regardless of the structure of the "or- area! *t
is a good idea to define the "or- area "ith reference to the structure of the database table!
*f the database table contains a line "ith the same primar$ -e$ as specified in the "or- area# the
operation is completed successfull$ and s%-su&rc is set to F! 1ther"ise# no line is changed# and
s%-su&rc is set to >!
A shortened form of the aboe statement is+
)P&AT0 dbtab!
*n this case# the contents of the table "or- area d&ta& are used to update the database table
"ith the same name! 3ou must declare this table "or- area using the TAB.0S statement! *n this
case# it is not possible to specif$ the name of the database table d$namicall$! Table "or- areas
"ith the same name as the database table (necessar$ before %elease >!F) should no longer be
used for the sa-e of clarit$!
Overwriting Several ines .sing an Internal -a&le
To oer"rite seeral lines in a database table "ith the contents of an internal table# use the
follo"ing for lines+
)P&AT0 target ,%1' TAB.0 itab!
ABAP Programming (BC-ABA) 44?
The contents of the internal table ita&oer"rite the lines in the database table d&ta& that hae
the same primar$ -e$s! The same rules appl$ to the line t$pe of ita& as to the "or- area wa
described aboe!
*f the s$stem cannot change a line because no line "ith the specified -e$ e/ists# it does not
terminate the entire operation# but continues processing the ne/t line of the internal table!
*f all lines from the internal table are used# s%-su&rc is set to F! 1ther"ise# it is set to >! *f not
all lines are used# $ou can calculate the number of unused lines b$ subtracting the number of
processed lines in s%-d&cnt from the total number of lines in the internal table! *f the internal
table is empt$# s%-su&rc and s%-d&cnt are set to F!
Wheneer $ou "ant to oer"rite more than one line in a database table# it is more efficient to
"or- "ith an internal table than to change the lines one b$ one!
05amples
.P)A-0 sflig$t S0- planet%pe F ?AC8@?
price F price - ?8@@9@@?
W+0(0 carrid F ?+? AN) connid F ?@D@B?9
This e/ample oer"rites the contents of the P.AN0T3P0 column "ith A:1F and decreases the
alue of the P%*C0 column b$ 1FF for each entr$ in S,.*(6T "here CA%%*& contains J.6= and
C1NN*& contains J>F4=!
-AB0S spfli9
)A-A wa -7P0 spfli9
,O!0 ?AA? -O wa-carrid9
,O!0 ?@@HD? -O wa-connid9
,O!0 ?WAS+IN/-ON? -O wa-cit%from9
999
.P)A-0 spfli 2(O, wa9
,O!0 ?+? -O spfli-carrid9
,O!0 ?@@8I? -O spfli-connid9
,O!0 ?B0(IN? -O spfli-cit%from9
999
.P)A-0 spfli9
CA%%*& and C1NN*& are the primar$ -e$ fields of table SP,.*! All the field alues of those
lines "here the primar$ -e$s are AA FF@> or .6 FF1B are replaced b$ the alues of the "or-
area wa or the table "or- area spfli! The ariant "ith a table "or- area declared using -AB0S
should no longer be used!

)A-A= ita& -7P0 +AS+0) -AB0 O2 spfli
WI-+ .NIW.0 "07 carrid connid4
wa I"0 IN0 O2 ita&9
wa-carrid F ?.A?9 wa-connid F ?@@88?9 wa-cit%from F 999
INS0(- wa IN-O -AB0 ita&9
wa-carrid F ?+?9 wa-connid F ?8BDG?9 wa-cit%from F 999
INS0(- wa IN-O -AB0 ita&9
wa-carrid F ?AA?9 wa-connid F ?DGID?9 wa-cit%from F 999
INS0(- wa IN-O -AB0 ita&9
999
.P)A-0 spfli 2(O, -AB0 ita&9
This e/ample fills a hashed table ita& and then oer"rites the lines in SP,.* that hae the same
primar$ -e$ (CA%%*& and C1NN*&) as a line in the internal table!
)eleting ines
The 1pen SC. statement for deleting lines from a database table is+
&0.0T0 X,%1'Y target lines!
*t allo"s $ou to delete one or more lines from the database table target! As described in the
section *nserting Table .ines# the database table target can be specified staticall$ and
d$namicall$!
Selecting ines .sing Conditions
ABAP Programming (BC-ABA) 44@
To select the lines that $ou "ant to delete using a condition# use the follo"ing+
&0.0T0 ,%1' target W60%0 cond!
All of the lines in the database table that satisf$ the conditions in the W+0(0 clause are
deleted! The 2(O, e/pression must occur bet"een the -e$"ord and the database table!
3ou should ta-e particular care "hen programming the W+0(0 clause to ensure that $ou do not
delete the "rong lines! ,or e/ample# if $ou specif$ an empt$ internal table in a d$namic W+0(0
clause# all of the lines in the table are deleted!
*f at least one line has been deleted# s%-su&rc is set to F [ other"ise to >! s%-d&cnt is set to the
number of deleted lines!
Selecting Single ines .sing Wor* Areas
*nstead of using a W+0(0 clause# $ou can select lines for deletion using the contents of a "or-
area! *n this case# $ou "ould "rite+
&0.0T0 target ,%1' "a!
This deletes the line "ith the same primar$ -e$ as the "or- area wa! The 2(O,e/pression must
not occur bet"een the -e$"ord and the database table! The "or- area wa must be a data ob2ect
"ith at least the same length and alignment as the line structure of the database table! The -e$
is read according to the structure of the table line# and not that of the "or- area! *t is a good
idea to define the "or- area "ith reference to the structure of the database table!
*f the database table contains a line "ith the same primar$ -e$ as specified in the "or- area# the
operation is completed successfull$ and s%-su&rc is set to F! 1ther"ise# the line is not deleted#
and s%-su&rc is set to >!
A shortened form of the aboe statement is+
&0.0T0 dbtab!
*n this case# the contents of the table "or- area d&ta& are used to delete from the database
table "ith the same name! 3ou must declare this table "or- area using the -AB0Sstatement! *n
this case# it is not possible to specif$ the name of the database table d$namicall$! Table "or-
areas "ith the same name as the database table (necessar$ before %elease >!F) should no longer
be used for the sa-e of clarit$!
Selecting Several ines .sing an Internal -a&le
3ou can also use an internal table to delete seeral lines+
&0.0T0 target ,%1' TAB.0 itab "a!
This deletes all lines from the database that hae the same primar$ -e$ as a line in the internal
table ita&! The same rules appl$ to the line t$pe of ita& as to the "or- area wa described aboe!
*f the s$stem cannot delete a line because no line "ith the specified -e$ e/ists# it does not
terminate the entire operation# but continues processing the ne/t line of the internal table!
*f all lines from the internal table are used# s%-su&rc is set to F! 1ther"ise# it is set to >! *f not
all lines are used# $ou can calculate the number of unused lines b$ subtracting the number of
deleted lines in s%-d&cnt from the total number of lines in the internal table! *f the internal
table is empt$# s%-su&rc and s%-d&cnt are set to F!
Wheneer $ou "ant to delete more than one line from a database table# it is more efficient to
"or- "ith an internal table than to insert the lines one b$ one!
05amples
&0.0T0 ,%1' sflight W60%0 planet$pe H IA:1FI AN&
carrid H I.6I!
This deletes all lines from S,.*(6T "here P.AN0T3P0 has the alue A:1F and CA%%*& contains
the alue .6!
-AB0S spfli9
)A-A= B0/IN O2 wa4
carrid -7P0 spfli-carrid4
connid -7P0 spfli-connid4
0N) O2 wa9
,O!0 ?AA? -O wa-carrid9
,O!0 ?@@HD? -O wa-connid9
)00-0 spfli 2(O, wa9
,O!0 ?+? -O spfli-carrid9
,O!0 ?@@8I? -O spfli-connid9
ABAP Programming (BC-ABA) 44B
)00-0 spfli9
CA%%*& and C1NN*& are the primar$ -e$ fields of table SP,.*! The lines "ith the primar$ -e$s
AA FF@> and .6 FF1B are deleted! The ariant "ith a table "or- area declared using -AB0S
should no longer be used!

)A-A= B0/IN O2 wa4
carrid -7P0 spfli-carrid4
connid -7P0 spfli-connid4
0N) O2 wa4
ita& I"0 +AS+0) -AB0 O2 wa
WI-+ .NIW.0 "07 carrid connid9
wa-carrid F ?.A?9 wa-connid F ?@@88?9
INS0(- wa IN-O -AB0 ita&9
wa-carrid F ?+?9 wa-connid F ?8BDG?9
INS0(- wa IN-O -AB0 ita&9
wa-carrid F ?AA?9 wa-connid F ?DGID?9
INS0(- wa IN-O -AB0 ita&9
999
)00-0 spfli 2(O, -AB0 ita&9
This e/ample defines a hashed table ita& "ith the structure of the primar$ -e$ of the database
table SP,.*! After ita& has been filled# those lines in SP,.* are deleted that hae the same
contents in the primar$ -e$ fields as a line in the internal table!
Inserting or C$anging ines
To insert lines into a database table regardless of "hether there is alread$ a line in the table
"ith the same primar$ -e$# use the follo"ing+
'1&*,3 target lines!
*f the database table contains no line "ith the same primar$ -e$ as the line to be inserted#
,O)I27 "or-s li-e *INS0(- - that is# the line is added!
*f the database alread$ contains a line "ith the same primar$ -e$ as the line to be inserted#
,O)I27 "or-s li-e .P)A-0 - that is# the line is changed!
,or performance reasons# $ou should use ,O)I27 onl$ if $ou reall$ cannot distinguish bet"een
these t"o options in $our program!
3ou can add or change one or more lines lines in a database table target! As described in the
section *nserting Table .ines# the database table target can be specified staticall$ and
d$namicall$!
Inserting or C$anging Single ines
To insert or change a single line in a database table# use the follo"ing for lines+
'1&*,3 target ,%1' "a!
The contents of the "or- area wa are "ritten to the database table d&ta&! The "or- area wa
must be a data ob2ect "ith at least the same length and alignment as the line structure of the
database table! The data is placed in the database table according to the line structure of the
table# and regardless of the structure of the "or- area! *t is a good idea to define the "or- area
"ith reference to the structure of the database table!
*f the database table does not alread$ contain a line "ith the same primar$ -e$ as specified in
the "or- area# a ne" line is inserted! *f the database table does alread$ contain a line "ith the
same primar$ -e$ as specified in the "or- area# the e/isting line is oer"ritten! *f the line could
not be processed [ for e/ample# because a line "ith the same uni8ue secondar$ inde/ e/ists in the
database [ s$-subrc is set to ># other"ise to F
A shortened form of the aboe statement is+
'1&*,3 dbtab!
*n this case# the contents of the table "or- area d&ta& are inserted into the database table "ith
the same name! 3ou must declare this table "or- area using the -AB0Sstatement! *n this case#
it is not possible to specif$ the name of the database table d$namicall$! Table "or- areas "ith
the same name as the database table (necessar$ before %elease >!F) should no longer be used for
the sa-e of clarit$!
Inserting or C$anging Several ines
To insert or change seeral lines in a database table# use the follo"ing for lines+
ABAP Programming (BC-ABA) 44D
'1&*,3 target ,%1' TAB.0 itab!
Those lines of the internal table ita& for "hich there is not alread$ a primar$ -e$ in the database
table are inserted into the table! Those lines of the internal table ita& for "hich there is alread$
a primar$ -e$ in the database table oer"rite the e/isting line there! The same rules appl$ to the
line t$pe of ita& as to the "or- area wa described aboe!
*f the line could not be processed [ for e/ample# because a line "ith the same uni8ue secondar$
inde/ e/ists in the database [ s$-subrc is set to ># other"ise to F! s$-dbcnt is set to the number
of changed lines!
Committing )ata&ase C$anges
1pen SC. contains the statements
C1''*T W1%U!
and
%1..BACU W1%U!
for confirming or undoing database updates! C1''*T W1%U al"a$s concludes a database .)W
and starts a ne" one! %1..BACU W1%U al"a$s undoes all changes bac- to the start of the
database .)W!
These statements are part of the SAP transaction concept# and should onl$ be used in this
conte/t!
As "ell as the CO,,I- WO(" and (OBAC" WO(" statements# there are other situations
"here data is implicitl$ "ritten to the database or rolled bac-# and "here database .)Ws
therefore begin and end!
,urthermore# the aboe statements also control SAP .)Ws# "hich e/tend oer seeral database
.)Ws!
The ABAP statements C1''*T W1%U and %1..BACU W1%U onl$ "or- li-e the corresponding
Standard SC. statements if the entire application program is represented b$ a single implicit
database .)W# that is# for e/ample# in a single dialog step!
Performance Notes
The performance of an ABAP program is largel$ determined b$ the efficienc$ of its database
accesses! *t is therefore "orth anal$9ing $our SC. statements closel$! To help $ou to do this#
$ou should use the Performance Trace and %untime Anal$sis tools (Test menu in the ABAP
Wor-bench)! *n particular# the SC. Trace in the Performance Trace sho"s $ou "hich parts of
1pen SC. statements are processed "here# and ho" long the$ ta-e!
To understand ho" SC. statements affect the runtime of ABAP programs# $ou need to
understand the underl$ing s$stem architecture! The "or- processes of an application serer are
logged onto the database s$stem (serer) as users (clients) for as long as the SAP S$stem is
running! The database management s$stem (&B'S) forms the connection bet"een users and data!
)B,S arc$itecture
The general structure of a &B'S is as follo"s+
7 A database "or- process proides a serice that database clients can call!
7 There are different database serices for different tas-s# for e/ample# for establishing
connections# changing database tables# loc-ing database entries# archiing# and so on!
7 There is a large shared memor$ area# containing the &B'S cache and other resources such
as the statement cache# and redo information!
7 The database files are stored on a hard dis-# and are managed b$ the file s$stem!
ABAP Programming (BC-ABA) 44E
Within this architecture# there are four points that are important in respect of performance+
7 Ph$sical input;output (*;1)
%eading and "riting database files is the greatest bottlenec-! The mar- of a "ell-configured
s$stem is the speed of its *;1!
7 The memor$ used b$ the database cache!
7 The CP) usage on the host on "hich the database is installed!
1n a s$mmetrical multi-processor s$stem# this is irreleant!
7 Net"or- communication
Although unimportant for small data olumes# it becomes a bottlenec- "hen large 8uantities of
data are inoled!
-$e Optimi:er
0ach database s$stem uses an optimi9er "hose tas- is to create the e/ecution plan for SC.
statements (for e/ample# to determine "hether to use an inde/ or table scan)! There are t"o
-inds of optimi9ers+
(ule &ased
%ule based optimi9ers anal$9e the structure of an SC. statement (mainl$ the S00C- and
W+0(0 clauses "ithout their alues) and the table inde/ or inde/es! The$ then use an algorithm
to "or- out "hich method to use to e/ecute the statement!
Cost &ased
Cost based optimi9ers use the aboe procedure# but also anal$9e some of the alues in the
W+0(0 clause and the table statistics! The statistics contain lo" and high alues of the fields# or
a histogram containing the distribution of data in the table! Since the cost based optimi9er uses
more information about the table# it usuall$ leads to faster database access! *ts disadantage is
that the statistics hae to be periodicall$ updated!
.se
1%AC.0 databases up to and including release B!1 use a rule-based optimi9er! As of %elease B!4
(SAP %elease >!FA)# the$ use a cost-based optimi9er! All other database s$stems use a cost-
based optimi9er!
(ules for 0fficient Open SW Programming
Based on the aboe architecture# there are fie rules that $ou should follo" to ma-e database
accesses in ABAP programs more efficient! The$ appl$ in particular to the follo"ing database
s$stems+
7 1%AC.0
ABAP Programming (BC-ABA) 4:F
7 *N,1%'*_
7 A&ABAS
7 &B4;>FF (uses 0BC&*C codepage)!
7 'icrosoft SC. Serer
,or the follo"ing database s$stems# the$ appl$ either in part or not at all+
7 &B4;@FFF
7 &B4;'AS
7 1%AC.0 Parallel Serer (1PS)
The fie rules are e/plained in the follo"ing sections+
Ueep the %esult Set Small
'inimi9e the Amount of &ata Transferred
'inimi9e the Number of &ata Transfers
'inimi9e the Search 1erhead
%educe the &atabase .oad
"eep t$e (esult Set Small
3ou should aim to -eep the result set small! This reduces both the amount of memor$ used in the
database s$stem and the net"or- load "hen transferring data to the application serer! To
reduce the si9e of $our result sets# use the W+0(0 and +A!IN/clauses!
.sing t$e W+0(0 Clause
Wheneer $ou access a database table# $ou should use a W+0(0 clause in the corresponding 1pen
SC. statement! 0en if a program containing a S00C- statement "ith no W+0(0 clause
performs "ell in tests# it ma$ slo" do"n rapidl$ in $our production s$stem# "here the data olume
increases dail$! 3ou should onl$ dispense "ith the W+0(0 clause in e/ceptional cases "here $ou
reall$ need the entire contents of the database table eer$ time the statement is e/ecuted!
When $ou use the W+0(0 clause# the database s$stem optimi9es the access and onl$ transfers
the re8uired data! 3ou should neer transfer un"anted data to the application serer and then
filter it using ABAP statements!
.sing t$e +A!IN/ Clause
After selecting the re8uired lines in the W+0(0 clause# the s$stem then processes the /(O.P
B7 clause# if one e/ists# and summari9es the database lines selected! The +A!IN/ clause allo"s
$ou to restrict the grouped lines# and in particular# the aggregate e/pressions# b$ appl$ing
further conditions!
0ffect
*f $ou use the W+0(0 and +A!IN/ clauses correctl$+
7 There are no more ph$sical *;1s in the database than necessar$
7 No un"anted data is stored in the database cache (it could other"ise displace data that is
actuall$ re8uired)
7 The CP) usage of the database host is minimi9e
7 The net"or- communication to the ABAP "or- process is reduced# since onl$ the data that
is re8uired b$ the application is transferred to the application serer!
,inimi:e t$e Amount of )ata -ransferred
&ata is transferred bet"een the database s$stem and the application serer in bloc-s! 0ach bloc-
is up to :4 UB in si9e (the precise si9e depends on $our net"or- communication hard"are)!
Administration information is transported in the bloc-s as "ell as the data!
To minimi9e the net"or- load# $ou should transfer as fe" bloc-s as possible! 1pen SC. allo"s $ou
to do this as follo"s+
(estrict t$e Num&er of ines
*f $ou onl$ "ant to read a certain number of lines in a S00C-statement# use the .P -O n
(OWS der 2(O,- addition in the 2(O, clause! This tells the database s$stem onl$ to transfer n
lines bac- to the application serer! This is more efficient than transferring more lines than
necessar$ bac- to the application serer and then discarding them in $our ABAP program!
*f $ou e/pect $our W+0(0 clause to return a large number of duplicate entries# $ou can use the
)IS-INC- addition in the S00C- clause!
(estrict t$e Num&er of Columns
3ou should onl$ read the columns from a database table that $ou actuall$ need in the program! To
do this# list the columns in the S00C- clause! Note here that the IN-O CO((0SPON)IN/
2I0)Saddition in the IN-O clause is onl$ efficient "ith large olumes of data# other"ise the
runtime re8uired to compare the names is too great! ,or small amounts of data# use a list of
ariables in the IN-O clause!
ABAP Programming (BC-ABA) 4:1
&o not use U to select all columns unless $ou reall$ need them! 6o"eer# if $ou list indiidual
columns# $ou ma$ hae to ad2ust the program if the structure of the database table is changed in
the ABAP &ictionar$! *f $ou specif$ the database table d$namicall$# $ou must al"a$s read all of
its columns!
.se Aggregate 2unctions
*f $ou onl$ "ant to use data for calculations# it is often more efficient to use the aggregate
functions of the S00C- clause than to read the indiidual entries from the database and
perform the calculations in the ABAP program!
Aggregate functions allo" $ou to find out the number of alues and find the sum# aerage#
minimum# and ma/imum alues! ,ollo"ing an aggregate e/pression# onl$ its result is transferred
from the database!
)ata -ransfer w$en C$anging -a&le ines
When $ou use the .P)A-0 statement to change lines in the table# $ou should use the W+0(0
clause to specif$ the releant lines# and then S0- statements to change onl$ the re8uired
columns!
When $ou use a "or- area to oer"rite table lines# too much data is often transferred!
,urthermore# this method re8uires an e/tra S00C- statement to fill the "or- area!
,inimi:e t$e Num&er of )ata -ransfers
*n eer$ 1pen SC. statement# data is transferred bet"een the application serer and the
database s$stem! ,urthermore# the database s$stem has to construct or reopen the appropriate
administration data for each database access! 3ou can therefore minimi9e the load on the
net"or- and the database s$stem b$ minimi9ing the number of times $ou access the database!
,ultiple Operations Instead of Single Operations
When $ou change data using INS0(-# .P)A-0 and )00-0# use internal tables instead of single
entries! *f $ou read data using S00C-# it is "orth using multiple operations if $ou "ant to
process the data more than once# other "ise# a simple select loop is more efficient!
Avoid (epeated Access
As a rule $ou should read a gien set of data once onl$ in $our program# and using a single access!
Aoid accessing the same data more than once (for e/ample# S00C- before an .P)A-0 or
)00-0)!
Avoid Nested S00C- oops
A simple S00C- loop is a single database access "hose result is passed to the ABAP program
line b$ line! Nested S00C- loops mean that the number of accesses in the inner loop is multiplied
b$ the number of accesses in the outer loop! 3ou should therefore onl$ use nested S00C- loops
if the selection in the outer loop contains er$ fe" lines!
6o"eer# using combinations of data from different database tables is more the rule than the
e/ception in the relational data model! 3ou can use the follo"ing techni8ues to aoid nested
S00C- statements+
ABAP )ictionar% !iews
3ou can define 2oins bet"een database tables staticall$ and s$stem"ide as ie"s in the ABAP
&ictionar$! Such ie"s can be used b$ all ABAP programs! 1ne of their adantages is that fields
that are common to both tables (2oin fields) are onl$ transferred once from the database to the
application serer!
Aie"s in the ABAP &ictionar$ are implemented as inner 2oins! *f the inner table contains no lines
that correspond to lines in the outer table# no data is transferred! This is not al"a$s the desired
result! ,or e/ample# "hen $ou read data from a te/t table# $ou "ant to include lines in the
selection een if the corresponding te/t does not e/ist in the re8uired language! *f $ou "ant to
include all of the data from the outer table# $ou can program a left outer 2oin in ABAP!
The lin-s bet"een the tables in the ie" are created and optimi9ed b$ the database s$stem! .i-e
database tables# $ou can buffer ie"s on the application serer! The same buffering rules appl$ to
ie"s as to tables! *n other "ords# it is most appropriate for ie"s that $ou use mostl$ to read
data! This reduces the net"or- load and the amount of ph$sical *;1 in the database!
Yoins in t$e 2(O, Clause
3ou can read data from more than one database table in a single S00C- statement b$ using
inner or left outer 2oins in the 2(O, clause!
The disadantage of using 2oins is that redundant data is read from the hierarchicall$-superior
table if there is a 1+N relationship bet"een the outer and inner tables! This can considerabl$
increase the amount of data transferred from the database to the application serer! Therefore#
"hen $ou program a 2oin# $ou should ensure that the S00C- clause contains a list of onl$ the
ABAP Programming (BC-ABA) 4:4
columns that $ou reall$ need! ,urthermore# 2oins b$pass the table buffer and read directl$ from
the database! ,or this reason# $ou should use an ABAP &ictionar$ ie" instead of a 2oin if $ou onl$
"ant to read the data!
The runtime of a 2oin statement is heail$ dependent on the database optimi9er# especiall$ "hen
it contains more than t"o database tables! 6o"eer# 2oins are nearl$ al"a$s 8uic-er than using
nested S00C- statements!
Su&1ueries in t$e W+0(0 and +A!IN/ Clauses
Another "a$ of accessing more than one database table in the same 1pen SC. statement is to
use sub8ueries in the W+0(0 or +A!IN/ clause! The data from a sub8uer$ is not transferred to
the application serer! *nstead# it is used to ealuate conditions in the database s$stem! This is a
simple and effectie "a$ of programming comple/ database operations!
.sing Internal -a&les
*t is also possible to aoid nested S00C- loops b$ placing the selection from the outer loop in an
internal table and then running the inner selection once onl$ using the 2O( A 0N-(I0S
addition! This techni8ue stems from the time before 2oins "ere allo"ed in the 2(O, clause! 1n
the other hand# it does preent redundant data from being transferred from the database!
.sing a Cursor to (ead )ata
A further method is to decouple the IN-O clause from the S00C-statement b$ opening a
cursor using OP0N C.(SO( and reading data line b$ line using 20-C+ N0X- C.(SO(! 3ou must
open a ne" cursor for each nested loop! *n this case# $ou must ensure $ourself that the correct
lines are read from the database tables in the correct order! This usuall$ re8uires a foreign -e$
relationship bet"een the database tables# and that the$ are sorted b$ the foreign -e$!
,inimi:e t$e Searc$ Over$ead
3ou minimi9e the si9e of the result set b$ using the W+0(0 and +A!IN/clauses! To increase the
efficienc$ of these clauses# $ou should formulate them to fit "ith the database table inde/es!
)ata&ase Inde5es
*nde/es speed up data selection from the database! The$ consist of selected fields of a table# of
"hich a cop$ is then made in sorted order! *f $ou specif$ the inde/ fields correctl$ in a condition
in the W+0(0 or +A!IN/ clause# the s$stem onl$ searches part of the inde/ (inde/ range scan)!
The s$stem automaticall$ creates the primar% inde5! *t consists of the primar$ -e$ fields of the
database table! This means that for each combination of fields in the inde/# there is a ma/imum
of one line in the table! This -ind of inde/ is also -no"n as .NIW.0!
*f $ou cannot use the primar$ inde/ to determine the result set because# for e/ample# none of
the primar$ inde/ fields occur in the W+0(0 or +A!IN/clauses# the s$stem searches through
the entire table (full table scan)! ,or this case# $ou can create secondar$ inde/es# "hich can
restrict the number of table entries searched to form the result set!
3ou create secondar$ inde/es using the ABAP &ictionar$! There $ou can create its columns and
define it as .NIW.0! 6o"eer# $ou should not create secondar$ inde/es to coer all possible
combinations of fields!
1nl$ create one if $ou select data b$ fields that are not contained in another inde/# and the
performance is er$ poor! ,urthermore# $ou should onl$ create secondar$ inde/es for database
tables from "hich $ou mainl$ read# since inde/es hae to be updated each time the database table
is changed! As a rule# secondar$ inde/es should not contain more than four fields# and $ou should
not hae more than fie inde/es for a single database table!
*f a table has more than fie inde/es# $ou run the ris- of the optimi9er choosing the "rong one
for a particular operation! ,or this reason# $ou should aoid inde/es "ith oerlapping contents!
Secondar$ inde/es should contain columns that $ou use fre8uentl$ in a selection# and that are as
highl$ selectie as possible! The fe"er table entries that can be selected b$ a certain column# the
higher that column=s selectiit$! Place the most selectie fields at the beginning of the inde/!
3our secondar$ inde/ should be so selectie that each inde/ entr$ corresponds to# at most# fie
percent of the table entries! *f this is not the case# it is not "orth creating the inde/! 3ou should
also aoid creating inde/es for fields that are not al"a$s filled# "here their alue is initial for
most entries in the table!
*f all of the columns in the S00C- clause are contained in the inde/# the s$stem does not hae
to search the actual table data after reading from the inde/! *f $ou hae a S00C- clause "ith
er$ fe" columns# $ou can improe performance dramaticall$ b$ including these columns in a
secondar$ inde/!
2ormulating Conditions for Inde5es
ABAP Programming (BC-ABA) 4::
3ou should bear in mind the follo"ing "hen formulating conditions for the W+0(0 and +A!IN/
clauses so that the s$stem can use a database inde/ and does not hae to use a full table scan!
C$ec* for 01ualit% and in* .sing AN)
The database inde/ search is particularl$ efficient if $ou chec- all inde/ fields for e8ualit$ (0W#
F) and lin- the e/pressions using AN)!
.sing Positive Conditions
The database s$stem onl$ supports 8ueries that describe the result in positie terms# for
e/ample# 0W or I"0! *t does not support negatie e/pressions li-e N0 or NO- I"0!
*f possible# aoid using the logical NO-operator< instead use appropriate inerted operators
because the logical NO- is not supported b$ database inde/es!
.sing O(
The optimi9er usuall$ stops "or-ing "hen an O(e/pression occurs in the condition! This means
that the columns chec-ed using O( are not included in the inde/ choice! An e/ception to this are
O(e/pressions outside of conditions! 3ou should tr$ to reformulate conditions that appl$ Or
e/pressions to columns releant to the inde/ [ for e/ample# into an IN condition!
.sing Part of an Inde5
*f $ou construct an inde/ from seeral columns# the s$stem can still use it een if $ou onl$ specif$
a fe" of the columns in a condition! 6o"eer# in this case# the se8uence of the columns in the
inde/ is important! A column can onl$ be used in the inde/ search if all of the columns before it in
the inde/ definition hae also been specified in the condition!
C$ec*ing for Null !alues
The IS N. condition can cause problems "ith inde/es! Some database s$stems do not store
null alues in the inde/ structure! Conse8uentl$# this field cannot be used in the inde/!
Avoid Comple5 Conditions
Aoid comple/ conditions# since the statements hae to be bro-en do"n into their indiidual
components b$ the database s$stem!
(educing t$e )ata&ase oad
)nli-e application serers and presentation serers# there is onl$ one database serer in $our
s$stem! 3ou should therefore aim to reduce the database load as much as possible! 3ou can use
the follo"ing methods+
Buffer -a&les on t$e Application Server
3ou can considerabl$ reduce the time re8uired to access data b$ buffering it in the application
serer table buffer! %eading a single entr$ from table TFF1 can ta-e bet"een D and @FF
milliseconds# "hile reading it from the table buffer ta-es F!4 - 1 milliseconds!
Whether a table can be buffered or not depends its technical attributes in the ABAP &ictionar$!
There are three buffering t$pes+
7 (esident &uffering (1FFR)+ The first time the table is accessed# its entire contents are
loaded into the table buffer!
7 /eneric &uffering= *n this case# $ou need to specif$ a generic -e$ (some of the -e$ fields)
in the technical settings of the table in the ABAP &ictionar$! The table contents are then diided
into generic areas! When $ou access data "ith one of the generic -e$s# the "hole generic area is
loaded into the table buffer! Client-specific tables are often buffered genericall$ b$ client!
7 Partial &uffering (single record)+ 1nl$ single entries are read from the database and
stored in the table buffer!
When $ou read from buffered tables# the follo"ing happens+
!!!
1! An ABAP program re8uests data from a buffered table!
4! The ABAP processor interprets the 1pen SC. statement! *f the table is defined as a
buffered table in the ABAP &ictionar$# the ABAP processor chec-s in the local buffer on the
application serer to see if the table (or part of it) has alread$ been buffered!
:! *f the table has not $et been buffered# the re8uest is passed on to the database! *f the
data e/ists in the buffer# it is sent to the program!
>! The database serer passes the data to the application serer# "hich places it in the table
buffer!
?! The data is passed to the program!
When $ou change a buffered table# the follo"ing happens+
!!!
ABAP Programming (BC-ABA) 4:>
1! The database table is changed and the buffer on the application serer is updated! The
database interface logs the update statement in the table &&.1(! *f the s$stem has more than
one application serer# the buffer on the other serers is not updated at once!
4! All application serers periodicall$ read the contents of table &&.1(# and delete the
corresponding contents from their buffers "here necessar$! The granularit$ depends on the
buffering t$pe! The table buffers in a distributed s$stem are generall$ s$nchroni9ed eer$ @F
seconds (parameter+ rsdisp;bufreftime)!
:! Within this period# users on non-s$nchroni9ed application serers "ill read old data! The data
is not recogni9ed as obsolete until the ne/t buffer s$nchroni9ation! The ne/t time it is accessed#
it is re-read from the database!
3ou should buffer the follo"ing t$pes of tables+
7 Tables that are read er$ fre8uentl$
7 Tables that are rarel$ changed
7 %elatiel$ small tables (fe" lines# fe" columns# or short columns)
7 Tables "here it is acceptable for changes to the data to not be immediatel$ isible on all
application serers!
1nce $ou hae buffered a table# ta-e care not to use an$ 1pen SC. statements that b$pass the
buffer!
The S00C- statements b$pass the buffer+
7 The B7PASSIN/ B.220( addition in the 2(O, clause
7 The )IS-INC-addition in the S00C- clause
7 Aggregate e/pressions in the S00C- clause
7 aoins in the 2(O, clause
7 The IS N.condition in the W+0(0 clause
7 Sub8ueries in the W+0(0 clause
7 The O()0( B7 clause
7 The /(O.P B7 clause
7 The 2O( .P)A-0addition
,urthermore# all Natie SC. statements b$pass the buffer!
Avoid (eading )ata (epeatedl%
*f $ou aoid reading the same data repeatedl$# $ou both reduce the number of database accesses
and reduce the load on the database! ,urthermore# a Kdirt$ readi ma$ occur "ith database tables
other than 1racle! This means that the second time $ou read data from a database table# it ma$
be different from the data read the first time! To ensure that the data in $our program is
consistent# $ou should read it once onl$ and then store it in an internal table!
Sort )ata in 7our ABAP Program
The O()0( B7 clause in the S00C-statement is not necessaril$ optimi9ed b$ the database
s$stem or e/ecuted "ith the correct inde/! This can result in increased runtime costs! 3ou should
onl$ use O()0( B7 if the database sort uses the same inde/ "ith "hich the table is read! To
find out "hich inde/ the s$stem uses# use SC. Trace in the ABAP Wor-bench Performance
Trace! *f the inde/es are not the same# it is more efficient to read the data into an internal table
or e/tract and sort it in the ABAP program using the SO(-statement!
.se ogical )ata&ases
SAP supplies logical databases for all applications! A logical database is an ABAP program that
decouples 1pen SC. statements from application programs! The$ are optimi9ed for the best
possible database performance! 6o"eer# it is important that $ou use the right logical database!
The hierarch$ of the data $ou "ant to read must reflect the structure of the logical database!
1ther"ise# performance might be adersel$ affected! ,or e/ample# if $ou "ant to read data from
a table right at the bottom of the hierarch$ of the logical database# it has to read at least the
-e$ fields of all tables aboe it in the hierarch$! *n this case# it is more efficient to use a
S00C- statement!
Native SW
1pen SC. allo"s $ou to access database tables declared in the ABAP &ictionar$# regardless of
the database platform $ou are using! Natie SC. allo"s $ou to use database-specific SC.
statements in an ABAP program! This means that $ou can use database tables that are not
managed b$ the ABAP &ictionar$# and therefore integrate data that is not part of the SAP Web
AS ABAP S$stem!
ABAP Programming (BC-ABA) 4:?
As a rule# an ABAP program containing database-specific SC. statements "ill not run under
different database s$stems! *f $our program "ill be used on more than one database platform#
onl$ use 1pen SC. statements!
Native SW Statements in ABAP Programs
To use a Natie SC. statement# $ou must precede it "ith the 0X0C SW statement# and follo" it
"ith the 0N)0X0C statement as follo"s+
0_0C SC. XP0%,1%'*N( formY!
Natie SC. An"eisung
0N&0_0C!
There is no period (!) after Natie SC. statements! ,urthermore# using inerted commas (K) in a
Natie SC. statement or an asteris- (L) at the beginning of a line does not introduce a comment
as it "ould in normal ABAP s$nta/! 3ou need to -no" "hether table and field names are case-
sensitie in $our chosen database!
*n Natie SC. statements# the data is transported bet"een the database table and the ABAP
program using host ariables! These ariables are declared in the ABAP program# and preceded in
the Natie SC. statement b$ a colon (+)! 3ou can use elementar$ structures as host ariables!
0/ceptionall$# structures in an IN-O clause are treated as though all of their fields "ere listed
indiiduall$!
*f the selection in a Natie SC. S00C-statement is a table# $ou can pass it to ABAP line b$ line
using the P0(2O(,IN/addition! The program calls a subroutine form for each line read! 3ou can
process the data further "ithin the subroutine!
As in 1pen SC.# s%-d&cnt contains the number of processed lines after the statement
0N)0X0C! s%-su&rc contains in almost all cases the alue F after the statement 0N)0X0C!
0/ceptions are cursor operations+ after 20-C+# s%-su&rc is if not more records could be read!
This also applies "hen $ou read a result set using 0X0C SW P0(2O(,IN/!
(0PO(- demoEnativeEs1l9
)A-A= B0/IN O2 wa4
connid -7P0 spfli-connid4
cit%from -7P0 spfli-cit%from4
cit%to -7P0 spfli-cit%to4
0N) O2 wa9
)A-A c8 -7P0 spfli-carrid !A.0 ?+?9
0X0C SW P0(2O(,IN/ loopEoutput9
S00C- connid4 cit%from4 cit%to
IN-O =wa
2(O, spfli
W+0(0 carrid F =c8
0N)0X0C9
2O(, loopEoutput9
W(I-0= A wa-connid4 wa-cit%from4 wa-cit%to9
0N)2O(,9
The output is as follo"s+

The "or- area wa and the field c8 Natie SC. statement S00C- are used! wa is the target area
into "hich the selected data is "ritten! As a structure# wa is handled in the IN-O clause as if all
subfields "ere listed indiiduall$+ X!!Y IN-O =wa-connid4 =wa-cit%from4 =wa-cit%to! c8 is used in
the W+0(0 clause! The subroutine loopEoutput "rites the data from wa to the list!
Scope of Native SW
Natie SC. allo"s $ou to e/ecute (nearl$) all statements proided b$ the database and its SC.
programming interface (usuall$ -no"n as SC. Call *nterface or similar) for e/ecuting SC.
program code directl$ (using 0X0C I,,0)IA-0 or a similar command)! The follo"ing sections
list the statements that are not supported!
Native SW and t$e )ata&ase Interface
Natie SC. statements b$pass the database interface! There is no table logging# and no
s$nchroni9ation "ith the database buffer on the application serer! ,or this reason# $ou should#
ABAP Programming (BC-ABA) 4:@
"hereer possible# use 1pen SC. to change database tables declared in the ABAP &ictionar$! *n
particular# tables declared in the ABAP &ictionar$ that contain long columns "ith the t$pes .C6%
or .%AW should onl$ be addressed using 1pen SC.# since the columns contain e/tra# database-
specific length information for the column! Natie SC. does not ta-e this information into
account# and ma$ therefore produce incorrect results! ,urthermore# Natie SC. does not
support automatic client handling! *nstead# $ou must treat client fields li-e an$ other!
Native SW and -ransactions
To ensure that transactions are consistent# $ou should not use an$ transaction control statements
(CO,,I-# (OBAC"# !!!)# or an$ statements that set transaction parameters (isolation leel!!!)
using Natie SC.!
Stored Procedures
To standardi9e the specific s$nta/ of different database products# ABAP has a uniform s$nta/+
0_0C)T0 P%1C0&)%0 name ( parameterliste )
The parameters are separated b$ commas! 3ou must also specif$ "hether the parameter is for
input (*N)# output (1)T)# or input and output (*N1)T)! ,or further information# refer to SAPnet
note >>EBB!
0_0C SC.!
0_0C)T0 P%1C0&)%0 proc1 ( *N +/# 1)T +$ )
0N&0_0C!
Cursor Processing
Cursor processing in Natie SC. is similar to that in 1pen SC.+
7 1P0N cursorname ,1% an"eisung
7 ,0TC6 N0_T cursorname *NT1 9ielfeld(er)
7 C.1S0 cursorname
0_0C SC.!
1P0N c1 ,1%
S0.0CT client# arg1# arg4 ,%1' tableSFF1
W60%0 client H IFFFI AN& arg4 H +arg4
0N&0_0C!
&1!
0_0C SC.!
,0TC6 N0_T c1 *NT1 +"a-client# +"a-arg1# +"a-arg4
0N&0_0C!
*, s$-subrc ]G F!
0_*T!
0.S0!
!!!
0N&*,!
0N&&1!
0_0C SC.!
C.1S0 c1
0N&0_0C!
This e/ample opens a cursor# reads data line b$ line# and closes the cursor again! As in 1pen SC.#
s$-subrc indicates "hether a line could be read!
)ata -%pes and Conversions
)sing Natie SC.# $ou can
7 Transfer alues from ABAP fields to the database
7 %ead data from the database and process it in ABAP programs!
Natie SC. "or-s "ithout the administratie data about database tables stored in the ABAP
&ictionar$! Conse8uentl$# it cannot perform all of the consistenc$ chec-s used in 1pen SC.! This
places a larger degree of responsibilit$ on application deelopers to "or- "ith ABAP fields of the
correct t$pe! 3ou should al"a$s ensure that the ABAP data t$pe and the t$pe of the database
column are identical!
*f the database table is not defined in the ABAP &ictionar$# $ou cannot refer directl$ to its data
t$pe! *n this case# $ou should create a uniform t$pe description in the ABAP &ictionar$# "hich can
then be used b$ all application programs!
ABAP Programming (BC-ABA) 4:B
*f the table is defined in the ABAP &ictionar$# $ou should remember that [ "ith regard to their
structure [ the se8uence of fields in the ABAP &ictionar$ ma$ not be the same as the actual
se8uence of fields in the database columns! )sing the asteris- (U) in the S00C- clause to read
all columns into a corresponding "or- area "ould lead to meaningless results! *n the "orst case#
these "ould not necessaril$ be recogni9ed as incorrect!
The Natie SC. module of the database interface passes a description of the t$pe# si9e# and
memor$ location of the ABAP fields used to the database s$stem! The releant database s$stem
operations are usuall$ used to access and conert the data! 3ou can find details of these
operations in the manuals for the programming interface of the releant database s$stem! *n
some cases# Natie SC. also performs other compatibilit$ chec-s!
The documentation from the arious database manufacturers proides detailed lists of
combinations of ABAP data t$pes and database column t$pes# both for storing ABAP field alues
in database tables (INS0(-# .P)A-0) and for reading database contents into ABAP fields
(S00C-)! 3ou can also appl$ these descriptions for the input and output parameters of database
procedures! An$ combinations not listed there are undefined# and should not be used!
The follo"ing sections proide details of the data t$pes and conersions for indiidual databases!
Although the$ are database-specific# there are also some common features!
%ecommended t$pe combinations are underlined! 1nl$ for these combinations is behaior
guaranteed from release to release! ,or an$ other combinations# $ou should assume that the
description onl$ applies to the specified release!
The results of conersions are listed in a results column+
7 K1Ui+ The conersion can be performed "ithout loss of data!
7 1perations that fail are indicated b$ their SC. error code! 0rrors of this -ind al"a$s lead
to program termination and an ABAP short dump!
7 *n some cases# data is transferred "ithout an SC. error occurring! 6o"eer# the data is
truncated# rounded# or other"ise unusable+
7 XrtruncY %ight truncation!
K.efti or Krighti applies to the normal "a$ of "riting a alue! So# for e/ample# if a number
is truncated# its decimal places are affected!
7 XltruncY+ .eft truncation
7 XroundY+ Number is rounded up or do"n during conersion
7 XFY+ A number that "as Ktoo smalli is rounded to F (underflo")
7 XundefY+ The conersion result is undefined!
There are seeral possible results! The concrete result is either not -no"n at all# or can
onl$ be described using a set of rules that is too complicated for practical use!
7 XnullY+ The conersion returns the SC. alue N)..!
7 Xo-Y+ The conersion is performed "ithout fields and unchec-ed!
The original data is conerted# but "ithout its format being chec-ed! The result ma$
therefore be a alue inalid for the result t$pe# "hich cannot be processed further! An
e/ample of this is a date field containing the alue KEEEEEEEEi or Kabcdefghi after
conersion!
Combinations of ABAP data t$pe and database column t$pe can be diided into finer subcategories
[ here# for e/ample# using the transfer direction ABAP to the database (INS0(-# .P)A-0)+
7 *f the "idth of the ABAP field is greater than that of the database column# the ABAP field
ma$ contain alues for "hich there is not enough space in the database column! This can produce
other cases+ The concrete data alue in ABAP finds space in the database column# or not!
7 *f the ABAP field is at most as long as the database column# there is al"a$s space for the
ABAP alue in the database column!
7 Some t$pes# such as numeric columns# e/pect alues in a particular format! This is
particularl$ important in connection "ith character t$pes# for e/ample# "hen $ou "ant to "rite an
ABAP character field (t$pe C) into an integer column!
Natie SC. for 1racle
Natie SC. for *nformi/
Natie SC. for &B4 Common Serer
Native SW for Oracle
The 1racle-specific section of the Natie SC. documentation deals "ith combinations of ABAP
data t$pes and column t$pes of an 1racle table! *t describes in detail the t$pe conersions used
for each t$pe combination! The abbreiations introduced in the general description# such as
XrtruncY are used!
ABAP Programming (BC-ABA) 4:D
The list is diided roughl$ into the t"o data transfer directions+
7 Storing alues from ABAP fields in database columns (INS0(-)!
7 %eading alues from database columns into ABAP fields (S00C-)!
0ach description assumes that the starting alue is a permitted alue for the corresponding t$pe!
Cases "here inalid bit patterns are created in an ABAP field using a 2I0)-S7,BO "ill not be
ta-en into account!
The follo"ing inde/ supports direct entr$ using the t$pe of the initial alue!
This description is alid for 1racle D!F!> and SAP %elease >!?A!
Insert A ABAP-)ata -%pe
7 Character C(n)
7 Numeric Te/t N(n)
7 Pac-ed Number P(m#d)
7 *nteger *
7 ,loat ,
7 &ate &
7 Time T
7 6e/adecimal _(n)
Select A )ata&ase Column -%pe
7 Aarchar4
7 Char
7 .ong
7 Number (/)
7 Number (/#$)
7 ,loat
7 &ate
7 %a"
7 .ong %a"
7 %o"id

INS0(-
(A) The follo"ing applies to the database column t$pe number(/#$)# including the case $ ] F+
7 Significant figures are those "ith alues GH 1F
-$
!
7 Non-significant figures are those "ith alues ] 1F
-$
!
ABAP )ata -%pe= C$aracter C(n)
&ata alue "idth+ String length "ithout trailing spaces
)ata&ase
column
t%pe
Case (notes) (esult
varc$arB
(:)
ABAP data alue "idth G >FFF 8DH8
ABAP field "idth (n) G database column "idth (9)
ABAP data alue "idth G database column "idth
ABAP data alue "idth ]H database column "idth

8D@8
o-
ABAP field "idth (n) ]H database column "idth (9) o-
c$ar (:)
ABAP data alue "idth G >FFF 8DH8
ABAP field "idth (n) G database column "idth (9)
ABAP data alue "idth G database column "idth
ABAP data alue "idth GH database column "idth

8D@8
o-
ABAP field "idth (n) ]H database column "idth (9) o-
long o-
number (9)
ABAP data alue is non-numeric 8IBB
.oss of figures before decimal point in conersion 8DCJ
ABAP data alue contains decimal places XroundY
ABAP data alue "idth ]H database column "idth (9)
X data alue "idth+ Number of positions before
comma Y
o- ; XroundY
number
(9#$)
ABAP data alue is non-numeric 8IBB
.oss of significant figures (see (A))! 8DCJ
.oss of non-significant figures (see (A))! XroundY
ABAP Programming (BC-ABA) 4:E
ABAP data alue "idth ]H database column "idth (9)
X data alue "idth+ Number of significant positions
(see (A)) Y
o- ; XroundY
float
ABAP data alue is non-numeric 8IBB
ABAP data alue not in interal Y -1F
14@
# 1F
14@
8DBH
ABAP data alue in interal Y -1F
-1:F
# 1F
-1:F
X
X &atabase data alue rounded to F Y
XFY
ABAP data alue in interal Y -1F
14@
# 1F
14@
X
X :Dth place is rounded# filled "ith 9eros from the
right Y
o- ; XFY ;
XroundY
date(E)
ABAP data alue has an inalid database date format 8JH8
ABAP date alue has a alid database date format X 1F-
aan-EB Y
o-
ra" (9)
ABAP data alue "idth G >FFF 8DH8
ABAP data alue has an inalid he/adecimal format
X Aalid alues+ F-E# A-,# a-f< uppercase;lo"ercase are
e8ual in conersion Y
8DHG
ABAP field "idth (n) G database column "idth (nG49)
ABAP data alue "idth G database column "idth
ABAP data alue "idth ]H database column "idth
X *f the data alue "idth has an odd-numbered length#
a 9ero is added at the left Y

8D@8
o-
ABAP data alue "idth (n) ]H database column "idth
(n]H49)
X *f the data alue "idth has an odd-numbered length#
a 9ero is added at the left Y
o-
long ra"
ABAP data alue "idth G >FFF 8DH8
ABAP data alue has an inalid he/adecimal format
X Aalid alues+ F-E# A-,# a-f< uppercase;lo"ercase are
e8ual in conersion Y
8DHG
ABAP data alue "idth ]H >FFF o-

ABAP )ata -%pe= Numeric -e5t N(n)
&ata alue "idth+ Number of digits "ithout leading 9eros
)ata&ase
column
t%pe
Case (notes) (esult
varc$arB
(:)
&ata alue "idth G >FFF 8DH8
ABAP field "idth (n) G database column "idth (9) 8D@8
ABAP field "idth (n) ]H database column "idth (9) o-
char (9)
&ata alue "idth G >FFF 8DH8
ABAP field "idth (n) G database column "idth (9) 8D@8
ABAP field "idth (n) ]H database column "idth (9) o-
long o-
number (9)
ABAP field "idth (n) G database column "idth (9)
ABAP data alue "idth G database column "idth
ABAP data alue "idth ]H database column "idth
X leading 9eros truncated Y

8DCJ
o- ; XltruncY
ABAP field "idth (n) H database column "idth (9)
ABAP data alue "idth ]H database column "idth
X leading 9eros truncated Y

o- ; XltruncY
ABAP field "idth (n) ] database column "idth (9) o-
number
(/#$)
(9H/-$)
.oss of significant figures (see (A))! 8DCJ
ABAP data alue "idth ]H database column "idth (9)
X leading 9eros truncated Y
o- ; XltruncY
float ABAP data alue GH 1F
14@
8DBH
ABAP Programming (BC-ABA) 4>F
ABAP data alue ] 1F
14@
X
X :Dth place is rounded# filled "ith 9eros from the
right Y
o- ; XroundY
date 8JH8
ra" (9)
ABAP field "idth (n) G database column "idth (nG49) 8D@8
ABAP data alue "idth (n) ]H database column "idth
(n]H49)
X *f the data alue "idth has an odd-numbered length#
a 9ero is added at the left Y
o-
long ra"
&ata alue "idth G >FFF 8DH8
&ata alue "idth ]H >FFF o-

ABAP )ata -%pe= Pac*ed Num&er P(m4d)
mH b$tes# d H decimal places
&ata alue "idth (n)+ Number of digits "ithout leading 9eros# n]H4m-1< n is increased b$ one for
each of decimal point and minus sign!
)ata&ase
column
t%pe
Case (notes) (esult
archar4
(9)
ABAP data alue "idth (n) ] database column "idth (9) 8D@8
ABAP data alue "idth (n) ]H database column "idth (9) o-
char (9)
ABAP data alue "idth (n) ] database column "idth (9) 8D@8
ABAP data alue "idth (n) ]H database column "idth (9) o-
long o-
number (9)
.oss of figures before decimal point in conersion 8DCJ
ABAP data alue contains decimal places XroundY
ABAP data alue "idth (n) ]H database column "idth (9)
X data alue "idth+ Number of positions before
comma Y
o- ; XroundY
num&er
(54%)
(9H/-$)
.oss of significant figures (see (A))! 8DCJ
.oss of non-significant figures (see (A))! XroundY
ABAP data alue "idth ]H database column "idth (9)
X data alue "idth+ Number of significant positions
(see (A)) Y
o- ; XroundY
float o-
date KCB
ra" KCB
long ra" KCB

ABAP )ata -%pe= Integer
&ata alue "idth+ Number of digits "ithout leading 9eros< n is increased b$ one if there is a minus
sign!
)ata&ase
column
t%pe
Case (notes) (esult
archar4
(9)
ABAP data alue "idth G database column "idth (9) 8D@8
ABAP data alue "idth ]H database column "idth (9) o-
char (9)
ABAP data alue "idth G database column "idth (9) 8D@8
ABAP data alue "idth ]H database column "idth (9) o-
long o-
num&er (:)
ABAP data alue "idth G &atabase column "idth (9)
X data alue "idth+ Number of digits Y
8DCJ
ABAP data alue "idth ]H &atabase column "idth (9)
X data alue "idth+ Number of digits Y
o-
.oss of significant figures (see (A))! 8DCJ
.oss of non-significant figures (see (A))! XroundY
ABAP Programming (BC-ABA) 4>1
number (/#$)
(9H/-$)
ABAP data alue "idth ]H database column "idth (9)
X data alue "idth+ Number of significant positions
(see (A)) Y
o- ; XroundY
float o-
date KCB
ra" KCB
long ra" KCB

ABAP )ata -%pe= 2loat
*naccuracies can occur "ith an$ conersions inoling floating point numbers!
&ata alue "idth+ Number of digits "ithout leading 9eros< n is increased b$ one for each of
decimal point and minus sign!
)ata&ase
column
t%pe
Case (notes) (esult
archar4
(9)
ABAP data alue "idth G database column "idth (9) 8D@8
ABAP data alue "idth ]H database column "idth (9) o-
char (9)
ABAP data alue "idth G database column "idth (9) 8D@8
ABAP data alue "idth ]H database column "idth (9) o-
long o-
number (9)
ABAP data alue "idth G database column "idth (9)
X data alue "idth+ Number of positions before comma Y
8DCJ
ABAP data alue contains decimal places XroundY
ABAP data alue "idth ]H database column "idth (9)
X data alue "idth+ Number of positions before
comma Y
o- ; XroundY
number
(/#$)
(9H/-$)
.oss of significant figures (see (A))! 8DCJ
.oss of non-significant figures (see (A))! XroundY
ABAP data alue "idth ]H database column "idth (9)
X data alue "idth+ Number of significant positions
(see (A)) Y
o- ; XroundY
float
ABAP data alue not in interal Y -1F
14@
# 1F
14@
8DBH
ABAP data alue in interal Y -1F
-1:F
# 1F
-1:F
X
X &atabase data alue rounded to F Y
XFY
ABAP data alue not in interal Y -1F
14@
# 1F
14@
X o- ; XFY
date KCB
ra" KCB
long ra" KCB

ABAP )ata -%pe= )ate )(J)
&ata alue "idth H D (fi/ed)
)ata&ase
column
t%pe
Case (notes) (esult
varc$arB
(:)
ABAP data alue "idth (D) G database column "idth (9) 8D@8
ABAP data alue "idth (D) ]H database column "idth (9) o-
c$ar (:)
ABAP data alue "idth (D) G database column "idth (9) 8D@8
ABAP data alue "idth (D) ]H database column "idth (9) o-
long o-
number (9)
ABAP data alue is non-numeric 8IBB
ABAP data alue "idth (D) G database column "idth (9) 8DCJ
ABAP data alue "idth (D) ]H database column "idth (9) o-
number
(/#$)
(9H/-$)
ABAP data alue is non-numeric 8IBB
ABAP data alue "idth (D) G database column "idth (9) 8DCJ
ABAP data alue "idth (D) ]H database column "idth (9) o-
float ABAP data alue is non-numeric 8IBB
ABAP Programming (BC-ABA) 4>4
ABAP data alue is numeric o-
date 8JH8
ra" (9)
ABAP data alue has an inalid he/adecimal format
X Aalid alues+ F-E# A-,# a-f< uppercase;lo"ercase are
e8ual in conersion Y
8DHG
ABAP data alue "idth (D) G database column "idth
(>G9)
8D@8
ABAP data alue "idth (D) ]H database column "idth
(>]H9)
o-
long ra"
ABAP data alue has an inalid he/adecimal format
X Aalid alues+ F-E# A-,# a-f< uppercase;lo"ercase are
e8ual in conersion Y
8DHG
ABAP data alue has a alid he/adecimal format o-

ABAP )ata -%pe= )ate -(H)
&ata alue "idth H @ (fi/ed)
)ata&ase
column
t%pe
Case (notes) (esult
varc$arB
(:)
ABAP data alue "idth (@) G database column "idth (9) 8D@8
ABAP data alue "idth (@) ]H database column "idth (9) o-
c$ar (:)
ABAP data alue "idth (@) G database column "idth (9) 8D@8
ABAP data alue "idth (@) ]H database column "idth (9) o-
long o-
number (9)
ABAP data alue is non-numeric 8IBB
ABAP data alue "idth (@) G database column "idth (9) 8DCJ
ABAP data alue "idth (@) ]H database column "idth (9) o-
number
(/#$)
(9H/-$)
ABAP data alue is non-numeric 8IBB
ABAP data alue "idth (@) G database column "idth (9) 8DCJ
ABAP data alue "idth (@) ]H database column "idth (9) o-
float
ABAP data alue is non-numeric 8IBB
ABAP data alue is numeric o-
date 8JH8
ra" (9)
ABAP data alue has an inalid database ra" format
X Aalid alues+ F-E# A-,# a-f< uppercase;lo"ercase are
e8ual in conersion Y
8DHG
ABAP data alue "idth (@) G database column "idth
(:G9)
8D@8
ABAP data alue "idth (@) ]H database column "idth
(:]H9)
o-
long ra"
ABAP data alue has an inalid database ra" format
X Aalid alues+ F-E# A-,# a-f< uppercase;lo"ercase are
e8ual in conersion Y
8DHG
ABAP data alue has a alid he/adecimal format o-

ABAP )ata -%pe= +e5adecimal X(n)
&ata alue "idth+ Number of he/adecimal digits "ithout trailing 9eros
)ata&ase
column
t%pe
Case (notes) (esult
archar4
(9)
n G >FFF 8DH8
ABAP field "idth (4n) G database column "idth (9)# (4n
G 9)
8D@8
ABAP field "idth 4n H DFFF# database column "idth H
>FFF
Xrtrunc jY
ABAP Programming (BC-ABA) 4>:
ABAP field "idth (4n) ]H database column "idth (9)# (4n
]H 9)
o-
char (9)
ABAP field "idth (4n) G database column "idth (9)# (4n G
9)
8D@8
ABAP field "idth (4n) ]H database column "idth (9)# (4n
]H 9)
o-
long
n G >FFF 8DH8
n ]H >FFF Xrtrunc jY
number (9) KCB
number
(9#$)
KCB
float KCB
date KCB
raw (:)
n G >FFF 8DH8
ABAP field "idth (n) G database column "idth (9)# (nG9) 8D@8
ABAP field "idth (n)]H database column "idth (9)#
(n]H9)
o-
long ra"
n G >FFF XrtruncY
n ] >FFF o-

S00C-
(B) ABAP &ata T$pes+ &ate# Time
Conerting a database alue into an ABAP date or time field is li-e conerting it into an ABAP
character field "ith length D or @ respectiel$! *t is technicall$ possible to conert an inalid
format# but this returns an ABAP field alue "ith an inalid format# "hich $ou cannot usefull$ use!
Conersions of this -ind are indicated in the table "ith Xo-Y!
Conersion of database data alues to
7 ABAP date format re8uire the form+ 3333''&&!
7 ABAP time format re8uire the form+ 66''SS!

(C) ABAP &ata T$pe+ Numeric Te/t
Conersions into the ABAP t$pe numeric te/t N(n) behae li-e conersions into an ABAP
character field C(n)# that is# the field contents are left-2ustified and filled "ith trailing spaces!
This is contrar$ to the numeric te/t definition# according to "hich a numeric te/t field ma$ onl$
contain digits# and is filled "ith leading 9eros! The numeric te/t field ma$ contain a string "ith an
inalid numeric te/t format follo"ing the conersion! Conersions of this -ind are indicated in the
table "ith Xo-Y!

(&) ABAP &ata T$pe+ 6e/adecimal
*f the data alue "idth is less than the field "idth# a result string is transferred (if the data
alue contains an odd number of characters# a leading 9ero is added)! The rest of the field length
is not filled "ith trailing 9eros# but "ith undefined alues!

)ata&ase Column -%pe= varc$arB (:)
&ata alue "idth+ String length (trailing spaces are not saed)
ABAP
)ata t%pe
Case (notes) (esult
C$aracter
C(n)
&atabase column "idth (9) G ABAP field "idth (n)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
o-
&atabase column "idth (9) ]H ABAP field "idth (n) o-
Numeric
te/t (N(n)#
(see(C))
X Conersion as for character fields
left-2ustified# filled "ith trailing spaces Y
Xo-Y
Pac-ed
Number
&atabase data alue is non-numeric 8IBB
.oss of figures before decimal point in conersion XnullY
.oss of decimal places in conersion XrtruncY
ABAP Programming (BC-ABA) 4>>
P(m#d)
(nH4m-1)
&atabase data alue "idth ]H ABAP field "idth (n-d)
X &ata alue "idth; field "idth+ Number of positions
before comma Y
o- ; XrtruncY
*nteger *
&atabase data alue is non-numeric 8IBB
ABAP data alue not in interal Y -4
:1
# 4
:1
X 8DGG
&atabase data alue contains decimal places XrtruncY
&atabase data alue in interal Y -4:1# 4
:1
X o- ; XrtruncY
,loat ,
&atabase data alue is non-numeric 8IBB
&atabase data alue GH 1F
14@
X %esult is ma/! database float alue (10514@) or ma/!
ABAP float alue (1!EBE05:FD) Y
XundefY
&atabase data alue ]H -1F
14@
X %esult is 9ero or min! ABAP float alue (-
1!BEB05:FD) Y
XundefY
&atabase data alue in interal Y -1F
-1:F
# 1F
-1:F
X
X %esult rounded to F Y
XFY
Truncation in conersion
X Accurac$ in floating point limited to appro/! 1?
decimal places Y
XroundY
&atabase data alue in interal Y -1F
14@
# 1F
14@
X
X Possible inaccuracies in conersion Y
o- ; XFY ;
XroundY
&ate &(D)
(see (B))
&atabase column "idth (9) G ABAP field "idth (D)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
Xo-Y
&atabase column "idth (9) ]H ABAP field "idth (D) Xo-Y
Time T(@)
(see (B))
&atabase column "idth (9) G ABAP field "idth (@)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
Xo-Y
&atabase column "idth (9) ]H ABAP field "idth (@) Xo-Y
6e/adecimal
_(n)
(see (&))
&atabase data alue has an inalid he/adecimal format
X Aalid alues+ F-E# A-,# a-f< uppercase;lo"ercase are
e8ual in conersion Y
8DHG
&atabase data alue "idth (/) G ABAP field "idth# (/ ]H
9# / G 4n)
&atabase data alue "idth (/) H ABAP field "idth# (/ ]H
9# / H 4n)
&atabase data alue "idth (/) ] ABAP field "idth# (/ ]H
9# / ] 4n)
X ,illed "ith trailing undefined alues Y
XrtruncY
o-
XundefY

)ata&ase Column -%pe= c$ar (:)
&ata alue "idth+ String length (trailing spaces are not saed)
ABAP
)ata t%pe
Case (notes) (esult
C$aracter
C(n)
&atabase column "idth (9) G ABAP field "idth (n)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
o-
&atabase column "idth (9) ]H ABAP field "idth (n) o-
Numeric
te/t (N(n)#
(see(C))
X Conersion as for character fields
left-2ustified# filled "ith trailing spaces Y
Xo-Y
Pac-ed
Number
P(m#d)
(nH4m-1)
&atabase data alue is non-numeric 8IBB
.oss of figures before decimal point in conersion XnullY
.oss of decimal places in conersion XrtruncY
&atabase data alue "idth ]H ABAP field "idth (n-d)
X &ata alue "idth; field "idth+ Number of positions
before comma Y
o- ; XrtruncY
ABAP Programming (BC-ABA) 4>?
*nteger *
&atabase data alue is non-numeric 8IBB
ABAP data alue not in interal Y -4
:1
# 4
:1
X 8DGG
&atabase data alue contains decimal places XrtruncY
&atabase data alue in interal Y -4:1# 4
:1
X o- ; XrtruncY
,loat ,
&atabase data alue is non-numeric 8IBB
&atabase data alue GH 1F
14@
X %esult is ma/! database float alue (10514@) or ma/!
ABAP float alue (1!EBE05:FD) Y
XundefY
&atabase data alue ]H -1F
14@
X %esult is 9ero or min! ABAP float alue (-
1!BEB05:FD) Y
XundefY
&atabase data alue in interal Y -1F
-1:F
# 1F
-1:F
X
X %esult rounded to F Y
XFY
Truncation in conersion
X Accurac$ in floating point limited to appro/! 1?
decimal places Y
XroundY
&atabase data alue in interal Y -1F
14@
# 1F
14@
X
X Possible inaccuracies in conersion Y
o- ; XFY ;
XroundY
&ate &(D)
(see (B))
&atabase column "idth (9) G ABAP field "idth (D)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
Xo-Y
&atabase column "idth (9) ]H ABAP field "idth (D) Xo-Y
Time T(@)
(see (B))
&atabase column "idth (9) G ABAP field "idth (@)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
Xo-Y
&atabase column "idth (9) ]H ABAP field "idth (@) Xo-Y
6e/adecimal
_(n)
(see (&))
&atabase data alue has an inalid he/adecimal format
X Aalid alues+ F-E# A-,# a-f< uppercase;lo"ercase are
e8ual in conersion Y
8DHG
&atabase column "idth (9) G ABAP field "idth (n)#
(9G4n)
&atabase data alue "idth (/) G ABAP field "idth# (/ ]H
9# / G 4n)
&atabase data alue "idth (/) ]H ABAP field "idth# (/
]H 9# / ]H 4n)

XrtruncY
8DHG
&atabase column "idth (9) H ABAP field "idth(n)#
(9H4n)
&atabase data alue "idth (/) H ABAP field "idth# (/ ]H
9# / H 4n)
&atabase data alue "idth (/) ] ABAP field "idth# (/ ]H
9# / ] 4n)

o-
8DHG
&atabase column "idth (9) ] ABAP field "idth (n)# (9 ]H
4n)
X ,illed "ith trailing undefined alues Y
XundefY

)ata&ase Column -%pe= long
&ata alue "idth+ String length (trailing spaces are not saed)
ABAP
)ata t%pe
Case (notes) (esult
C$aracter
C(n)
&atabase data alue "idth G ABAP field "idth XrtruncY
&atabase data alue "idth ]H ABAP field "idth o-
Numeric
te/t (N(n)#
(see(C))
X Conersion as for character fields
left-2ustified# filled "ith trailing spaces Y
Xo-Y
Pac-ed
P(m#d)
(nH4m-1)
&ata alue is non-numeric 8IBB
.oss of digits before the decimal point XnullY
.oss of digits after the decimal point XrtruncY
ABAP Programming (BC-ABA) 4>@
&atabase data alue "idth ]H ABAP field "idth (n-d)
X &ata alue "idth; field "idth+ Number of positions
before comma Y
o- ; XrtruncY
*nteger * XundefY
,loat , XundefY
&ate &(D)
(see (B))
&atabase data alue "idth G ABAP field "idth (D) XrtruncY
&atabase data alue "idth ]H ABAP field "idth (D) Xo-Y
Time T(@)
(see (B))
&atabase data alue "idth G ABAP field "idth (@) XrtruncY
&atabase data alue "idth ]H ABAP field "idth (@) Xo-Y
6e/adecimal
_(n)
(see (&))
XundefY

)ata&ase Column -%pe= varc$arB (:)
&ata alue "idth+ Number of digits "ithout leading 9eros< n is increased b$ one if there is a minus
sign!
ABAP
)ata t%pe
Case (notes) (esult
Character
C(n)
&atabase data alue "idth G ABAP field "idth (n) XrtruncY
&atabase data alue "idth ]H ABAP field "idth (n) o-
Numeric
te/t (N(n)#
(see(C))
X Conersion as for character fields
left-2ustified# filled "ith trailing spaces Y
Xo-Y
Pac*ed
P(m4d)
(nH4m-1)
.oss of figures before decimal point in conersion XnullY
&atabase data alue "idth ]H ABAP field "idth (n-d)
X &ata alue "idth; field "idth+ Number of positions
before comma Y
o-
Integer I
ABAP data alue not in interal Y -4
:1
# 4
:1
X 8DGG
&atabase data alue in interal Y -4:1# 4
:1
X o-
,loat ,
Truncation in conersion
X Accurac$ in floating point limited to appro/! 1? decimal
places Y
XroundY
&atabase data alue 7 Y -1F
14@
# 1F
14@
X
X Possible inaccuracies in conersion Y
o- ; XroundY
&ate &(D)
(see (B))
&atabase column "idth (9) G ABAP field "idth (D)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
Xo-Y
&atabase column "idth (9) ]H ABAP field "idth (D) Xo-Y
Time T(@)
(see (B))
&atabase column "idth (9) G ABAP field "idth (@)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
Xo-Y
&atabase column "idth (9) ]H ABAP field "idth (@) Xo-Y
6e/adecimal
_(n)
(see (&))
KCB

)ata&ase Column -%pe= num&er (:4%)
&ata alue "idth+ Number of digits (9) "ithout leading 9eros< data alue "idth is increased b$ one
for each of decimal point and minus sign!
ABAP
)ata t%pe
Case (notes) (esult
Character
C(n)
&atabase data alue "idth G ABAP field "idth (n) XrtruncY
&atabase data alue "idth ]H ABAP field "idth (n) o-
Numeric
te/t (N(n)#
(see(C))
X Conersion as for character fields
left-2ustified# filled "ith trailing spaces Y
Xo-Y
.oss of significant figures (see (A))! XnullY
ABAP Programming (BC-ABA) 4>B
Pac*ed
P(m4d)
(nH4m-1)
.oss of non-significant figures (see (A))! XrtruncY
&atabase data alue "idth ]H ABAP field "idth (n-d)
X &ata alue "idth; field "idth+ Number of positions
before comma Y
o- ; XrtruncY
*nteger *
ABAP data alue not in interal Y -4
:1
# 4
:1
X 8DGG
&atabase data alue contains decimal places XrtruncY
&atabase data alue in interal Y -4:1# 4
:1
X o- ; XrtruncY
,loat ,
Truncation in conersion
X Accurac$ in floating point limited to appro/! 1? decimal
places Y
XroundY
&atabase data alue in interal Y -1F
14@
# 1F
14@
X
X Possible inaccuracies in conersion Y
o- ; XroundY
&ate &(D)
(see (B))
&atabase column "idth (9) G ABAP field "idth (D)# (9GHD)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
Xo-Y
&atabase column "idth (9) ]H ABAP field "idth (D)#
(9]D)
Xo-Y
Time T(@)
(see (B))
&atabase column "idth (9) G ABAP field "idth (@)# (9GH@)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
Xo-Y
&atabase column "idth (9) ]H ABAP field "idth (@)#
(9]@)
Xo-Y
6e/adecimal
_(n)
(see (&))
KCB

)ata&ase Column -%pe= float
&ata alue "idth+ Number of digits "ithout leading 9eros< n is increased b$ one for each of
decimal point and minus sign!
ABAP
)ata t%pe
Case (notes) (esult
Character
C(n)
&atabase data alue "idth G ABAP field "idth (n) XrtruncY
&atabase data alue "idth ]H ABAP field "idth (n) o-
Numeric
te/t (N(n)#
(see(C))
X Conersion as for character fields
left-2ustified# filled "ith trailing spaces Y
Xo-Y
Pac-ed
P(m#d)
(nH4m-1)
.oss of figures before decimal point in conersion XnullY
.oss of decimal places in conersion XrtruncY
&atabase data alue "idth ]H ABAP field "idth (n-d)
X &ata alue "idth; field "idth+ Number of positions
before comma Y
o- ; XrtruncY
*nteger *
ABAP data alue not in interal Y -4
:1
# 4
:1
X 8DGG
&atabase data alue contains decimal places XrtruncY
&atabase data alue in interal Y -4:1# 4
:1
X o- ; XrtruncY
2loat 2
Truncation in conersion
X Accurac$ in floating point limited to appro/! 1? decimal
places Y
XroundY
&atabase data alue in interal Y -1F
14@
# 1F
14@
X
X Possible inaccuracies in conersion Y
o- ; XroundY
&ate &(D)
(see (B))
&atabase data alue "idth G ABAP field "idth (D) XrtruncY
&atabase data alue "idth ]H ABAP field "idth (D) Xo-Y
Time T(@)
(see (B))
&atabase data alue "idth G ABAP field "idth (@) XrtruncY
&atabase data alue "idth ]H ABAP field "idth (@) Xo-Y
6e/adecimal
_(n)
(see (&))
KCB

ABAP Programming (BC-ABA) 4>D
)ata&ase Column -%pe= date(K)
&ata alue "idth H E (fi/ed)
ABAP
)ata t%pe
Case (notes) (esult
C$aracter
C(n)
&atabase data alue "idth (E) G ABAP field "idth (n)#
(n]E)
XrtruncY
&atabase data alue "idth (E) ]H ABAP field "idth (n)#
(nGHE)
o-
Numeric
te/t (N(n)#
(see(C))
X Conersion as for character fields
left-2ustified# filled "ith trailing spaces Y
Xo-Y
Pac-ed P KCB
*nteger * KCB
,loat , KCB
&ate &(D)
(see (B))
o- ; XrtruncY
Time T(@)
(see (B))
o- ; XrtruncY
6e/adecimal
_(n)
(see (&))
KCB

)ata&ase Column -%pe= raw(5)
Column "idth+ 9 H 4/
&ata alue "idth+ Number of he/adecimal digits "ithout trailing 9eros
ABAP
)ata t%pe
Case (notes) (esult
Character
C(n)
&atabase column "idth (9) G ABAP field "idth (n)# (9Gn)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
o-
&atabase column "idth (9) ]H ABAP field "idth (n)#
(9]Hn)
o-
Numeric
te/t (N(n)#
(see(C))
X Conersion as for character fields
left-2ustified# filled "ith trailing spaces Y
Xo-Y
Pac-ed P KCB
*nteger * KCB
,loat , KCB
&ate &(D)
(see (B))
&atabase column "idth (9) G ABAP field "idth (D)# (9GD)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
Xo-Y
&atabase column "idth (9) ]H ABAP field "idth (D)#
(9]HD)
Xo-Y
Time T(@)
(see (B))
&atabase column "idth (9) G ABAP field "idth (@)# (9]@)
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth ]H ABAP field "idth

XrtruncY
Xo-Y
&atabase column "idth (9) ]H ABAP field "idth (@)#
(9]H@)
Xo-Y
6e/adecimal
_(n)
(see (&))
&atabase data alue "idth G ABAP field "idth
&atabase data alue "idth H ABAP field "idth
&atabase column "idth ] ABAP field "idth
X ,illed "ith trailing undefined alues Y
XrtruncY
o-
XundefY

)ata&ase Column -%pe= long raw
&ata alue "idth+ Number of he/adecimal digits "ithout trailing 9eros
ABAP
)ata t%pe
Case (notes) (esult
ABAP Programming (BC-ABA) 4>E
Character
C(n)
&atabase data alue "idth ]H ABAP field "idth o-
&atabase data alue "idth G ABAP field "idth XrtruncY
Numeric
te/t (N(n)#
(see(C))
X Conersion as for character fields
left-2ustified# filled "ith trailing spaces Y
Xo-Y
Pac-ed P KCB
*nteger * KCB
,loat , KCB
&ate &(D)
(see (B))
&atabase data alue "idth G ABAP field "idth (D) XrtruncY
&atabase data alue "idth ]H ABAP field "idth (D) Xo-Y
Time T(@)
(see (B))
&atabase data alue "idth G ABAP field "idth (@) XrtruncY
&atabase data alue "idth ]H ABAP field "idth (@) Xo-Y
6e/adecimal
_(n)
(see (&))
&atabase data alue "idth G ABAP field "idth (4n) XrtruncY
&atabase data alue "idth H ABAP field "idth (4n) o-
&atabase column "idth ] ABAP field "idth (4n)
X ,illed "ith trailing undefined alues Y
XundefY

)ata&ase Column -%pe= rowid(8J)
&ata alue "idth H 1D (fi/ed)
ABAP
)ata t%pe
Case (notes) (esult
C$aracter
C(n)
&atabase data alue "idth (1D) G ABAP field "idth (n)#
(1D G E)
XrtruncY
&atabase data alue "idth (1D) ]H ABAP field "idth (n)#
(1D ]H E)
o-
Numeric
te/t (N(n)#
(see(C))
X Conersion as for character fields
left-2ustified# filled "ith trailing spaces Y
Xo-Y
Pac-ed P KCB
*nteger * KCB
,loat , KCB
&ate &(D)
(see (B))
XundefY
Time T(@)
(see (B))
XundefY
6e/adecimal
_(n)
(see (&))
KCB
)ata Interfaces
The data "ith "hich the ABAP programs "or-# is mostl$ stored in the central databan- of the
SAP S$stem! 6o"eer ABAP programs can also access the file s$stems of the other t"o la$ers of
the client-serer architecture! That means the$ can also sae or read persistent data from the
"or-stations of the application la$er or the des-top computers of the presentation la$er!
A common use of this possibilit$ is the transfer of data "ithin the SAP s$stem! 3ou can import
files into an ABAP program# regardless of "hat format the$ hae in the file s$stem of the serer#
edit them there and then sae them to the databan-! 3ou can also "rite data from a databan- to
be edited further in these file s$stems# as for e/ample "ith des-top applications for
presentation purposes!
Wor-ing "ith ,iles on the Applications Serer
As the names of files and director$ paths ar$ from operating s$stem to operating s$stem# it is
usuall$ the case that programs that access files directl$ are not platform-independent! The SAP
Web AS ABAP S$stem contains a function module and a range of transactions that allo" $ou to
"or- "ith platform-independent filenames!
)sing Platform-*ndependent ,ilenames
Wor*ing wit$ 2iles on t$e Application Server

ABAP Programming (BC-ABA) 4?F
*n ABAP# there is a range of statements for processing data that is stored in se8uential files on
the application serer instead of the database!

7 OP0N )A-AS0- opens a file for a particular t$pe of access and storage!
7 -(ANS20( transfers the contents of a data ob2ect to a file!
7 (0A) )A-AS0- transfers data from a file to a data ob2ect!
7 /0- )A-AS0- using the addition POSI-ION the current position of the file pointer in a
file is ascertained! )sing the addition A--(IB.-0S further characteristics of the file are
obtained!
7 S0- )A-AS0- using the addition POSI-ION the position of the file pointer is specified!
)sing the addition A--(IB.-0S further characteristics of the file can be specified!
7 -(.NCA-0 )A-AS0- sets the end of a file to a specified alue# thereb$ changing the
si9e of the file!
7 COS0 )A-AS0- closes a file!
7 )00-0 )A-AS0- deletes a file!

,or further details about these statements and their additions# see the -e$"ord documentation!

&uring se8uential file operations# the s$stem performs a range of automatic chec-s# some of
"hich ma$ lead to runtime errors!
%efer also to the chapter+
Automatic Chec-s in ,ile 1perations!
Wor*ing wit$ 2iles on t$e Presentation Server
)se the follo"ing function modules "hen "or-ing "ith files on the presentation serer+
()*S&1WN.1A& and ()*S)P.1A&!
Class C.S()*S,%1NT0N&SS0%A*C0S gies $ou the releant information!
The ph$sical names of the files depend on the operating s$stem of the presentation serer! 3ou
can# ho"eer# ma-e $our ABAP programs platform-independent b$ using logical filenames! ,or
further information# refer to )sing Platform-*ndependent ,ilenames!
.sing Platform-Independent 2ilenames
The file names that $ou use in ABAP statements for processing files are ph$sical names! This
means that the$ must be s$ntacticall$ correct filenames for the operating s$stem under "hich
$our SAP s$stem is running! 1nce $ou hae created a file from an ABAP program "ith a particular
name and path# $ou can find the same file using the same name and path at operating s$stem leel!
Since the naming conentions for files and paths differ from operating s$stem to operating
s$stem# ABAP programs are onl$ portable from one operating s$stem to another if $ou use the
tools described belo"!
To ma-e programs portable# the SAP s$stem has a concept of logical filenames and paths! These
are lin-ed to ph$sical files and paths! This lin- is defined in special tables! 3ou can define these
tables in accordance "ith $our re8uirements! *n an ABAP program# $ou can then use the function
module ,*.0S(0TSNA'0 to generate a ph$sical filename from a logical one!
'aintaining platform-independent filenames is part of Customi9ing! ,or a full description# choose
Tools 7 Business 0ngineer 7 Customi9ing# follo"ed b$
*mplement! pro2ects 7 SAP %eference *'(! 1n the ne/t screen# choose Basis Components 7
S$stem Administration 7 Platform-independent ,ile Names!
,or a more detailed description of the function module ,*.0S(0TSNA'0# enter its name on the
initial screen of the ,unction Builder and choose (oto 7 &ocumentation! 1n the ne/t screen#
choose ,unction module doc!
Another "a$ of maintaining platform-independent filenames is to use the Transaction ,*.0! ,or
information about platform-dependent filenames# refer to the Platform *ndependent ,ilename
Assignment section of the 0/tended Applications ,unction .ibrar$ documentation!
)ata Clusters
*n the follo"ing section a t$pe of data storage is introduced that can onl$ be used b$ ABAP
programs! The content of an$ number of data ob2ects of an$ comple/it$ can be stored in
different storage media using the ABAP specific format -no"n as data clusters! 1nl$ ABAP
programs can use this format and therefore onl$ ABAP programs can import data stored in this
fashion bac- into data ob2ects!
The follo"ing illustration sho"s the schematic structure of a data cluster in the storage medium!
ABAP Programming (BC-ABA) 4?1
A data cluster is made up of different administration information# "hich aries depending on the
storage medium# and a data area# "hich contains the compressed data ob2ects!
The follo"ing storage media e/ist+
7 B$te String
7 *nternal Table
7 ABAP 'emor$
7 &atabase Tables
7 Cross Transaction Application Buffer
See Statements for &ata Clusters to find out ho" to "rite data ob2ects to different storage
media# ho" to read them again later# ho" to delete storage media and ho" to create a director$
of a data cluster!
Storage ,edia for )ata Clusters
&ata clusters are stored in a storage medium "ith the help of the statement 0XPO(- ( see+
Statements for &ata Clusters) ! This is achieed using the different ariations of the addition
medium! These are as follo"s+
7 )A-A B.220( 5str for storage in a b$te string 5str
7 IN-0(NA -AB0 ita& for storage in an internal table ita& (Standard table)
7 ,0,O(7 I) id for storage under the name id in the ABAP 'emor$
7 )A-ABAS0 d&ta& 999 I) id for storage under the name id in a database table in the
ABAP &ictionar$
7 S+A(0) ,0,O(7 d&ta& 999 I) id and S+A(0) B.220( d&ta& 999 I) id for storage
under the name id in the cross-transaction application buffer of the applications sererIs shared
memor$!
*n the follo"ing $ou "ill learn more about the temporar$ storage of data clusters in ABAP
memor$ and shared memor$# as "ell as permanent storage in databan-s! 3ou can find detailed
information about the different storage media in the -e$"ord documentation!
ABAP ,emor%
ABAP memor$ is a memor$ area "ithin the internal session (roll area) of an ABAP program and an$
other program called from it using CA -(ANSAC-ION or S.B,I-!
ABAP memor$ is independent of the ABAP program or program module from "hich it "as
generated! *n other "ords# an ob2ect saed in ABAP memor$ can be read from an$ other ABAP
program in the same call chain! ABAP memor$ is not the same as the cross-transaction global SAP
memor$! ,or further information# refer to Passing &ata Bet"een Programs!
This allo"s $ou to pass data from one module to another oer seeral leels of the program
hierarch$! ,or e/ample# $ou can pass data
7 from e/ecutable programs that hae been called using S.B,I-
7 ,rom a transaction to an e/ecutable program!
7 Bet"een dialog modules!
7 ,rom a program to a function module!
and so on!
The contents of the memor$ are released "hen $ou leae the transaction!
)ata&ase -a&les
3ou can store data clusters in databases in the ABAP &ictionar$! *n order to do so# $ou must
create databan- tables "ith a special structure! SAP proides a template databan- table called
*N&_# "hich $ou can cop$ and modif$! This is "h$ "e also ma-e reference to *N&_ t$pe tables
(see the -e$"ord documentation)!
This method allo"s $ou to store comple/ data ob2ects "ith deep structures in a single step#
"ithout haing to ad2ust them to conform to the flat structure of a relational database! 3our
data ob2ects are then aailable s$stem-"ide to eer$ user! To read these ob2ects from the
database successfull$# $ou must -no" their data t$pes!
3ou can use *N&_-t$pe database tables to store the results of anal$ses of data from the
relational database! ,or e/ample# if $ou "ant to create a list of $our customers "ith the highest
reenue# or an address list from the personnel data of all of $our branches# $ou can "rite ABAP
programs to generate the list and store it as a data cluster! To update the data cluster# $ou can
schedule the program to run periodicall$ as a bac-ground 2ob! 3ou can then "rite other programs
that read from the data cluster and "or- "ith the results! This method can considerabl$ reduce
ABAP Programming (BC-ABA) 4?4
the response time of $our s$stem# since it means that $ou do not hae to access the distributed
data in the relational database tables each time $ou "ant to loo- at $our list!
Although *N&_ t$pe tables are normal databan- tables from the ABAP &ictionar$# $ou should
onl$ use them in con2unction "ith the special statements for data clusters! 1nl$ in e/ceptional
cases# for e/ample in order to delete man$ data clusters from one area "ith a single statement#
can $ou use 1pen SC. statements! *n order to do this $ou must hae a good "or-ing -no"ledge of
the structure of *N&_ t$pe tables and it is recommended that the table and its contents first
be chec-ed for different application cases using the data bro"ser of the ABAP Wor-bench
(transaction S01@)!Although it is possible to access an *N&_-t$pe database using SC.
statements# it is onl$ possible to interpret the structure of the data cluster using ABAP
statements!
Cross -ransaction Application Buffer
The cross transaction application buffer is a storage area on an application serer "hich all ABAP
programs of the SAP s$stem running on the same applications serer can access! &ata clusters in
the cross transaction application buffer are e/actl$ the same as data clusters that are organi9ed
in databan- tables! 6ere "e "ill refer to the databan- table d&ta&! The data are not stored in
the databan- table itself but in a table "ith a corresponding set up! Therefore the databan-
table d&ta& must also be an *N&_ t$pe (see -e$"ord documentation)! The structure of this table
is then copied for the storage of the cluster in the buffer! This gies $ou the possibilit$ to store
$our o"n administratie information in eer$ cluster in the buffer and import it again as
necessar$!
The difference bet"een the application buffers S+A(0) ,0,O(7 and S+A(0) B.220( lies in
ho" the s$stem reacts "hen the storage limit is reached (see Ue$"ord documentation)!
Statements for )ata Clusters
To store and read data clusters# ABAP offers the follo"ing statements+
7 0XPO(- parameter list -O medium
7 I,PO(- parameter list 2(O, medium
The data cluster is defined "ith help of a parameter list parameter list# (see -e$"ord
documentation)# and specifies the Storage 'edium in medium!
3ou can "rite a director$ of the data ob2ects of a data cluster to an internal table using the
statement *'P1%T &*%0CT1%3!! The data cluster "as stored in a database table using 0_P1%T!
To delete data clusters# $ou can use the follo"ing statements+
7 2(00 ,0,O(7 deletes all data cluster from the ABAP memor$
7 )00-0 2(O, 999 I) id deletes a data cluster "ith the identification id# "hich "as
stored in the ABAP memor$ of a database table# or in an application buffer of an application
serer!
,or further details about these statements and additions# see the -e$"ord documentation!
)ata Consistenc%
The SAP transaction concept illustrates ho" database changes can be programmed!
See also the descriptions in the ABAP 0ditor under )tilities 7 Ue$"ord documentation 7 ABAP
1erie" 7 &escription of S$nta/ and Concepts 7 Transaction processing!
The statements that carr$ out the actual database changes are a part of 1pen SC.!

Transactions and .ogical )nits of Wor-
Chec-ing Authori9ations
The SAP .oc- Concept
)pdate Techni8ues
Creating )pdate ,unction 'odules
Calling )pdate ,unctions
Special .)W Considerations
0rror 6andling for Bundled )pdates
-ransactions and ogical .nits of Wor*
*n eer$da$ language# a transaction is a se8uence of actions that logicall$ belong together in a
business sense and that either procure or process data! *t coers a self-contained procedure# for
e/ample# generating a list of customers# creating a flight boo-ing# or sending reminders to
customers! ,rom the user=s ie"point# it forms a logical unit!
The completeness and correctness of data must be assured "ithin this unit! *n the middle of a
transaction# the data "ill usuall$ be inconsistent! ,or e/ample# "hen $ou transfer an amount in
financial accounting# this must first be deducted from one account before being credited to
ABAP Programming (BC-ABA) 4?:
another! *n bet"een the t"o postings# the data is inconsistent# since the amount that $ou are
posting does not e/ist in either account! *t is essential for application programmers to -no" that
their data is consistent at the end of the transaction! *f an error occurs# it must be possible to
undo the changes made "ithin a logical process!
There are three releant concepts in this conte/t+
)ata&ase ogical .nit of Wor* (.W)
A database .)W is the mechanism used b$ the database to ensure that its data is al"a$s
consistent!
SAP .W
An SAP .)W is a logical unit consisting of dialog steps# "hose changes are "ritten to the
database in a single database .)W!
SAP -ransaction
An SAP transaction is an ABAP application program that $ou start using a transaction code! *t
ma$ contain one or more SAP .)Ws!
The follo"ing sections of this documentation e/plain these three terms in more detail!
)ata&ase ogical .nit of Wor* (.W)
,rom the point of ie" of database programming# a database .)W is an inseparable se8uence of
database operations that ends "ith a database commit! The database .)W is either full$
e/ecuted b$ the database s$stem or not at all! 1nce a database .)W has been successfull$
e/ecuted# the database "ill be in a consistent state! *f an error occurs "ithin a database .)W#
all of the database changes since the beginning of the database .)W are reersed! This leaes
the database in the state it "as in before the transaction started!
The database changes that occur "ithin a database .)W are not actuall$ "ritten to the database
until after the database commit! )ntil this happens# $ou can use a database rollbac- to reerse
the changes! *n the SAP S$stem# database commits and rollbac-s can be triggered either
implicitl$ or using e/plicit commands!
Implicit )ata&ase Commits
A "or- process can onl$ e/ecute a single database .)W! The conse8uence of this is that a "or-
process must al"a$s end a database .)W "hen it finishes its "or- for a user or an e/ternal call!
Wor- processes trigger an implicit database commit in the follo"ing situations+
7 When a dialog step is completed
Control changes from the "or- process bac- to the SAP ()*!
7 When a function module is called in another "or- process (%,C)!
Control passes to the other "or- process!
7 When the called function module (%,C) in the other "or- process ends!
Control returns to the calling "or- process!
7 When a WAI- statement interrupts the "or- process!
Control passes to another "or- process!
7 0rror dialogs (information# "arning# or error messages) in dialog steps!
Control passes from the "or- process to the SAP ()*!
05plicit )ata&ase Commits
There are t"o "a$s to trigger an e/plicit database commit in $our application programs+
7 Call the function module &BSC1''*T
The sole tas- of this function module is to start a database commit!
ABAP Programming (BC-ABA) 4?>
7 )se the ABAP statement CO,,I- WO("
This statement starts a database commit# but also performs other tas-s (refer to the
-e$"ord documentation for CO,,I- WO(")!
Implicit )ata&ase (oll&ac*s
The follo"ing cases lead to an implicit database rollbac-+
7 %untime error in an application program
This occurs "heneer an application program has to terminate because of an unforeseen
situation (for e/ample# tr$ing to diide b$ 9ero)!
7 Termination message
Termination messages are generated using the ABAP statement ,0SSA/0 "ith the message
t$pe A or _! *n certain cases (updates)# the$ are also generated "ith message t$pes *# W# and
0! These messages end the current application program!
05plicit )ata&ase (oll&ac*s
3ou can trigger a database rollbac- e/plicitl$ using the ABAP statement (OBAC" WO("!
This statement starts a database rollbac-# but also performs other tas-s (refer to the
-e$"ord documentation for (OBAC" WO(")!
,rom the aboe# "e can dra" up the follo"ing list of points at "hich database .)Ws begin and
end!
A )ata&ase .W Begins
7 0ach time a dialog step starts ("hen the dialog step is sent to the "or- process)!
7 Wheneer the preious database .)W ends in a database commit!
7 Wheneer the preious database .)W ends in a database rollbac-!
A )ata&ase .W 0nds
7 0ach time a database commit occurs! This "rites all of the changes to the database!
7 0ach time a database rollbac- occurs! This reerses all of the changes made during the
.)W!
)ata&ase .Ws and )ata&ase oc*s
As "ell as the database changes made "ithin it# a database .)W also consists of database loc-s!
The database s$stem uses loc-s to ensure that t"o or more users cannot change the same data
simultaneousl$# since this could lead to inconsistent data being "ritten to the database! A
database loc- can onl$ be actie for the duration of a database .)W! The$ are automaticall$
released "hen the database .)W ends! *n order to program SAP .)Ws# "e need a loc-
mechanism "ithin the %;: S$stem that allo"s us to create loc-s "ith a longer lifetime (refer to
The SAP .oc-ing Concept)!
SAP .W
The 1pen SC. statements INS0(-# .P)A-0# ,O)I27# and )00-0 allo" $ou to program
database changes that e/tend oer seeral dialog steps! 0en if $ou hae not e/plicitl$
programmed a database commit# the implicit database commit that occurs after a screen has
been processed concludes the database .)W! The follo"ing diagram sho"s the indiidual
database .)Ws in a t$pical screen se8uence+
ABAP Programming (BC-ABA) 4??
)nder this procedure# $ou cannot roll bac- the database changes from preious dialog steps! *t is
therefore onl$ suitable for programs in "hich there is no logical relationship bet"een the
indiidual dialog steps!
6o"eer# the database changes in indiidual dialog steps normall$ depend on those in other dialog
steps# and must therefore all be e/ecuted or rolled bac- together! These dependent database
changes form logical units# and can be grouped into a single database .)W using the bundling
techni8ues listed belo"!
A logical unit consisting of dialog steps# "hose changes are "ritten to the database in a single
database .)W is called an SAP .)W! )nli-e a database .)W# an SAP .)W can span seeral
dialog steps# and be e/ecuted using a series of different "or- processes! *f an SAP .)W
contains database changes# $ou should either "rite all of them or none at all to the database! To
ensure that this happens# $ou must include a database commit "hen $our transaction has ended
successfull$# and a database rollbac- in case the program detects an error! 6o"eer# since
database changes from a database .)W cannot be reersed in a subse8uent database .)W# $ou
must ma-e all of the database changes for the SAP .)W in a single database .)W! To maintain
data integrit$# $ou must bundle all of $ou database changes in the final database .)W of the SAP
.)W! The follo"ing diagram illustrates this principle+

The bundling techni8ue for database changes "ithin an SAP .)W ensures that $ou can still
reerse them! *t also means that $ou can distribute a transaction across more than one "or-
process# and een across more than one SAP s$stem! The possibilities for bundling database
changes "ithin an SAP .)W are listed belo"+
The simplest form of bundling is to process a "hole application "ithin a single dialog step! 6ere#
the s$stem chec-s the user=s input and updates the database "ithout a database commit
occurring "ithin the dialog step itself! 1f course# this is not suitable for comple/ business
processes! *nstead# the SAP s$stem contains the follo"ing bundling techni8ues!
Bundling using 2unction ,odules for .pdates
*f $ou call a function module using the statement CA 2.NC-ION 999 IN .P)A-0 -AS"# the
function module is flagged for e/ecution using a special update "or- process! This means that $ou
can "rite the 1pen SC. statements for the database changes in the function module instead of
in $our program# and call the function module at the point in the program "here $ou "ould
other"ise hae included the statements! When $ou call a function module using the IN .P)A-0
-AS"addition# it and its interface parameters are stored as a log entr$ in a special database
table called AB.1(!
The function module is e/ecuted using an update "or- process "hen the program reaches the
CO,,I- WO("statement! After the CO,,I- WO("statement# the dialog "or- process is
free to receie further user input! The update "or- process is responsible for the update part of
the SAP .)W! The statement CO,,I- WO("closes the SAP .)W for the dialog part of the
program and starts the update! The SAP .)W is complete once the update process has
committed or rolled bac- all of the database changes! Bundling using function modules is called
.pdate!
ABAP Programming (BC-ABA) 4?@
,or further information about ho" to create function modules for use in update# refer to
Creating ,unction 'odules for &atabase )pdates
&uring the update# errors onl$ occur in e/ceptional casses# since the s$stem chec-s for all logical
errors# such as incorrect entries# in the dialog phase of the SAP .)W! *f a logical error occurs#
the program can terminate the update using the (OBAC" WO("statement! Then# the function
modules are not called# and the log entr$ is deleted from table AB.1(! 0rrors during the update
itself are usuall$ technical# for e/ample# memor$ shortage! *f a technical error occurs# the
update "or- process triggers a database rollbac-# and places the log entr$ bac- into AB.1(! *t
then sends a mail to the user "hose dialog originall$ generated the AB.1( entr$ "ith details of
the termination! These errors must be corrected b$ the s$stem administrator! After this# the
returned AB.1( entries can be processed again!
,or further information about update administration# see )pdate Administration
This techni8ue of bundling database changes in the last database .)W of the SAP .)W allo"s
$ou to update the database as$nchronousl$! This decreases the response times in the dialog
process! 3ou can# for e/ample# decouple the update entirel$ from the dialog "or- process and use
a central update "or- process on a remote database serer!
Bundling .sing Su&routines
The statement P0(2O(, ON CO,,I-calls a subroutine in the dialog "or- process! 6o"eer# it
is not e/ecuted until the s$stem reaches the ne/t CO,,I- WO("statement! 6ere# as "ell# the
ABAP statement CO,,I- WO(" defines the end of the SAP .)W# since all statements in a
subroutine called "ith P0(2O(, ON CO,,I-that ma-e database changes are e/ecuted in the
database .)W of the corresponding dialog step!
The adantage of this bundling techni8ue against CA 2.NC-ION 999 IN .P)A-0 -AS" is
better performance# since the update data does not hae to be "ritten into an e/tra table#
therefore reducing the database accesses!! The disadantage# ho"eer# is that $ou cannot pass
parameters in a P0(2O(, 999 ON CO,,I-statement! &ata is passed using global ariables and
ABAP memor$! There is a considerable danger of data inconsistenc$ "hen $ou use this method to
pass data!
Bundling .sing 2unction ,odules in Ot$er SAP S%stems
,unction modules that $ou call using CA 2.NC-ION 999 IN BAC"/(O.N) -AS"
)0S-INA-ION are registered for bac-ground e/ecution in another SAP S$stem "hen the
program reaches the ne/t CO,,I- WO(" statement (using %emote ,unction Call)! After the
CO,,I- WO("# the dialog process does not "ait for these function modules to be e/ecuted
(as$nchronous update)! All of the function modules that $ou register in this "a$ are e/ecuted
together in a single database .)W! These updates are useful# for e/ample# "hen $ou need to
maintain identical data in more than one database!
,or further details# refer to the -e$"ord documentation!
,or more details of %,C processing# refer to the %emote Communications section of the Basis
Serices documentation!
SAP -ransactions
An SAP .)W is a logical unit consisting of dialog steps# "hose changes are "ritten to the
database in a single database .)W! *n an application program# $ou end an SAP .)W "ith either
the CO,,I- WO(" or (OBAC" WO(" statement! An SAP transaction is an ABAP application
ABAP Programming (BC-ABA) 4?B
program that $ou start using a transaction code! *t ma$ contain one or more SAP .)Ws!
Wheneer the s$stem reaches a CO,,I- WO(" or (OBAC" WO(" statement that is not at
the end of the last dialog step of the SAP transaction# it opens a ne" SAP .)W!
*f a particular application re8uires $ou to "rite a comple/ transaction# it can often be useful to
arrange logical processes "ithin the SAP transaction into a se8uence of indiidual SAP .)Ws! 3ou
can structure SAP transactions as follo"s+
7 With one or more SAP .)Ws!
Transactions in this form consist entirel$ of processing bloc-s (dialog modues# eent bloc-s#
function module calls# and subroutines)! 3ou should be careful to ensure that e/ternal
subroutines or function modules do not lead to CO,,I- WO(" or (OBAC" WO("
statements accidentall$ being e/ecuted!
7 B$ inserting an SAP .)W
The ABAP statements CA -(ANSAC-ION (start a ne" transaction)# S.B,I- (start an
e/ecutable program)# and CA 2.NC-ION 999 )0S-INA-ION (call a function module using
%,C) open a ne" SAP .)W! When $ou call a program# it al"a$s opens its o"n SAP l)W!
6o"eer# it does not end the .)W of the SAP transaction that called it! This means that a
CO,,I- WO(" or (OBAC" WO(" statement onl$ applies to the SAP .)W of the called
program! When the ne" .)W is complete# the s$stem carries on processing the first SAP
.)W!
7 B$ running t"o SAP .)Ws in parallel
The CA 2.NC-ION 999 S-A(-IN/ N0W -AS"statement calls a function module
as$nchronousl$ in a ne" session! )nli-e normal function module calls# the calling transaction
carries on "ith its o"n processing as soon as the function module has started# and does not
"ait for it to finish processing! The function call is as$nchronous! The called function module
can no" call its o"n screens and interact "ith the user!
C$ec*ing Aut$ori:ations
*n ABAP programs# it is often necessar$ to chec- a user=s authori9ations for special actiities!
,or e/ample# in ABAP programs# SC. Statements do not trigger authori9ation chec-s in the
database s$stem! Thus# 1pen SC. and Natie SC. statements allo" unrestricted access to all
database tables! 6o"eer# not all users hae authori9ation to access all data that is accessible to
the SC. statements in an ABAP program!
When a program is released# it can be e/ecuted b$ an$ user "ith the releant authori9ation! *t is
therefore the programmer=s responsibilit$ to chec- that eer$ user "ho can call the program is
also authori9ed to access the data processed in it!
Authori9ation Concept
Authori9ation Chec-s
Aut$ori:ation Concept
All SAP S$stem data must be protected from unauthori9ed access# so that onl$ those users "ho
hae e/plicit permission can access it!
3ou assign authori9ation in the user master maintenance! *t must be possible to specif$ e/plicitl$
to "hich data the user has access and "hat -ind of access is possible! ,or e/ample# it is possible
that a user has the authorit$ to displa$ the data for all airlines# but onl$ has the authorit$ to
change the data for some of them! Accordingl$# at each authori9ation chec- the combination of
IactionI and IairlineI must be chec-ed! When $ou create the authori9ation# in the user master
record# the default settings for the operands must be set (for e/ample# action IchangeI and
airline I.6I or action Idispla$I and airline ILI!)!I
*n the SAP S$stem these tas-s are carried out b$ aut$ori:ation o&3ects! The operands "hose
combinations must be chec-ed in authori9ation ob2ects are called fields! An authori9ation ob2ect
can contain up to 1F fields! ,or the aboe e/ample the authori9ation ob2ect is made up of the t"o
fields IactionI and IairlineI! An authori9ation ob2ect is addressed during the assignment of
authori9ation in the conte/t of user maintenance as "ell as during authori9ation chec-s!
Abbreiations for actions can be found in tables TACT and TACTT# as "ell as in the
documentation for the corresponding ob2ects!
An authori9ation ob2ect defines the combination of fields "hich must be simultaneousl$
addressed and acts as a template for the authori9ation as "ell as for the authori9ation chec-! *n
order to ma-e the management and location of the authori9ation ob2ects easier# the$ are
organi9ed into ob2ect classes# to "hich one or more classes of application are allocated!
*n the ABAP &eelopment Wor-bench $ou can find the maintenance transactions for
authori9ation ob2ects b$ choosing &eelopment 7 'ore Tools 7 Authori9ation 7 1b2ects! 3ou "ill
ABAP Programming (BC-ABA) 4?D
also find a complete list of all the ob2ects "ith the releant fields and documents# organi9ed b$
class# here!
,or more information about the authori9ation concept# refer to the )sers and
%olesdocumentation!
This authori9ation ob2ect SSCA%%*& contains t"o fields! (eneric alues can be entered in the
first field# CA%%*& (Airline)! *n the second field# ACTAT (Action)# numbers for create (F1)#
change (F4) and displa$ (F:) can be entered!
*n the user master record alues can be assigned to each of the fields in the authori9ation ob2ect
SSCA%%*& for eer$ user! The indiidual application must chec- "hen it is e/ecuted "hether the
user has the necessar$ authori9ation!
Aut$ori:ation
,or authori9ation chec-s# there are man$ "a$s of lin-ing authori9ation ob2ects "ith user actions
in an SAP s$stem! The follo"ing discusses three possibilities in the conte/t of ABAP
programming!
Aut$ori:ation C$ec* for -ransactions
3ou can directl$ lin- authori9ation ob2ects "ith transaction codes! 3ou can enter alues for the
fields of an authori9ation ob2ect in the transaction maintenance! Before the transaction is
e/ecuted# the s$stem compares these alues "ith the alues in the user master record and onl$
starts the transaction if the appropriate authori9ation e/ists!
Aut$ori:ation C$ec* for ABAP Programs
,or ABAP programs# the t"o ob2ects SS&0A0.1P (program deelopment and program e/ecution)
and SSP%1(%A' (program maintenance) e/ist! The$ contains a field PS(%1)P that is connected
"ith the program attribute authori9ation group! Thus# $ou can assign users program-specific
authori9ations for indiidual ABAP programs!
Aut$ori:ation C$ec* in ABAP Programs
A more sophisticated# user-programmed authori9ation chec- is possible using the Aut$orit%-
C$ec* statement! *t allo"s $ou to chec- the entries in the user master record for specific
authori9ation ob2ects against an$ other alues! Therefore# if a transaction or program is not
sufficientl$ protected or not eer$ user that is authori9ed to use the program can also e/ecute
all the actions# this statement must be used!
A)T61%*T3-C60CU 1Ba0CT ob2ect
*& name
1
,*0.& f
1
*& name
4
,*0.& f
4
!!!
*& name
n
,*0.& f
n
!
ob2ect is the name of an authori9ation ob2ect! With name
8
# name
B
!!! # and so on# $ou must list all
fields of the authori9ation ob2ect ob2ect! With f
1
# f
4
!!! # and so on# $ou must specif$ the alues
that the s$stem is to chec- against the entries in the releant authori9ation of the user master
record! The A)T61%*T3-C60CU statement searches for the specified ob2ect in the user profile
ABAP Programming (BC-ABA) 4?E
and chec-s the user=s authori9ations for all alues of f
1
# f
4
!!! ! 3ou can aoid chec-ing a field
name
8
# name
B
!!! b$ replacing 2I0) f
1
2I0) f
4
"ith ).,,7!
After the 2I0) addition# $ou can onl$ specif$ an elementar$ field# not a selection table!
6o"eer# there are function modules aailable that e/ecute the A.-+O(I-7-C+0C" statement
for all alues of selection tables! The A.-+O(I-7-C+0C" statement is supported b$ a
statement pattern!
1nl$ if the user has all authori9ations# is the return alue s%-su&rc of the A.-+O(I-7-C+0C"
statement set to F! The most important return alues are+
7 F+ The user has an authori9ation for all specified alues!
7 >+ The user does not hae the authori9ation!
7 D+ The number of specified fields is incorrect!
7 14+ The specified authori9ation ob2ect does not e/ist!
A list of all possible return alues is aailable in the ABAP -e$"ord documentation! The content of
s%-su&rc has to be closel$ e/amined to ascertain the result of the authori9ation chec- and react
accordingl$!
(0PO(- demoEaut$orit$%Ec$ec*9
PA(A,0-0(S paEcarr I"0 sflig$t-carrid9
)A-A waEflig$ts I"0 demoEfocc9
A- S00C-ION-SC(00N9
A.-+O(I-7-C+0C" OBY0C- ?SECA((I)?
I) ?CA((I)? 2I0) paEcarr
I) ?AC-!-? 2I0) ?@C?9
I2 s%-su&rc F D9
,0SSA/0 e@DG(sa&apdocu) WI-+ paEcarr9
0S0I2 s%-su&rc VN @9
,0SSA/0 e8JD(sa&apdocu) WI-+ te5t-@8@9
0N)I29
S-A(--O2-S00C-ION9
S00C- carrid connid fldate seatsma5 seatsocc
2(O, sflig$t
IN-O CO((0SPON)IN/ 2I0)S O2 waEflig$ts
W+0(0 carrid F paEcarr9
W(I-0= A waEflig$ts-carrid4
waEflig$ts-connid4
waEflig$ts-fldate4
waEflig$ts-seatsma54
waEflig$ts-seatsocc9
0N)S00C-9
*n this e/ample# the s$stem chec-s "ith the authori9ation ob2ect SSCA%%*& "hether or not the
user has a displa$ authori9ation (F:) for the airline entered on a selection screen! *f this is not
the case# or a different error occurs# the Selection Screen Processing goes bac- to the displa$
of the selection screen!
-$e SAP oc* Concept
(easons for Setting oc*s
Suppose a trael agent "ant to boo- a flight! The customer "ants to fl$ to a particular cit$ "ith a
certain airline on a certain da$! The boo-ing must onl$ be possible if there are still free places on
the flight! To aoid the possibilit$ of oerboo-ing# the database entr$ corresponding to the flight
must be loc-ed against access from other transactions! This ensures that one user can find out
the number of free places# ma-e the boo-ing# and change the number of free places "ithout the
data being changed in the meantime b$ another transaction!
oc* ,ec$anisms in t$e )ata&ase S%stem
The database s$stem automaticall$ sets database loc-s "hen it receies change statements
(INS0(-4 .P)A-04 ,O)I274 )00-0) from a program! &atabase loc-s are ph$sical loc-s on
the database entries affected b$ these statements! 3ou can onl$ set a loc- for an e/isting
database entr$# since the loc- mechanism uses a loc- flag in the entr$! These flags are
automaticall$ deleted in each database commit! &atabase loc-s are therefore neer aailable
ABAP Programming (BC-ABA) 4@F
longer than for onl$ one database .)W! That means that in ABAP application programming#
database loc-s can no longer e/ist than the duration of one dialog step!
The ph$sical loc- mechanisms in the database s$stem are therefore insufficient for the
re8uirements of an ABAP transaction! The loc-s must remain set for the duration of a "hole SAP
.)W# that is# oer seeral dialog steps! The$ must also be capable of being handled b$ different
"or- processes and een different application serers! Conse8uentl$# each loc- must not onl$
appl$ on the application serer that carries out the loc-ing transaction# but on all installed
serers of the SAP Web AS ABAP!
SAP oc*s
To complement the SAP .)W concept# in "hich bundled database changes are made in a single
database .)W# the SAP S$stem also contains a loc- mechanism# full$ independent of database
loc-s# that allo"s $ou to set a loc- that spans seeral dialog steps! These loc-s are -no"n as SAP
loc*s!
The complete documentation on SAP loc-s can be found in The SAP .oc- Concept! This is a
short introduction "ithin the enironment of ABAP programming!
The SAP loc- concept is based on loc* o&3ects! .oc- ob2ects allo" $ou to set SAP loc-s for entire
application ob2ects! An application ob2ect consists of one or more entries in a database table# or
entries from more than one database table that are lin-ed using foreign -e$ relationships!
Before $ou can set an SAP loc- in an ABAP program# $ou must first create a loc- ob2ect in the
ABAP &ictionar$! A loc- ob2ect definition contains the database tables and their -e$ fields on the
basis of "hich $ou "ant to set a loc-! When $ou create a loc- ob2ect# the s$stem automaticall$
generates t"o function modules "ith the names 0NC)0)0SName and &0C)0)0SName! 3ou can
then set and release SAP loc-s in $our ABAP program b$ calling these function modules in a CA
2.NC-ION statement!
See also+ 0/ample Transaction+ SAP .oc-ing
These function modules are e/ecuted in a special en8ueue "or- process! Within an SAP S$stem#
en8ueue "or- processes run on a single application serer! This serer maintains a central loc-
table for the entire SAP S$stem in its shared memor$!
The en8ueue function module sets an SAP loc- b$ "riting entries in the central loc- table! *f the
loc- cannot be set because the application ob2ect (or a part of it) is alread$ loc-ed# the function
module informs the user! The follo"ing figure sho"s the components inoled in the loc- process+

ABAP Programming (BC-ABA) 4@1

)nli-e the database# "hich sets ph$sical loc-s# the SAP loc- mechanism sets logical loc-s! This
means that+
7 A loc-ed database entr$ is not ph$sicall$ loc-ed in the database table!
The loc- entr$ is merel$ entered as a loc- argument in the central loc- table! The loc-
argument is made up of the primar$ -e$ field alues for the tables in the loc- ob2ect! These
are import parameters of the en8ueue function module! The loc- is independent of database
.)Ws! *t is released either implicitl$ "hen the database update or the SAP transaction ends#
or e/plicitl$# using the corresponding de8ueue function module! 3ou can use a special
parameter in the update function module to set the e/act point at "hich the loc- is released
during the database update!
7 A loc-ed entr$ does not necessaril$ hae to e/ist in a database table!
3ou can# for e/ample# set a loc- as a precaution for a database entr$ that is not "ritten to
the database until the update at the end of the SAP .)W!
7 The effectieness of the loc-s depends on cooperatie application programming!
Since there are no ph$sical loc-s in the database tables themseles# all programs that use the
same application ob2ects must loo- in the central table themseles for an$ loc-s! There is no
mechanism that automaticall$ preents a program from ignoring the loc-s in the loc- table!
oc* -%pes
There are four t$pes of loc-s in the SAP S$stem+
7 Shared loc-
7 0/clusie loc-
7 0/clusie but not cumulatie loc-
7 1ptimistic loc-
7 see also
oc* )uration
When $ou set a loc-# $ou should bear in mind that if it remains set for a long time# the aailabilit$
of the ob2ect to other transactions is reduced! Whether or not this is acceptable depends on the
nature of the tas- $our program is performing!
%emember in particular that setting too man$ shared loc-s "ithout good reason can hae a
considerable effect on programs that "or- "ith database tables! *f seeral programs running
concurrentl$ all set a shared loc- for the same application ob2ect in the SAP s$stem# it can ma-e
it almost impossible to set an e/clusie loc-# since the program that needs to set that loc- "ill be
unable to find an$ time "hen there are no loc-s at all set for that ob2ect! Conersel$# a single
e/clusie loc- preents all other programs from reading the loc-ed ob2ect!
At the end of an SAP .)W# $ou should release all loc-s! This either happens automaticall$ during
the database update# or e/plicitl$# "hen $ou call the corresponding de8ueue function module!
.oc-s that are not lin-ed to a database update are released at the end of the SAP transaction!
05ample Program= SAP oc*ing
The follo"ing e/ample program sho"s ho" $ou can loc- and unloc- database entries using a loc-
ob2ect!
ABAP Programming (BC-ABA) 4@4
%0P1%T demoStransactionSen8ueue '0SSA(0-*& sabapdocu!
TAB.0S sflight!
&ATA te/t(D) T3P0 c!
&ATA o-Scode T3P0 s$-ucomm!
CA.. SC%00N 1FF!
'1&).0 init 1)TP)T!
S0T P,-STAT)S IBAS*CI!
sflight-carrid H I.6I! sflight-connid H I>FFI!
0N&'1&).0!
'1&).0 e/it *NP)T!
.0AA0 P%1(%A'!
0N&'1&).0!
'1&).0 en8ueue *NP)T!
CAS0 o-Scode!
W60N I0NC)0)0I!
CA.. ,)NCT*1N I0NC)0)0S0&0'1,.6TI
0_P1%T*N(
modeSsflight H I_I
carrid H sflight-carrid
connid H sflight-connid
fldate H sflight-fldate
0_C0PT*1NS
foreignSloc- H 1
s$stemSfailure H 4
1T60%S H :!
CAS0 s$-subrc!
W60N F!
'0SSA(0 iDDD W*T6 I0n8ueue successfulI(FF1)!
W60N 1!
te/t H s$-msg1!
'0SSA(0 eDDD W*T6 I%ecord alread$I(FF4)
Iloc-ed b$I(FF:) te/t!
CA.. T%ANSACT*1N IS'14I!
W60N 4 1% :!
'0SSA(0 eDDD W*T6 I0rror in en8ueue`I(FF>)!
0N&CAS0!
W60N I&0C)0)0I!
CA.. ,)NCT*1N I&0C)0)0S0&0'1,.6TI
0_P1%T*N(
modeSsflight H I_I
carrid H sflight-carrid
connid H sflight-connid
fldate H sflight-fldate
0_C0PT*1NS
1T60%S H 1!
CAS0 s$-subrc!
W60N F!
'0SSA(0 iDDD W*T6 I&e8ueue successfulI(FF?)!
W60N 1!
'0SSA(0 eDDD W*T6 I0rror in de8ueue`I(FF@)!
0N&CAS0!
W60N IS'14I!
CA.. T%ANSACT*1N IS'14I!
0N&CAS0!
0N&'1&).0!
'1&).0 select *NP)T!
CAS0 o-Scode!
ABAP Programming (BC-ABA) 4@:
W60N IS0.0CTI!
S0.0CT L ,%1' sflight W60%0 carrid H sflight-carrid
AN& connid H sflight-connid
AN& fldate H sflight-fldate!
0N&S0.0CT!
'0SSA(0 iDDD W*T6 IS3-S)B%C+I s$-subrc!
0N&CAS0!
0N&'1&).0!
The staticall$-defined ne/t screen for screen 1FF is 1FF! *t uses components of the structure
S,.*(6T# copied from the ABAP &ictionar$# and loo-s li-e this+
The screen flo" logic is as follo"s+
P%1C0SS B0,1%0 1)TP)T!
'1&).0 init!
P%1C0SS A,T0% *NP)T!
'1&).0 e/it AT 0_*T-C1''AN&!
C6A*N!
,*0.&+ sflight-carrid# sflight-connid# sflight-fldate!
'1&).0 en8ueue!
0N&C6A*N!
'1&).0 select!
)sing the function codes 0NC)0)0 and &0C)0)0 of the ()* status# $ou can loc- and unloc-
the specified fields of the table S,.*(6T! To do this# use the specificall$ created loc- ob2ect
0&0'1,.6T ia the function modules 0NC)0)0S0&0'1,.6T and &0C)0)0S0&0'1,.6T!
*n addition# the function code S0.0CT allo"s to access the specified fields and the function code
S'14 calls the transaction S'14 to list the loc- entries in the central loc-ing table!
After a successful loc- b$ a user# no other user can loc- the same datasets again! 6o"eer# eer$
user can access the loc-ed datasets using S00C- if the program does not chec- the loc-s in
adance "ith 0NC)0)0S0&0'1,.6T!
.pdate -ec$ni1ues
The main update techni8ue for bundling database changes in a single database .)W is to use
CA 2.NC-ION 999 IN .P)A-0 -AS"! This section describes arious "a$s of updating the
database!
A program can send an update re8uest using CO,,I- WO("
7 To the update "or- process# "here it is processed as$nchronousl$! The program does not
"ait for the "or- process to finish the update (As$nchronous )pdate)!
7 ,or as$nchronous processing in t"o steps ()pdating As$nchronousl$ in Steps!)
7 To the update "or- process# "here it is processed s$nchronousl$! The program "aits for
the "or- process to finish the update (S$nchronous )pdate)!
7 To its o"n "or- process locall$! *n this case# of course# the program has to "ait until the
update is finished (.ocal )pdate!)
As%nc$ronous .pdate
A t$pical SAP s$stem installation contains dialog "or- processes and at least one update "or-
process! The update "or- processes are responsible for updating the database! *f# in a dialog
"or- process# the function modules stored in interim storage through CA 2.NC-ION 999 IN
.P)A-0 -AS" are released for processing b$ means of the ABAP statement CO,,I- WO("#
the dialog "or- process "ill not "ait for the update process to finish! This -ind of update is
called as$nchronous update!
ABAP Programming (BC-ABA) 4@>
The follo"ing diagram sho"s a t$pical as$nchronous update+
,or e/ample# let us suppose a user "ishes to change an entr$ in a database table# or add a ne"
one! 6e or she enters the necessar$ data# and then starts the update process b$ choosing Sae!
This starts the follo"ing procedure in the ABAP program+
!!!
1! ,irstl$# the program loc-s the database entr$ against other users! ,or this purpose# the
en8ueue "or- process is addressed (in a distributed s$stem# this ta-es place through the message
serer)! This generates a corresponding entr$ in the loc- table! The user is informed "hether the
update "as successful# or "hether the loc- could not be set because of other users!
4! *f the loc- is set# the program reads the entr$ that is to be changed and modifies it! *f the
user has created a ne" entr$# the program chec-s "hether a record "ith the same -e$ alues
alread$ e/ists!
:! *n the current dialog "or- process# the program calls a function module using CA
2.NC-ION 999 IN .P)A-0 -AS"# and this "rites the change details as an entr$ in table
AB.1(!
>! When the program is finished (ma$be after further dialog steps)# a CO,,I- WO("
statement starts the final part of the SAP .)W! The "or- process that is processing the current
dialog step starts an update "or- process!
?! Based on the information passed to it from the dialog "or- process# the update "or- process
reads the log entries belonging to the SAP .)W from table AB.1(!
@! The update "or- process passes this data to the database for updating# and anal$9es the
return message from the database! *f the update "as successful# the update "or- process
triggers a database commit after the last database change and deletes the log entries from table
AB.1(! *f an error occurrs# the update "or- process triggers a database rollbac-# leaes the log
ABAP Programming (BC-ABA) 4@?
entries in table AB.1(# flags them as containing errors# and sends an SAPmail to the user# "ho
should then inform the s$stem administrator!
B! The corresponding entries in the loc- table are reset b$ the update "or- process!
As$nchronous updating is useful "hen the response time from the transaction is critical# and the
database updates themseles are so comple/ that the$ 2ustif$ the e/tra s$stem load of logging
them in AB.1(! *f $ou are running a transaction in a bac-ground "or- process# as$nchronous
update offers no adantages!
.pdating As%nc$ronousl% in Steps
When $ou process a AB.1( entr$ as$nchronousl$# $ou can do it in t"o update steps! This allo"s
$ou to diide the contents of the update into primar$ and secondar$ steps! The primar$ step is
called A1# the secondar$ step A4! The A1 and A4 steps of a log entr$ are processed in separate
database .)Ws! The entries in the loc- table are usuall$ deleted once the A1 step has been
processed! There is no loc-ing for the A4 step! &iiding up the update process allo"s $ou to
separate time-critical updates that re8uire database loc-s from less critical data updates that do
not need loc-s! A4 steps receie lo"er priorit$ from the dispatcher than A1 steps! This ensures
that the time- and loc--critical updates are processed 8uic-l$# een "hen the s$stem is bus$!
*f an error occurs during the A1 processing# the database rollbac- applies to all A1 steps in the
log entr$! The entire entr$ is replaced in table AB.1(! *f an error occurs during A4 processing#
all of the A4 steps in the log entr$ are replaced in table AB.1(# but the A1 updates are not
reersed!
The s$stem mar-s rolled-bac- function modules as error functions in the update tas- log! The
error can then be corrected and the function restarted later! To access the update tas- log#
choose Tools 7 Administration 7'onitoring7)pdate! ,or further information about update
administration# see the 'anaging )pdating section of the BC S$stem Serices documentation!
S%nc$ronous .pdate
*n s$nchronous update# $ou do not submit update re8uests using CA 2.NC-ION Z IN
.P)A-0 -AS" ! *nstead $ou use the ABAP statement CO,,I- WO(" AN) WAI-! When the
update is finished# control passes bac- to the program! S$nchronous update "or-s in the same
"a$ as bundling update re8uests in a subroutine (P0(2O(, ON CO,,I-)! This -ind of update is
useful "hen $ou "ant to use both as$nchronous and s$nchronous processing "ithout haing to
program the bundles in t"o separate "a$s! The follo"ing diagram illustrates the s$nchronous
update process+
)se this t$pe of update "heneer the changed data is re8uired immediatel$! ,or e/ample# $ou ma$
"ant to lin- SAP .)Ws together "here one .)W depends on the results of the preious one!
ocal .pdate
*n a local update# the update program is run b$ the same "or- process that processed the
re8uest! The dialog user has to "ait for the update to finish before entering further data! This
-ind of update is useful "hen $ou "ant to reduce the amount of access to the database! The
disadantage of local updates is their parallel nature! The updates can be processed b$ man$
different "or- processes# unli-e as$nchronous or s$nchronous update# "here the update is
seriali9ed due to the fact that there are fe"er update "or- processes (and ma$be onl$ one)!
3ou s"itch to local update using the ABAP statement S0- .P)A-0 -AS" OCA! This
statement sets a Klocal update s"itchi! When it is set# the s$stem interprets CA
ABAP Programming (BC-ABA) 4@@
2.NC-ION 999IN .P)A-0 -AS" as a re8uest for local update! The update is processed in the
same "or- process as the dialog step containing the CO,,I- WO("! The transaction "aits for
the update to finish before continuing!
As an e/ample# suppose $ou hae a program that uses as$nchronous update that $ou normall$ run
in dialog mode! 6o"eer# this time $ou "ant to run it in the bac-ground! Since the s$stem
response time is irreleant "hen $ou are running the program in the bac-ground# and $ou onl$
"ant the program to continue processing "hen the update has actuall$ finished# $ou can set the
S0- .P)A-0 -AS" OCAs"itch in the program! 3ou can then use a s$stem ariable to chec- at
runtime "hether the program is currentl$ running in the bac-ground!
B$ default# the local update s"itch is not set# and it is reset after each CO,,I- WO(" or
(OBAC" WO("! 3ou therefore need to include a S0- .P)A-0 -AS" OCA statement at
the beginning of each SAP .)W!
*f $ou reset data "ithin the local update# the (OBAC" WO(" statement applies to both the
dialog and the update part of the transaction# since no ne" SAP .)W is started for the update!
Creating .pdate 2unction ,odules
To create a function module# $ou first need to start the ,unction Builder! Choose Tools 7 ABAP
Wor-bench# ,unction Builder! ,or more information about creating function modules# refer to the
ABAP Wor-bench Tools documentation!
To be able to call a function module in an update "or- process# $ou must flag it in the ,unction
Builder! When $ou create the function module# set the Process T$pe attribute to one of the
follo"ing alues+
)pdate "ith immediate start
Set this option for high priorit$ (WA1W) functions that run in a shared (SAP .)W)! These
functions can be restarted b$ the update tas- in case of errors!
)pdate "! imm! start# no restart
Set this option for high priorit$ (WA1W) functions that run in a shared (SAP .)W)! These
functions ma$ not be restarted b$ the update tas-!
)pdate "ith dela$ed start
Set this option for lo" priorit$ (WA4W) functions that run in their o"n update transactions!
These functions can be restarted b$ the update tas- in case of errors!
To displa$ the attributes screen in the ,unction Builder# choose (oto 7 Administration!
)efining t$e Interface
,unction modules that run in the update tas- hae a limited interface+
%esult parameters or e/ceptions are not allo"ed since update-tas- function modules
cannot report on their results!
3ou must specif$ input parameters and tables "ith reference fields or reference
structures defined in the ABAP &ictionar$!
Calling .pdate 2unctions
S%nc$ronous or As%nc$ronous Processing[
,unction modules that run in the update tas- can run s$nchronousl$ or as$nchronousl$! 3ou
determine this b$ the form of the CO,,I-statement $ou use+
7 CO,,I- WO("
This is the standard form# "hich specifies as$nchronous processing! 3our program does not
"ait for the re8uested functions to finish processing!
7 CO,,I- WO(" AN) WAI-
This form specifies s$nchronous processing! The CO,,I-statement "aits for the end of
processing! Control returns to $our program after all high priorit$ (A1) function modules hae
run successfull$!
The AN) WAI- form is conenient for s"itching old programs to s$nchronous processing
"ithout haing to re-"rite the code! ,unctionall$# using AN) WAI- for update-tas- updates
is 2ust the same as dialog-tas- updates "ith P0(2O(, ON CO,,I-!
Parameter !alues at 05ecution
*n ABAP# $ou can call update-tas- function modules in t"o different "a$s! The "a$ $ou choose
determines "hat parameter alues are used "hen the function module is actuall$ e/ecuted!
Parameter alues can be set either at the time of the CA 2.NC-ION statement# or at the
time of the CO,,I- WO("! The follo"ing sections e/plain!
Calling )pdate ,unctions &irectl$
Adding )pdate Tas- Calls to a Subroutine
ABAP Programming (BC-ABA) 4@B
The e/amples in these sections sho" as$nchronous commits "ith C1''*T W1%U!
Calling .pdate 2unctions )irectl%
To call a function module directl$# use CA 2.NC-ION IN .P)A-0 -AS" directl$ in $our
source code!
CA.. ,)NCT*1N I,)NCT'1&I *N )P&AT0 TASU 0_P1%T*N(!!!
The s$stem then logs $our re8uest and e/ecutes the function module "hen the ne/t CO,,I-
WO(" statement is reached! The parameter alues used to e/ecute the function module are
those current at the time of the call!

a H 1!
CA.. ,)NCT*1N I)P&S,'I *N )P&AT0 TASU 0_P1%T*N( par H a!!!
a H 4!
CA.. ,)NCT*1N I)P&S,'I *N )P&AT0 TASU 0_P1%T*N( par H a!!!
a H :!
C1''*T W1%U!
6ere the function module )P&S,' is e/ecuted t"ice in the update tas- [ once "ith the alue 1 in
par and once "ith the alue 4 in par!
Adding .pdate--as* Calls to a Su&routine
3ou can put the CA 2.NC-ION IN .P)A-0 -AS" into a subroutine and call the subroutine
"ith+
P0%,1%' S)B%1)T 1N C1''*T!
*f $ou choose this method# the subroutine is e/ecuted at the commit! Thus the re8uest to run the
function in the update tas- is also logged during commit processing! As a result# the parameter
alues logged "ith the re8uest are those current at the time of the commit!
a H 1!
P0%,1%' , 1N C1''*T!
a H 4!
P0%,1%' , 1N C1''*T!
a H :!
C1''*T W1%U!
,1%' f!
CA.. ,)NCT*1N I)P&S,'I *N )P&AT0 TASU 0_P1%T*N( par H a!
0N&,1%'!
*n this e/ample# the function module )P&S,' is carried out "ith the alue : in par! The update
tas- e/ecutes the function module onl$ once# despite the t"o P0(2O(, ON CO,,I-
statements! This is because a repeatedl$ registered one can onl$ be e/ecuted once in the case of
CO,,I- WO("! The subroutine itself# containing the function module call# can not hae
parameters!

The method described here is not suitable for use inside dialog module code!
Special .W Considerations
*n the update tas- 8ueue# the s$stem identifies all function modules belonging to the same
transaction (SAP .)W) b$ assigning them a common update -e$! At the ne/t CO,,I- WO("#
the update tas- reads the 8ueue and processes all re8uests "ith the predefined update -e$!
*f $our program calls an update-tas- function module# the re8uest to e/ecute the module (or the
subroutine calling it) is proided "ith the update -e$ of the current .)W and placed in the 8ueue!
The follo"ing sections e/plain "hat happens to .)Ws "hen update function modules are included
in other modules (transactions or dialog modules) that are called b$ other programs!
Transactions That Call )pdate Tas- ,unctions
&ialog 'odules That Call )pdate Tas- ,unctions
-ransactions -$at Call .pdate 2unction ,odules
*f $our program calls another program that itself calls an update function module# $ou should be
a"are of the follo"ing+
When the ne" program is called# a ne" SAP .)W begins# and a ne" update -e$ is generated! This
-e$ is used to identif$ all update-tas- operations re8uested during the called program!
ABAP Programming (BC-ABA) 4@D
When returning from the program# the .)W of the calling program is restored together "ith the
old update -e$!
*f the called program does not contain its o"n CO,,I- WO("# the database update re8uests
are not processed# and the update function modules are not called! *n the follo"ing e/ample# ,1#
,4# and ,: are update function modules+
6ere# ,1 and ,: are e/ecuted in the update tas-# because the CO,,I- WO(" for the main
program triggers their e/ecution! 6o"eer# since transaction TABC contains no CO,,I-
WO("statement# the function ,4 is neer e/ecuted b$ the update tas-!
)ialog ,odules t$at Call .pdate 2unction ,odules
)nli-e transactions and e/ecutable programs# dialog modules do not start a ne" SAP .)W! Calls
to update-tas- function modules from a dialog module use the same update -e$ as the ones in the
calling program! The result is that calls to update function modules from a dialog module are
e/ecuted onl$ if a CO,,I- WO(" statement occurs in the calling program!
*f $ou place a CO,,I- WO(" in a dialog module# it does commit changes to the database (for
e/ample# "ith .P)A-0)!6o"eer# it does not start the update tas-! The function modules are not
actuall$ e/ecuted until a CO,,I- WO(" statement occurs in the calling program!
*f $ou use dialog modules# tr$ to aoid including calls to update function modules in subroutines
called "ith P0(2O(, ON CO,,I-! *n general# an$ occurrence of P0(2O(, ON CO,,I-("ith
or "ithout update-tas- function calls) in a dialog module can be problematic!
This is because dialog modules hae their o"n roll area# "hich disappears "hen the module
finishes! Conse8uentl$# all local data (including data used for parameter alues "hen calling an
update function module) disappears as soon as the commit in the main program is reached!
*f $ou must use this method in a dialog module (i!e! include the call to an update-tas- function in a
subroutine)# $ou must ensure that the alues of the actual parameters still e/ist "hen the
update-tas- function actuall$ runs! To do this# $ou can store the re8uired alues "ith 0XPO(-
-O ,0,O(7 and then import them bac- into the main program (I,PO(- 2(O, ,0,O(7)
before the CO,,I- WO(" statement!
0rror +andling for Bundled .pdates
%untime errors can occur during e/ecution of bundled updates! 6o" are the$ handledg *n general#
CO,,I- WO(" processing occurs in the follo"ing order+
!!!
1! All dialog-tas- 2O(,routines logged "ith P0(2O(, ON CO,,I- are e/ecuted!
4! All high-priorit$ (A1) update-tas- function modules are e/ecuted!
The end of A1-update processing mar-s the end of the ! *f $ou used CO,,I- WO(" AN)
WAI- to trigger commit processing# control returns to the dialog-tas- program!
:! All lo"-priorit$ (A4) update-tas- function modules are triggered!
All bac-ground-tas- function modules are triggered!
%untime errors can occur either in the s$stem itself or as a result of a termination message
(,0SSA/0 t$pe JA=)! Also# the (OBAC" WO("statement automaticall$ signals a runtime error!
The s$stem handles errors according to "here the$ occur+
7 in a 2O(, routine (called "ith P0(2O(, ON CO,,I-)
7 )pdates alread$ e/ecuted for the current update transaction are rolled bac-!
7 No other 2O(, routines "ill be started!
7 No further update-tas- or bac-ground-tas- functions "ill be started!
ABAP Programming (BC-ABA) 4@E
7 An error message appears on the screen!
7 in a !8 update-tas* function module(re8uested IN .P)A-0 -AS")
7 )pdates alread$ e/ecuted for A1 functions are rolled bac-!
7 All further update-tas- re8uests (A1 or A4) are thro"n a"a$!
7 All bac-ground-tas- re8uests are thro"n a"a$!
7 )pdates alread$ e/ecuted for 2O(,routines called "ith P0(2O(, ON CO,,I-
are not rolled bac-!
7 An error message appears on the screen# if $our s$stem is set up to send them
7 in a !B update-tas* function module(re8uested IN .P)A-0 -AS")
7 )pdates alread$ e/ecuted for the current A4 function are rolled bac-!
7 All update-tas- re8uests (A4) still to be e/ecuted are discarded!
7 All bac-ground-tas- re8uests still to be e/ecuted are carried out!
7 No updates for preiousl$ e/ecuted A1 functions are rolled bac-!
7 No updates preiousl$ e/ecuted for 2O(,routines (called "ith ON CO,,I-) are
rolled bac-!
7 An error message appears on the screen# if $our s$stem is set up to send them
7 in a &ac*ground-tas* function module(re8uested IN BAC"/(O.N) -AS"
)0S-INA-ION)
7 Bac-ground-tas- updates alread$ e/ecuted for the current )0S-INA-ION are not
rolled bac-!
7 All further bac-ground-tas- re8uests for the same )0S-INA-ION are discarded!
7 1ther preiousl$ e/ecuted updates are rolled bac-!
7 No error message appears on the screen!
*f $our program detects that an error in remote processing has occurred# the re8uests can be
resubmitted at a later time!
,or further information about %,C processing# refer to the %emote Communications
documentation!
05ecuting ABAP Program .nits
ABAP programs can be e/ecuted onl$ on a NetWeaer Application Serer ABAP! The NetWeaer
Application Serer ABAP contains a component Uernel f 'anagement Serices# "hich seres as
the platform-independent runtime enironment for ABAP programs (see NetWeaer AS ABAP+
1erie")!
0ach ABAP program consists of self-contained processing &loc*s# "hich ma$ occur in an$ order in
the source code! Processing bloc-s are sections of programs# made up of structure bloc-s! The$
are processed se8uentiall$! A processing bloc- can be called either from outside the ABAP
program# or from a processing bloc- "ithin the same ABAP program (see also Structure of the
Processing .ogic)! When a processing bloc- is called from outside the program# it can be called
either b$ the ABAP runtime enironment or another ABAP program!
ABAP Programming (BC-ABA) 4BF
To start an ABAP program# at least one of its processing bloc-s must be started from outside the
program itself! 0ach ABAP program has a program t$pe# "hich determines "hether and ho" a
program can be run!
Programs t$at can &e run
These programs can be run b$ a user b$ entering the program name or a transaction code! The$
are the actual application programs# and are e/plained in more depth later on!
05ecuta&le Programs
05ecuta&le programs can be started b$ entering the program name! When $ou start an
e/ecutable program# processors are started in the runtime enironment that call a series of
processing bloc-s (eent bloc-s) in a predefined se8uence! The se8uence is oriented to"ards
reporting tas-s! This is "h$ e/ecutable programs "ere also -no"n as reports! ,or more
information# see &irect 0/ecution!
A special propert$ of e/ecutable programs is the fact that the$ can be lin-ed to logical
data&ases! A logical database contains subroutines that are called b$ an inisible s$stem program
in a prescribed se8uence for e/ecutable programs! The subroutines ma-e certain reporting
functions reusable! ,or further information# refer to ogical )ata&ases!
,odule Pools
3ou can onl$ start module pools using a transaction code! A transaction code starts a screen#
"hich consists of the screen itself and its flo" logic! Screen flo" logic can call special processing
bloc-s (dialog modules) in the corresponding ABAP program! The$ are named module pools after
these dialog modules! ,or more information on e/ecuting modules pools# see Transactions!

As of release @!1F# the public methods of global and local classes can be attached to
transaction codes# "hich ma-es their frame"or- programs Ke/ecutableK ia transaction codes!

Programs t$at Cannot Be (un )irectl%
These programs cannot be started directl$ b$ a user! *nstead# the$ contain processing bloc-s or
other source code that can onl% be used b$ an application program that is alread$ running! The$
are described in more detail in a later section!
2unction /roups
The$ sere as a container for function modules! When $ou call a function module from an ABAP
program# the entire main program is loaded into the internal session of the current program!
,unction modules are a t$pe of procedure! The$ are described in more detail in the Procedures
section!
Class Pools
Class pools sere as containers for global classes! Classes belong to ABAP 1b2ects and are
described in more detail in that section!
Interface Pools
*nterface pools sere as containers for global interfaces! *nterfaces belong to ABAP 1b2ects
and are described in more detail in that section!
Su&routine Pools
Subroutine pools are container programs for subroutines that should onl$ be called e/ternall$!
When $ou call a subroutine from an ABAP program# the entire main program is loaded into the
internal session of the current program! Subroutines are a t$pe of procedure! The$ are
described in more detail in the Procedures section!
Include Programs
*nclude programs do not contain an$ callable processing bloc-s! The$ are used e/clusiel$ for
modulari9ing ABAP source code# and are included in other programs! *nclude programs are
described in more detail in the Source Code 'odules section!
As of release @!1F# function groups# class pools and subroutine pools can be started ia
transaction codes# "hich are attached to the public methods of local or global classes of
these programs!
Starting Programs in ABAP
,or all programs that can be started directl$# there are ABAP statements that $ou can use to call
a program from another application program that is alread$ running! ,or further information#
refer to Calling Programs!
ABAP Programming (BC-ABA) 4B1
Summar% of Calla&le .nits

ABAP Programs
Procedures
Screens and Screen Se8uences
ABAP Programs
An$ ABAP programs that hae their o"n screens (that is# e/ecutable programs# module pools or
function groups) can be called e/ternall$ in their own internal session and "ith their own SAP
.W!
0ach time a program is called using S.B,I- or using transaction codes# a ne" internal session is
opened# triggering the eent OA)-O2-P(O/(A,!
05ecuta&le Programs
3ou can directl$ call an e/ecutable program using the statement+
S)B'*T prog !!! XAN& %0T)%NY!
*f $ou omit the AN) (0-.(N addition# the s$stem terminates the calling program and calls the
ne" e/ecutable program prog! The internal session of the calling program is replaced b$ the
internal session of the ne" program! When the ne" program has finished# control returns to the
point from "hich the calling program "as started!
*f $ou use the AN) (0-.(N addition# the e/ecutable program prog is started in a ne" session!
The internal session of the calling program is returned# and control returns to the calling program
after the ne" program has finished!
All Programs wit$ Screens
3ou can assign a transaction code to an$ screen of a program! Normall$# $ou assign a transaction
code to a single screen in a module pool! This then allo"s $ou to start the program using one of
the statements
.0AA0 T1 T%ANSACT*1N tcode !!!
or
CA.. T%ANSACT*1N tcode !!!
The program starts b$ processing the screen that $ou specified "hen $ou defined the transaction
code! This is called the initial screen!
*f $ou use 0A!0 -O -(ANSAC-ION# the calling program is terminated! All preious internal
sessions are deleted from the batch! At the same time# the ABAP memor$ is deleted "ith the
result that $ou cannot pass an$ data using 0XPO(-AI,PO(- -O ,0,O(7 if $ou use 0A!0 -O
-(ANSAC-ION! A ne" internal session is created for the program called! 1nce $ou e/it the
program called# the s$stem returns to the area menu in "hich the first program of the batch "as
started! *f $ou use 0A!0 -O -(ANSAC-ION SPAC0# the s$stem destro$s the batch and
returns directl$ to the area menu!
ABAP Programming (BC-ABA) 4B4
*f $ou use CA -(ANSAC-ION# the programm called is started in a ne" session! The session of
the calling program is retained! When the ne" program has finished# control returns to the point
from "hich the calling program "as started!
eaving a Called Program
To leae a program that $ou hae called# use the ABAP statement
.0AA0 P%1(%A'!
Procedures
Called procedures (subroutines# function modules# and methods) al"a$s run in the same internal
session as the calling program!
-bc-
Su&routines
3ou call a subroutine using the
P0%,1%' subrcX(prog)Y !!!
Without the (prog) addition# the call is internal! The subroutine is in the calling program and does
not hae to be loaded!
*f $ou use the (prog) addition# the call is e/ternal! The subroutine is in the program prog! When
$ou call the subroutine# the entire program prog is loaded into the internal session of the calling
program (if it has not been alread$)! The loaded program belongs to the program group of the
calling program! 6o"eer# if the subroutine belongs to a function group# a ne" additional program
group is created! The program group to "hich the e/ternal subroutine belongs determines the
interface "or- areas and screens that it "ill use! 6o"eer# this assignment can ar$ d$namicall$#
so it is best to aoid using e/ternal subroutines!
2unction ,odules
3ou call function modules using the
CA.. ,)NCT*1N func !!!
,unction module calls are e/ternal unless a function module is called b$ another procedure "ithin
the same function group! When $ou call a function module# its entire function group is loaded into
the internal session of the calling program (unless it has alread$ been loaded)! Within the internal
session# the function group forms an additional program group "ith its o"n interface "or- areas
and screens! This means that function modules proide better encapsulation of data and screens
than e/ternal subroutines!
,et$ods
3ou call a method using the
CA.. '0T61& Xref-GZclassHGYmeth !!!
*f $ou omit the ref or class part of the statement# the call is local "ithin the same class! The
class is not reloaded!
*f $ou use one of the aboe (ref or class)! the method of a particular class is called either
through an ob2ect reference ref or through the class name class! When $ou call the method# the
entire class pool is loaded into the internal session of the calling program (unless it has alread$
been loaded)! The class pool forms an additional program group in the internal session# "hich does
not share data and screens "ith the caller# and from "hich $ou cannot call e/ternal subroutines!
eaving a Called Procedure
ABAP Programming (BC-ABA) 4B:
3ou can leae a procedure using the
0_*T!
and
C60CU loge/p!
statement!
Screens and Screen Se1uences
Screens and their flo" logic# "hich together form d$namic programs# are instances that control
the flo" of an ABAP program b$ calling a series of dialog modules! Screens can be combined into
se8uences# "here the ne/t screen in the se8uence can be defined either staticall$ or d$namicall$!
The simplest screen se8uence is a single screen! The se8uence starts "hen $ou call its first
screen! 3ou can do this in a ariet$ of "a$s!
Calling Screens Internall% from t$e Same ABAP Program
*n eer$ program that has its o"n screens (e/ecutable programs# module pools or function
groups)# the statement+
CA.. SC%00N d$nnr!
can be used to call a screen and its subse8uent se8uence "ithin that program! The flo" logic of
each screen calls dialog modules in the program that called the screen!
When the screen se8uence ends# control returns to the statement after the dialog module call!
The special screen t$pes selection screen and list are onl$ eer called internall$! 3ou should onl$
call subscreens internall$!
Calling Screens as a -ransaction
A transaction# or a transaction code# can be lin-ed to a screen of an$ main program! Normall$
module pools are used for this purpose!
3ou can call a transaction from an$ ABAP program using the
CA.. T%ANSACT*1N tcod !!!
or
.0AA0 T1 T%ANSACT*1N tcod !!!
statements! The transaction starts "ith the initial screen that $ou specified "hen $ou defined it!
The program of the transaction is started in a ne" internal session# and $as its own SAP .W!
The screens in the screen se8uence call the arious dialog modules of the main program!
When the screen se8uence is finished# control returns to the program that contained the CA
-(ANSAC-ION statement! *f $ou start a transaction using 0A!0 -O -(ANSAC-ION# control
returns to the point from "hich the calling program "as started!
Calling Screens as a )ialog ,odule
A dialog module can be lin-ed to a screen of an$ main program! Normall$ module pools are used for
this purpose!
3ou can call a dialog module from an$ ABAP program using the
CA.. &*A.1( diag !!!
ABAP Programming (BC-ABA) 4B>
statement! The dialog module starts "ith the initial screen that $ou specified "hen $ou defined
it! The program of the dialog module is started in a ne" internal session# but it does not $ave its
own SAP .W! The screens in the screen se8uence call the arious dialog modules of the main
program!
When the screen se8uence ends# control returns to the statement after the dialog module call!
&ialog modules are obsolete# and should no longer be used! *nstead# $ou can encapsulate screen
se8uences in function groups and call them from an appropriatel$-programmed function module!
0nding a Called Screen Se1uence
A screen se8uence terminates "hen a screen ends and the defined ne/t screen has the number F!
3ou can leae a single screen "ithin a se8uence using the
.0AA0 SC%00N!
or
.0AA0 T1 SC%00N d$nnr!
statements! These statements e/it the current screen and call the defined ne/t screen! *f the
ne/t screen is screen F# the entire screen se8uence concludes!
Special Single Screens
There are three special t$pes of screen+
Selection Screens
A selection screen is a special screen# created using ABAP statements! 3ou can onl$ call them
using the
CA.. S0.0CT*1N-SC%00N d$nnr !!!
statement! The selection screen is processed (reaction to user input in the selection screen
eents) in the calling program!
ists
0ach screen in a screen se8uence has a corresponding list s$stem of t"ent$ leels! 3ou can start
this list s$stem using the
.0AA0 T1 .*ST-P%1C0SS*N( XAN& %0T)%N T1 SC%00N d$nnrY!
statement! This statement calls a s$stem program that contains the standard container screen
used for lists! This replaces the current screen! 1n this screen# $ou can displa$ a basic list and up
to 1E detail lists! .ist processing (reacting to user actions in list eents) ta-es place in the calling
program!
3ou can leae the list s$stem using the
.0AA0 .*ST-P%1C0SS*N(!
statement!
*n an e/ecutable program# the list s$stem is automaticall$ called after the last reporting eent!
Su&screens
*n the PB1 eent of the flow logic of a screen# $ou can call a subscreen using the follo"ing
statement+
CA.. S)BSC%00N area *NC.)&*N( XprogY d$nnr!
The screen of a subscreen that $ou call is placed in the subscreen area area on the main screen!
*f $ou do not specif$ a program prog# the s$stem uses a screen from the current ABAP program!
*f $ou do specif$ a program prog# the s$stem uses a screen from the program prog for the
subscreen! This program is treated in the same "a$ as an e/ternal subroutine call! *n other
"ords# it is loaded into the program group of the calling program# or# if it is a function group# as
its o"n program group in the same internal session as the calling ABAP program!
Calling Programs
*f $ou need to program an e/tensie application# one single program can become er$ comple/! To
ma-e the program easier to read# it is often a good idea to diide the re8uired functions among
seeral programs!
As "ell as using e/ternal modulari9ation# in "hich $ou store procedures in special non-e/ecutable
ABAP programs li-e function groups# $ou can also call independent programs from "ithin an ABAP
program!
The follo"ing ABAP statements allo" $ou to start an e/ecutable program or transaction! 3ou can
either e/it the calling program# or hae the s$stem return to it "hen the called program finishes
running!

0/ecutable Program Transaction
Call "ithout return S.B,I- 0A!0 -O
ABAP Programming (BC-ABA) 4B?
-(ANSAC-ION
Call "ith return S.B,I- AN) (0-.(NCA -(ANSAC-ION

3ou can use these statements in an$ ABAP program! ,or e/ample# "hile processing a user action in
the output list of an e/ecutable program# $ou might call a transaction "hose initial screen is filled
"ith data from the selected list line!
The eent OA)-O2-P(O/(A, is triggered each time a program is called! *f a corresponding
eent bloc- is defined in the frame"or- program# it is e/ecuted once before the first other
processing bloc- is e/ecuted!
An interesting remar- at this point is that eac$ e/ecution of an e/ecutable program actuall$ has
a S.B,I- statement as its source! When $ou enter the program name in a transaction li-e S0:D
or SA:D and choose 0/ecute# a S.B,I- statement occurs in the transaction! Technicall$
spea-ing# therefore# e/ecutable programs hae the attribute of being able to be called using
S.B,I-# although their principal characteristic from a user=s point of ie" is that the$ are
started in the foreground!
,emor% Organi:ation in Program Calls
The first ABAP program in a session on the application serer opens its o"n internal session (roll
area) "ithin the main session! All e/ternall$-called procedures run in the same internal session as
the calling program# that is# the main program and "or-ing data of the procedure are loaded into
the same memor$ area in the internal session!
When $ou call an e/ecutable program or a transaction# the s$stem opens a ne" internal session
for each program! 6ere# there are t"o possible cases+ *f the second program does not return
control to the calling program "hen it has finished running# the called program replaces the calling
program in the internal session! The contents of the memor$ of the calling program are deleted!
*f the second program does return control to the calling program "hen it has finished running#
the session of the called program is not deleted! *nstead# it becomes inactie# and its memor$
contents are placed on a stac-! The s$stem can open up to E further internal sessions in e/ternal
program calls!
As "ell as e/ecutable programs and transactions# dialog modules also open a ne" internal session!
&ialog modules "ere preiousl$ used for modulari9ing screen se8uences!
Program Calls and SAP .Ws
An SAP .)W is a logical unit consisting of dialog steps# "hose changes are "ritten to the
database in a single database .)W! There are arious bundling techni8ues that $ou can use to
ensure that all of the database updates belonging to an SAP .)W are made in the same single
database .)W!
0/ternall$-called procedures do not open a ne" SAP .)W!
6o"eer# "hen $ou start a ne" e/ecutable program or transaction# a ne" SAP .)W starts!
&atabase updates belonging to these programs are collected in their o"n database .)W! *f the
ne" program does not return control to the calling program# the SAP .)W of the old program
concludes "hen the ne" program is called! *f# on the other hand# the ne" program does return
control to the calling program# the ne" SAP .)W runs parallel to the SAP .)W of the calling
program!
No ne" SAP .)W is opened "hen $ou call a dialog module! Bundling techni8ues in a dialog module
add the database updates to the database .)W of the calling program! 3ou ma$ sometimes need
to call a transaction that runs in the same SAP .)W as the calling program! 1ne techni8ue for
doing this is to use the e/isting transaction as a dialog module! To do this# $ou need to create a
ne" dialog module "ith the same main program and initial screen as the transaction! Transactions
that are used both as transactions and as dialog modules must be programmed to obe$ certain
rules! ,or further information# refer to Calling Screen Se8uences!
The fact that an e/ternal program shares (or does not share) the SAP .)W "ith its caller has
special conse8uences if the program calls update-tas- functions or uses CO,,I- WO("! ,or
further information# refer to Special .)W Considerations!

,or more information# see+
1erie" of Program Calls
Calling 0/ecutable Programs
&irect 0/ecution
Transactions
ABAP Programming (BC-ABA) 4B@
Passing &ata Bet"een Programs
Program Calls - Overview
*n a program call# the unit that $ou call is an independent ABAP program! At runtime# the called
program is loaded into its own internal session in the current e/ternal session (memor$ area for
a user session)! An$ program that can hae its o"n screens can be called in an e/ternal program
call! The most usual e/ternal program calls are for e/ecutable programs and transactions assigned
to a module pool! At eer$ e/ternal program call# a ne" internal session is opened# and therefore
eer$ call triggers the eent OA)-O2-P(O/(A,!

05ecuta&le Programs
When $ou call an e/ecutable program# the program is loaded# and the ABAP runtime enironment
calls the processors that control its flo"!
-ransactions
When $ou call a transaction# the program lin-ed to the transaction code is loaded and its initial
screen is processed! The initial screen calls dialog modules in the called program# and then
branches to its ne/t screen!
Calling 05ecuta&le Programs
3ou can call e/ecutable programs from other ABAP programs using the follo"ing statement+
S)B'*T progZ(field) XAN& %0T)%NY XoptionsY!
3ou can either specif$ the name of the program $ou "ant to call staticall$ b$ entering the
program name in the code of the calling program# or d$namicall$ b$ specif$ing the name of a field
(in parentheses) containing the name of the program! *f the s$stem cannot find the specified
e/ecutable program "hen tr$ing to e/ecute the S)B'*T statement# a runtime error occurs!
*f $ou omit the AN) (0-.(N addition# all data and list leels of the calling program (the entire
internal session) are deleted! After the called e/ecutable program has finished# control returns
to the leel from "hich $ou started the calling program!
ABAP Programming (BC-ABA) 4BB
*f $ou use AN) (0-.(N# the s$stem stores the data of the calling e/ecutable program and
returns to the calling after processing the called program! The s$stem resumes e/ecuting the
calling program at the statement follo"ing the call!
The S.B,I- statement has a set of additions options for passing data to the called program and
specif$ing arious other processing options! Some of them are described in the follo"ing sections+
,illing the Selection Screen of a Called Program
Affecting .ists in Called Programs
Program Statements for 0/iting a Called Program
2illing t$e Selection Screen of a Called Program
When $ou start an e/ecutable program# the standard selection screen normall$ appears#
containing the selection criteria and parameters of both the logical database connected to the
program and of the program itself (see &irect 0/ecution - %eports)! When $ou start an
e/ecutable program using S.B,I-# there are arious additions that $ou can use to fill the input
fields on the selection screen+
S)B'*T!!! XA*A S0.0CT*1N-SC%00NY
X)S*N( S0.0CT*1N-S0T arY
XW*T6 sel criterionY
XW*T6 ,%00 S0.0CT*1NS freeselY
XW*T6 S0.0CT*1N-TAB.0 rsparY!
These additions hae the follo"ing effects+
7 !IA S00C-ION-SC(00N
The selection screen of the called e/ecutable program appears! *f $ou transfer alues to the
program using one or more of the other options# the corresponding input fields in the
selections screen are filled! The user can change these alues! B$ default# the s$stem does
not displa$ a selection screen after S.B,I-!
7 .SIN/ S00C-ION-S0- VvarN
This addition tells the s$stem to start the called program "ith the ariant var!
7 WI-+ sel criterion
)se this addition to fill indiidual elements sel of the selection screen (selection tables and
parameters) "ith the help of the language elements criterion!
7 WI-+ 2(00 S00C-ION freesel
)ser dialog for d$namic selections! To use this option# the called program must be connected to a
logical database that supports d$namic selections!
7 WI-+ S00C-ION--AB0 rspar
&$namic transfer of different alues! An internal table rspar "ith the &ictionar$ structure
%SPA%A'S is created! This table can be filled d$namicall$ in the calling program "ith all the
re8uired alues for the selection screen of the called program!
,or more information on these additions# refer to the -e$"ord documentation!
0/cept for WI-+ S00C-ION--AB0# $ou can use an$ of the aboe options seeral times and in
an$ combination "ithin a S.B,I-statement! *n particular# $ou can use the WI-+ sel addition
seeral times for one single criterion sel! The onl$ combination possible for the WI-+
S00C-ION--AB0 addition is .SIN/ S00C-ION-S0-!
*f the input fields on the selection screen are lin-ed to SPA;(PA parameters# $ou can also use
this techni8ue to pass alues to the selection screen (see Passing &ata Bet"een Programs)!
The follo"ing e/ecutable program creates a selection screen containing the parameter paramet
and the selection criterion selecto+
(0PO(- demoEprogramEsu&mitErep89
)A-A num&er -7P0 i9
PA(A,0-0(S paramet(8D) -7P0 c9
S00C--OP-IONS selecto 2O( num&er9
The program &0'1demoEprogramEsu&mitErep8 is called b$ the follo"ing program using arious
parameters+
(0PO(- demoEprogramEsu&mitEselEscreen NO S-AN)A() PA/0 +0A)IN/9
)A-A= int -7P0 i4
rspar -7P0 -AB0 O2 rsparams4
waErspar I"0 IN0 O2 rspar9
(AN/0S selta& 2O( int9
ABAP Programming (BC-ABA) 4BD
W(I-0= ?Select a Selection\?4
A ?--------------------?9
S"IP9
2O(,A- +O-SPO- COO( G IN!0(S0 ON9
W(I-0= ?Selection 8?4
A ?Selection B?9
A- IN0-S00C-ION9
CAS0 s%-lilli9
W+0N D9
selta&-sign F ?I?9 selta&-option F ?B-?9
selta&-low F 89 selta&-$ig$ F G9
APP0N) selta&9
S.B,I- demoEprogramEsu&mitErep8 !IA S00C-ION-SC(00N
WI-+ paramet e1 ?Selection 8?
WI-+ selecto IN selta&
WI-+ selecto ne C
AN) (0-.(N9
W+0N G9
waErspar-selname F ?S00C-O?9 waErspar-*ind F ?S?9
waErspar-sign F ?0?9 waErspar-option F ?B-?9
waErspar-low F 8D9 waErspar-$ig$ F 8I9
APP0N) waErspar -O rspar9
waErspar-selname F ?PA(A,0-?9 waErspar-*ind F ?P?9
waErspar-low F ?Selection B?9
APP0N) waErspar -O rspar9
waErspar-selname F ?S00C-O?9 waErspar-*ind F ?S?9
waErspar-sign F ?I?9 waErspar-option F ?/-?9
waErspar-low F 8@9
APP0N) waErspar -O rspar9
S.B,I- demoEprogramEsu&mitErep8 !IA S00C-ION-SC(00N
WI-+ S00C-ION--AB0 rspar
AN) (0-.(N9
0N)CAS09
After $ou start the program# a basic list appears and clic-ing the hotspots displa$s the selection
screen of rep8 filled "ith different alues!
,or both calls of demoEprogramEsu&mitErep8# the s$stem transfers alues that lead to t"o-line
selection tables selecto! The second line appears in the respectie dialog bo/ 'ultiple Selection
for Selecto! Without the !IA S00C-ION-SC(00N option of the S.B,I- statement# paramet
and selecto "ould be filled accordingl$ in demoEprogramEsu&mitErep8# but the$ "ould not be
displa$ed!
Affecting ists in Called Programs
When $ou call an ABAP program# $ou can modif$ its lists# send them to a spool file instead of the
screen# or store them in ABAP memor$!
,odif%ing t$e ist Structure
3ou can modif$ the list structure of a called program b$ using the follo"ing additions in the
S.B,I- statement+
S)B'*T!!! X.*N0-S*T0 "idthY X.*N0-C1)NT lengthY!
*f the called program contains no such options in the (0PO(- statement# the s$stem formats the
lists of the called program according to the options in the S.B,I- statement! *f# on the other
hand# the (0PO(- statement in the called program does specif$ a list structure# the additions in
the S.B,I- statement are ignored! ,or further information about these additions# refer to
&efining 3our 1"n .ist Structure!
(0PO(- demoEprogrammEsu&mitEline NO S-AN)A() PA/0 +0A)IN/9
)A-A= name -7P0 s%-title !A.0 ?)0,OEP(O/(A,E(0A)E-AB0SE8?4
wid -7P0 i !A.0 J@4
len -7P0 i !A.0 @9
S0- P2-S-A-.S ?S00C-?9
ABAP Programming (BC-ABA) 4BE
W(I-0= ?Select a report and its list format=?4
A ?-------------------------------------?9
S"IP9
W(I-0= ?(eport ?4 name INP.- ON4
A ?ine si:e ?4 wid INP.- ON4
A ?Page lengt$?4 len INP.- ON9
A- .S0(-CO,,AN)9
CAS0 s%-ucomm9
W+0N ?S00?9
(0A) IN0= D 2I0) !A.0 name4
G 2I0) !A.0 wid4
H 2I0) !A.0 len9
S.B,I- (name) IN0-SI60 wid IN0-CO.N- len AN) (0-.(N9
0N)CAS09
3ou can use this program to start programs "ith user-defined list formatting! 1n the basic list#
the user can enter a report name and the desired list "idth and length b$ oer"riting the default
alues+
*n the A- .S0(-CO,,AN)eent# the s$stem reads the alues and starts the specified
e/ecutable program using S.B,I-! *f the (0PO(- statement in the called program has no
IN0-SI60 or IN0-CO.N-specification of its o"n# its lists are displa$ed using the alues wid
and len! At the end of the called program# $ou can change the input alues on the basic list and
start a ne" program!
Printing ists
3ou can send a list from a called program directl$ to the spool s$stem instead of displa$ing it on
the screen! To do this# use the -O SAP-SPOO addition in the S.B,I- statement+
S)B'*T!!! T1 SAP-SP11. print-parameters!
,or details of the parameters that $ou can use here# refer to Printing .ists!
Saving ists
3ou can store a list from a called program in the ABAP memor$ instead of displa$ing it on the
screen! To do this# use the 0XPO(-IN/ IS- -O ,0,O(7 addition in the S.B,I- statement+
S)B'*T!!! AN& %0T)%N
0_P1%T*N( .*ST T1 '0'1%3!
This statement stores the list in ABAP memor$# allo"ing the calling program to access it once the
called program has finished! 3ou must use the AN) (0-.(N addition in this case! 3ou cannot use
the additions 0XPO(-IN/ IS- -O ,0,O(7and -O SAP-SPOO together!
The function group S.ST proides function modules for accessing the saed list# including for
e/ample+
7 .*STS,%1'S'0'1%3
7 W%*T0S.*ST
7 &*SP.A3S.*ST
Program Statements to eave a Called Program
)suall$# the user e/its a program $ou called using S.B,I-999 AN) (0-.(N b$ choosing ,: or
,1? on list leel F of the called program!
6o"eer# if $ou need to e/ecute further statements before returning to the called program (for
e/ample# to place data in ABAP memor$ using the 0XPO(- statement)# $ou need to modif$ the
user interface of the called program! ,or e/ample# $ou can define $our o"n function code for the
Bac- function and process it in the A- .S0(-CO,,AN) eent! After $ou hae "ritten $our
additional statements# $ou can leae the called program using the .0AA0 statement!
.0AA0!
statement! Control then returns to the point from "hich the program "as called!
ABAP Programming (BC-ABA) 4DF
(0PO(- demoEprogrammEleave NO S-AN)A() PA/0 +0A)IN/9
)A-A= ita& -7P0 -AB0 O2 i4
num -7P0 i9
S.B,I- demoEprogramErepC AN) (0-.(N9
I,PO(- ita& 2(O, ,0,O(7 I) ?+"?9
OOP A- ita& IN-O num9
W(I-0 A num9
0N)OOP9
-OP-O2-PA/09
W(I-0 ?(eport 8?9
.IN09
This program calls the follo"ing e/ecutable program (report)+
(0PO(- demoEprogramErepC NO S-AN)A() PA/0 +0A)IN/9
)A-A= num&er -7P0 i4
ita& -7P0 -AB0 O2 i9
S0- P2-S-A-.S ?,7BAC"?9
)O G -I,0S9
num&er F s%-inde59
APP0N) num&er -O ita&9
W(I-0 A num&er9
0N))O9
-OP-O2-PA/09
W(I-0 ?(eport B?9
.IN09
A- .S0(-CO,,AN)9
CAS0 s%-ucomm9
W+0N ?,BC"?9
0XPO(- ita& -O ,0,O(7 I) ?+"?9
0A!09
0N)CAS09
*n the self-defined status ,7BAC"# the function code 'BCU is assigned to the function -e$s
,:and ,1?+
*f the user chooses Bac-on the interface ,7BAC"# the s$stem transfers Table ita&into the
ABAP memor$ and then leaes demoEprogramErepC! *n demoEprogrammEleave# it reads Table
ita& again!
)irect e5ecution
)sers can run e/ecutable programs either directl$ in the foreground b$ entering the program
name in transaction SA:D (S$stem 7 Serices 7 %eporting)# or as a bac-ground 2ob! 3ou can onl$
run a program in the bac-ground if there is no dialog controlled e/ecution! 3ou do not need to
assign a transaction code to an e/ecutable program# although $ou ma$ if $ou "ish# and $ou do not
hae to use the Screen Painter to create an$ screens for it!
When $ou run an e/ecutable program# the program flo" is controlled b$ a series of processors in
the runtime enironment! These trigger a set se8uence of eents# to "hich $ou can react in
corresponding processing bloc-s in the program! The flo" an e/ecutable program conforms to the
programming standard &*N @@44F!
ABAP Programming (BC-ABA) 4D1
The program starts "ith an initiali9ation phase# follo"ed b$ a selection screen! *t then retriees#
processes# and displa$s data! This process is best suited to reading and displa$ing data
(reporting)! Because of this# e/ecutable programs "ere often -no"n as reports! 3ou can either
program the bloc-s for selecting and reading data in $our program# or $ou can use a logical
database instead!
*f a standard selection screen is declared in an e/ecutable program# the same program "ill be
automaticall% called again after it "as completel$ processed! *n this process# the user inputs are
automaticall$ buffered and are aailable again for the follo"ing selection screen!
.in-ing to a .ogical &atabase
0ent Bloc-s in 0/ecutable Programs
in*ing to a ogical )ata&ase
When $ou create an e/ecutable program# $ou can specif$ the name of a logical database in its
program attributes! A logical database is a special ABAP program that combines the contents of
certain database tables! 3ou can use a logical database "ith an$ number of e/ecutable programs!
*f $ou enter an asteris- (L) for the logical database# the s$stem uses a standard database that
controls the selection screen# but does not read an$ data!
(unning Programs Wit$ and Wit$out ogical )ata&ases
When $ou run an e/ecutable program that has a logical database lin-ed to it# the t"o programs
function li-e a single e/ecutable program "hose processing bloc-s are called b$ the runtime
enironment in a particular order! ,or further details# refer to the diagram in the section .in-
"ith 0/ecutable Programs!
The main functions of a logical database are to call t$e selection screen and read data! *f there
is an appropriate logical database in the s$stem# $ou no longer need to program these functions!
0/ecutable programs that do not use a logical database# but define their o"n selection screen and
read data using 1pen SC. statements (S00C-) often re8uire onl$ one single processing bloc- [
the standard eent bloc- S-A(--O2-S00C-ION! *n this case (and onl$ in this case)# an
e/ecutable program behaes li-e a classic se8uentiall$-processed program! 6o"eer# as soon as
$ou process a selection screen in the program (for e/ample# filling input fields before the call or
chec-ing user input after the call)# $ou hae to include further processing bloc-s
(INI-IAI6A-ION# A- S00C-ION-SC(00N)! *f $ou use a logical database# the program is
full$ eent-drien! The most important eent used "ith logical databases is /0-! At this time# the
logical database passes an imported record to the appropriate processing bloc- in the e/ecutable
program!
,or an oerie" of eents and the se8uence in "hich the$ are processed# refer to 0ent Bloc-s in
0/ecutable Programs! 3ou can# of course# program $our o"n database accesses using 1pen SC. in
an$ eent bloc-!
ABAP Programming (BC-ABA) 4D4
The follo"ing e/ample compares t"o simple e/ecutable programs that read data from the
hierarchical database tables SP,.* and S,.*(6T! 1ne does not use a logical database# the other
uses the logical database ,1S! Both programs generate the same list!
05ecuta&le program wit$out logical data&ase
(0PO(- demoEprogramEreadEta&lesE89
)A-A= waEspfli -7P0 spfli4
waEsflig$t -7P0 sflig$t9
S00C--OP-IONS= selEcarr 2O( waEspfli-carrid9
S00C- carrid connid cit%from cit%to
2(O, spfli
IN-O CO((0SPON)IN/ 2I0)S O2 waEspfli
W+0(0 carrid IN selEcarr9
W(I-0= A waEspfli-carrid4
waEspfli-connid4
waEspfli-cit%from4
waEspfli-cit%to9
S00C- fldate
2(O, sflig$t
IN-O CO((0SPON)IN/ 2I0)S O2 waEsflig$t
W+0(0 carrid F waEspfli-carrid
AN) connid F waEspfli-connid9
W(I-0= A waEsflig$t-fldate9
0N)S00C-9
0N)S00C-9
This program does not need an$ e/plicitl$-declared processing bloc-s! All non-declaratie
statements automaticall$ belong to the default eent bloc- S-A(--O2-S00C-ION! The
selection screen# "or- areas for data# and the S00C- statements all hae to be "ritten in the
program itself!
05ecuta&le program wit$ logical data&ase
The logical database ,1S is entered in the attributes of the e/ecutable program+
(0PO(- demoEprogramEreadEta&lesEB9
NO)0S= spfli4 sflig$t9
/0- spfli 2I0)S carrid connid cit%from cit%to9
W(I-0= A spfli-carrid4
spfli-connid4
spfli-cit%from4
spfli-cit%to9
/0- sflig$t 2I0)S fldate9
W(I-0= A sflig$t-fldate9
*f $ou compare this program "ith the e/ecutable program "ithout a logical database# $ou see
that this program does not hae to ta-e on an$ tas-s# e/cept the list output! These tas-s are
performed b$ the logical database! The NO)0S statement declares the "or- areas into "hich
the logical database places the data that it reads!
Controlling t$e ogical )ata&ase from t$e 05ecuta&le Program
When $ou use a logical database# $ou can control the selection screen and the depth to "hich the
logical database reads data! With NO)0Sstatement# $ou specif$ the nodes of the logical
ABAP Programming (BC-ABA) 4D:
database that $ou "ant to use in the e/ecutable program! The statement declares table "or-
areas for these nodes in the program! These are data ob2ects "ith the same name and structure
as the corresponding node! The selection screen of the logical database onl$ contains input fields
for the nodes that $ou hae declared using NO)0S!
3ou control the depth to "hich the logical database reads data b$ defining /0- eent bloc-s! 3ou
do not hae to program a /0- eent bloc- for eer$ node declared using NO)0S! The logical
database al"a$s reads the necessar$ data [ that is# at least the -e$ fields [ for all nodes along
the path of the hierarch$ tree up to the lo"est-leel node for "hich a /0- eent bloc- is
defined! *f $ou hae not defined a particular node for processing# the logical database also
ignores all the corresponding subordinate parts of the hierarch$ tree!
0ach /0- eent bloc- -no"s both the fields of the current node and the fields that it has read
from all the higher-leel tables that are along the current read path! At the end of a hierarch$
leel# the logical database resets the table "or- area in the e/ecutable program to 60_ null!
3ou can also d$namicall$ change the depth to "hich the logical database is read b$ terminating a
/0- eent bloc- (0XI-# C+0C")! When $ou terminate a /0- eent bloc-# the logical database
ignores an$ subordinate nodes in the hierarch$!
B$ specif$ing a field list in the definition of the /0- eent bloc-# $ou can hae the program
control the amount of data read for each node! This onl$ "or-s if the releant node in the logical
database has been defined for field selections!
0/ample of read depth using logical database ,1S+
N1&0S+ spfli# sflight# sboo-!
!!!
(0T spfli!
The logical database does not read an$ data from the table S,.*(6T or SB11U!
N1&0S+ spfli# sboo-!
!!!
(0T sboo-!
The logical database reads data from the tables SP,.* and S,.*(6T# since the$ are on the
access path for the node SB11U! 6o"eer# $ou cannot access data from S,.*(6T in the
e/ecutable program!
Advantages of .sing ogical )ata&ases
.ogical databases sae $ou haing to program a selection screen and read data from the database
in each e/ecutable program! The program does not hae to specif$ ho" to retriee the data# but
instead onl$ has to process it and displa$ it on the output screen!
An e/ecutable program can al"a$s onl$ "or- "ith one logical database# but each logical database
can be used b$ seeral e/ecutable programs! This offers considerable adantages compared "ith
the method of integrating the database accesses into the indiidual e/ecutable programs using
S00C-statements! *t means that $ou onl$ hae to code identical access paths once! The same
applies to coding authori9ation chec-s!
When $ou use logical databases# most e/ecutable programs benefit from haing
7 An eas$-to-use and standard user interface
7 Chec- functions "hich chec- that user input is complete# correct# and plausible
7 'eaningful data selection
7 Central authori9ation chec-s for database accesses
7 (ood read access performance (for e/ample# "ith ie"s) "hile retaining the hierarchical
data ie" determined b$ the application logic!
0en though $ou are using central logical databases# the program itself remains fle/ible because+
7 3ou can still create $our o"n selection screens for each program
7 3ou can code $our o"n functions in an$ eent bloc- in the program! ,or e/ample# $ou ma$
"ant to "rite user dialogs for further authori9ation or plausibilit$ chec-s on the selection
screen!
Programming ogical )ata&ases
.ogical databases are editing using the tool .ogical &atabase Builder in the ABAP Wor-bench
(Transaction S.&B or Tools ' ABAP Wor-bench ' &eelopment ' Programming 0nironment '
.ogical &atabase Builder! ,or further information about programming logical databases# refer to
the section .ogical &atabases!
0vent Bloc*s in 05ecuta&le Programs
ABAP Programming (BC-ABA) 4D>
When $ou run an e/ecutable program# the program flo" is controlled b$ the e/ternal eents in
the ABAP runtime enironment! The follo"ing diagram sho"s the se8uence of the eents+
The eents in the gra$ bo/ are onl$ processed if $ou hae entered a logical database in the
program attributes! The AT S0.0CT*1N-SC%00N eent is onl$ processed if a selection screen is
defined in the program or the logical database lin-ed to the program! The other eents occur
"hen an$ e/ecutable program is run! (See also Processing Bloc-s in ABAP Programs!)
As "ell as these eents# there are others that can# as in other ABAP programs# occur "hen a list
is created (T1P-1,-PA(0# 0N&-1,-PA(0)# and in interactie lists (AT .*N0-S0.0CT*1N# AT
)S0%-C1''AN&)! ,or more information about these eents# refer to .ists!
*f $ou "ant to handle an eent# $ou must define the corresponding eent bloc- in $our program! *f
$ou do not define the eent bloc-# there is no reaction to the eent!
&escription of 0ents
.eaing 0ent Bloc-s!
)escription of (eporting 0vents
This section describes in more detail the eents that occur "hen $ou run an e/ecutable program!
The follo"ing eents occur "hen $ou run a t$pical e/ecutable program that is lin-ed "ith a logical
database+

0ent Time
INI-IAI6A-ION

Before the standard selection screen is displa$ed

A- S00C-ION-
SC(00N
After user input on a selection screen has been
processed# but "hile the selection screen is still
actie
S-A(--O2-
S00C-ION

After the standard selection screen has been
processed# before data is read from the logical
database
After the logical database has read a data record
from the node node
After all of the nodes of the logical database hae
been processed that are hierarchicall$ subordinate
to the node node in the structure of the logical
database
After all data has been read b$ the logical database

.ist processor eents+

0ent Time
-OP-O2-PA/0 *n list processing "hen a ne" page starts
ABAP Programming (BC-ABA) 4D?
0N)-O2-PA/0 *n list processing "hen a page ends
A- IN0-
S00C-ION
When the user triggers the predefined function code
P*CU
A- P2nn When the user triggers the predefined function code
P,nn
A- .S0(-CO,,AN) When the user triggers a function code defined in
the program

The aboe are treated under .ists!
INI-IAI6A-ION
This eent occurs before the standard selection screen is called! &uring this eent bloc-# the
input fields of the standard selection screen can onl$ be initiali9ed once after the program has
been started! *f an e/ecutable program declares a standard selection screen the same program
"ill be automaticall$ called again b$ the s$stem once the selection screen has been e/ecuted (see
S.B,I-)! This triggers the INI-IAI6A-ION eent again! *t is important to note ho"eer
that the initiali9ation of parameters or selection criteria "ill not hae an effect because at this
point the alue of the AT S0.0CT*1N-SC%00N 1)TP)T is assigned using the preious user
inputs! 1nl$ the remaining global fields "hich "ere set during INI-IAI6A-ION are initiali9ed
during each program run!
&uring INI-IAI6A-ION (but also during AT S0.0CT*1N-SC%00N 1)TP)T) the standard
alues for parameters or selection criteria# "hich are declared in logical databases# can be
changed! To change a selection criterion# $ou must fill at least the components selta&-sign#
selta&-option and selta&-low of the selection table selta&# other"ise it remains undefined!
*f $ou "ant to initiali9e the input fields of a logical database# $ou need to find out the names of
the fields! To do this for the logical database SAP&B]ldbG# use Transaction S.&B or choose Tools
'
ABAP Wor-bench# follo"ed b$ &eelopment ' Programming eniron! ' .ogical databases! 3ou can
also displa$ the technical information for the re8uired field on the selection screen! To do this#
call the ,1 help for the re8uired field and then choose Technical info! *n the field Scrn ,ield of
the follo"ing dialog bo/# $ou then see the name of the field used in the program!
The follo"ing e/ecutable program is connected to the logical database ,1S!
%0P1%T eentSdemo!
PA%A'0T0%S datum T3P0 s$-datum &0,A).T s$-datum!
N1&0S spfli!
When $ou start the program# the selection screen appears+
ABAP Programming (BC-ABA) 4D@
1nl$ the parameter &AT)' is defined in the program itself! All of the other input fields are
defined in the logical database ,1S!
When $ou call the ,1 help for the first input field for Airline and then choose Technical info! the
field name CA%%*&-.1W appears in the Scrn field field! This is the component of the selection
table that corresponds to the input field! ,rom this# $ou see that the name of the selection
criterion is CA%%*&! *n the same procedure as described aboe# $ou find that the parameters of
the input fields ,rom and To are named C*T3S,% and C*T3ST1!
Suppose "e no" change the program as follo"s+
(0PO(- demoEprogramEinitiali:ation9
PA(A,0-0(S datum -7P0 s%-datum )02A.- s%-datum9
NO)0S spfli9
INI-IAI6A-ION9
airpEfr-sign F ?I?9
airpEfr-option F ?0W?9
airpEfr-low F ?Y2"?9
APP0N) airpEfr9
airpEto-sign F ?I?9
airpEto-option F ?0W?9
airpEto-low F ?2(A?9
APP0N) airpEto9
carrid-sign F ?I?9
carrid-option F ?B-?9
carrid-low F ?AA?9
carrid-$ig$ F ?+?9
APP0N) carrid9
datumTH(B) F ?@8?9
The selection screen is no" filled "ith default alues as follo"s+
ABAP Programming (BC-ABA) 4DB

A- S00C-ION-SC(00N
The eent A- S00C-ION-SC(00N is the basic form of a "hole series of eents that occur
"hile the selection screen is being processed!
The standard selection screen# either in an e/ecutable program or in the logical database lin-ed
to it# is automaticall$ called bet"een the INI-IAI6A-ION and S-A(--O2-
S00C-IONeents! When $ou call the selection screen# and "hen users interact "ith it# the
ABAP runtime enironment generates selection screen eents# "hich occur bet"een
INI-IAI6A-ION and S-A(--O2-S00C-ION!
3ou can define eent bloc-s for these eents in $our program to change the selection screen or
process user input!
,or further information about selection screen eents# refer to Processing Selection Screens!
S-A(--O2-S00C-ION
This eent occurs after the selection screen has been processed and before data is read using
the logical database! 3ou can use it to prepare for reading data and creating the list b$# for
e/ample# setting alues for internal fields and "riting introductor$ notes on the output list!
*n an e/ecutable program# an$ non-declaratie statements that occur bet"een the (0PO(- or
P(O/(A,statement and the first processing bloc- are also processed in the S-A(--O2-
S00C-ION bloc-! See also &efining 0ent Bloc-s!
The follo"ing e/ecutable program is connected to the logical database ,1S!
(0PO(- demoEprogramEstartEofEselectio9
NO)0S spfli9
999
A- S00C-ION-SC(00N9
999
S-A(--O2-S00C-ION9
W(I-0= A ?ist of 2lig$ts? COO( COE+0A)IN/4
A ?Created &%?4 S7-.S0(I)4 ?on?4 s%-datum9
.IN09
/0- spfli9
999
/0-
This is the most important eent for e/ecutable programs that use a logical database! *t occurs
"hen the logical database has read a line from the node node and made it aailable to the program
in the "or- area declared using the statement NO)0S node!
When $ou define the corresponding eent bloc- in the program# $ou can specif$ a field list if the
logical database supports field selection for this node+
/0- node P2I0)S f8 fB999Q9
3ou can process the data in the "or- area in this eent bloc-! ,or e/ample# $ou can "rite it
directl$ to a list# or store it in a se8uential dataset (internal table or e/tract) so that $ou can
process it later!
The logical database reads all columns from all nodes that are not designated for field selection
in the logical database and are superior to node on the access path of the logical database! This
"or-s independentl$ of "hether $ou hae defined /0- eent bloc-s for these nodes or not!
ABAP Programming (BC-ABA) 4DD
6o"eer# $ou can onl$ access the data of the nodes for "hich $ou hae declared a "or- area in
the NO)0Sstatement!
At the end of a hierarch$ leel of the logical database# all of the fields in the "or- area node are
set to the alue 6e/adecimal null! *f $ou are using e/tracts# there is a special sort rule for fields
"ith the content he/adecimal FF! ,or further information# refer to Sorting 0/tract &atasets!
Performance can be much better for tables that are designated for field selection in the logical
database! *f there are nodes of this t$pe aboe node in the hierarch$ of the logical database for
"hich there are no /0- eent bloc-s# the data for all columns is onl$ read for the nodes for
"hich there is a NO)0S statement in the program! ,or nodes "ithout a NO)0Sstatement# onl$
the -e$ fields are read! The logical database needs the -e$ fields to construct an access path!
3ou can use the 2I0)S option to specif$ e/plicitl$ the columns of a node that the logical
database should read! With the 2I0)S option# the logical database program reads onl$ the
fields f8 fB999 and the -e$ fields from the node ta&le! 6o"eer# the node ta&le must hae been
designated for field selection in the logical database!
)sing 2I0)S can result in much better response times than "hen the logical database has to
read all of the columns!
All fields of the node node that are not -e$ fields and are not listed after 2I0)S are not read
b$ the logical database! The contents of the corresponding components of the table "or- area
node are set to he/adecimal null! This means that the$ are also set to he/ 9ero during the /0-
eents of the nodes belo" node in the hierarch$! 3ou should therefore not use these fields in
$our program or call subroutines that "or- "ith them! *f an e/tract dataset is filled in the /0-
eent bloc-# remember that e/tracts hae a special sort rule for fields "ith the contents
he/adecimal null!
The follo"ing e/ecutable program is connected to the logical database ,1S!
(0PO(- demoEprogramEget9
NO)0S= spfli4 sflig$t4 s&oo*9
S-A(--O2-S00C-ION9
W(I-0 ?-est Program for /0-?9
/0- spfli9
S"IP9
W(I-0= A ?2rom=?4 spfli-cit%from4
?-O =?4 spfli-cit%to9
/0- sflig$t9
S"IP9
W(I-0= A ?Carrid=?4 sflig$t-carrid4
?Connid=?4 sflig$t-connid9
.IN09
/0- s&oo*9
W(I-0= A ?2ldate=?4 sflig$t-fldate4
?Boo*id=?4 s&oo*-&oo*id4
?uggweig$t?4 s&oo*-luggweig$t .NI- ?*g?9
.IN09
The table "or- area S,.*(6T is also used in the eent bloc- for /0- s&oo*! &epending on "hat
$ou enter on the selection screen# the beginning of the list displa$ might loo- li-e this+
ABAP Programming (BC-ABA) 4DE
*n the logical database ,1S# the nodes S,.*(6T and SB11U are designated for field selection!
This means that $ou can specif$ a field list in their /0- eent bloc-s+
(0PO(- eventEdemo9
NO)0S= sflig$t4 s&oo*9
/0- sflig$t 2I0)S carrid connid9
999
/0- s&oo* 2I0)S &oo*id9
999
/0- sflig$t A-0 2I0)S planet%pe9
999
*n this case# the logical database reads the follo"ing fields+
7 'AN&T# CA%%*&# C1NN*&# ,.&AT0# and P.AN0T3P0 from S,.*(6T
7 'AN&T# CA%%*&# C1NN*&# ,.&AT0# and B11U*& from SB11U
The s$stem reads the fields 'AN&T and ,.&AT0 from S,.*(6T# een though the$ are not
specified in the field list# since the$ belong to the table -e$!
1nl$ the -e$ fields of SB11U are read!
/0- Z A-0
This eent is triggered "hen all of the data records for a node of the logical database hae been
read!
When $ou define the corresponding eent bloc- in the program# $ou can [ as "ith (0T [specif$ a
field list if the logical database supports field selection for this node+
/0- node A-0 P2I0)S f
8
f
B
999Q9
3ou can use the eent bloc- for processing steps that should occur at the end of the bloc-# li-e#
for e/ample# calculating statistics!
The follo"ing e/ecutable program is connected to the logical database ,1S!
(0PO(- demoEprogramEgetElate9
NO)0S= spfli4 sflig$t4 s&oo*9
)A-A weig$t -7P0 i !A.0 @9
S-A(--O2-S00C-ION9
W(I-0 ?-est Program for /0- node A-0?9
/0- spfli9
S"IP9
W(I-0= A ?Carrid=?4 spfli-carrid4
?Connid=?4 spfli-connid4
A ?2rom= ?4 spfli-cit%from4
ABAP Programming (BC-ABA) 4EF
?-o= ?4 spfli-cit%to9
.IN09
/0- sflig$t9
S"IP9
W(I-0= A ?)ate=?4 sflig$t-fldate9
/0- s&oo*9
weig$t F weig$t T s&oo*-luggweig$t9
/0- sflig$t A-09
W(I-0= A ?-otal luggage weig$t F?4 weig$t9
.IN09
weig$t F @9
The total "eight is calculated for each flight in the eent# then issued in the output list in the
eent /0- sflig$t A-0 and reset! &epending on "hat $ou enter on the selection screen# the
beginning of the list displa$ might loo- li-e this+
0N)-O2-S00C-ION
This is the last of the eents called b$ the runtime enironment to occur! *t is triggered after all
of the data has been read from the logical database# and before the list processor is started! 3ou
can use the corresponding eent bloc- to process and format all data that the program has stored
in se8uential datasets# such as internal tables or e/tracts# during the arious /0- eents!
The follo"ing e/ecutable program is connected to the logical database ,1S!
(0PO(- demoEprogramEendEofEselection9
NO)0S spfli9
)A-A= spfliEta& -7P0 SO(-0) -AB0 O2 spfli
WI-+ .NIW.0 "07 cit%from cit%to carrid connid4
spfliEline -7P0 spfli9
S-A(--O2-S00C-ION9
W(I-0 ?)emo program for 0N)-O2-S00C-ION?9
S"IP9
/0- spfli 2I0)S carrid connid cit%from cit%to9
ABAP Programming (BC-ABA) 4E1
,O!0-CO((0SPON)IN/ spfli -O spfliEline9
INS0(- spfliEline IN-O -AB0 spfliEta&9
0N)-O2-S00C-ION9
OOP A- spfliEta& IN-O spfliEline9
W(I-0= A spfliEline-cit%from4
spfliEline-cit%to4
spfliEline-carrid4
spfliEline-connid9
0N)OOP9
This program fills a sorted table "ith data from the logical database in the /0- spfli eent# and
displa$s them in a list in the 0N)-O2-S00C-ION eent! &epending on "hat $ou enter on the
selection screen# the beginning of the list displa$ might loo- li-e this+
05iting 0vent Bloc*s
ABAP contains a series of statements that allo" $ou to leae an eent bloc-! The$ return control
to the runtime enironment! The subse8uent se8uence of eents in the runtime enironment
depends on "hich statement $ou use and the eent bloc- in "hich $ou use it!
0/iting 0ent Bloc-s )sing S-OP
0/iting 0ent Bloc-s )sing 0XI-
0/iting 0ent Bloc-s )sing C+0C"
0/iting a /0- 0ent Bloc- )sing (0Y0C-
ABAP Programming (BC-ABA) 4E4
05iting 0vent Bloc*s .sing S-OP
*f $ou use the S-OP statement "ithin an eent bloc-# the s$stem stops processing the bloc-
immediatel$! The ABAP runtime enironment triggers the ne/t eent according to the follo"ing
diagram+
Before and during selection screen processing# the ne/t eent in the prescribed se8uence is
al"a$s called! ,rom the A- S00C-ION-SC(00N eent on"ards# the s$stem al"a$s triggers the
0N)-O2-S00C-ION eent "hen an eent bloc- "ith S-OP is e/ited! 1nce the corresponding
eent bloc- has been processed# the s$stem displa$s the list!
The follo"ing e/ecutable program is connected to the logical database ,1S!
(0PO(- demoEprogramEstop9
NO)0S= spfli4 sflig$t4 s&oo*9
S-A(--O2-S00C-ION9
W(I-0 ?-est Program for S-OP?9
/0- s&oo*9
W(I-0= ?Boo*id?4 s&oo*-&oo*id9
S-OP9
ABAP Programming (BC-ABA) 4E:
0N)-O2-S00C-ION9
W(I-0= A ?0nd of Selection?9
This produces the follo"ing output+
Test Program for ST1P
Boo-id FFF1FFF1
0nd of Selection
As soon as the first line of SB11U has been read# the s$stem calls the 0N)-O2-S00C-ION
eent bloc-!
05iting 0vent Bloc*s .sing 0XI-
*f $ou use the 0XI- statement "ithin an eent bloc- but not in a loop# the s$stem stops
processing the bloc- immediatel$! The ABAP runtime enironment triggers the ne/t eent
according to the follo"ing diagram+
Before and during selection screen processing# the ne/t eent in the prescribed se8uence is
al"a$s called! ,rom the S-A(--O2-S00C-ION eent on"ards# the s$stem starts the list
processor directl$ "hen the 0XI-statement occurs# and displa$s the list!
*f the 0XI- statement occurs inside a )O# W+I0# or OOP loop# it is the loop that terminates#
not the processing bloc-!
ABAP Programming (BC-ABA) 4E>
The follo"ing e/ecutable program is connected to the logical database ,1S!
(0PO(- demoEprogramEe5itE89
NO)0S= spfli4 sflig$t4 s&oo*9
S-A(--O2-S00C-ION9
W(I-0 ?-est Program for 0XI-?9
/0- s&oo*9
W(I-0= ?Boo*id?4 s&oo*-&oo*id9
0XI-9
0N)-O2-S00C-ION9
W(I-0= A ?0nd of selection?9
This produces the follo"ing output+
Test Program for 0_*T
Boo-id FFF1FFF1
After the first line of SB11U has been read# the list is displa$ed immediatel$!
The follo"ing e/ecutable program is connected to the logical database ,1S!
(0PO(- demoEprogramEe5itEB9
NO)0S= spfli4 sflig$t4 s&oo*9
)A-A flag(8) -7P0 c9
A- S00C-ION-SC(00N9
I2 carrid-low IS INI-IA9
flag F ?X?9
0XI-9
0N)I29

S-A(--O2-S00C-ION9
I2 flag F ?X?9
W(I-0 A ?No input for CA((I)?9
0XI-9
0N)I29
/0- spfli9
/0- sflig$t9
/0- s&oo*9
0N)-O2-S00C-ION9
W(I-0 A ?0nd of Selection?9
*f the user does not enter a alue for CA%%*&-.1W# the output appears as follo"s+
No selection made for CA%%*&
After the first 0XI- statement# the ne/t S-A(--O2-S00C-ION eent is triggered! After
the second 0XI-statement# the output list is displa$ed!
eaving 0vent Bloc*s .sing C+0C"
*f $ou use the C+0C" e5pr statement "ithin an eent bloc- but not wit$in a loop# and the
condition e5pris not fulfilled# the s$stem e/its the processing bloc- immediatel$!
e5pr can be an$ logical e/pression or the name of a selection table! *f $ou specif$ a selection
table and the contents of the corresponding table "or- area do not fulfill the condition in the
selection table# it has the same effect as a false logical e/pression!
The ABAP runtime enironment triggers the ne/t eent according to the follo"ing diagram+
ABAP Programming (BC-ABA) 4E?
The ne/t eent in the prescribed se8uence is al"a$s called!
*f the C+0C" statement occurs in a loop using )O# W+I0# or OOP# it is the loop that
terminates# not the processing bloc-!
Within a /0- eent bloc-# this means the ne/t /0- eent at the same $ierarc$ical level!When it
leaes the eent bloc-# the logical database reads the ne/t line of the current node# or the ne/t-
highest node if it has alread$ reached the end of the hierarch$ leel! Nodes that are lo"er do"n
in the hierarchical structure of the logical database are not processed!
*nside /0- eents# $ou can use an e/tra ariant of the C+0C" statement+
C+0C" S00C--OP-IONS9
This statement chec-s the contents of the table "or- area of the current node against all
selection tables lin-ed to that node!
Note that C+0C" statements for chec-ing database contents in /0- eents are onl$ processed
after the data has been read from the logical database! ,or performance reasons# $ou should
therefore aoid using chec-s of this -ind! *nstead# tr$ to chec- before the data is read# for
e/ample# b$ using d$namic selections!
The follo"ing e/ecutable program is connected to the logical database ,1S!
(0PO(- demoEprogramEc$ec*E89
NO)0S= spfli4 sflig$t4 s&oo*9
S-A(--O2-S00C-ION9
OOP A- airpEfr9
C+0C" airpEfr-low N0 ? ?9
W(I-0= A ?Selected Aiport-2rom=?4 airpEfr-low9
.IN09
ABAP Programming (BC-ABA) 4E@
0N)OOP9
OOP A- airpEfr9
C+0C" airpEto-low N0 ? ?9
W(I-0= A ?Selected Airport--o=?4 airpEto-low9
.IN09
0N)OOP9
/0- sflig$t9
W(I-0= A ?Connid=?4 sflig$t-connid4
?Carrid=?4 sflig$t-carrid4
?2ldate=?4 sflig$t-fldate9
*f the user enters K,ran-furti for C*T3S,%# but nothing for C*T3ST1# the beginning of the list
"ould loo- li-e this+
After the second C+0C" statement# the s$stem leaes the S-A(--O2-S00C-ION bloc- and
triggers the eent /0- sflig$t!
The follo"ing e/ecutable program is connected to the logical database ,1S!
(0PO(- demoEprogramEc$ec*EB9
NO)0S= spfli4 sflig$t4 s&oo*9
/0- sflig$t9
C+0C" sflig$t-carrid 0W ?+?9
W(I-0= A ?Connid=?4 sflig$t-connid4
?Carrid=?4 sflig$t-carrid4
?2ldate=?4 sflig$t-fldate9
/0- s&oo*9
C+0C" s&oo*-&oo*id - @@@@@CB@9
W(I-0= A ?Boo*id=?4 s&oo*-&oo*id9
/0- sflig$t A-09
.IN09
This produces the follo"ing output list+
ABAP Programming (BC-ABA) 4EB
*n the e/ample aboe# all lines of the node S,.*(6T and# if S,.*(6T-CA%%*& is W.6W# all lines
of the node SB11U# must be read! ,or performance reasons# $ou should avoid programming
selections as a&ove! *nstead# use the selections of the logical database!
eaving a /0- 0vent Bloc* .sing (0Y0C-
The (0Y0C- statement "as speciall$ deeloped for leaing /0- eent bloc-s! )nli-e C+0C" and
0XI-# (0Y0C- al"a$s refers to the current /0- eent bloc-! *f C+0C" and 0XI- occur in a loop#
the$ refer to the loop# and in a subroutine# the$ al"a$s refer to the subroutine! The (0Y0C-
statement# on the other hand# allo"s $ou to e/it a /0- eent bloc- directl$ from a loop or a called
subroutine!
The statement
%0a0CT XdbtabY!
al"a$s terminates the processing of the current line of the node of the logical database! Without
the optional d&ta&specification# the logical database automaticall$ reads the ne/t line of the
same node# and the ne/t /0- eent at the same hierarch$ leel is triggered! *f $ou use the
optional d&ta& specification# the logical database reads the ne/t line of the node d&ta&! The node
d&ta& must occur aboe the current node in the logical database hierarch$!
ABAP Programming (BC-ABA) 4ED
The follo"ing e/ecutable program is connected to the logical database ,1S!
(0PO(- 0!0N-E)0,O9
NO)0S= SP2I4 S2I/+-4 SBOO"9
/0- S2I/+-9
S"IP9
W(I-0= A ?Carrid=?4 S2I/+--CA((I)4
?Connid=?4 S2I/+--CONNI)4
?2ldate=?4 S2I/+--2)A-09
.IN09
/0- SBOO"9
P0(2O(, S.B9
2O(, S.B9
W(I-0= A ?Boo*id=?4 SBOO"-BOO"I)9
(0Y0C- ?S2I/+-?9
0N)2O(,9
This program reads and displa$s onl$ the first boo-ing for each flight# since the logical database
reads the ne/t line of S,.*(6T after the (0Y0C- statement!
This produces the follo"ing output list+
-ransactions

A transaction is an ABAP program that $ou start using a transaction code! There are dialog and
report transactions# parameter and ariant transactions# and [ as of release @!1F [ 11
transactions! To start a transaction# $ou either enter the transaction code in the input field of
the standard toolbar or use the statements CA -(ANSAC-ION or 0A!0 -O
-(ANSAC-ION! Transaction codes are created in the transaction maintenance of the ABAP
Wor-bench!

Called b$ the )ser (Transaction Code)
Calling Transactions
ABAP Programming (BC-ABA) 4EE
Called &% t$e .ser (-ransactions Code)
*n a dialog-drien ABAP program# the program flo" is controlled b$ a series of user dialogs!
&ialog-drien programs are t$picall$ started using transaction codes# "hich specif$ the first
screen of the program! This initial screen allo"s users to enter or re8uest information! The
screen flo" logic then reacts to the user input b$ calling arious modules of ABAP processing
logic! *t then moes on to the ne/t screen! The corresponding ABAP processing logic might
contain statements for displa$ing data or updating the database!
Suppose a trael agent "ants to boo- a flight! The agent enters the corresponding data on the
screen! The s$stem either confirms the desired re8uest# that is# the agent can boo- the flight
and the customer traels on the desired da$ in the resered seat to the chosen destination# or
the s$stem displa$s the information that the flight is alread$ full$ boo-ed!
To fulfill such re8uirements# a dialog program must offer+
7 a user-friendl$ user interface
7 format and consistenc$ chec-s for the data entered b$ the user
7 an eas$ "a$ of correcting "rong entries
7 access to data b$ storing it in the database
ABAP offers a ariet$ of tools and language elements to meet the re8uirements stated aboe in
the dialog programs!
)ialog Programs= Overview
&ialog-drien programs# or an$ program started using a transaction code# are -no"n as SAP
transactions# or 2ust transactions! The term Ktransactioni is used in seeral different conte/ts in
the *T "orld! *n 1.TP (1nline Transaction Processing)# "here seeral users are "or-ing in one
s$stem in dialog mode# the term Ktransactioni stands for a user re8uest! *n con2unction "ith
database updates# it means a change in state in the database!
'odule pools can onl$ be started using a transaction code# in "hich an initial screen is defined!
0/ecutable programs can be started either using a transaction code# or b$ entering the program
name in one of the transactions S0:D or SA:D! Screens call dialog modules in the associated
ABAP program from their flo" logic! 'odules pools are mainl$ used as containers for dialog
modules! 0/ecutable programs# or function modules can also s"itch to dialog mode b$ calling
screens using the CA SC(00N statement! The program te/t of the e/ecutable program or
function module must contain the releant dialog module!
Programs that are partiall$ or "holl$ dialog-drien cannot &e e5ecuted in t$e &ac*ground! The$
are therefore sometimes referred to as dialog programs!
Components of a )ialog Program
A dialog-drien program consists of the follo"ing basic components+
ABAP Programming (BC-ABA) :FF
7 Transaction Code
The transaction code starts a screen se8uence! 3ou create transaction codes in the
%epositor$ Bro"ser in the ABAP Wor-bench or using Transaction S0E:! A transaction code is
lin-ed to an ABAP program and an initial screen! As "ell as using a transaction code# $ou can
start a screen se8uence from an$ ABAP program using the CA SC(00N statement!
7 Screens
0ach dialog in an SAP s$stem is controlled b$ one or more dialog screens ! These screens
consist of a screen mas- and its flo" logic! Since the flo" logic influences the program flo"#
screens are sometimes referred to as Kd$namic programsi! 3ou create screens using the
Screen Painter in the ABAP Wor-bench! 0ach screen belongs to an ABAP program!
The screen has a la$out that determines the positions of input;output fields and other
graphical elements such as chec-bo/es and radio buttons! The flo" logic consists of t"o parts+
[ Process Before 1utput (PB1)! This defines the processing that ta-es place before
the screen is displa$ed!
[ Process After *nput (PA*)! This defines the processing that ta-es place after the
user has chosen a function on the screen!
All of the screens that $ou call "ithin an ABAP program must belong to that program! The
screens belonging to a program are numbered! ,or each screen# the s$stem stores the number
of the screen "hich is normall$ displa$ed ne/t! This screen se8uence can be either linear or
c$clic! ,rom "ithin a screen chain# $ou can call another screen chain and# after processing it#
return to the original chain! 3ou can also oerride the staticall$-defined ne/t screen from
"ithin the dialog modules of the ABAP program!
7 ()* Status
0ach screen has a ()*-Status! This controls the menu &ars# standard tool&ar# and
application tool&ar# "ith "hich the user can choose functions in the application! .i-e screens#
()* statuses are independent components of an ABAP program! 3ou create them in the ABAP
Wor-bench using the 'enu Painter!
7 ABAP Program
0ach screen and ()* status in the SAP S$stem belongs to one ABAP program! The ABAP
program contains the dialog modules that are called b$ the screen flo" logic# and also process
the user input from the ()* status! ABAP programs that use screens are also -no"n as dialog
programs! *n a module pool the first processing bloc- to be called is al"a$s a dialog module!
6o"eer# $ou can also use screens in other ABAP programs# such as e/ecutable programs or
ABAP Programming (BC-ABA) :F1
function modules! The first processing bloc- is called differentl$ in this case< for e/ample# b$
the runtime enironment or a procedure call! The screen se8uence is then started using the
CA SC(00N statement!
&ialog modules are split into PB1 modules and PA* modules! &ialog modules called in the PB1
eent are used to prepare the screen# for e/ample b$ setting conte/t-specific field contents
or b$ suppressing fields from the displa$ that are not needed! &ialog modules called in the
PA* eent are used to chec- the user input and to trigger appropriate dialog steps# such as
the update tas-!
Passing )ata Between ABAP Programs and Screens
6o" are fields from ABAP programs displa$ed on the screeng And ho" is user input on the screen
passed bac- to the ABAP programg )nli-e in list programming# $ou cannot "rite field data to the
screen using the W(I-0 statement! *nstead# the s$stem transfers the data b$ comparing the
names of screen fields "ith the names of the ABAP fields in the program! *f it finds a pair of
matching names# the data is transferred bet"een the screen and the ABAP program! This
happens immediatel$ before and immediatel$ after displa$ing the screen!
2ield Attri&utes
The field attributes# for all screen fields of a dialog screen# are defined in the Screen Painter! *f
a field name in the screen corresponds to the name of an ABAP &ictionar$ field# the s$stem
automaticall$ establishes a reference bet"een these t"o fields! Thus# a large number of field
attributes for the screen are automaticall$ copied from the ABAP &ictionar$! The field
attributes together "ith data element and domain of the assigned &ictionar$ field form the basis
for the standard functions the screen e/ecutes in a dialog (automatic format chec- for screen
fields# automatic alue range chec-# online help# and so on)!
0rror )ialogs
Another tas- of the screen processor is to produce error dialogs! Chec-ing the input data is
carried out either automaticall$ using chec- tables of the ABAP &ictionar$ or b$ the ABAP
program itself! The screen processor includes the error message into the receied screen and
returns the screen to the user! The message ma$ be conte/t-sensitie# that is# the s$stem
replaces placeholders in the message te/t "ith current field contents! *n addition# onl$ fields
"hose contents is related to the error and for "hich a correction ma$ sole the error can accept
input! See also 'essages on Screens!
)ata Consistenc%
To -eep data consistent "ithin comple/ applications# ABAP offers techni8ues for optimi9ing
database updates that operate independent of the underl$ing database and correspond to the
special re8uests of dialog programming!
See also+ &ata consistenc$!
Sample -ransaction
The simple sample transaction &0'1ST%ANSACT*1N from the SABAP&1C) pac-age illustrates
the concept behind dialog-drien transactions and their use!
2eatures
The sample transaction consists of a single dialog screen! The user can enter the *& of an airline
compan$ and a flight number to re8uest flight information+
ABAP Programming (BC-ABA) :F4
*f the user chooses &ispla$# the s$stem retriees the re8uested data from the database and
displa$s it+
Structure
The structure of the sample transaction is described belo"!
All of its components belong to the program SAP&0'1ST%ANSACT*1N! 3ou can displa$ them in
the %epositor$ Bro"ser! 3ou can also choose S$stem 7 Status from "ithin the transaction# and
then double-clic- one of the listed components to s"itch to the appropriate tool in the ABAP
Wor-bench!
ABAP Programming (BC-ABA) :F:
Screen
0ach screen contains fields used to displa$ or re8uest information! ,ields can be te/t strings#
input or output fields# radio buttons# chec-bo/es# or pushbuttons! The screen of Transaction
&0'1ST%ANSACT*1N contains onl$ te/ts and input;output fields!
A screen consists of seeral components+
7 Screen attri&utes= Specif$ the screen number# the number of the ne/t screen and other
attributes!
7 a%out= Positions of the te/ts# fields# pushbuttons# and so on for a screen!
7 2ield attri&utes= &efinition of the properties of the indiidual fields on the screen!
7 2low logic+ Call of the ABAP modules for a screen!
3ou create all of the components of a screen using the Screen Painter! To start the Screen
Painter# create a screen in the %epositor$ Bro"ser or double-clic- an e/isting one! The %epositor$
Bro"ser calls the Screen Painter# in "hich $ou can enter the flo" logic of the screen $ou "ant to
create or change! The flo" logic editor also contains pushbuttons that $ou can use to s"itch to
the la$out editor# the field list# or the screen attributes screen!
Screen Attri&utes
,rom the userIs point of ie"# a transaction is a se8uence of screens# displa$ed one after
another! 6o" is the se8uence determinedg The transactionsIs attributes determine the first
screen to be displa$ed! The attributes of the indiidual d$npros determine "hich screen to
displa$ after the current screen! 3ou can also set the number of the subse8uent screen
d$namicall$ from "ithin the ABAP program!
,or our e/ample# the screen attributes need not be changed# since no subse8uent screen is called!
a%out
To start the la$out editor in the Screen Painter# choose ,ullscreen! 6ere $ou can determine the
la$out of the screen! ,or Transaction &0'1ST%ANSACT*1N# the desired fields can be copied
from table SP,.* of the ABAP &ictionar$! ,or further information# refer to the Screen
Painter documentation!
2ield Attri&utes
*n the element list# $ou can displa$ or change the attributes of each field on the screen!
(*nput;output fields# re8uired fields# "hether the possible entries button is displa$ed# "hether
the field is inisible# and so on!)
The fields Airline (SP,.*-CA%%*&) and ,light number (SP,.*-C1NN*&) are defined as
input;output fields! All other fields are used to displa$ the flight data onl$!
2low ogic
The flo" logic code of a dialog screen consists of a fe" statements that s$ntacticall$ resemble
ABAP statements! 3ou cannot use flo" logic -e$"ords in ABAP programs# or ABAP statements in
screen flo" logic! The flo" logic is a component of the screen! 3ou enter it in the flo" logic editor
of the Screen Painter!
The flo" control for the screen in Transaction &0'1ST%ANSACT*1N loo-s li-e this+
P%1C0SS B0,1%0 1)TP)T!
'1&).0 setSstatusSF1FF!
L
ABAP Programming (BC-ABA) :F>
P%1C0SS A,T0% *NP)T
'1&).0 userScommandSF1FF!
The P(OC0SS statements introduce the flo" logic for the t"o eents PB1 and PA*! The
,O).0statements each call one dialog module in the associated ABAP program! *n this e/ample#
there is onl$ one '1&).0 for each eent PB1 and PA*! 6o"eer# the flo" logic can# of course#
contain more statements# calling more than one dialog module in each eent! 3ou can also call the
same dialog module from more than one screen!
The flo" logic s$nta/ contains onl$ a fe" statements! The most important are ,O).0# 2I0)#
C+AIN# OOP# CA S.BSC(00N! ,or information about flo" logic s$nta/# choose )tilities 7
6elp on!!! from the flo" logic editor! A dialog bo/ appears# in "hich $ou select ,lo" logic -e$"ord
and then enter the -e$"ord for "hich $ou "ant more information!
ABAP Program
The ABAP program is a module pool! When $ou create a module pool in the %epositor$ Bro"ser#
the ABAP Wor-bench automaticall$ organi9es the program code into a series of include programs!
*f $our ABAP program obseres the naming conention SAP,name# the hierarch$ tree in the
%epositor$ Bro"ser allo"s $ou to create the follo"ing include programs+
7 /lo&al fields+ (lobal data declarations in the include ,name-OP! This data is isible in all
modules "ithin the program!
7 PBO modules+&ialog modules in the includes ,nameOnn# "hich are called before a screen is
displa$ed!
7 PAI modules+&ialog modules in the includes ,nameInn# "hich are called after user actions
on screens!
7 Su&routines= Subroutines "ithin the program# stored in the includes ,name2nn! These can
be called from an$"here in the program!
7 ist events= 0ent bloc-s for list processor eents# stored in the includes ,name0nn!
These occur during list processing!
*nclude programs can contain seeral processing bloc-s! These normall$ all hae the same t$pe
(for e/ample# onl$ PB1 modules or onl$ PA* modules)! 6o"eer# $ou could create a separate
include program for each processing bloc-# or combine arious t$pes of processing bloc- in a
single include program!
*f $ou follo" the "or-ing method suggested b$ the ABAP Wor-bench# the source code of $our
main program is empt$ apart from a series of INC.)0 statements that incorporate the
indiidual includes into $our program+
Lf---------------------------------------------------------------L
Lf 'odule pool SAP,)0,OE-(ANSAC-ION L
Lf L
Lf---------------------------------------------------------------L
Lf L
Lf &ispla$ &ata of Table SP,.* L
Lf L
Lf---------------------------------------------------------------L
L (lobal data
*NC.)&0 mdemoStransactiontop!
L PA* modules
*NC.)&0 mdemoStransactioniF1!
L PB1 modules
*NC.)&0 mdemoStransactionoF1!
*n the current e/ample program# the resoled include programs loo- li-e this+
Lf---------------------------------------------------------------L
Lf 'odule pool SAP'&0'1ST%ANSACT*1N L
Lf ,)NCT*1N+ &ispla$ &ata of Table SP,.* L
Lf L
Lf---------------------------------------------------------------L
L----------------------------------------------------------------L
L *NC.)&0 '&0'1ST%ANSACT*1NT1P (This is the T1P include+ L
L the T1P module contains global data declarations) L
ABAP Programming (BC-ABA) :F?
L----------------------------------------------------------------L
P%1(%A' sapmdemoStransaction!
TAB.0S+ spfli!
&ATA o-Scode(>)!
L----------------------------------------------------------------L
L *NC.)&0 '&0'1ST%ANSACT*1N1F1 (This is a PB1 include!) L
L----------------------------------------------------------------L
Lf---------------------------------------------------------------L
Lf 'odule STAT)SSF1FF
Lf---------------------------------------------------------------L
L Specif$ ()* status and title for screen 1FF L
L----------------------------------------------------------------L
'1&).0 statusSF1FF!
S0T P,-STAT)S JTTF1FF=!
S0T T*T.0BA% J1FF=!
0N&'1&).0!
L----------------------------------------------------------------L
L *NC.)&0 '&0'1ST%ANSACT*1N*F1 (This is a PA* include!) L
L----------------------------------------------------------------L
Lf---------------------------------------------------------------L
Lf 'odule )S0%SC1''AN&SF1FF *NP)T
Lf---------------------------------------------------------------L
L (et data from SP,.* or leae transaction L
L----------------------------------------------------------------L
'1&).0 )S0%SC1''AN&SF1FF!*NP)T!
CAS0 o-Scode!
W60N JS61W=!
C.0A% o-Scode!
S0.0CT S*N(.0 L ,%1' spfli W60%0 carrid H spfli-carrid
AN& connid H spfli-connid!
W60N space!
W60N 1T60%S!
C.0A% o-Scode!
S0T SC%00N F! .0AA0 SC%00N!
0N&CAS0!
0N&'1&).0!
*n the include program mdemoStransactiontop# the -AB0Sstatement creates a table "or- area
for the database table SP,.*! The table "or- area seres as an interface for passing data
bet"een the screen and the ABAP program# since the input;output fields on the screen "ere
created "ith the same ABAP &ictionar$ reference! The o*Ecodefield is used to receie function
codes from the identicall$-named screen field!
*n the include program mdemoStransactionoF1# the PB1 module for screen 1FF sets the dialog
status STAT)SSF1FF and the ()* title 1FF! This ()* status and title appl$ to all subse8uent
screens until $ou set ne" ones! *t is important that $ou set a dialog status# since the s$stem
other"ise uses an empt$ dialog status that does not allo" the user to leae the program!
*n the include program mdemoStransactioniF1# the PA* module )S0%SC1''AN&SF1FF chec-s
"hich pushbutton the user chose (CAS0 o-Scode)! The &ispla$ pushbutton has the function code
JS61W=! *f the user chooses this function# the program reads the entries from database table
SP,.* that correspond to the details entered b$ the user! *n the W+0(0 condition of the
S00C- statement# the s$stem compares the fields SP,.*-CA%%*& and SP,.*-C1NN*& (filled in
on the screen b$ the user) "ith the -e$ fields CA%%*& and C1NN*& of database table SP,.*!
Before the screen is ne/t displa$ed# the data from the table "or- area is passed to the
corresponding screen fields# and therefore appears on the screen!
/.I Status and /.I -itle
The ()* status and ()* title are interface elements of screens! 3ou create both of them using
the 'enu Painter in the ABAP Wor-bench! 1n screens# ()* statuses of t$pe dialog status are
used!
ABAP Programming (BC-ABA) :F@
A dialog status is a collection of interactie interface elements for a screen! To appl$ such a set
of elements to a screen# $ou use the ABAP statement S0- P2-S-A-.S to lin- the dialog status
to the screen! The dialog status for a screen of a transaction t$picall$ contains all elements it
supports+ menu bar# standard toolbar# application toolbar# and -e$ assignment! 0ach of these
functions send a function code to the PA* modules of the current screen "hen the user chooses
them b$ choosing a menu entr$# pushbutton# or function -e$! There are also more special ()*
statuses called (status for) dialog "indo"s and conte/t menus! The$ contain# adapted to the
special purpose# fe"er elements! A status for a dialog "indo" has no menu bar and no standard
toolbar! A conte/t menu is an indiidual conte/t-dependent menu# "hich can be actiated b$
using the right mouse -e$ (S6*,T ,1F)!
The ()* title is the screen title displa$ed in the title bar of the "indo"! The ()* title is not
combine "ith the other )* elements under a ()* status! 0er$ ()* title must be set e/plicitl$
using the ABAP statement S0- -I-0BA(!
Interaction &etween Screens and ABAP Programs
*n its most simple form# a transaction is a collection of screens and ABAP routines# controlled and
e/ecuted b$ the runtime enironment! The runtime enironment processes the screens in
se8uence# and calls the corresponding ABAP processing modules!
The runtime enironment comprises the screen processor and ABAP processor (see Wor-
Processes)! ,or each screen# the screen processor e/ecutes the flo" logic# from "hich the
corresponding ABAP processing is called! The control alternates bet"een the screen processor
and ABAP processor# and the flo" of the application program changes accordingl$ bet"een screen
flo" logic and ABAP processing logic! *n the same "a$ that "e tal- about eents in ABAP
programs# "e can also distinguish t"o eents in screen processing - PB1 and PA*! The runtime
enironment (screen processor in this case)# triggers the eents (for e/ample# PA* after a user
action on the screen)!
The se8uence of eents for Transaction &0'1ST%ANSACT*1N# for e/ample# loo-s li-e this+
ABAP Programming (BC-ABA) :FB
!!!
1! *n the screen eent PB1# the statement ,O).0 S-A-.SE@8@@ calls the corresponding
dialog module and passes control to the ABAP processor!
4! After processing the module S-A-.SE@8@@# control returns to the flo" logic! The screen
processor displa$s the screen!
:! The PA* eent is triggered b$ a user action on the screen! The statement ,O).0
.S0(ECO,,AN)E@8@@ calls the corresponding dialog module and passes control to the ABAP
processor!
>! After processing the module .S0(ECO,,AN)E@8@@# control returns to the screen
processor! Since the screen has the static ne/t screen 1FF (defined in the screen attributes)#
the program flo" begins again at step 1!
0ach time control passes bet"een the t"o processors# the s$stem transfers data bet"een
identicall$-named fields in the program and screen! When control passes from the flo" logic to
the processing logic# the glo&al ABAP ariables are filled "ith the contents of an$ identicall$-
named screen fields! &ata is transferred in the opposite direction "hen control passes from the
processing logic bac- to the flo" logic! 0ach screen has a field "ith t$pe 1U that contains the
function code of the action that the user chose! To read this alue in $our ABAP programs# $ou
need a glo&al field "ith the same name in $our ABAP program!
Calling -ransactions
*f a program has a transaction code# there are t"o "a$s of starting it from another program!
*f $ou do not "ant to return to the calling program at the end of the ne" transaction# use the
statement+
.0AA0 T1 T%ANSACT*1N tcod XAN& SU*P ,*%ST SC%00NY!
This statement ends the calling program and starts transaction tcod! This deletes the call stac-
(internal sessions) of all preious programs! At the end of the transaction# the s$stem returns to
the area menu from "hich the original program in the call stac- "as started!
*f# on the other hand# $ou do not "ant to return to the calling program at the end of the ne"
transaction# use the statement+
CA.. T%ANSACT*1N tcod XAN& SU*P ,*%ST SC%00NY X)S*N( itabY!
This statement saes the data of the calling program# and starts transaction tcod! At the end of
the transaction# the s$stem returns to the statement follo"ing the call in the calling report! *f
the 0A!0statement occurs "ithin the called transaction# the transaction ends and control
returns to the program in "hich the call occurred!
3ou can use a ariable to specif$ the transaction tcod ! This allo"s $ou to call transactions
staticall$ as "ell as d$namicall$!
The addition AN) S"IP 2I(S- SC(00N allo"s $ou to preent the initial screen of the ne"
transaction from being displa$ed! The first screen to be displa$ed is then the specified Ne/t
screen in the screen attributes of the initial screen! *f the first screen calls itself as the ne/t
screen# $ou cannot s-ip it!
ABAP Programming (BC-ABA) :FD
,urthermore# the AN) S"IP 2I(S- SC(00N option "or-s onl$ if all mandator$ fields on the
initial screen of the ne" transaction are filled completel$ and correctl$ "ith input alues from
SPA;(PA parameters!
The .SIN/ I-AB addition in the CA -(ANSAC-ION statement allo"s $ou to pass an internal
table ita& to the ne" transaction! ita& has the format of a batch input table! ,or further
information about batch input tables# refer to *mporting &ata With Batch *nput!
Calling Screen Se1uences as ,odules
*f $ou "ant to encapsulate a screen se8uence "ith all of its flo" logic and application logic# $ou
must ensure that all of the screens in the se8uence are lin-ed to a single ABAP program! The
ABAP program contains all of the dialog modules called b$ the screens in the se8uence!
*t is not currentl$ possible to assign screens to a single procedure (subroutine# function module#
or method) [ these belong instead to the main program of the procedure!
When $ou call a ne" main program in order to use a screen se8uence (for e/ample# using CA
-(ANSAC-ION)# a ne" SAP .)W begins! This ma$ be an undesired effect# especiall$ "hen $ou
are tr$ing to modulari9e a transaction that updates the database!
An alternatie to this is to use an e5ternal procedure# "hose main program is lin-ed to a screen
se8uence# and "hich contains the corresponding dialog modules! Procedures run in the same SAP
.)W and internal session as their calling program!
.sing 2unction ,odules
,unction modules and their function groups are often used to define and call screen se8uences
that $ou "ant to run in the same SAP .)W as their calling program!
To encapsulate a screen se8uence in a function module# $ou use the CA SC(00N statement in
the function module source code! The called screen and all of its subse8uent screens belong to
the function group to "hich the function module belongs! The dialog modules that $ou call from
the screen flo" logic are defined in the main program of the function module! The ,unction
Builder assists $ou in defining dialog modules b$ automaticall$ creating the appropriate include
programs!
A function group li-e the one aboe contains onl$ one function module and one screen se8uence!
6o"eer# $ou can also hae seeral function modules "ith seeral independent screen se8uences in
the same function group!
.sing )ialog ,odules
&ialog modules "ere the predecessors of function modules! The$ are no" obsolete# and $ou should
no longer create ne" ones! 6o"eer# for the sa-e of completeness# this section contains a brief
description of their structure and function!
ABAP Programming (BC-ABA) :FE
&ialog modules are ob2ects that# li-e transaction codes# are lin-ed to a screen se8uence in an
ABAP program b$ means of an initial screen! When $ou call a dialog module# the s$stem calls the
corresponding ABAP program and the initial screen of the dialog module! &ialog modules can also
hae an interface! Before $ou can do this# $ou must hae declared the parameters as glo&al data
in the ABAP program! &ialog modules are created and administered in the ABAP Wor-bench using
a tool (Transaction S0:?) similar to the ,unction Builder! 3ou can assign more than one dialog
module to the same ABAP program!

3ou call dialog modules using the CA )IAO/ statement+
CA.. &*A.1( dialog
XAN& SU*P ,*%ST SC%00NY
X0_P1%T*N( f
1
,%1' a
1
!!! f
n
,%1' a
n
Y
X*'P1%T*N( f
1
T1 a
1
!!! f
n
T1 a
n
Y
X)S*N( itabY!
CA )IAO/ has the same s$nta/ as CA -(ANSAC-ION! 3ou can also pass alues to the
global data of the called program using the interface!
Although a dialog module occupies a ne" internal session# it runs in t$e same SAP .W as the
calling program! 6o"eer# since the$ open a ne" session# the$ are less efficient than function
modules in performance terms! Neertheless# the$ are the onl$ means of s"itching internal
session "ithout starting a ne" SAP .)W! 3ou can onl$ run an entire transaction "ithin the SAP
.)W of a calling program b$ lin-ing the initial screen of the transaction "ith a dialog module!
*f $ou "ant to run screen se8uences and dialog modules in the SAP .)W of the calling program
and as a transaction in their o"n SAP .)W# $ou must ensure that all database update tas-s can
be e/ecuted "ithout compromising data integrit$! The follo"ing special conditions appl$+
7 &ialog modules inherit loc-s set b$ the calling program!
*f the screen se8uence is called as a dialog module# the s$stem assumes that a loc- for a
particular ob2ect alread$ e/ists! When $ou start the screen se8uence as a transaction# $ou
must set $our o"n loc-s! To find out at runtime if a program is running as a called program#
use the s$stem ariable s%-calld!
7 &ialog modules inherit update -e$s from the calling program!
7 When the screen se8uence is running as a dialog module# the s$stem partl$ ignores
CO,,I- and (OBAC" WO(" statements!
*n the called program# the statements CO,,I- WO(" and (OBAC" WO(" lead to
database commits or database rollbac-s! 6o"eer# procedures registered "ith CA
ABAP Programming (BC-ABA) :1F
2.NC-ION IN .P)A-0 -AS" and P0(2O(, ON PCO,,I-O(OBAC"Q are not e/ecuted
till the corresponding statements in the calling program!
7 )pdate function modules called using the IN .P)A-0 -AS" addition are not started if
the screen se8uence is running as a dialog module!
3ou must ensure that an$ such function modules can be dela$ed until the ne/t CO,,I-
WO(" in the calling program!
7 P0(2O(, ON CO,,I- routines are not e/ecuted in the dialog module!
3ou must ensure that an$ such function modules can be dela$ed until the ne/t CO,,I-
WO(" in the calling program! %emember that the global data of the dialog module is
destro$ed along "ith the internal session "hen control returns to the calling program!
Conse8uentl$# subroutines called using P0(2O(, ON CO,,I- must not use this global data!
7 *f $ou "ant to run the screen se8uence as a transaction# $ou must ensure that the input
parameters of the interface contain reasonable default alues!
Passing )ata Between Programs
There are t"o "a$s of passing data to a called program+
Passing )ata .sing Internal ,emor% Areas
ABAP programs hae access to t"o cross-program memor$ areas that can be used for passing
data!
SAP ,emor%
SAP memor$ is a memor$ area to "hich all main sessions "ithin a SAPgui hae access! 3ou can use
SAP memor$ either to pass data from one program to another "ithin a session# or to pass data
from one session to another! Application programs that use SAP memor$ must do so using
SPA;(PA parameters (also -no"n as S0T;(0T parameters)! These parameters can be set either
for a particular user or for a particular program at the time of logon using the S0- PA(A,0-0(
statement! 1ther ABAP programs can then retriee the set parameters using the /0-
PA(A,0-0( statement! The most fre8uent use of SPA;(PA parameters is to fill input fields on
screens (see belo")!
ABAP ,emor%
ABAP memor$ is a memor$ area that all ABAP programs "ithin the same internal session can
access using the 0XPO(- and I,PO(- statements! &ata "ithin this memor$ area remains
throughout a se8uence of program calls# "ith the e/ception of 0A!0 -O -(ANSAC-ION! To
pass data to a program that $ou are calling# the data needs to be placed in ABAP memor$ before
the call is made from the internal calling session using the 0XPO(- statement! The internal
session of the called program then replaces that of the calling program! The program called can
then read from the ABAP memor$ using the I,PO(- statement! *f control is then returned to
the program that made the initial call# the same procedure operates in reerse (see also Storage
'edia for &ata Cluster)! *f a transaction is called using 0A!0 -O -(ANSAC-ION# the ABAP
memor$ and the call stac- are deleted! The$ cannot be used for data transfer!
Since ob2ects belonging to ABAP ob2ects can onl$ be accessed "ithin an internal session# it does
not ma-e sense and is therefore forbidden (from a s$nta/ point of ie") to pass a reference to
an ob2ect to a calling program through the ABAP memor$!
2illing Input 2ields on an Initial Screen
'ost programs that $ou call from other programs hae their o"n initial screen that the user must
fill "ith alues! ,or an e/ecutable program# this is normall$ the selection screen! The S.B,I-
statement has a series of additions that $ou can use to fill the input fields of the called selection
screen+
,illing the Selection Screen of a Called Program
3ou cannot fill the input fields of a screen using additions in the calling statement! *nstead# $ou
can use SPA;(PA parameters!
,illing *nitial Screens using SPA;(PA Parameters
,odulari:ation -ec$ni1ues
All ABAP programs are modular in structure and made up of processing bloc-s (see Structure of
Processing .ogic)! There are t"o -inds of processing bloc-s# those that are called from outside a
program b$ the ABAP runtime s$stem# and those that can be called b$ ABAP statements in ABAP
programs!

Processing bloc-s that are called using the ABAP runtime s$stem+
7 0ent Bloc-s
7 &ialog 'odules
ABAP Programming (BC-ABA) :11

Processing bloc-s that are called from ABAP programs+
7 Subroutines
7 ,unction modules
7 'ethods (see ABAP 1b2ects)

The processing bloc-s that $ou call from ABAP programs are called procedures!

As "ell as modulari9ation in processing bloc-s# ABAP allo"s $ou to modulari:e source code b$
placing ABAP statements either in local macros or global include programs!

The modulari9ation of ABAP programs in eent bloc-s and dialog modules seres for general
e/ecution of ABAP programs "hile modulari9ation in procedures and source code modules seres
for improing the readabilit$ and maintainabilit$ of ABAP programs# preention of redundancies#
reusabilit$ of functions# and the encapsulation of data!
)efining Processing Bloc*s

0ent Bloc-s
&ialog 'odules
Procedures
0vent Bloc*s
0ent bloc-s are introduced b$ an event *e%word! The$ end "hen the ne/t processing bloc-
begins! The follo"ing processing bloc- can either be an eent bloc- or another processing bloc-
allo"ed in this conte/t [ for e/ample# a subroutine or a dialog module! 0ent -e$"ords hae the
same name as the eents to "hich the$ react!
0/ample for the structure of an e/ecutable program+
%0P1%T!!!
N1&0S+ spfli# sflight!
&ATA+!!!
*N*T*A.*TAT*1N!
!!!
AT S0.0CT*1N-SC%00N!
!!!
STA%T-1,-S0.0CT*1N!
!!!
(0T spfli!!!
!!
(0T sflight!!!
!!!
ABAP Programming (BC-ABA) :14
(0T spfli .AT0!
!!!
0N&-1,-S0.0CT*1N!
!!!
,1%'!!!
!!!
0N&,1%'!
The se8uence in "hich the processing bloc-s occur in the program is irreleant! The actual
processing se8uence is determined b$ the e/ternal eents! 6o"eer# to ma-e $our programs
easier to understand# $ou should include the eent bloc-s in $our program in appro/imatel$ the
same order in "hich the$ "ill be called b$ the s$stem! Subroutines should be placed at the end of
the program!
With onl$ t"o e/ceptions (A- S00C-ION-SC(00N and /0-)# eent bloc-s hae no local data
area! All declaratie statements in eent bloc-s are handled "ith the global data declarations in
the program! 3ou should therefore include all of $our declarations at the start of the program
(see also Structure of ABAP Programs)!
Statements that are not assigned to a processing bloc- are neer e/ecuted! *n e/ecutable
programs# all non-declaratie statements bet"een the (0PO(- or P(O/(A, statement and the
first processing bloc- are assigned to the default eent S-A(--O2-S00C-ION9 if a program
does not contain an e/plicit S-A(--O2-S00C-ION eent bloc-# these statements form the
entire S-A(--O2-S00C-ION bloc-! *f a program contains an e/plicitl$ defined S-A(--O2-
S00C-ION eent bloc-# these statements are inserted at the beginning of this eent bloc-! *f a
program does not contain an$ e/plicit eent bloc-s# all non-declaratie statements form the
processing bloc- S-A(--O2-S00C-ION!
%0P1%T demoEa&apEeventsE89
W%*T0 ; IStatement 1I!
,1%' routine!
W%*T0 ; ISubroutineI!
0N&,1%'!
W%*T0 ; IStatement 4I!
P0%,1%' routine!
W%*T0 ; IStatement :I!
This produces the follo"ing output+
Statement 1
1nl$ the eent bloc- S-A(--O2-S00C-ION is started in this program! This bloc- consists of
the first W(I-0 statement!
No" "e insert a S-A(--O2-S00C-ION statement in the program+
%0P1%T demoEa&apEeventsEB9
W%*T0 ; IStatement 1I!
,1%' routine!
W%*T0 ; ISubroutineI!
0N&,1%'!
STA%T-1,-S0.0CT*1N!
W%*T0 ; IStatement 4I!
P0%,1%' routine!
W%*T0 ; IStatement :I!
The output is no" as follo"s+
Statement 1
Statement 4
Subroutine
Statement :
*n this program# the S-A(--O2-S00C-ION processing bloc- consists of all statements e/cept
the 2O(, [ 0N)2O(, bloc-! A more readable form of the same program "ould loo- li-e this+
%0P1%T demoEa&apEeventsEC9
STA%T-1,-S0.0CT*1N!
W%*T0 ; IStatement 1I!
W%*T0 ; IStatement 4I!
ABAP Programming (BC-ABA) :1:
P0%,1%' routine!
W%*T0 ; IStatement :I!
,1%' routine!
W%*T0 ; ISubroutineI!
0N&,1%'!
*n this case# $ou could also omit the eent -e$"ord S-A(--O2-S00C-ION!
)ialog ,odules
&ialog modules are defined using the follo"ing pair of statements+
'1&).0 mod 1)TP)TZX*NP)TY!
!!!
0N&'1&).0
The O.-P.- addition defines the dialog module mod as one that ma$ be called from the PB1
eent of the flo" logic of an$ screen!
The INP.- addition defines the dialog module mod as one that ma$ be called from the PA* eent
of the flo" logic of an$ screen! INP.-is the standard addition! *t ma$ be omitted!
3ou can define t"o dialog modules# both called mod# in the same program as long as one of them
has the addition O.-P.- and the other has the addition INP.-!
&ialog modules do not $ave local data areas! All declaratie statements in dialog modules are
handled "ith the global data declarations in the program! 3ou should therefore include all of $our
declarations at the start of the program (see also Structure of ABAP Programs)!
Procedures
Procedures contain a set of statements# and are called from other ABAP programs!
3ou define procedures in ABAP programs! When the program is generated# the$ remain as
standalone modules! 3ou can call procedures in the program in "hich the$ are defined# or from
e/ternal programs! Procedures hae an interface for passing data# and can also contain local data!
ABAP contains the follo"ing -inds of procedures+
7 Subroutines
Subroutines are principall$ for local modulari9ation# that is# the$ are generall$ called from the
program in "hich the$ are defined! 3ou can use subroutines to "rite functions that are used
repeatedl$ "ithin a program! 3ou can define subroutines in an$ ABAP program!
7 ,unction 'odules
,unction modules are for glo&al modulari9ation# that is# the$ are al"a$s called from a
different program! ,unction modules contain functions that are used in the same form b$
man$ different programs! ,unction modules pla$ an important roll in encapsulating processing
logic and ma-ing it reusable! ,unction modules must be defined in a function group# and can be
called from an$ program!
7 'ethods
Contain the functions of classes and their instances in ABAP 1b2ects! 'ethods must be
defined in classes! When $ou call them# $ou must obsere certain special rules of ob2ect-
oriented programming!
)efining Su&routines
A subroutine is a bloc- of code introduced b$ 2O(, and concluded b$ 0N)2O(,!
,1%' subr X)S*N( p1 T3P0 t$pe
p4 .*U0 field
!!!
AA.)0(p:) T3P0 t$pe
AA.)0(p>) .*U0 field
ABAP Programming (BC-ABA) :1>
!!! Y
XC6AN(*N( b bAA.)0(p1)cZbp1 XbT3P0 t$pecZb.*U0 fieldcYc
bAA.)0(p4)cZbp4 XbT3P0 t$pecZb.*U0 fieldcYc
!!! c Y
!!!
0N&,1%'!
su&r is the name of the subroutine! The optional additions .SIN/ and C+AN/IN/ define the
parameter interface! .i-e an$ other processing bloc-# subroutines cannot be nested! 3ou should
therefore place $our subroutine definitions at the end of the program# especiall$ for e/ecutable
programs! *n this "a$# $ou eliminate the ris- of non-e/ecutable statements occurring b$ mista-e
through a subroutine closing an eent bloc- at the "rong place!
)ata +andling in Su&routines
(lobal &ata from the 'ain Program
.ocal &ata in the Subroutine
The Parameter *nterface
/lo&al )ata from t$e 2ramewor* Program
Subroutines can access all of the global data in the program in "hich the$ are defined (main
program)! 3ou therefore do not need to define a parameter interface if $ou do not "ant to
change an$ data in the subroutine# or if er$ little data is inoled!
,1%' header!
W%*T0+ ; IProgram started b$I# s$-uname#
; Ion hostI# s$-host#
Idate+I# s$-datum# Itime+I# s$-u9eit!
).*N0!
0N&,1%'!
This e/ample creates a subroutine called $eader# "hich# li-e the e/ample of an include program#
displa$s a list header!
6o"eer# if $ou "ant subroutines to perform comple/ operations on data "ithout affecting the
global data in the program# $ou should define a parameter interface through "hich $ou can pass
e/actl$ the data $ou need! *n the interests of good programming st$le and encapsulation# $ou
should alwa%s use a parameter interface# at least "hen the subroutine changes data!
Protecting /lo&al )ata O&3ects Against C$anges
To preent the alue of a global data ob2ect from being changed inside a subroutine# use the
follo"ing statement+
.1CA. f!
This statement ma$ onl$ occur bet"een the 2O(, and 0N)2O(,statements! With OCA# $ou
can presere the alues of global data ob2ects "hich cannot be hidden b$ a data declaration inside
the subroutine!
,or e/ample# $ou cannot declare a table "or- area that is defined b$ the -AB0S statement "ith
another -AB0Sstatement inside a subroutine! *f $ou "ant to use the table "or- area locall$# but
presere its contents outside the subroutine# $ou must use the OCAstatement!
(0PO(- demoEmodEtec$Elocal9
-AB0S sflig$t9
P0(2O(, ta&test89
W(I-0= A sflig$t-planet%pe4 sflig$t-price currenc% sflig$t-currenc%9
P0(2O(, ta&testB9
W(I-0= A sflig$t-planet%pe4 sflig$t-price currenc% sflig$t-currenc%9
2O(, ta&test89
sflig$t-planet%pe F ?AC8@?9
sflig$t-price F ?8G@9@@?9
W(I-0= A sflig$t-planet%pe4 sflig$t-price currenc% sflig$t-currenc%9
0N)2O(,9
2O(, ta&testB9
OCA sflig$t9
sflig$t-planet%pe F ?BIDI?9
sflig$t-price F ?G@@9@@?9
ABAP Programming (BC-ABA) :1?
W(I-0= A sflig$t-planet%pe4 sflig$t-price currenc% sflig$t-currenc%9
0N)2O(,9
When $ou run the program# the follo"ing is displa$ed+
A:1F 1?F!FF
A:1F 1?F!FF
BB>B ?FF!FF
A:1F 1?F!FF
*n this e/ample# the program creates a table "or- area sflig$t for the database table sflig$t!
&ifferent alues are assigned to the table "or- area sflig$t in ta&test8 and ta&testB! While the
alues assigned in ta&test8 are alid globall$# the alues assigned in ta&testB are onl$ alid locall$!
ocal )ata in t$e Su&routine
&ata declarations in procedures create local data t$pes and ob2ects that are onl$ isible "ithin
that procedure! There are t"o -inds of data t$pes and ob2ects [ d$namic and static! &$namic data
ob2ects onl$ e/ist "hile the subroutine is running# "hile static ob2ects still e/ist after the
subroutine has finished running# and retain their alues until the ne/t time the subroutine is
called! ,ield s$mbols can be declared locall$! 3ou can also use a special -ind of data ob2ect for
subroutines [ copies of global data on a local data stac-! 3ou define and address them using field
s$mbols!
)%namic ocal )ata -%pes and O&3ects
.ocal data t$pes and ob2ects declared in subroutines using the -7P0S and )A-Astatements are
deleted "hen the subroutine ends# and recreated each time the routine is called!
0er$ subroutine has its o"n local namespace! *f $ou declare a local data t$pe or ob2ect "ith the
same name as a global data t$pe or ob2ect# the global t$pe or ob2ect cannot be addressed from
"ithin the subroutine! .ocal data t$pes or data ob2ects hide identicall$ named global data t$pes
or ob2ects! This means that if $ou use the name of a data t$pe or ob2ect in the subroutine# $ou
al"a$s address a locall$ declared ob2ect [ if this e/ists [ and other"ise a globall$ declared one!
To preent global data t$pes or ob2ects from being hidden# local t$pes and ob2ects must hae
other names assigned to them! ,or e/ample# all local names in subroutines could begin "ith J, S=!
(0PO(- demoEmodEtec$EdataEt%pes 9
-7P0S word(8@) -7P0 c9
)A-A te5t -7P0 word9
te5t F ?8BCDGHIJK@?9 W(I-0 A te5t9
P0(2O(, datatest9
W(I-0 A te5t9
2O(, datatest9
-7P0S word(G) -7P0 c9
)A-A te5t -7P0 word9
te5t F ?ABC)02/+Y"?9 W(I-0 A te5t9
0N)2O(,9
When $ou run the program# the follo"ing is displa$ed+
14:>?@BDEF
ABC&0
14:>?@BDEF
*n this e/ample# a data t$pe word and a global data ob2ect te5t "ith t$pe word are declared
globall$ in the main program! After a alue has been assigned to te5t and this has been displa$ed
on the list# the internal subroutine datatest is called! *nside the subroutine# a data t$pe word and
a local data ob2ect te5t "ith t$pe word are declared locall$! The$ hide the global t$pe and ob2ect!
1nl$ after the subroutine is finished are the global definitions are alid again!
Static ocal )ata O&3ects
*f $ou "ant to -eep the alue of a local data ob2ect after e/iting the subroutine# $ou must use
the S-A-ICS statement to declare it instead of the )A-A statement! With S-A-ICS $ou
declare a data ob2ect that is globall$ defined# but onl$ locall$ isible from the subroutine in "hich
it is defined!
(0PO(- demoEmodEtec$Estatics9
P0(2O(, datatest89
P0(2O(, datatest89
ABAP Programming (BC-ABA) :1@
S"IP9
P0(2O(, datatestB9
P0(2O(, datatestB9
2O(, datatest89
-7P0S fEword(G) -7P0 c9
)A-A fEte5t -7P0 fEword !A.0 ?INI-?9
W(I-0 fEte5t9
fEte5t F ?8BCDG?9
W(I-0 fEte5t9
0N)2O(,9
2O(, datatestB9
-7P0S fEword(G) -7P0 c9
S-A-ICS fEte5t -7P0 fEword !A.0 ?INI-?9
W(I-0 fEte5t9
fEte5t F ?ABC)0?9
W(I-0 fEte5t9
0N)2O(,9
When $ou run the program# the follo"ing is displa$ed+
*N*T 14:>? *N*T 14:>?
*N*T ABC&0 ABC&0 ABC&0
*n this e/ample# t"o similar subroutines datatest8 and datatestB are defined! *n datatestB # the
S-A-ICSstatement is used instead of the )A-A statement to declare the data ob2ect fEte5t!
&uring each call of datatest8# fEte5t is initiali9ed again# but it -eeps its alue for datatestB! The
!A.0 addition of the S-A-ICSstatement functions onl$ during the first call of datatestB!
ocal 2ield S%m&ols
All field s$mbols declared in a subroutine using the ,*0.&-S3'B1.S statement are local! ,or
local field s$mbols# the follo"ing rules appl$+
7 3ou cannot address local field s$mbols outside the subroutine!
7 When $ou call the subroutine# no field is assigned to a local field s$mbol [ not een if an
ASSI/N "as e/ecuted in the last run!
7 .ocal field s$mbols can hae the same names as global field s$mbols! *f the$ do# the$ hide
the global field s$mbols "ithin the subroutine!
7 3ou can also declare structured field s$mbols locall$! The$ can hae local structures and
$ou can assign local fields to them!
ocal Copies of /lo&al 2ields
*n a subroutine# $ou can create local copies of global data on the local stac-! To do this# use a
local field s%m&ol and the follo"ing ariant of the ASSI/N statement+
ASS*(N .1CA. C1P3 1, field T1 ]fsG!
The s$stem places a cop$ of the specified global field field on the stac-! *n the subroutine# $ou
can access and change this cop$ "ithout changing the global data b$ addressing the field s$mbol
]fsG!
3ou can use the .1CA. C1P3 1,addition "ith all ariants of the ASS*(N statement# e/cept
ASS*(N C1'P1N0NT!
1ther ariants of the ASS*(N statement that are used in subroutines are+
ASS*(N .1CA. C1P3 1, *N*T*A. field T1 ]fsG!
This statement creates an initiali9ed cop$ of the global field field on the stac- "ithout
transporting the field contents!
ASS*(N .1CA. C1P3 1, *N*T*A. .*N0 1, itab T1 ]fsG!
This statement creates an initial cop$ of the lines of a global internal table ita& on the stac-!
ASS*(N .1CA. C1P3 1, *N*T*A. .*N0 1, (field) T1 ]fsG!
This statement creates an initial cop$ of the lines of a global internal table ita& on the stac-! The
internal table is specified d$namicall$ as the contents of the field field!
(0PO(- demoEmodEtec$EassignElocalEcop9
)A-A te5t(G) -7P0 c !A.0 ?-e5t8?9
P0(2O(, routine9
W(I-0 te5t9
ABAP Programming (BC-ABA) :1B
2O(, routine9
2I0)-S7,BOS VfsN -7P0 AN79
ASSI/N OCA COP7 O2 te5t -O VfsN9
W(I-0 VfsN9
VfsN F ?-e5tB?9
W(I-0 VfsN9
ASSI/N te5t -O VfsN9
W(I-0 VfsN9
VfsN F ?-e5tC?9
0N)2O(,9
The list output is+
Te/t1 Te/t4 Te/t1 Te/t:
B$ assigning the field te5t to the local subroutine ]fsG in the subroutine routine# $ou place a cop$
of te5t on the local data stac-! B$ addressing ]fsG# $ou can read and change this cop$! The global
field te5t is not affected b$ operations on the local cop$! After $ou hae assigned the field to
the field s$mbol "ithout the OCA COP7 O2 addition# the field s$mbol points directl$ to the
global field! 1perations "ith the field s$mbol then affect the global field!
-$e Parameter Interface
The .SIN/ and C+AN/IN/ additions in the 2O(,statement define the formal parameters of a
subroutine! The se8uence of the additions is fi/ed! 0ach addition can be follo"ed b$ a list of an$
number of formal parameters! When $ou call a subroutine# $ou must fill all formal parameters
"ith the alues from the actual parameters! At the end of the subroutine# the formal parameters
are passed bac- to the corresponding actual parameters!
Within a subroutine# formal parameters behae li-e d$namic local data! 3ou can use them in the
same "a$ as normal local data ob2ects that $ou "ould declare "ith the )A-A statement! The$
mas- global data ob2ects "ith the same name! The alue of the parameters at the start of the
subroutine is the alue passed from the corresponding actual parameter!
Subroutines can hae the follo"ing formal parameters+
Parameters Passed &% (eference
3ou list these parameters after .SIN/ or C+AN/IN/ "ithout the !A.0addition+
,1%' subr )S*N( p1 XbT3P0 t$pecZb.*U0 fieldcY
p4 XbT3P0 t$pecZb.*U0 fieldcY
!!!
C6AN(*N( p1 XbT3P0 t$pecZb.*U0 fieldcY
p4 XbT3P0 t$pecZb.*U0 fieldcY
!!!
The formal parameter has no memor$ of its o"n! &uring a subroutine call# onl$ the address of the
actual parameter is transferred to the formal parameter! The subroutine "or-s "ith the field
from the calling program! *f the alue of the formal parameter changes# the contents of the
actual parameter in the calling program also change!
,or calling b$ reference# .SIN/ and C+AN/IN/ are e8uialent! ,or documentation purposes# $ou
should use .SIN/ for input parameters "hich are not changed in the subroutine# and C+AN/IN/
for output parameters "hich are changed in the subroutine!
To aoid the alue of an actual parameter being changed automaticall$# $ou must pass it b$ alue!
Input Parameters -$at Pass !alues
3ou list these parameters after .SIN/ "ith the !A.0addition+
,1%' subr )S*N( AA.)0(p1) XbT3P0 t$pecZb.*U0 fieldcY
AA.)0(p4) XbT3P0 t$pecZb.*U0 fieldcY
!!!
The formal parameter occupies its o"n memor$ space! When $ou call the subroutine# the alue of
the actual parameter is passed to the formal parameter! *f the alue of the formal parameter
changes# this has no effect on the actual parameter!
Output Parameters -$at Pass !alues
3ou list these parameters after C+AN/IN/ "ith the !A.0addition+
,1%' subr C6AN(*N( AA.)0(p1) XbT3P0 t$pecZb.*U0 fieldcY
AA.)0(p4) XbT3P0 t$pecZb.*U0 fieldcY
!!!
The formal parameter occupies its o"n memor$ space! When $ou call the subroutine# the alue of
the actual parameter is passed to the formal parameter! *f the subroutine concludes
ABAP Programming (BC-ABA) :1D
successfull$# that is# "hen the 0N)2O(, statement occurs# or "hen the subroutine is
terminated through a C+0C" or 0XI-statement# the current alue of the formal parameter is
copied into the actual parameter!
*f the subroutine terminates prematurel$ due to an error message# no alue is passed! *t onl$
ma-es sense to terminate a subroutine through an error message in the PA* processing of a
screen# that is# in a PA* module# in the A- S00C-ION-SC(00N eent# or after an interactie
list eent!
Specif%ing t$e -%pe of 2ormal Parameters
,ormal parameters can hae an$ alid ABAP data t$pe! 3ou can specif$ the t$pe of a formal
parameter using the -7P0 or I"0addition! 3ou can specif$ the t$pe either genericall$ or in full!
*f $ou specif$ a generic t$pe# the t$pe of the formal parameter is either partiall$ specified or
not specified at all! An$ attributes that are not specified are inherited from the corresponding
actual parameter "hen the subroutine is called! *f $ou specif$ the t$pe full$# all of the technical
attributes of the formal parameter are defined "ith the subroutine definition!
The follo"ing remar-s about specif$ing the t$pes of parameters also appl$ to the parameters of
other procedures (function modules and methods)!
*f $ou hae specified the t$pe of the formal parameters# the s$stem chec-s that the
corresponding actual parameters are compatible "hen the subroutine is called! ,or internal
subroutines# the s$stem chec-s this in the s$nta/ chec-! ,or e/ternal subroutines# the chec-
cannot occur until runtime!
B$ specif$ing the t$pe# $ou ensure that a subroutine al"a$s "or-s "ith the correct data t$pe!
(eneric formal parameters allo" a large degree of freedom "hen $ou call subroutines# since $ou
can pass data of an$ t$pe! This restricts accordingl$ the options for processing data in the
subroutine# since the operations must be alid for all data t$pes! ,or e/ample# assigning one data
ob2ect to another ma$ not een be possible for all data t$pes! *f $ou specif$ the t$pes of
subroutine parameters# $ou can perform a much "ider range of operations# since onl$ the data
appropriate to those operations can be passed in the call! *f $ou "ant to process structured data
ob2ects component b$ component in a subroutine# $ou must specif$ the t$pe of the parameter!
3ou can specif$ the t$pe of formal parameters either genericall$ or in full!

/eneric -%pe Specification
When the t$pe is specified genericall$# one of the generic data t$pes listed in the -e$"ord
documentation# such as an%# c# numeric# or inde5 ta&le# is specified! The actual parameter need
onl$ hae the selection of attributes possessed b$ the formal parameter! The formal parameter
adopts its remaining unnamed attributes from the actual parameter!
Note that formal parameters inherit the attributes of their corresponding actual parameters
d$namicall$ at runtime# and so the$ cannot be identified in the program code! ,or e/ample# $ou
cannot address an inherited table -e$ staticall$ in a subroutine# but $ou probabl$ can d$namicall$!
-7P0S= B0/IN O2 line4
col8(8) -7P0 c4
colB(8) -7P0 c4
0N) O2 line9
)A-A= wa -7P0 line4
ita& -7P0 +AS+0) -AB0 O2 line WI-+ .NIW.0 "07 col84
*e%(D) -7P0 c !A.0 ?col8?9
wa-col8 F ?X?9 INS0(- wa IN-O -AB0 ita&9
wa-col8 F ?7?9 INS0(- wa IN-O -AB0 ita&9
P0(2O(, demo .SIN/ ita&9
2O(, demo .SIN/ p -7P0 AN7 -AB09
999
(0A) -AB0 p WI-+ -AB0 "07 (*e%) F ?X? IN-O wa9
999
0N)2O(,9
The table -e$ is addressed d$namicall$ in the subroutine! 6o"eer# the static address
(0A) -AB0 p WI-+ -AB0 "07 col8 F ?X? IN-O wa9
is s$ntacticall$ incorrect# since the formal parameter P does not adopt the -e$ of table ita& until
runtime!
ABAP Programming (BC-ABA) :1E
Specif%ing t$e -%pe 2ull%
When $ou use the follo"ing t$pe assignments# the technical attributes of the formal parameters
are full$ specified! After -7P0# $ou can specif$ an$ non-generic data t$pe from the ABAP
&ictionar$# a non-generic local t$pe alread$ defined "ith -7P0S# or a non-generic built-in ABAP
t$pe (d# f# i# string# t# 5string) When $ou specif$ a preiousl$ declared data ob2ect do&3 after
I"0# $ou are also specif$ing the t$pe in full!
The technical attributes of the actual parameter must match the attributes of the formal
parameter!
When $ou use a formal parameter that is full$ t$ped# $ou can address its attributes staticall$ in
the program# since the$ are recogni9ed in the source code!
Structured 2ormal Parameters
Since formal parameters can ta-e an$ alid ABAP data t$pe# the$ can also ta-e structures and
internal tables "ith a structured line t$pe# as long as the t$pe of the formal parameter is full%
specified! 3ou can address the components of the structure staticall$ in the subroutine!
/eneric structures
*f $ou pass a structured actual parameter genericall$ to a formal parameter "hose t$pe is not
correctl$ specified# $ou cannot address the components of the structure staticall$ in the
subroutine! ,or internal tables# this means that onl$ line operations are possible!
To access the components of a genericall$ passed structure# $ou must use field s$mbols# and the
assignment
ASSI/N CO,PON0N- id5Oname O2 S-(.C-.(0 s -O VfsN9
id5 is interpreted as the component number and the contents of name are interpreted as a
component name in the generic structure s!
(0PO(- demoEmodEtec$EassignEcomponent9
)A-A= B0/IN O2 line4
col8 -7P0 c !A.0 ?X?4
colB -7P0 c !A.0 ?7?4
0N) O2 line9
)A-A comp(D) -7P0 c !A.0 ?CO8?9
P0(2O(, demo .SIN/ line9
2O(, demo .SIN/ p -7P0 an%9
2I0)-S7,BOS VfsN -7P0 AN79
ASSI/N CO,PON0N- comp O2 S-(.C-.(0 p -O VfsN9
W(I-0 VfsN9
ASSI/N CO,PON0N- B O2 S-(.C-.(0 p -O VfsN9
W(I-0 VfsN9
0N)2O(,9
The list output is+
_ 3
The components col8 and colB of the structure of p (passed genericall$) are assigned to the field
s$mbol VfsN! 3ou cannot address the components directl$ eit$er staticall% or d%namicall%!
2itting Parameters into Structures
*nstead of using -7P0 or I"0# for reasons of compatibilit$ $ou can also specif$ the t$pe of a
structure as follo"s+
!!! p
1
XST%)CT)%0 sY !!!
!!! p
4
XST%)CT)%0 sY !!!
"here s is a local structure in the program (data ob2ect# not a t$pe) or a flat structure from the
ABAP &ictionar$! The appropriate formal parameter p
1
p
4
\ is structured according to s# and $ou
can address its indiidual components in the subroutine! When the actual parameter is passed# the
s$stem onl$ chec-s to ensure that the actual parameter is at least as long as the structure!
S-(.C-.(0therefore allo"s $ou to force a structured view of an$ actual parameter!
(0PO(- demoEmodEtec$Estructure9
)A-A= B0/IN O2 line4
col8(8) -7P0 c4
colB(8) -7P0 c4
0N) O2 line9
ABAP Programming (BC-ABA) :4F
)A-A te5t(B) -7P0 c !A.0 ?X7?9
P0(2O(, demo .SIN/ te5t9
2O(, demo .SIN/ p S-(.C-.(0 te5t9
W(I-0= p-col84 p-colB9
0N)2O(,9
The list output is+
_ 3
The string te5t is fitted into the structure line!
-$e -AB0S Addition
To ensure compatibilit$ "ith preious releases# the follo"ing addition is still allo"ed before the
.SIN/ and C+AN/IN/ additions+
,1%' subr TAB.0S !!! itab
1
XT3P0 tZ.*U0 fY !!!
!!! itab
4
XT3P0 tZ.*U0 fY !!!
The formal parameters ita&
8
ita&
B
\ are defined as standard internal tables wit$ $eader lines!
*f $ou use an internal table "ithout header line as the corresponding actual parameter for a
formal parameter of this t$pe# the s$stem creates a local $eader line in the subroutine for the
formal parameter! *f $ou pass an internal table "ith a header line# the table bod$ and the table
"or- area are passed to the subroutine! ,ormal parameters defined using -AB0S cannot be
passed b$ reference! *f $ou "ant to address the components of structured lines# $ou must
specif$ the t$pe of the -AB0S parameter accordingl$!
,rom %elease :!F# $ou should use .SIN/ or C+AN/IN/ instead of the -AB0Saddition for
internal tables# although for performance reasons# $ou should not pass them b$ alue!
2unction ,odules
,unction modules are procedures that are defined in special ABAP programs onl$# so-called
function groups# but can be called from all ABAP programs! ,unction groups act as containers for
function modules that logicall$ belong together! 3ou create function groups and function modules
in the ABAP Wor-bench using the ,unction Builder!
,unction modules allo" $ou to encapsulate and reuse global functions in the SAP S$stem! The$ are
managed in a central function librar$! The SAP S$stem contains seeral predefined functions
modules that can be called from an$ ABAP program! ,unction modules also pla$ an important role
during updating and in interaction bet"een different SAP s$stems# or bet"een SAP s$stems and
remote s$stems through remote communications!
)nli-e subroutines# $ou do not define function modules in the source code of $our program!
*nstead# $ou use the ,unction Builder! The actual ABAP interface definition remains hidden
from the programmer! 3ou can define the input parameters of a function module as optional! 3ou
can also assign default alues to them! ,unction modules also support e/ception handling! This
allo"s $ou to catch certain errors "hile the function module is running! 3ou can test function
modules "ithout haing to include them in a program using the ,unction Builder!
The ,unction Builder also has a release process for function modules! This ensures that
incompatible changes cannot be made to an$ function modules that hae alread$ been released!
This applies particularl$ to the interface! Programs that use a released function module "ill not
cease to "or- if the function module is changed!
,unction (roups
Creating ,unction 'odules
2unction /roups
,unction groups are containers for function modules! 3ou cannot e/ecute a function group! When
$ou call a function module# the s$stem loads the "hole of its function group into the internal
session of the calling program (if it has not alread$ been loaded)! ,or further information# refer
to 1rgani9ation of 0/ternal Procedure Calls!
The follo"ing diagram sho"s the structure of a function group+ The name of a function group#
fgrpcan be up to 4@ characters long! This is used b$ the s$stem to create the components of the
group (main program and corresponding include programs)! When $ou create a function group or
function module in the ,unction Builder # the main program and include programs are generated
automaticall$!
ABAP Programming (BC-ABA) :41
The main program SAPfgrp contains nothing but the INC.)0 statements for the follo"ing
include programs+
7 fgrp-OP! This contains the 2.NC-ION-POO statement (e8uialent for a function group
of the (0PO(- or P(O/(A,statement) and global data declarations for the entire function
group!
7 fgrp.XX! This contains further INC.)0statements for the include programs fgrp.@8#
fgrp.@B#!!! These includes contain the actual function modules!
7 The include programs fgrp2@8# fgrp2@B#!!! can contain the coding of subroutines that can
be called "ith internal subroutine calls from all function modules of the group!
The creation of these INC.)0 programs is supported from the ABAP Wor-bench b$ for"ard
naigation (for e/ample creation of a subroutine include b$ double clic-ing on the name of a
subroutine in a P0(2O(, statement "ithin a function module)!
3ou cannot declare a CO,,ON PA(- in a function group! ,unction groups hae their o"n table
"or- areas (-AB0S)! ,unction groups encapsulate data! *n this respect# the$ are a precursor of
ABAP 1b2ects (see ,rom ,unction (roups to 1b2ects )!
All of the function modules in a function group can access the global data of the group! ,or this
reason# $ou should place all function modules that use the same data in a single function group!
,or e/ample# if $ou hae a set of function modules that all use the same internal table# $ou could
place them in a function group containing the table definition in its global data!
,unction groups# li-e e/ecutable programs and module pools# can contain screens (selection
screens and lists) as components! )ser input is processed either in dialog modules or in the
corresponding eent bloc-s in the main program of the function group! There are special include
programs in "hich $ou can "rite this code! *n this "a$# $ou can use function groups to encapsulate
single screens or screen se8uences!
Creating 2unction ,odules
3ou can onl$ create function modules and function groups using the ,unction Builder in the ABAP
Wor-bench! ,or further information# refer to Creating Ne" ,unction 'odules! This section
uses an e/ample to illustrate ho" a function module is created from the point of ie" of ABAP
programming!
We are going to create a function module %0A&SSP,.*S*NT1STAB.0 to read data for a
specified airline from table SP,.* into an internal table# "hich it then passes bac- to the calling
program!
2unction /roups and 2unction ,odules
,irstl$# "e create a ne" function group &0'1SSP,.* to hold the function module (see
Creating a ,unction (roup)! Then# "e can create the ne" function module (see Creating a
,unction 'odule)!
Parameter Interface
3ou can specif$ the t$pes of interface parameters in function modules in the same "a$ as the
parameter interfaces of subroutines! Since function modules can be used an$"here in the s$stem#
ABAP Programming (BC-ABA) :44
their interfaces can onl$ contain references to data t$pes that are declared s$stem-"ide! These
are the elementar$ ABAP data t$pes# the s$stem-"ide generic t$pes# such as an% ta&le# and t$pes
defined in the ABAP &ictionar$! 3ou cannot use I"0 to refer to data t$pes declared in the
frame"or- program!
The function module %0A&SSP,.*S*NT1STAB.0 re8uires an import parameter to restrict the
selection to a single airline! To specif$ the t$pe# "e can refer to the -e$ field CA%%*& of the
database SP,.*+
)nder %ef! field;structure# $ou can enter a column of a database table# a component of a ABAP
&ictionar$ structure# or a "hole ABAP &ictionar$ structure! The import parameter *& is optional#
and has a default alue!
The follo"ing t$pe specification "ould hae the same effect+
%ef! t$pe can contain an$ generic or full data t$pe that is recogni9ed s$stem-"ide! 6ere# the
parameter is defined "ith reference to the elementar$ ABAP &ictionar$ t$pe (or data element)
SSCA%%S*&! This is the t$pe used to define the field SP,.*-CA%%*&!
To pass data bac- to the calling program# the function module needs an e/port parameter "ith
the t$pe of an internal table! ,or this# "e define a s$stem-"ide table t$pe SP,.*STAB "ith the
line t$pe SP,.* in the ABAP )ictionar%!
We can no" use this data t$pe to specif$ the t$pe of the e/port parameter *TAB+
ABAP Programming (BC-ABA) :4:
The internal table is passed b$ alue! 1nl$ internal tables that are passed using tables
parameters can be passed e/clusiel$ b$ reference!
05ceptions
1ur function module needs an e/ception that it can trigger if there are no entries in table SP,.*
that meet the selection criterion! The e/ception N1TS,1)N& seres this function+
Source Code
6aing defined the parameter interface and e/ceptions# "e can no" "rite the source code of our
function module! To do this# choose Source code in the ,unction Builder! This opens the ABAP
0ditor for the include program fgrp.55 (see ,unction (roups )! This is the include in "hich the
function module is programmed+
The function of the function module can be programmed bet"een the 2.NC-ION and
0N)2.NC-ION statements! The definitions of the parameter interface and the e/ceptions is
displa$ed here in comment lines! *ts real coding is generated inisibl$ b$ the ,unction Builder!
)ata in 2unction ,odules
3ou can use the -7P0S and )A-A statements to create local data t$pes and ob2ects! The
interface parameters also behae li-e local data ob2ects! *n addition# $ou can access all of the
global data of the main program! This data is defined in the include program fgrp-OP! To open
this include# choose (oto 7 (lobal data in the ,unction Builder! The global data behaes li-e the
instance attributes of a class! The first time $ou call a function module in a particular function
group# the data is loaded into memor$! *t can then be accessed and changed b$ all of the function
modules in the group! The s$stem retains the alues until the ne/t time a function module is
called!
Calling Su&routines
ABAP Programming (BC-ABA) :4>
3ou use subroutines for local program modulari9ation! ,unction modules can also use this
techni8ue! The function module that the$ call are defined in the corresponding main program!
*f $ou onl$ "ant to call a subroutine from a single function module# it is best to define them in
the same include program as the function module itself# directl$ after the 0N)2.NC-ION
statement! These subroutines can be called from all function modules in the function group# but
for clarit$# the$ should onl$ be called from the function module that precedes them!
*f $ou "ant to define a subroutine that "ill be called from seeral different function modules#
$ou can define a special include program for it "ith the name fgrp2559
(aising 05ceptions
There are t"o ABAP statements for raising e/ceptions! The$ can onl$ be used in function
modules+
%A*S0 e/cept!
und
'0SSA(0!!!!!%A*S*N( e/cept!
The effect of these statements depends on "hether the calling program handles the e/ception or
not! The calling program handles an e/ception *f the name of the e5cept e/ception or O-+0(S is
specified after the 0XC0P-ION option of the CA 2.NC-ION statement!
*f the calling program does not handle the e/ception
7 The (AIS0statement terminates the program and s"itches to debugging
mode!
7 The ,0SSA/099999 (AISIN/ statement displa$s the specified message!
Processing is continued in relation to the message t$pe!
*f the calling program handles the e/ception# both statements return control to the program! No
alues are transferred! The ,0SSA/099999 (AISIN/ statement does not displa$ a message!
*nstead# it fills the s$stem fields s%-msgid# s%-msgt%# s%-msgno # and S7-,S/!8 to S7-
,S/!D!
Source Code of (0A)ESP2IEIN-OE-AB0
The entire source code of %0A&SSP,.*S*NT1STAB.0 loo-s li-e this+
2.NC-ION readEspfliEintoEta&le9
U;------------------------------------------------------------
U;U;ocal Interface=
U; I,PO(-IN/
U; !A.0(I)) I"0 SP2I-CA((I) )02A.- ?+ ?
U; 0XPO(-IN/
U; !A.0(I-AB) -7P0 SP2IE-AB
U; 0XC0P-IONS
U; NO-E2O.N)
U;------------------------------------------------------------
S00C- U 2(O, spfli IN-O -AB0 ita& W+0(0 carrid F id9
I2 s%-su&rc N0 @9
,0SSA/0 e@@I(at) (AISIN/ notEfound9
0N)I29
0N)2.NC-ION9
The function module reads all of the data from the database table SP,.* "here the -e$ field
CA%%*& is e8ual to the import parameter *& and places the entries that it finds into the internal
table spfliEta&! *f it cannot find an$ entries# the e/ception N1TS,1)N& is triggered "ith
,0SSA/0 999 (AISIN/! 1ther"ise# the table is passed to the caller as an e/porting parameter!
Calling (0A)ESP2IEIN-OE-AB0
The follo"ing program calls the function module %0A&SSP,.*S*NT1STAB.0+
(0PO(- demoEmodEtec$Ef&EreadEspfli9
PA(A,0-0(S carrier -7P0 sEcarrEid9
)A-A= 3ta& -7P0 spfliEta&4
wa I"0 IN0 O2 3ta&9
CA 2.NC-ION ?(0A)ESP2IEIN-OE-AB0?
0XPO(-IN/
id F carrier
I,PO(-IN/
ita& F 3ta&
0XC0P-IONS
ABAP Programming (BC-ABA) :4?
notEfound F 8
O-+0(S F B9
CAS0 s%-su&rc9
W+0N 89
,0SSA/0 I) s%-msgid -7P0 s%-msgt% N.,B0( s%-msgno9
W+0N B9
,0SSA/0 eI@B(at)9
0N)CAS09
OOP A- 3ta& IN-O wa9
W(I-0= A wa-carrid4 wa-connid4 wa-cit%from4 wa-cit%to9
0N)OOP9
The actual parameters carrier and 3ta& hae the same data t$pes as their corresponding
interface parameters in the function module! The e/ception N1TS,1)N& is handled in the
program! *t displa$s the same message that the function module "ould hae displa$ed had it
handled the error!
ource Code ,odules
When $ou modulari9e source code# $ou place a se8uence of ABAP statements in a module! Then#
instead of placing all of the statements in $our main program# $ou 2ust call the module!
When the program is generated# the source code in the modulari9ation unit is treated as though
it "ere actuall$ ph$sicall$ present in the main program! Source code modules help $ou to aoid
repeatedl$ "riting the same set of statements and to ma-e $our programs easier to read and
understand! The$ are not used to modulari9e tas-s and functions! 3ou should use procedures for
this purpose!
ABAP contains t"o -inds of source code modules+ .ocal modules are called macros# and cross-
program modules are called include programs!
,acros
*f $ou "ant to reuse the same set of statements more than once in a program# $ou can include
them in a macro! ,or e/ample# this can be useful for long calculations or comple/ W(I-0
statements! 3ou can onl$ use a macro "ithin the program in "hich it is defined# and it can onl$ be
called in lines of the program follo"ing its definition!
The follo"ing statement bloc- defines a macro macro+
&0,*N0 ma-ro!
statements
0N&-1,-&0,*N*T*1N!
3ou must specif$ complete statements bet"een )02IN0 and 0N)-O2-)02INI-ION! These
statements can contain up to nine placeholders #8# #B#!!!!# #K)! 3ou must define the macro &efore
the point in the program at "hich $ou "ant to use it!
'acros do not belong to the definition part of the program! This means that the )02IN0
statement bloc- is not interpreted before the processing bloc-s in the program! At the same
time# ho"eer# macros are not operational statements that are e/ecuted "ithin a processing
bloc- at runtime! When the program is generated# macro definitions are not ta-en into account at
the point at "hich the$ are defined! ,or this reason# the$ do not appear in the oerie" of the
structure of processing logic!
A macro definition inserts a form of shortcut at an% point in a program and can be used at an%
su&se1uent point in the program! As the programmer# $ou must ensure that the macro definition
occurs in the program before the macro itself is used! Particular care is re8uired if $ou use both
ABAP Programming (BC-ABA) :4@
macros and include programs# since not all include programs are included in the s$nta/ chec-
(e/ception+ T1P include)!
To use a macro# use the follo"ing form+
ma-ro Xp1 p4!!! pEY!
When the program is generated# the s$stem replaces the macro b$ the appropriate statements
and the placeholders #8# #B# \# #K b$ the parameter p8# pB# \# pK! 3ou can use macros "ithin
macros! 6o"eer# a macro cannot call itself!
(0PO(- demoEmodEtec$Emacros9
)A-A= result -7P0 i4
n8 -7P0 i !A.0 G4
nB -7P0 i !A.0 H9
)02IN0 operation9
result F #8 #B #C9
output #8 #B #C result9
0N)-O2-)02INI-ION9
)02IN0 output9
write= A ?-$e result of #8 #B #C is?4 #D9
0N)-O2-)02INI-ION9
operation D T C9
operation B UU I9
operation nB - n89
This produces the follo"ing output+
The result of > 5 : is B
The result of 4 LL B is 14D
The result of N4 - N1 is 1
*n this e/ample# the t"o macros operation and output are defined! output is nested in operation!
operation is called three times "ith different parameters! Note ho" the placeholders f1# f4#!!!
are replaced in the macros!
The follo"ing e/ample sho"s that a macro definition onl$ "or-s in the program lines follo"ing its
definition! &o not cop$ it`
.et us hae a loo- at a program "ith a subroutine test+
P(O/(A, macroEtest9
999
2O(, test9
W(I-0 ?999?9
0N)2O(,9
We can re"rite the program b$ introducing a macro macro+
P(O/(A, macroEtest9
999
2O(, test9
)02IN0 macro9
W(I-0 ?999?9
0N)2O(,9
0N)-O2-)02INI-ION9
,AC(O9
*nserting the macro changes not$ing in the generated form of the program! Processing bloc-s -
here a subroutine - are al"a$s indiisible! We could also "rite the program as follo"s+
P(O/(A, macroEtest9
999
)02IN0 macro9
W(I-0 ?999?9
0N)2O(,9
0N)-O2-)02INI-ION9
999
2O(, test9
,AC(O9
ABAP Programming (BC-ABA) :4B
The most essential feature of a macro definition is that it should occur &efore the macro is used!
Include Programs
*nclude programs are global %;: %epositor$ ob2ects! The$ are solel$ for modulari9ing source
code# and hae no parameter interface!
The$ hae the follo"ing functions+
i&rar%+ *nclude programs allo" $ou to use the same source code in different programs!
,or e/ample# this can be useful if $ou hae length$ data declarations that $ou "ant to use
in different programs!
Order! *nclude programs allo" $ou to manage comple/ programs in an orderl$ "a$! ,unction
groups and module pools use include programs to store parts of the program that belong
together! The ABAP Wor-bench supports $ou e/tensiel$ "hen $ou create such comple/
programs b$ creating the include programs automaticall$ and b$ assigning them uni8ue
names! A special include is the T1P include of a program! *f $ou name it according to the
naming conention# it is al"a$s included in program naigation and in the s$nta/ chec-!
Creating 7our Own Include Programs
*f $ou create an include program $ourself# $ou must assign it the t$pe * in its program attributes!
3ou can also create or change an include program b$ double-clic-ing on the name of the program
after the *NC.)&0 statement in $our ABAP program! *f the program e/ists# the ABAP
Wor-bench naigates to it! *f it does not e/ist# the s$stem creates it for $ou!
An include program cannot run independentl$# but must be built into other programs! *nclude
programs can contain other includes!
The onl$ restrictions for "riting the source code of include programs are+
*nclude programs cannot call themseles!
*nclude programs must contain complete statements!
3ou must ensure that the statements of $our include program fit logicall$ into the source code of
the programs from "hich it is called! Choosing Chec- "hile editing an include program in the ABAP
0ditor is normall$ not sufficient for this!
LLL*NC.)&0 *NC.STST!
T0_T H I6ello`I!
6ere# the s$nta/ chec- reports an error because the field T0_T is not declared!
6o"eer# $ou can include *NC.STST in an$ program in "hich a field called T0_T
"ith the correct t$pe has been declared!
,or the s$nta/ chec- to produce alid results# $ou must chec- the program in "hich the include
occurs! The e/ception to this is the T1P include# the contents of "hich are al"a$s included "hen
$ou chec- the s$nta/ of another include!
.sing Include Programs
To use an include program in another program# enter the statement
*NC.)&0 ]inclG!
The *NC.)&0 statement has the same effect as cop$ing the source code of the include program
]inclG into the program! *n the s$nta/ chec-# the contents of the include program are also
anal$9ed! *nclude programs are not loaded at runtime# but are e/panded "hen the program is
generated! 1nce the program has been generated# the load ersion contains static ersions of all
of its includes! *f $ou subse8uentl$ change an include program# the programs that use it are
automaticall$ regenerated!
The *NC.)&0 statement must be the onl$ statement on a line and cannot e/tend oer seeral
lines!
Suppose "e hae the follo"ing program+
LLL*NC.)&0 STA%TT_T!
W%*T0+ ; IProgram started b$I# S3-)NA'0#
; Ion hostI# S3-61ST#
Idate+I# S3-&AT)'# Itime+I# S3-)T0*T!
).*N0!
We can then include this program in an$ other ABAP program to displa$ a standard
list header!
P%1(%A' SAP'TTST!
*NC.)&0 STA%TT_T!
ABAP Programming (BC-ABA) :4D
!!!!!!!!!!!!
This could produce the follo"ing output+
Program started &% "00(+
on $ost ds@@BG date= @CA8KA8KKJ time= @K=@@=CK
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
9999999999999999
Calling Procedures

3ou can call procedures either internall$ or e/ternall$! *f $ou call procedures e/ternall$# it is
important that $ou understand ho" memor$ is organi9ed in the SAP s$stem# ho" screens are
processed# and ho" interface "or- areas are used!
Calling Procedures - 1erie"
Calling Subroutines
Calling ,unction 'odules
Calling Procedures - Overview

*nternal Procedure Calls
0/ternal Procedure Calls
1rgani9ation of 0/ternal Procedure Calls
Internal Procedure Calls
*n an internal procedure call# the called unit is part of the calling program! The source code of
the called unit is either part of the source code of the calling program or attached to it as an
include program! This means that# at runtime# no other programs hae to be loaded into the
internal session of the calling program!
Procedures
All procedures - subroutines# function modules# and methods - can be called internall$ in the
program in "hich the$ are defined!
7 )sing an internal call is the recommended and most fre8uentl$ used method of calling a
subroutine!
7 ,unction modules can onl$ be called internall$ if a function module calls another function
module from the same group! 1ther"ise# function modules are called e/ternall$!
7 'ethods are called internall$ "hen a class calls one of its o"n methods# or "hen $ou use a
method of a local class in an ABAP program!
05ternal Procedure Calls
*n an e/ternal procedure call# the called unit is not part of the calling program! This means that#
at runtime# an e/tra program has to be loaded into t$e internal session of t$e calling program!
3ou can use e/ternal calls for procedures and subscreens!
ABAP Programming (BC-ABA) :4E
The additional loaded program is an instance "ith its o"n global data area! When $ou call an
e/ternal subroutine# the calling program and the loaded program form a single program group#
unless the loaded program is a function group! ,unction groups al"a$s form their o"n program
group! ,urthermore# "hen $ou call methods e/ternall$# the loaded class forms its o"n program
group! Within a program group# interface "or- areas and the screens of the calling program are
shared! Classes cannot contain interface "or- areas!


Procedures
All procedures# that is# subroutines# function modules# and methods# can be called e/ternall$ from
an$ ABAP program!
7 3ou are recommended not to use e/ternal calls for subroutines# in particular if the
subroutines share interface "or- areas "ith the calling program and call their o"n screens! The
program group into "hich the main program of a subroutine is loaded depends on the se8uence of
the calls! The se8uence is often not staticall$ defined# but changes depending on user actions or
the contents of fields! ,or this reason# it ma$ not be clear "hich interface "or- areas and
screens "ill be used b$ an e/ternall$-called subroutine!
7 ,unction modules are intended for e/ternal procedure calls!
7 Accessing an e/ternall$-isible method of a global class counts as an e/ternal procedure
call!
At the first call of an e/ternal sub-screen or a function module# the frame"or- program of the
called procedure is loaded to the internal session of the calling program! *n doing so# the eent
OA)-O2-P(O/(A, is triggered and the associated processing bloc- is e/ecuted before the
called procedure is e/ecuted! At eer$ further call of a procedure of the same frame"or-
program b$ a caller of the same internal session# the eent OA)-O2-P(O/(A, is no longer
triggered!
Su&screen screens
3ou can call a subscreen screen e/ternall$ b$ specif$ing an ABAP program other than the current
program "hen calling in the screen flo" logic! This program is treated in the same "a$ as in an
e/ternal subroutine call! *n other "ords# it is loaded into the program group of the calling
program# or# if it is a function group# as its o"n program group in the same internal session as the
calling ABAP program!
,or this reason# $ou should not use e/ternal subscreens that do not belong to a function group#
since the same problems can occur "ith interface "or- areas and screen calls as can occur "ith
e/ternal subroutines!
Organi:ation of 05ternal Procedure Calls
0ach e/ecution (start or call) of an e/ecutable program opens up an internal session "ith the main
session of an SAP application! When the program calls e/ternal procedures# their main program
ABAP Programming (BC-ABA) ::F
and "or-ing data are also loaded into the memor$ area of the internal session! 6ere# there is a
difference bet"een calling e/ternal subroutines# function modules# and "or-ing "ith classes in
ABAP 1b2ects! When $ou load a frame"or- program into an internal session# the eent OA)-
O2-P(O/(A, is triggered! *f a corresponding eent bloc- is defined in the frame"or- program#
it is e/ecuted once before the first other processing procedure of the frame"or- program is
e/ecuted!
Program /roups in an Internal Session
This illustration sho"s the memor$ organi9ation for e/ternal subroutines and function modules!

The main program (e/ecutable program or module pool) belongs to a main program group! When
$ou call# using CA 2.NC-ION# a function module from a function group that has not alread$
been loaded# an additional program group is opened! The function group of the function module is
stored here! The additional program group# along "ith its data# e/ists for the rest of the lifetime
of the internal session!
*f $ou call an e/ternal subroutine using P0(2O(,# the frame"or- program of the subroutine is
loaded into the e/isting main program or function group in the corresponding main or additional
program group (if it has not alread$ been loaded)!
An additional program group is onl$ opened in an e/ternal P0(2O(, if the subroutine belongs to a
function group that has not $et been loaded! This "ill happen if the main program of the
subroutine begins "ith the 2.NC-ION-POOstatement! The program t$pe does not necessaril$
hae to be set to ,!
Classes in ABAP 1b2ects behae li-e function groups! The first time $ou address a class (for
e/ample# using the C(0A-0 OBY0C-statement) or address a static class component# the s$stem
opens an additional program group for the class!
O&3ect +andling
The transient ob2ects of ABAP 1b2ects e/ist "ith e8ual status in the data area of an internal
session! All the programs and ob2ects of an internal session can use the ob2ects of ABAP 1b2ects
of the same internal session! This means that references to ob2ects "ithin an internal session can
be passed to e/ternal procedures (subroutines# function modules# and methods)!
There are no memor$ areas for cross-transaction ob2ects on the application serer! Persistent
ob2ects in the database are handled b$ persistence serices that do not belong to the language
scope of ABAP!
Screen +andling
The s$stem onl$ displa$s and processes the screens# selection screens# and lists of the main
program and main program group or function group of an additional program group# along "ith
their associated ()* statuses! The CA SC(00N# CA S00C-ION-SC(00N or list output
statements in e/ternal subroutines appl$ to the screens of the main program or function group!
The screens are processed in the main program or function group! So# for e/ample# een if the
frame"or- program of an e/ternal subroutine has a screen "ith the number 1FF# a CA SC(00N
8@@ statement "ill call screen number 1FF in the calling main program!
Interface Wor* Areas
*nterface "or- areas that $ou declare using the -AB0S# NO)0S# or )A-A B0/IN O2
CO,,ON PA(- statements e/ist once onl$ in each program group# and are shared b$ all of its
programs! 0ach main program that begins "ith the P(O/(A, or (0PO(-statement# and each
ABAP Programming (BC-ABA) ::1
function group that begins "ith 2.NC-ION-POO shares the interface "or- areas "ith the
frame"or- programs of all of its e/ternal subroutines!
)%namic Assignment
The assignment of screens and interface "or- areas to subroutines is defined b$ the se1uence of
the subroutine calls! The first program to call an e/ternal subroutine shares its interface "or-
areas "ith the subroutine# and the subroutine uses its screens! The se8uence of the subroutine
calls is not necessaril$ staticall$ defined! *nstead# it can change d$namicall$ depending on user
actions or the contents of fields! ,or e/ample# a subroutine ma$ belong to a main program group
on occasion "hen it is run# but the ne/t time# it ma$ belong to an additional program group! ,or
this reason# $ou should aoid using e/ternal subroutines if the$ use interface "or- areas or call
screens!
Calling Su&routines
3ou call subroutines using the statement
P0%,1%' !!! X)S*N( p1 p4 !!! Y
XC6AN(*N( p1 p4 !!! Y!
Subroutines can call other subroutines (nested calls) and ma$ also call themseles (recursie
calls)! 1nce a subroutine has finished running# the calling program carries on processing after the
P0(2O(, statement! 3ou can use the .SIN/ and C+AN/IN/ additions to suppl$ alues to the
parameter interface of the subroutine!
Naming Subroutines
Passing Parameters to Subroutines
0/amples of Subroutines
Common &ata Area
Terminating a Subroutine
Naming Su&routines
With the P0(2O(, statement# $ou can call subroutines "hich are coded in the same ABAP
program (internal calls)# or subroutines "hich are coded in other ABAP programs (e/ternal calls)!
3ou can also specif$ the name of the subroutine d$namicall$ at runtime# and call subroutines from
a list!
Internal Su&routine Calls
To call a subroutine defined in the same program# $ou need onl$ specif$ its name in the P0(2O(,
statement+
P0%,1%' subr X)S*N( p1 p4!!! Y
XC6AN(*N( p1 p4!!! Y!
The internal subroutine can access all of the global data of the calling program!
(0PO(- demoEmodEtec$EperformEint9
)A-A= num8 -7P0 i4
numB -7P0 i4
sum -7P0 i9
num8 F B9 numB F D9
P0(2O(, addit9
num8 F I9 numB F 889
P0(2O(, addit9
2O(, addit9
sum F num8 T numB9
P0(2O(, out9
0N)2O(,9
2O(, out9
W(I-0= A ?Sum of?4 num84 ?and?4 numB4 ?is?4 sum9
0N)2O(,9
This produces the follo"ing output+
Sum of 4 and > is @
Sum of B and 11 is 1D
*n this e/ample the subroutines addit and out are defined at the end of the program! addit is
called b$ the program and out is called b$ addit! The subroutines hae access to the global fields
num8# numB und sum!

ABAP Programming (BC-ABA) ::4
0/ternal Subroutine Calls
The principal function of subroutines is for modulari9ing and structuring local programs! 6o"eer#
subroutines can also be called e/ternall$ from other ABAP programs! *n an e/treme case# $ou
might hae an ABAP program that contained nothing but subroutines! These programs cannot run
on their o"n# but are used b$ other ABAP programs as pools of e/ternal subroutines!
6o"eer# if $ou "ant to ma-e a function aailable throughout the s$stem# $ou should use function
modules instead of e/ternal subroutines! 3ou create function modules in the ABAP Wor-bench
using the ,unction Builder! The$ are stored in a central librar$# and hae a defined release
procedure!
3ou can encapsulate functions and data in the attributes and methods of classes in ABAP
1b2ects! ,or an$ re8uirements that e/ceed pure functions# $ou can use global classes instead of
e/ternal subroutines!
When $ou call a subroutine e/ternall$# $ou must -no" the name of the program in "hich it is
defined+
P0%,1%' subr(prog) X)S*N( p1 p4!!! Y
XC6AN(*N( p1 p4!!! Y X*, ,1)N&Y!
3ou specif$ the program name prog staticall$! 3ou can use the I2 2O.N) option to preent a
runtime error from occurring if the program progdoes not contain a subroutine su&r! *n this case#
the s$stem simpl$ ignores the P0(2O(, statement!
When $ou call an e/ternal subroutine# the s$stem loads the "hole of the program containing the
subroutine into the internal session of the calling program (if it has not alread$ been loaded)! *n
order to sae memor$ space# $ou should -eep the number of subroutines called in different
programs to a minimum!
Suppose a program contains the follo"ing subroutine+
(0PO(- formpool9
2O(, $eader9
W(I-0= A ?Program started &%?4 s%-uname4
A ?on $ost?4 s%-$ost4
?date=?4 s%-datum4 ?time=?4 s%-u:eit9
.IN09
0N)2O(,9
The subroutine can then be called from another program as follo"s+
(0PO(- demoEmodEtec$EperformEe5t9
P0(2O(, $eader(demoEmodEtec$EformpoolE8) I2 2O.N)9
*n this e/ample# no data is passed bet"een the calling program and the subroutine!
Specif%ing Su&routines )%namicall%
3ou can specif$ the name of a subroutine and# in the case of e/ternal calls# the name of the
program in "hich it occurs# d$namicall$ as follo"s+
P0%,1%' (fsubr)X*N P%1(%A' (fprog)YX)S*N( p1 p4!!! Y
XC6AN(*N( p1 p4!!! Y
X*, ,1)N&Y!
The names of the subroutine and the e/ternal program are the contents of the fields fsu&r und
fprogrespectiel$! B$ using the option I2 2O.N)# $ou can preent a runtime error from being
triggered if no subroutine "ith the name fsu&r is found! *f $ou omit the parentheses# this ariant
of the P0(2O(,statement behaes li-e the static ariant!
Assume a program contains the follo"ing subroutines+
P%1(%A' formpool!
,1%' sub1!
W%*T0+ ; ISubroutine 1I!
0N&,1%'!
,1%' sub4!
W%*T0+ ; ISubroutine 4I!
0N&,1%'!
&$namic Subroutine Specification+
P%1(%A' formStest!
ABAP Programming (BC-ABA) :::
&ATA+ progname(D) T3P0 c AA.)0 I,1%'P11.I#
subrname(D) T3P0 c!
subrname H IS)B1I!
P0%,1%' (subrname) *N P%1(%A' (progname) *, ,1)N&!
S)B%NA'0 H IS)B4I!
P0%,1%' (subrname) *N P%1(%A' (progname) *, ,1)N&!
This produces the follo"ing output+
Subroutine 1
Subroutine 4
The character field progname contains the name of the program# in "hich the subroutines are
contained! The names of the subroutines are assigned to the character field su&rname!
Calling Subroutines from a .ist
3ou can call a subroutine from a list as follo"s+
P0%,1%' id/ 1, subr
1
subr
4
!!! subr
n
!
The s$stem calls the subroutine specified in the subroutine list in position id5! 3ou can onl$ use
this ariant of the P0(2O(,statement for internal subroutine calls# and onl% for su&routines
wit$out a parameter interface! The field id5 can be a ariable or a literal!
(0PO(- demoEmodEtec$EperformElist9
)O B -I,0S9
P0(2O(, s%-inde5 O2 su&8 su&B9
0N))O9
2O(, su&89
W(I-0 A ?Su&routine 8?9
0N)2O(,9
2O(, su&B9
W(I-0 A ?Su&routine B?9
0N)2O(,9
This produces the follo"ing output+
Subroutine 1
Subroutine 4
*n this e/ample# the t"o internal subroutines# su&8 and su&B# are called consecutiel$ from a list!
Passing Parameters to Su&routines
*f a subroutine has a parameter interface# $ou must suppl$ alues to all of the formal parameters
in its interface "hen $ou call it! 3ou list the actual parameters after the .SIN/ or C+AN/IN/
additions in the P0(2O(,statement!
When $ou pass the alues# the se1uence of the actual parameters in the P0(2O(,statement is
crucial! The alue of the first actual parameter in the list is passed to the first formal
parameter# the second to the second# and so on! The additions .SIN/ and C+AN/IN/ hae
e/actl$ the same meaning! 3ou onl$ need to use one or the other! 6o"eer# for documentar$
reasons# it is a good idea to diide the parameters in the same "a$ in "hich the$ occur in the
interface definition!
Actual parameters can be an$ data ob2ects or field s$mbols of the calling program "hose
technical attributes are compatible "ith the t$pe specified for the corresponding formal
parameter! When $ou specif$ the actual parameters# note that those $ou pass b$ reference to a
formal parameter and those $ou pass b$ alue to an output parameter can be changed b$ the
subroutine! 3ou should therefore ensure that onl$ data ob2ects that $ou "ant to be changed
appear in the corresponding position of the actual parameter list!
*f a subroutine contains TAB.0S parameters in its interface# $ou must call them as actual
parameters after the -AB0Saddition of the P0(2O(, statement before the .SIN/ and
C+AN/IN/parameters! -AB0S parameters are onl$ supported to ensure compatibilit$ "ith
earlier releases# and should no longer be used!
3ou can use offset addressing for actual parameters in the same "a$ as offset addressing for
field s$mbols! That is# $ou can select memor$ areas that lie outside the boundaries of the
specified actual parameter!
P(O/(A, formEtest9
ABAP Programming (BC-ABA) ::>
)A-A= a8 -7P0 p )0CI,AS C4
aB -7P0 i4
aC -7P0 d4
aD -7P0 spfli-carrid4
aG(8) -7P0 c9
999
P0(2O(, su&r .SIN/ a8 aB aC aD aG9
999
P0(2O(, su&r C+AN/IN/ a8 aB aC aD aG9
999
P0(2O(, su&r .SIN/ a8 aB aC
C+AN/IN/ aD aG9
999
2O(, su&r .SIN/
value(f8) -7P0 p
value(fB) -7P0 i
fC I"0 aC
C+AN/IN/
value(fD) -7P0 spfli-carrid
fG9
999
0N)2O(,9
This e/ample defines a subroutine su&r "ith a parameter interface consisting of fie formal
parameters# f8 to fG! The subroutine is called internall$ three times! The actual parameters are
the data ob2ects a8 to aG! -$e t$ree su&routine calls are all e1uall% valid9 There are further
P0(2O(,statements that are also e8uall$ alid# so long as the se8uence of the actual parameters
remains unchanged! *n each call# a8 is passed to f8# aB to fB# and so on! When the subroutine
ends# aC# aD# and aG receie the alues of fC# fD# and fG respectiel$! The third of the subroutine
calls documents in the program "hat the parameter interface of the subroutine sho"s# namel$
that onl$ aD and aG are changed! *n the case of reference parameter fC# it depends on the
programming of the subroutine "hether aC is changed all the same!
The follo"ing e/ample sho"s ho" genericall$-t$ped formal parameters inherit their technical
attributes from their corresponding actual parameters!
(0PO(- demoEmodEtec$Edescri&e9
)A-A=
date8 -7P0 d4 dateB -7P0 t4
string8(H) -7P0 c4 stringB(J) -7P0 c4
num&er8 -7P0 p )0CI,AS B4 num&erB -7P0 p )0CI,AS @4
count8 -7P0 i4 countB -7P0 i9
P0(2O(, t%petest .SIN/ date8 string8 num&er8 count89
S"IP9
P0(2O(, t%petest .SIN/ dateB stringB num&erB countB9
2O(, t%petest .SIN/ now
t5t -7P0 c
value(num) -7P0 p
int -7P0 i9
)A-A= t(8) -7P0 c9
)0SC(IB0 2I0) now -7P0 t9
W(I-0= A ?-%pe of NOW is?4 t9
)0SC(IB0 2I0) t5t 0N/-+ t IN C+A(AC-0( ,O)09
W(I-0= A ?engt$ of -X- is?4 t9
)0SC(IB0 2I0) num )0CI,AS t9
W(I-0= A ?)ecimals of N., are?4 t9
)0SC(IB0 2I0) int -7P0 t9
W(I-0= A ?-%pe of IN- is?4 t9
0N)2O(,9
This produces the follo"ing output+
ABAP Programming (BC-ABA) ::?
T$pe of N1W is &
.ength of T_T is @
&ecimals of N)' are 4
T$pe of *NT is *
T$pe of N1W is T
.ength of T_T is D
&ecimals of N)' are F
T$pe of *NT is *
An internal subroutine t%petest is called t"ice "ith different actual parameters! All actual and
formal parameters are compatible and no error message occurs during the s$nta/ chec-! 6ad $ou
declared countB "ith t$pe f instead of t$pe i# the s$nta/ chec- "ould hae returned an error#
since the formal parameter IN- is specified "ith t$pe i! The formal parameters "ith generic
t$pes adopt different technical attributes depending on their corresponding technical attributes!
05amples of Su&routines
05ample of Passing Parameters &% (eference
(0PO(- demoEmodEtec$Ee5ampleE89
)A-A= num8 -7P0 i4
numB -7P0 i4
sum -7P0 i9
num8 F B9 numB F D9
P0(2O(, addit .SIN/ num8 numB C+AN/IN/ sum9
num8 F I9 numB F 889
P0(2O(, addit .SIN/ num8 numB C+AN/IN/ sum9
2O(, addit
.SIN/ addEnum8 -7P0 an%
addEnumB -7P0 an%
C+AN/IN/ addEsum -7P0 an%9
addEsum F addEnum8 T addEnumB9
P0(2O(, out .SIN/ addEnum8 addEnumB addEsum9
0N)2O(,9
2O(, out
.SIN/ outEnum8 -7P0 an%
outEnumB -7P0 an%
outEsum -7P0 an%9
W(I-0= A ?Sum of?4 outEnum84 ?and?4 outEnumB4 ?is?4 outEsum9
0N)2O(,9
This produces the follo"ing output+
Sum of 4 and > is @
Sum of B and 11 is 1D
*n this e/ample# the actual parameters num8# numB# and sum are passed b$ reference to the
formal parameters of the subroutine addit! After changing addEsum# the latter parameters are
then passed to the formal parameters outEnum8# outEnumB# and outEsum of the subroutine out!
*nput parameters that are changed in the subroutine are also changed in the calling program! To
preent this# $ou must pass the parameter as a alue in a .SIN/ addition!
05ample of Passing Parameters &% (eference
(0PO(- demoEmodEtec$Ee5ampleEB9
)A-A= num -7P0 i !A.0 G4
fac -7P0 i !A.0 @9
P0(2O(, fact .SIN/ num C+AN/IN/ fac9
W(I-0= A ?2actorial of?4 num4 ?is?4 fac9
2O(, fact
.SIN/ value(fEnum) -7P0 i
C+AN/IN/ fEfact -7P0 i9
fEfact F 89
W+I0 fEnum /0 89
fEfact F fEfact U fEnum9
ABAP Programming (BC-ABA) ::@
fEnum F fEnum - 89
0N)W+I09
0N)2O(,9
This produces the follo"ing output+
,actorial of ? is 14F
To ensure that an input parameter is not changed in the calling program# een if it is changed in
the subroutine# $ou can pass data to a subroutine b$ alue! *n this e/ample# the factorial of a
number num is calculated! The input parameter num is passed to the formal parameter fEnum of
the subroutine! Although fEnum is changed in the subroutine# the actual parameter num -eeps its
old alue! The output parameter fac is passed b$ reference!
05ample of Output Parameters
(0PO(- demoEmodEtec$Ee5ampleEC9
)A-A= op8 -7P0 i4
opB -7P0 i4
res -7P0 i9
op8 F C9
opB F D9
P0(2O(, multip
.SIN/ op8 opB
C+AN/IN/ res9
W(I-0= A ?After su&routine=?4
A ?(0SF? .N)0( ?(0SF?4 res9
2O(, multip
.SIN/ value(o8) -7P0 an%
value(oB) -7P0 an%
C+AN/IN/ value(r) -7P0 an%9
r F o8 U oB9
W(I-0= A ?Inside su&routine=?4
A ?(F?4 r4 ?(0SF?4 res9
0N)2O(,9
This produces the follo"ing output+
*nside subroutine+
%H 14 %0SH F
After subroutine+
%0SH 14
To return a changed formal parameter once the subroutine has finished successfull$# $ou can use
a C+AN/IN/ parameter and pass the parameter b$ reference! *n this e/ample# the actual
parameters op8 and opB are passed b$ alue in the .SIN/ addition to the formal parameters o8
and oB! The actual parameter res is passed b$ alue to the formal parameter r using C+AN/IN/!
B$ "riting r and res onto the screen from "ithin the subroutine# it is demonstrated that res has
not changed its contents before the 0N)2O(, statement! After returning from the subroutine#
its contents hae changed!
05ample of Passing Structures
(0PO(- demoEmodEtec$Ee5ampleED9
-7P0S= B0/IN O2 line4
name(8@) -7P0 c4
age(B) -7P0 n4
countr%(C) -7P0 c4
0N) O2 line9
)A-A w$o -7P0 line9
w$o-name F ?Otto?9 w$o-age F ?8@?9 w$o-countr% F ?)?9
P0(2O(, components C+AN/IN/ w$o9
W(I-0= A w$o-name4 w$o-age4 w$o-countr%9
2O(, components
C+AN/IN/ value(person) -7P0 line9
ABAP Programming (BC-ABA) ::B
W(I-0= A person-name4 person-age4 person-countr%9
person-name F ?,ic*e%?9
person-age F ?H@?9
person-countr% F ?.SA?9
0N)2O(,9
This produces the follo"ing output+
1tto 1F &
'ic-e$ @F )SA
The actual parameter w$o "ith the user-defined# structured data t$pe line is passed to the
formal parameter person! The formal parameter person is t$ped "ith -7P0 line! Since line is a
user-defined data t$pe# the t$pe of person is completel$ specified! The subroutine accesses and
changes the components of person! The$ are then returned to the components of w$o in the
calling program!
05ample of Passing Internal -a&les
(0PO(- demoEmodEtec$Ee5ampleEG9
)A-A= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A ita& I"0 S-AN)A() -AB0 O2 line9
P0(2O(, fill C+AN/IN/ ita&9
P0(2O(, out .SIN/ ita&9
2O(, fill C+AN/IN/ fEita& I"0 ita&9
)A-A fEline I"0 IN0 O2 fEita&9
)O C -I,0S9
fEline-col8 F s%-inde59
fEline-colB F s%-inde5 UU B9
APP0N) fEline -O fEita&9
0N))O9
0N)2O(,9
2O(, out .SIN/ value(fEita&) I"0 ita&9
)A-A fEline I"0 IN0 O2 fEita&9
OOP A- fEita& IN-O fEline9
W(I-0= A fEline-col84 fEline-colB9
0N)OOP9
0N)2O(,9
This produces the follo"ing output+
1 1
4 >
: E
3ou can define the t$pes of the formal parameters of the parameter interface of procedures as
internal tables! *n the e/ample# the subroutines fill and out each hae one formal parameter
defined as an internal table! An internal table "ithout header line is passed to the subroutines!
0ach subroutine declares a "or- area fEline as a local data ob2ect! Were ita& a table "ith a
header line# $ou "ould hae to replace ita& "ith ita&PQ in the P0(2O(, and 2O(, statements!
05ample of t$e -AB0S parameter
This e/ample is proided for completeness! The -AB0S parameter is onl$ supported for the
sa-e of compatibilit$ and should not be used!
(0PO(- demoEmodEtec$Ee5ampleEH9
-7P0S= B0/IN O2 line4
col8 -7P0 i4
colB -7P0 i4
0N) O2 line9
)A-A= ita& -7P0 S-AN)A() -AB0 O2 line WI-+ +0A)0( IN04
3ta& -7P0 S-AN)A() -AB0 O2 line9
P0(2O(, fill -AB0S ita&9
ABAP Programming (BC-ABA) ::D
,O!0 ita&PQ -O 3ta&9
P0(2O(, out -AB0S 3ta&9
2O(, fill -AB0S fEita& I"0 ita&PQ9
)O C -I,0S9
fEita&-col8 F s%-inde59
fEita&-colB F s%-inde5 UU B9
APP0N) fEita&9
0N))O9
0N)2O(,9
2O(, out -AB0S fEita& I"0 3ta&9
OOP A- fEita&9
W(I-0= A fEita&-col84 fEita&-colB9
0N)OOP9
0N)2O(,9
The produces the follo"ing output+
1 1
4 >
: E
*n this e/ample# an internal table ita& is declared "ith a header line and an internal table 3ta& is
declared "ithout a header line! The actual parameter ita& is passed to the formal parameter
fEita& of the subroutine fill in the -AB0S addition! The header line is passed "ith it! After the
bod$ of the table has been copied from ita& to 3ta&# the actual parameter 3ta& is passed to the
formal parameter fEita& of the subroutine out using the -AB0S addition! The header line
fEita&# "hich is not passed# is generated automaticall$ in the subroutine!
S$ared )ata Areas
The follo"ing statements are obsolete and are onl$ aailable to ensure compatibilit$ "ith
%eleases prior to >!@ and @!1F! The statements ma$ appear in older programs but should no longer
be used!

,or the sa-e of completeness# this section describes a techni8ue that allo"s $ou to access the
global data of the calling program from an e5ternal subroutine! To do this# $ou declare a common
data area for the calling program and the program containing the subroutine! All interface "or-
areas declared using -AB0Sand NO)0S behae li-e the common data area!
.i-e e/ternal subroutines themseles# $ou should use common data areas er$ sparingl$! The rules
for accessing common data areas can become er$ complicated if $ou call function modules from
nested subroutines!
3ou declare a common data area in all programs concerned using the )A-A statement+
&ATA+ B0(*N 1, C1''1N PA%T XnameY#

0N& 1, C1''1N PA%T XnameY!
Bet"een the t"o )A-A statements# $ou declare all of the data $ou "ant to include in the common
data area!
The common area declaration must be e/actl$ the same in all of the programs in "hich $ou "ant
to use it! *t is therefore a good idea to put the declaration in an include program!
3ou can use seeral shared data areas in one program! *n this case# $ou must assign a name
nameto each! *f $ou onl$ hae one common area in each program# $ou do not hae to specif$ a
name! To aoid conflicts bet"een programs that hae different common area declarations# $ou
should al"a$s assign uni8ue names to common areas!
Assume an include program incommon contains the declaration of a shared area num&ers! The
common part comprises three numeric fields+ num8# numB and sum+
LLL*NC.)&0 incommon!
&ATA+ B0(*N 1, C1''1N PA%T numbers#
num1 T3P0 i#
num4 T3P0 i#
sum T3P0 i#
0N& 1, C1''1N PA%T numbers!
The program formpool includes incommon and contains the subroutines addit and out+
ABAP Programming (BC-ABA) ::E
P%1(%A' formpool!
*NC.)&0 incommon!
,1%' addit!
sum H num1 5 num4!
P0%,1%' out!
0N&,1%'!
,1%' out!
W%*T0+ ; ISum ofI# num1# IandI# num4# IisI# sum!
0N&,1%'!
A calling program formEtest includes incommon and calls the subroutine addit from the program
formpool!
P%1(%A' formStest!
*NC.)&0 incommon!
num1 H 4! num4 H >!
P0%,1%' addit(formpool)!
num1 H B! num4 H 11!
P0%,1%' addit(formpool)!
This produces the follo"ing output+
Sum of 4 and > is @
Sum of B and 11 is 1D
The subroutines in the program formpool access the global data of the shared data area!
Assume a program formpool that contains t"o subroutines ta&test8 and ta&testB as follo"s+
P%1(%A' formpool!
TAB.0S sflight!
,1%' tabtest1!
sflight-planet$pe H IA:1FI!
sflight-price H I1?F!FFI!
W%*T0+ ; sflight-planet$pe# sflight-price!
0N&,1%'!
,1%' tabtest4!
.1CA. sflight!
sflight-planet$pe H IBB>BI!
sflight-price H I?FF!FFI!
W%*T0+ ; sflight-planet$pe# sflight-price!
0N&,1%'!
Assume a program formEtest that calls ta&test8 and ta&testB as follo"s+
P%1(%A' formStest!
TAB.0S sflight!
P0%,1%' tabtest1(formpool)!
W%*T0+ ; sflight-planet$pe# sflight-price!
P0%,1%' tabtest4(formpool)!
W%*T0+ ; sflight-planet$pe# sflight-price!
formEtest then produces the follo"ing output+
A:1F 1?F!FF
A:1F 1?F!FF
BB>B ?FF!FF
A:1F 1?F!FF
All of the programs can access the table "or- area sflight# declared "ith the -AB0Sstatement!
*n the subroutine ta&testB# the global "or- area is protected against changes in the subroutine
b$ the OCAstatement!
-erminating Su&routines
A subroutine normall$ ends at the 0N&,1%' statement! 6o"eer# $ou can terminate them
earlier b$ using the 0_*T or C60CU statement! When $ou terminate a subroutine "ith 0_*T or
C60CU# the current alues of the output parameters (C6AN(*N( parameters passed b$ alue)
are passed bac- to the corresponding actual parameter!
)se 0_*T to terminate a subroutine unconditionall$! The calling program regains control at the
statement follo"ing the P0%,1%' statement!
ABAP Programming (BC-ABA) :>F
P%1(%A' ,1%'ST0ST!
P0%,1%' T0%'*NAT0!
W%*T0 IThe 0ndI!
,1%' T0%'*NAT0!
W%*T0 I1I!
W%*T0 I4I!
W%*T0 I:I!
0_*T!
W%*T0 I>I!
0N&,1%'!
The produces the follo"ing output+
1 4 : The 0nd
*n this e/ample# the subroutine T0%'*NAT0 is terminated after the third W%*T0
statement!
)se C60CU to terminate a subroutine conditionall$! *f the logical e/pression in the C60CU
statement is untrue# the subroutine is terminated# and the calling program resumes processing
after the P0%,1%' statement!
P%1(%A' ,1%'ST0ST!
&ATA+ N)'1 T3P0 *#
N)'4 T3P0 *#
%0S T3P0 P &0C*'A.S 4!
N)'1 H :! N)'4 H >!
P0%,1%' &*A*&0 )S*N( N)'1 N)'4 C6AN(*N( %0S!
N)'1 H ?! N)'4 H F!
P0%,1%' &*A*&0 )S*N( N)'1 N)'4 C6AN(*N( %0S!
N)'1 H 4! N)'4 H :!
P0%,1%' &*A*&0 )S*N( N)'1 N)'4 C6AN(*N( %0S!
,1%' &*A*&0 )S*N( N1 N4 C6AN(*N( %!
C60CU N4 N0 F!
% H N1 ; N4!
W%*T0+ ; N1# I;I# N4# IHI# %!
0N&,1%'!
The produces the follo"ing output+
: ; > H F!B?
4 ; : H F!@B
*n this e/ample# the s$stem leaes the subroutine &*A*&0 during the second call
after the C60CU statement because the alue of N4 is 9ero!
*f the 0_*T or C60CU statement occurs "ithin a loop in a subroutine# it applies to the loop# and
not to the subroutine! 0_*T and C60CU terminate loops in different "a$s (see .oops)# but behae
identicall$ "hen terminating subroutines!
Calling 2unction ,odules
This section describes calling function modules from the ,unction Builder!
2inding 2unction ,odules
Before programming a ne" function or creating a ne" function module# $ou should loo- in the
,unction Builder to see "hether there is an e/isting function module that alread$ performs the
same tas-!
,or more information about this# refer to ,inding ,unction 'odules in the ABAP Wor-bench
documentation! ,or e/ample# $ou might loo- for function modules that process strings b$ entering
LST%*N(L as a search criterion in the %epositor$ *nformation S$stem! This is an e/tract from
the list of function modules found+
ABAP Programming (BC-ABA) :>1
The title CS-( is the function group! Therefore# there is a function group SAPCS-( that
contains these function modules! *f $ou select a function module# $ou can displa$ its attributes in
the ,unction Builder!
*mportant attributes+
7 &ocumentation
The documentation describes the purpose of the function module# lists the parameters for
passing data to and from the module# and the e/ceptions!
*t tells $ou the input and output parameters of the function module# and "hich errors it
handles!
7 *nterface parameters and e/ceptions
This section proides further information about the interface parameters and e/ceptions# and
ho" to use the function module! ,or further information# refer to &ispla$ing *nformation
about *nterface Parameters in the ABAP Wor-bench documentation! ,unction modules can
hae the follo"ing interface parameters+
7 I,PO(-parameters! These must be supplied "ith data "hen $ou call the function
module# unless the$ are flagged as optional! 3ou cannot change them in the function
module!
7 0XPO(-parameters! These pass data from the function module bac- to the calling
program! 0XPO(- parameters are al"a$s optional! 3ou do not hae to receie them in
$our program!
7 C+AN/IN/ parameters! These must be supplied "ith data "hen $ou call the
function module# unless the$ are flagged as optional! The$ can be changed in the
function module! The changed alues are then returned to the calling program!
7 Tables parameters! 3ou use these to pass internal tables! The$ are treated li-e
C+AN/IN/ parameters! 6o"eer# $ou can also pass internal tables "ith other
parameters if $ou specif$ the parameter t$pe appropriatel$!
The interface parameters can be t$ped! 3ou can do so either b$ referring to ABAP &ictionar$
t$pes or elementar$ ABAP t$pes! When $ou call a function module# $ou must ensure that the
actual parameter and the interface parameters are compatible!
*nterface parameters are# b$ default# passed b$ alue! 6o"eer# the$ can also be passed b$
reference! Tables parameters can onl$ be passed b$ reference! 3ou can assign default alues
to optional importing and C+AN/IN/ parameters! *f an optional parameter is not passed in a
function module call# it either has an initial alue# or is set to the default alue!
70/ceptions are used to handle errors that occur in function modules! The calling program
chec-s "hether an$ errors hae occurred and then ta-es action accordingl$!
-esting 2unction ,odules
Before $ou include a function module in a program# $ou can test it in the ,unction Builder!
,or more information about this# refer to Testing ,unction 'odules in the ABAP Wor-bench
documentation!
Calling 2unction ,odules in ABAP
To call a function module# use the CA 2.NC-IONstatement+
CA.. ,)NCT*1N module
X0_P1%T*N( f
1
H a
1
!!! f
n
H a
n
Y
X*'P1%T*N( f
1
H a
1
!!! f
n
H a
n
Y
XC6AN(*N( f
1
H a
1
!!! f
n
H a
n
Y
XTAB.0S f
1
H a
1
!!! f
n
H a
n
Y
X0_C0PT*1NS e
1
H r
1
!!! e
n
H r
n
X0%%1%S'0SSA(0 H r
0
Y
X1T60%S H r
o
YY!
ABAP Programming (BC-ABA) :>4
3ou can specif$ the name of the function module moduleeither as a literal or a ariable! An actual
parameter a
8
# a
B
\ is e/plicitl$ assigned to eer$ interface parameter f
8
# f
B
\ used! A return
alue r
8
# r
B
\ can be assigned to each e/ception e
8
# e
B
\ The assignment al"a$s ta-es the form
interface parameter H actual parameter! The e8uals sign (H) is not an assignment operator in this
conte/t!
7 After 0XPO(-IN/# $ou must suppl$ all non-optional import parameters "ith alues
appropriate to their t$pe! 3ou can suppl$ alues to optional import parameters if $ou "ish!
7 After I,PO(-IN/# $ou can receie the e/port parameters from the function module b$
assigning them to ariables of the appropriate t$pe!
7 After C+AN/IN/ or -AB0S# $ou must suppl$ alues to all of the non-optional
C+AN/IN/ or tables parameters! When the function module has finished running# the changed
alues are passed bac- to the actual parameters! 3ou can suppl$ alues to optional C+AN/IN/ or
tables parameters if $ou "ish!
3ou can use the 0XC0P-IONS option to handle the e/ceptions of the function module! *f an
e/ception e
8
# e
B
\ is raised "hile the function module is running# the s$stem terminates the
function module and does not pass an$ alues from the function module to the program# e/cept
those that "ere passed b$ reference! *f e
8
# e
B
\ is specified after the option 0XC0P-ION# the
calling program handles the e/ception b$ assigning the alue r
8
# r
B
\ to s%-su&rc! 3ou must
specif$ r
8
# r
B
\ as a numeric literal!
*f $ou specif$ of 0((O(E,0SSA/0 in the 0XC0P-ION list $ou can influence the message
handling of function modules! Normall$# $ou should onl$ call messages in function modules using
the ,0SSA/09999(AISIN/statement! With 0((O(E,0SSA/0 $ou can force the s$stem to
treat messages that are called "ithout the (AISIN/ option in a function module as follo"s+
7 'essages of classes S# *# and W are ignored (but "ritten to the log in a bac-ground 2ob)!
7 'essages of classes 0 and A stop the function module as if the e/ception
0((O(E,0SSA/0 had occurred (s%-su&rc is set to r
0
)!
*f $ou specif$ O-+0(S after 0XC0P-IONS# the s$stem assigns a single return code to all other
e/ceptions that $ou hae not specified e/plicitl$ in the list!
3ou can use the same number r
8
# r
B
\ for seeral e/ceptions!
The recommended and easiest "a$ to call a function module is to use the *nsert statement
function in the ABAP 0ditor! *f $ou select Call ,unction and specif$ the name of the function
module (,> help is aailable)# the s$stem inserts a CA 2.NC-ION statements "ith all of the
options of that function module in the source code!
1ptional parts of the function call are inserted as comments! *n the aboe e/ample# S-(IN/ and
POSare obligator$ parameters! AN/.# on the other hand# is optional! *t has the default alue
s%-langu (the s$stem field for the logon language)! 6andling e/port parameters is optional!
ABAP Programming (BC-ABA) :>:
6andling e/ceptions is also theoreticall$ optional! 6o"eer# $ou should al"a$s do so! That is "h$
the 0_C0PT*1NS lines are not commented out!
3ou can trigger e/ceptions in the function module using either the (AIS0 or the ,0SSA/0 Z
(AISIN/ statement! *f the calling program handles the e/ception# both statements return
control to the program! The ,0SSA/099999 (AISIN/ statement does not displa$ a message in
this case! *nstead# it sets the follo"ing s$stem fields+
7 'essage class 7 s%-msgid
7 'essage t$pe 7 s%-msgt%
7 'essage number 7 s%-msgno
7 s%-msgv8 to s%-msgvD (contents of fields f8 to fD# included in a message)!
3ou can use the s$stem fields to trigger the message from the calling program!
To ensure that $ou use the right data t$pes for the actual parameters# $ou must refer to the
function module interface! *f $ou double-clic- the name of a function module in the source code
of $our program# the s$stem naigates to its source code in the ,unction Builder! 3ou can then
displa$ the interface b$ choosing (oto 7 *nterface!
,or e/ample# in the aboe case
7 S-(IN/# S-(IN/8# and S-(IN/Bhae the generic t$pe c! The actual
parameter must also hae t$pe c# but the length does not matter!
7 POSand POSEN0W hae the full$-specified t$pe i! The actual parameter
must also hae t$pe i!
7 AN/.also has a full$-defined t$pe# since it is defined "ith reference to
the ABAP &ictionar$ field S7-AN/.! The actual parameter must hae the same
t$pe!
A complete call for the function module S-(IN/ESPI-EA-EPOSI-ION might loo- li-e this+
(0PO(- demoEmodEtec$Ef&EstringEsplit9
)A-A= te5t(8@) -7P0 c !A.0 ?@8BCDGHIJK?4
te5t8(H) -7P0 c4
te5tB(H) -7P0 c9
PA(A,0-0(S position -7P0 i9
CA 2.NC-ION ?S-(IN/ESPI-EA-EPOSI-ION?
0XPO(-IN/
string F te5t
pos F position
I,PO(-IN/
string8 F te5t8
stringB F te5tB
0XC0P-IONS
string8EtooEsmall F 8
stringBEtooEsmall F B
posEnotEvalid F C
O-+0(S F D9
CAS0 s%-su&rc9
W+0N @9
W(I-0= A te5t4 A te5t84 A te5tB9
W+0N 89
W(I-0 ?-arget field 8 too s$ort\?9
W+0N B9
W(I-0 ?-arget field B too s$ort\?9
W+0N C9
W(I-0 ?Invalid split position\?9
W+0N D9
W(I-0 ?Ot$er errors\?9
0N)CAS09
The function module splits an input field into t"o output fields at a specified position! *f the
content of position is in the interal X>#@Y# the function module is e/ecuted "ithout an$
e/ceptions being raised! ,or the interals X1#:Y and XB#EY# the s$stem triggers the e/ceptions
string8EtooEsmall and stringBEtooEsmall respectiel$! ,or all other alues of position# the
e/ception posEnotEvalid is triggered!

ABAP Programming (BC-ABA) :>>

You might also like