You are on page 1of 72

Introduction to ABAP Programming

What Is ABAP?
ABAP stands for Advanced Business Application Programming. ABAP is a programming
language that was developed by SAP for developing commercial applications in SAP
environment.
The development process of ABAP went through the following evolutionary stages:
In early days (!"#s$ ABAP stood for %Allgemeiner Berichts&Aufbereitungs
Pro'essor( ()eneric *eport )eneration Processor$. That time ABAP was
implemented as a macro assembler under *+, and e-clusively used for creating
reports.
In mid !.#s/ ABAP had become an interpreted language and was powerful
enough to be used to create business application programs/ in particular to
program dialog&controlled transactions.
In early !!#s/ the SAP *+0 system was born and ABAP become ABAP+1/ that
ABAP 1)2 (1
th
)eneration Programming 2anguage$. It now formed the technical
and software basis of the entire SAP System. Apart from system core which is
written in 3/ all SAP application modules/ *+0 Basis System and the development
environment were now created in ABAP+1.
At the end of !!#s/ ABAP is e-tended with ob4ect oriented programming
constructs and from this point on/ the language was 5nown as ABAP 6b4ects.
In the beginning of ,###s ABAP programs were made 7nicode&3ompatible in
order to support the internationali'ation of the SAP System.
8ith SAP technology platform under the name %SAP 9et8eaver(/ ABAP become
the programming interface of the SAP 9et8eaver Application Server ABAP (AS
ABAP$.

Introduction to ABAP Programming


What is SAP NetWeaver?
SAP 9et8eaver is SAP:s (Systems Applications and Products in ;ata Processing$
technological platform (3omponents/ Tools and Applications$ which provides a runtime
and development environment for all SAP applications.
SAP 9et8eaver is the fully interoperable 8eb&based cross&application platform that can
be used to develop not only SAP applications but others as well. It allows a developer to
integrate information and processes from geographically dispersed locations using
diverse technologies/ including <icrosoft:s .9=T/ IB<:s 8ebSphere/ and Sun:s >ava
technologies.
SAP 9et8eaver is based on Structure 6riented Architecture (S6A$. S6A define methods
for systems development and integration where systems provide functionality as
interoperable services. The concept of a service/ specifically a 8eb service && is a 5ey part
of the S6A. A 8eb Service is defined by the 803 as ?a software system designed to
support interoperable machine&to&machine interaction over a networ5?. 2oose coupling
(no service is tightly attached to a single system$/ Interoperability and Portability define
the ground rules for development/ maintenance/ and usage of the S6A.
=nterprise S6A (eS6A$ is the term SAP gives to its own S6A tools and technologies.
SAP 9et8eaver platform comprises of the following components/ tools and applications:
,
Introduction to ABAP Programming
Components:
Application Server: Supports platform&independent 8eb services/ business
applications/ and standards&based development
Business Warehouse: Integrate data from across the enterprise and transform it
into information to drive sound decision ma5ing.
Business Process Management: Provides tools to help you model/ e-ecute/ and
monitor business processes based on a single/ consistent process model.
Process Integration: ;elivers S6A&based technology that supports application&
to&application (A,A$ and business&to&business (B,B$ integration/ and to
accelerate composite application development.
Master Data Management: =nsures cross&system data consistency and a single
version of master data for supplier/ product/ customer/ or user&defined data ob4ects
in heterogeneous environments.
SAP NetWeaver Mobile: Provides a mobile runtime environment based on open
and fle-ible technology standards and a powerful development environment for
building integrated mobile solutions with native or browser&based user interfaces.
SAP NetWeaver Portal: 7nifies critical information and applications to give
users role&based views that span the enterprise/ enabling you to ta5e full
advantage of your information resources.
SAP Auto-ID Inrastructure: )ives you all the capabilities you need to integrate
all automated sensing devices @ including *AI; (*adio AreBuency Identification$
technology electronically captures/ stores/ and transmits data readers and printers/
Bluetooth devices/ embedded systems/ and bar&code devices.
I!entit" Management: Celps companies manage users: access to applications
securely and efficiently/ while meeting audit and compliance reBuirements.
Inormation #iec"cle Management: =nables companies to decommission
redundant SAP system while preserving full auditing and reporting capabilities
for stored data.
$ools:
A!aptive Computing Controller: Provides a central point of control for
assigning computing resources and optimi'ing their use.
0
Introduction to ABAP Programming
Composition %nvironment: Provides a robust environment for design/
deployment/ and running of composite applications that comply with a service&
oriented architecture.
Developer Stu!io: 6ffers a convenient user interface and rich functionality for
developing >,== applications.
&isual Composer: Allows composing model&based business applications in a
fle-ible way/ without manual coding.
SAP Solution Manager: Application management solution facilitates technical
support for distributed systems.
Applications
%nterprise Search: Celps business users navigate critical business information
by enabling seamless/ secure access to SAP and non&SAP information and
processes.
Duet: =nables seamless access to SAP business processes and data via <icrosoft
6ffice.
Allo": Simplifies interaction with people/ processes/ and information by
providing intuitive access to SAP software and information via the familiar IB<
2otus 9otes.
SAP Central Process Sche!uling application b" 'e!(oo!s: Celps companies
manage/ monitor/ and e-ecute business&critical processes from a central location
by delivering adaptive/ real&time/ event&driven 4ob scheduling and process&
automation capabilities across distributed and heterogeneous platforms.
%nterprise Mo!eling Applications b" IDS Scheer: ;eliver 8eb&based
components that support the process life cycle for business process design/
analysis/ optimi'ation/ and implementation.
1
Introduction to ABAP Programming
Another (a" o !eining SAP NetWeaver)
SAP 9et8eaver is a set of capabilities that are provided by different SAP products
constructed to wor5 with each other to ma5e applications wor5 together/ build new
applications on top of e-isting applications and lower the Total 3ost of 6wnership
(T36$. T36 is about all the different e-penses involved in owning and running an
enterprise application.
The figure above depicts that the core capabilities of SAP 9et8eaver are consists of the
following four layers:
People Integration
Information Integration
Process Integration
Application Platform
D
Introduction to ABAP Programming
People Integration
People Integration means to bring people together and help them wor5 more efficiently.
Information Integration means to bring information from different locations and have it
ma5e sense in the conte-t what a user do everyday.
Process Integration
Processes Integration means coordinating the flow of wor5 across departments/ divisions
and between companies.
Application Platorm
Application Platform is called the SAP Application Server (SAP AS$. SAP AS is
foundation for the entire SAP software stac5. It is the engine behind the scene of SAP
9et8eaver that drives all SAPEs Applications and Tools. It provides a platform for
9et8eaver components (=nterprise Portal etc.$ and ABAP and >ava applications.
Composite Application *rame(or+
3omposite Application Aramewor5 (SAP 3AA$ is modeling and development
environment for creating composite applications. 3omposite applications are applications
built out of services provided by other applications.
#ie C"cle Management
The SAP 2ifecycle <anagement (SAP 2<$ offers all the functionality needed for
integrated product and asset management li5e Program and pro4ect management and
Fuality management.
G
Introduction to ABAP Programming
SAP Application Server
SAP Application Server (SAP AS$ is foundation for the entire SAP software stac5. It is
the engine behind the scene of SAP 9et8eaver that drives all SAPEs Applications and
Tools. It provides a platform for 9et8eaver components (=nterprise Portal etc$.
SAP systems are used for mapping business processes or business applications. These
applications should be implemented independent of the hardware environment used
(operating system/ database$ to the greatest e-tent possible. Aor this/ the SAP Application
Server provides two runtime environments: the ABAP runtime environment (AS ABAP$
and a >ava runtime environment (AS >AHA$. Both application servers wor5 on different
data (different database schemas$ and are lin5ed together by allowing mutual access
through the >ava 3onnector (>3o$.
Application Server ABAP
The Application Server ABAP provides the ABAP runtime environment that is a virtual
machine for ABAP programs independent of the hardware/ operating system and data
base system. Aigure below shows a simplified overview of the main AS ABAP
components.
AS ABAP can be used by user or by software/ including the remaining components of
SAP 9et8eaver. 7ser can access it using user interfaces that are available in the form of
"
Introduction to ABAP Programming
web browser or SAP )7Is installed on des5top P3s. Software components generally
access it through the networ5/ for which two protocols are used: CTTP+CTTPS+S<TP for
Internet connections and SAPEs own *emote Aunction 3all (*A3$ protocol for calling
ABAP functionality through any e-ternal clients.
The components of AS ABAP can be divided according to their tas5s into three layers of
a client&server system:
Presentation 2ayer
Application 2ayer
Persistence 2ayer
Presentation #a"er
The components of the presentation layer are responsible for the presentation of data to
users and the receiving of user entries. 7ser interfaces for AS ABAP include commercial
web browsers and SAPEs SAP )7I.
8hen web browsers are used in application programs/ CT<2 pages prepared in the
presentation layer are accessed. Application program access these CT2<2 pages through
the Internet 3onnection Aramewor5 (I3A$. The I3A uses standard protocols (CTTP/
CTTPS/ and S<TP$ to operate communications between systems through the Internet.
Presentation in a web browser is based on 8eb ;ynpro and Business Server Pages (BSP$.
SAP )7I is the graphical user interface that runs on a <icrosoft 8indows/ Apple
<acintosh or 79II des5top. The 3ontrol Aramewor5 (3A8$ supports controls (ActiveI
and >avaBeans$ that are implemented within the SAP )7I/ depending on the version of
SAP )7I currently in use. The presentation in the SAP )7I is based on the classical
dynpro technology.
Web Dynpro ABAP
8eb ;ynpro for ABAP (8;1A/ 8;A$ is the SAP standard 7I technology for
developing 8eb applications in the ABAP environment. It consists of a runtime
environment and a graphical development environment with special 8eb ;ynpro tools
that are integrated in the ABAP 8or5bench. 8eb ;ynpro is based on <odel Hiew
3ontroller (<H3$. <H3 is an architectural pattern used in software engineering. The
pattern isolates business logic from input and presentation/ permitting independent
development/ testing and maintenance of each.
Business Server Pages
Business Server Pages (BSP$ can incorporate server&side scripts written directly in ABAP
or >ava Script. It enables direct access to all elements in the application server (such as
function modules/ database tables/ ABAP 6b4ects/ and so on.$. BSP is similar to >ava
.
Introduction to ABAP Programming
Server Page (>SP$ as it is coded in CT<2 of AS ABAP Internet applications. BSPs
represent the predecessor technology of 8eb ;ynpro ABAP. BSP also supports <H3/
but is not a prereBuisite.
Dynpro
;ynamic program (;ynpro$ defines a user interface of an ABAP program in a window of
the SAP )7I. =ach dynpro is a component of an ABAP program. The screen of a dynpro
can contain a set of predefined screen elements or )7I controls. In addition to screen/ a
dynpro also contains a screen processing logic written in a separate programming
language that is called dialog modules in ABAP program.
7ser interfaces of new applications should be designed primarily with 8eb ;ynpro
ABAP/ even if it is not initially intended to use the system via the Internet.
The IC* and C*W provide services between the application program and presentation
layer.
Application #a"er
The application layer is the software layer in which application programs are e-ecuted.
The application layer contains a 5ernel written primarily in 3+3JJ that servers as a
platform for application programs which is independent from hardware/ operating system
and database. The 5ernel provides processors (virtual machines$ for the following
programming languages:
,S#$ an! S$
IS2T (eItensible Stylesheet 2anguage Transformation$ allows I<2 formats to be
converted into any other I<2 format. Simple Transformation (ST$ is an SAP&specific
language used to transform ABAP data to I<2 and vice versa. The IS2T and ST
processors e-ecute IS2T and ST programs. These programs are edited with
Transformation =ditor of the ABAP 8or5bench.
ABAP an! ABAP -b.ects
ABAP and ABAP 6b4ects (66 enhancement to ABAP$ is the programming interface of
AS ABAP for business management applications. The corresponding ABAP processor
accounts for the largest part of the AS ABAP 5ernel. ABAP programs are created with the
ABAP =ditor/ which can be used either as an independent application or as an add&on to
other tools such as 6b4ect 9avigator or 3lass Builder.
!
Introduction to ABAP Programming
/ava Script
>avaScript programs are e-ecuted by >avaScript processor. Hariables of the script can be
lin5ed to data ob4ects of an ABAP program. 7se of >avaScript on AS ABAP has
negligible significance. There is no dedicated editor for >avaScript programs in the ABAP
8or5benchK the CL_JAVA_SCRIPT system class provides an interface to the >avaScript
=ngine.
-b.ect Services
6b4ect Services provide global services/ which ABAP 6b4ects language elements cannot
provide themselves/ to applications written in ABAP 6b4ects. These 6b4ect Services
include: A Persistence Service/ A Transaction Service/ and A Fuery Service.
Persistence #a"er
The persistence layer is the software layer in which persistence data is held in a database.
=ach AS ABAP accesses a central database on which its entire dataset is stored. This
means that not only the application types/ but also all administrative data/ customi'ing
settings and ABAP source codes.
The central database can be accessed by ABAP programs through the !atabase interace
of AS ABAP. This interface ma5es AS ABAP independent from the database system that
is actually used. The database interface is subdivided into an 6pen SF2 interface and
SF2 interface.
-pen S0# is a sunset of SF2 reali'ed by ABAP statements and includes the ;ata
<anipulation 2anguage (;<2$ portion. The statements of 6pen SF2 access the AS
ABAP database through the 6pen SF2 interface/ irrespective of the platform. The 6pen
SF2 interface converts the 6pen SF2 statements into manufacturer specific SF2 and
passes it onto the ;B<S. 8ith 6pen SF2 you can read (SELECT$ and change
(INSERT, UPDATE, MODIFY, DELETE$ data in database tables that are defined in
the ABAP ;ictionary. 6nly the statements from 6pen SF2 should be used in application
programs.
Native S0# interface passes on the manufacturer&specific SF2 statements/ unchanged to
the ;B<S. 9ative SF2 refers to statements that can be e-ecuted in ABAP programs
between EXEC SQL and ENDEXEC statements.
Communication Components
3ommunication components are position somewhat aside from the three layers:
Inter Communication Manager
#
Introduction to ABAP Programming
Internet 3ommunication <anager (I3<$ is a process in ABAP 5ernel that allows it to
communicate directly with the Internet via CTTP+CTTPS+S<TP. I3< allows connection
to web based presentation components such as 8eb ;ynpro ABAP and BSP. It also
enables and AS ABAP to act both as a client and as a server for 8eb Services. ABAP
program access the I3< through the classes and interfaces of the Internet
3ommunication Aramewor5 (I3A$.
'emote *unction Call Interace
*emote Aunction 3all (*A3$ is an invocation of a function that is located in a different
system than the one in which the calling program is running. 3alls are possible between
different AS ABAPs/ or between an AS ABAP and e-ternal system.

Introduction to ABAP Programming


AS ABAP Processes
The SAP runtime system consists of a number of parallel processes that wor5 together.
The following graphic illustrates the most important processes of application server
ABAP.
AS ABAP Processes
In addition to several wor5 processes whose number and type are determined at the
startup of AS ABAP/ each ABAP application server contains a dispatcher/ a gateway/
I3< and a message server.
Dispatcher
The dispatcher is the lin5 between the wor5 processes and the users logged onto the
ABAP application server (that is/ the SAP )7Is of the users$. Its tas5 is to receive
reBuests from the SAP )7I and direct them to a free wor5 process. In the same way/ it
directs screen output bac5 to the appropriate user. If all the wor5 processes are occupied
the reBuests are stored in the dispatcher Bueue.
Wor+ Processes
8or5 processes are software components that e-ecute an application. =ach wor5 process
is lin5ed to a memory area containing the conte-t of the application being run. The
conte-t contains the current data for the application program. There are the following
types of wor5 process:
,
Introduction to ABAP Programming
Dialog: Aulfill all reBuests for the e-ecution of dialog steps triggered by an active
user. =very dispatcher reBuires at least two dialog wor5 processes.
Update: =-ecute update reBuests. At least one update wor5 process per SAP
system and you can have more than one per dispatcher.
Background (batch): =-ecute programs that run without interacting with the user.
Lou need at least two bac5ground wor5 processes for each SAP system. Lou can
configure more than one bac5ground wor5 process for each dispatcher.
Enqueue: Administers the loc5 table in the shared memory. The loc5 table
contains the logical database loc5s of the ABAP stac5 of the SAP system. 6nly
one enBueue wor5 process is needed for each system.
Spool: Pass seBuential data flows on to printers. =very SAP system reBuires at
least one spool wor5 processK you can also have more than one spool wor5
process per dispatcher.
Internet Communication Manager
The Internet 3ommunication <anager (I3<$ enables SAP systems to communicate
directly with the Internet. The I3< receives reBuests from the Internet and forwards them
to the SAP system for processing. It can also direct CTTP reBuests from an SAP system
to a 8eb server and send the response bac5 to the SAP system. Lou can configure a
ma-imum of one I3< process per application server. <emory Pipes are memory&based
communication ob4ects that are used to transfer data between the I3< and the wor5
processes.
Message Server
The message server (<S$ handles the communication between the distributed dispatchers
within the ABAP stac5 of an SAP system/ thereby enabling scalability of several parallel
application servers. The message server is configured only once per SAP system.
1ate(a"
The gateway ()8$ enables communication through *A3 interface between SAP systems/
or between SAP systems and e-ternal application systems. There is one per dispatcher.
0
Introduction to ABAP Programming
Memor" -rgani2ation o AS ABAP
AS ABAP is the system in which an ABAP programs runs. Arom software point of view/
the application layer of an AS ABAP is spread across at least one/ but usually several/
application servers. If an AS ABAP has several application servers/ they are usually also
installed on several machines/ whose operating systems donEt have to be identical.
ThereforeK in application layer there is <essage Server (<S$ that is responsible for
communication between the application servers.
=ach application server provides a range of services of operating the AS ABAP. The
services of an application server are implemented by wor5 processes/ whose number and
types are set when the AS ABAP is started. 8or5 processes are software components that
can e-ecute an application. There are different types of wor5 processes for different
applications: dialog/ enBueue/ bac5ground/ spool and update wor5 processes.
8or5 process is logged on as a user to the database system for the entire runtime of an
AS ABAP. ;uring the ASP ABAP runtime/ a database logon canEt be passed on from one
wor5 process to another. SAP <emory <anagement is used for memory areas of an
application server.
Aigure below shows where an ABAP program runs on an application server and what
memory areas it can access here.
1
Introduction to ABAP Programming
AS Memor" -rgani2ation
The memory areas of an application server that can be accessed in an ABAP program are
as follows:
Shared <emory
SAP <emory
ABAP <emory
*oll Area
Share! Memor"
=ach application server has its own shared memory. The shared memory is the memory
area that is used by all parts of an application server together. The ABAP runtime
environment uses the shared memory for programs/ program data and buffering (from
database in data dictionary in a table buffer$. ABAP programs can access shared ob4ects
and data clusters in the shared memory.
SAP Memor"
8hen a dialog user or an e-ternal client (via *A3 or I3A$ logs on to an AS ABAP/ it is
connected to an appropriate application server and opens a user session on this AS.
=ach user session is assigned its own memory area/ the SAP <emory/ in which all ABAP
programs of a user session have 4oint access to SPA+)PA parameter (7sed to fill the input
fields of a called transaction with data from the calling program$. The corresponding
statements are SET PARAMETER and GET PARAMETER. These parameters are only
suited to saving short character&type fields/ such as the name of the last programs called.
The input fields of dynpros can be lin5ed to SPA+)PA parameters and in order to pre&fill
them before a dynpros is called.
ABAP Memor"
At least one main session or e-ternal mode is opened for each user session. In dialog
processing/ a user session can manage up to G main sessions/ each of which is lin5ed to
separate window. If you e-ecute the function 3reate 9ew Session in the SAP )7I/ or
enter a transaction code behind +o in the input window of standard toolbar/ you open a
new main session in a new window. Arom an ABAP program a new main session can be
open via *A3 (CALL FUNCTION STARTING NEW TASK$.
=ach main session is assigned a separate memory area/ 5nown as the ABAP <emory/ in
which data clusters can be stored. The data in the ABAP memory is retained during a
seBuence of program calls within a call seBuence.
D
Introduction to ABAP Programming
A call seBuence is formed if you can return from called program to the calling program.
This is always the case when you call an ABAP program with SUBMIT AND RETURN
or CALL TRANSACTION. 6nly programs of a call seBuence have common access to
data in the ABAP memory/ and this is primarily for data transfer during program calls.
8hen the first program of a call seBuence is terminated/ the corresponding ABAP
memory is also released.
'oll Area
8ith each call via SUBMIT or CALL TRANSACTION or LEAVE TRANSACTION of an
ABAP program in main session/ an internal session is opened. A memory area called a
*oll Area is assigned to the internal session/ in which the data and ob4ects of an ABAP
program are stored while it is e-ecuted. This is the actual memory of an ABAP Program.
8ith program calls/ a ma-imum of nine internal sessions can be stac5ed as a call
seBuence in a main session. In main session/ only the internal session of the program that
is 4ust running e-ists in am active version. All memory content of previous programs is
saved on the stac5.
Technically each internal session is divided into a Program =-ecution Area (PIA$ and a
*oll Area. The PIA is further common memory area of the application server in which
the unchangeable data (bytecodes$ of t he programs that are currently running there is
stored. 6nly the roll area is individually reserved for an internal session and contains its
changeable data.
An internal session will e-ist for as long as its first program/ the main program/ is
e-ecuted. The additional loaded programs and their data also remain loaded until the end
of the internal session.
All programs of an internal session have 4oint access to anonymous data ob4ects and
instances of classes created with CREATE. 8ithin internal session/ references to ob4ects
can be copied from one program to procedures of another program.
6n G1&bit platform/ an internal session can theoretically reBuire up to 1TB of memory.
6n 0,&bit platforms/ the theoretical ma-imum limit is 1)B.
G
Introduction to ABAP Programming
ABAP3 A Practical Intro!uction
Change an! $ransport S"stem 4C$S5
The SAP 9et8eaver repository is the central place where development components in
the ABAP 8or5bench are stored. These components include all of the: process models/
data models/ business ob4ect models/ business ob4ects/ and all data and their relationships.
The repository also includes the ABAP ;ictionary.
The 3TS is the central tool for managing changes to repository ob4ects that you ma5e in
the ABAP 8or5bench. The 3TS records all changes in transport+change reBuests. 8hen
you have finished your wor5 in ABAP 8or5bench/ or have reached a certain stage/ you
can release the reBuest. The change reBuest is then used to copy the changes from this
client to other clients or systems. This automatic procedure is 5nown as a transport.
Transports of changes by the 3TS allow you to develop in one environment/ test your
development wor5 in a test environment/ and then/ if the tests are successful/ use it
productively. This ma5es sure that productive operations are not placed at ris5 by faulty
settings or program errors.
3TS enable you to define transport layer as an attribute of a pac5age. The transport layer
refers to the transport path a pac5age should ta5e in a system landscape. The usual
landscape has a least three layers:
The transport layer by itself does not transport anything. Lou need a transport+change
reBuest to get something transported.
A change reBuest can be created in two ways:
"
Introduction to ABAP Programming
. 8hen you create or modify ob4ects in the ABAP 8or5bench/ a window appears
as5ing you to assign the ob4ect to an e-isting change reBuest (6wn reBuests$ or to
create a new change reBuest (3reate reBuest$. See Pac5age 3reation Topic.
,. Through Transport 6rgani'er (S=#!$.
Creating a 'e6uest in the $ransport -rgani2er:
. To start application server/ follow the path Start &M Programs &M SAP
9etweaver ".# ABAP Trial Hersion &M 9SP &M Start Application Server.Select
3reate (AG$ to create new transport reBuest.
,. 2og on as a B37S=*.
.
Introduction to ABAP Programming
0. =nter S=#! transaction code in the te-t field of standard toolbar to open the
Transport 6rgani'er.
1. Select the 3reate (AG$ function from the toolbar of Transport 6rgani'er to
create new transport reBuest.
D. Select 8or5bench reBuest and clic5 continue.
G. 3reate *eBuest dialog will appear/ enter short description of the change
reBuest. And 3lic5 Save.
!
Introduction to ABAP Programming
". This will open up the ;isplay *eBuest 8indow/ where you can see the change
reBuest in hierarchal order. Lou can use it now during ob4ect creations.
,#
Introduction to ABAP Programming
Pac+ages
Pac5ages are used to organi'e development ob4ects (programs/ tables/ screens/ BAPIs/
function modules/ types/ and so on$ and handle their connection to the ABAP software
logistics (3hange and Transport System$. All ob4ects that can be changed using ABAP
8or5bench (*epository 6b4ects$ are part of pac5age. =very AS ABAP contains a
predefined pac5age named NT<P. NT<P pac5age is used for local practice and test
programs. =very pac5age starting with N character is considered local and canEt be
transported to other SAP system.
Pac5ages help developers to modularize/ encapsulate/ and decouple units in the SAP
System. Pac5ages may have the following attributes:
Nesting: allows to embed pac5ages in other pac5ages. 8ith nesting you can split
up larger units of the SAP System and structure them in a hierarchy.
&isibilit": is a property of pac5age elements. Arom the outside/ a pac5age loo5s
li5e a ?blac5 bo-.? They are always visible to other elements in the same pac5age
and always invisible to embedded (sub&$pac5ages within their pac5age. Aor an
element to be visible outside the pac5age/ it must be contained in at least one
pac5age interface.
7se access: is the right of one pac5age to use the visible elements in the interface
of a second pac5age (but not the other way round$.
8hen we create a pac5age/ we specify the following properties:
Pac5age: The name of the pac5age to be created. The name should follow the
customer namespace conventions.
;escription: To define the pac5age.
Application 3omponent: ;etermine the location of the pac5age within the
application hierarchy by specifying the corresponding application component.
Software 3omponent: The software component describes a set of development
ob4ects that can only be delivered in a single unit. Aor customer developments you
should enter C6<= as the software component.
Transport 2ayer: The transport layer determines if the ob4ects of this pac5age are
to be transported to a subseBuent system and/ if so/ to which system.
Pac5age Type: Lou can choose between three pac5age types:
o Standard pac5age + 9ot a main Pac5age (3an contain *epository ob4ects
and other pac5ages$
o <ain pac5age (3an only contain other pac5ages$
o Structure pac5age (3an only contain main pac5ages$
,
Introduction to ABAP Programming
Note: Values like pplication ! So"t#are component is de$eloped b% s%stem administrator
#hen s%stem is created&
Creating Package
Pac5age can be created in two ways:
a$ In the navigation area of 6b4ect 9avigator (S=.#$/ choose the ob4ect type
Pac5age from the ob4ect list and enter the name of the pac5age in the input field
below. 3hoose =nter. If the specified pac5age does not already e-ist/ the system
branches to a dialog for creating a pac5age.
b$ 3all the pac5age builder (S=, or SPA3OA)=$. =nter Pac5age 9ame and push
3reate button.
. =nter the following properties in 3reate Pac5age dialog.
a$ Pac5age: PQ<yPac5age
b$ ;escription: <y Training and ;emo Programs
c$ Application 3omponent: 3A (Press A1 for selection and A for detail
help$.
d$ Software 3omponent: Come (Press A1 for selection and A for detail
help$.
e$ Transport 2ayer: P9SP (Aor our demo system you should use the transport
layer P9SP$.
f$ Pac5age Type: 9ot a main Pac5age (since <ain Pac5age canEt directly
contain development ob4ects$.
,,
Introduction to ABAP Programming
,. After selecting Save you will be prompted for a transport reBuest.
0. If you have already created transport reBuest/ push 6wn *eBuests button or select the
3reate button to create new one.

1. In new create reBuest dialog enter short description.
Note: 'n a real(#orld de$elopment pro)ect %ou #ill al#a%s use a transport request
that is created in the *ransport +rganizer (SE,-) and paste this into the dialog #ith
,0
Introduction to ABAP Programming
the header .rompt "or transportable /orkbench 0equest1 i" %ou )ust need a transport
request #ithout an% particular properties1 %ou can do it the #a% #e do it here&
D. Pressing the Save button opens another dialog window and we are done with
transport reBuest.
G. 3lic5ing 3ontinue will bring Pac5age Builder: 3hange Pac5age 8indow. 3hec5 the
Pac5age 3hec5 as Server. This ensures that only ob4ects declared in the pac5age
interface of the pac5age can be addressed from other transportable pac5ages. 3lic5
Save button on standard toolbar and close the Pac5age Builder.
,1
Introduction to ABAP Programming
Creating 8ello Worl! Program in Pac+age
. =nter S=.# in te-t field of standard toolbar to open 6b4ect 9avigator.
,. Select Pac5age from 6b4ect 2ist and type PQ<yPac5age into te-t field below and
press return 5ey. Lou will see that our pac5age is now visible in the *epository
Browser.
0. *ight&clic5 on the pac5age PQ<yPac5age and choose 3reate @ Program.
1. =nter the name of the program we want to create PQAQC8. ;eselect %8ith T6P
I932( (Top Include$ because we do not need a top include and confirm.
D. 9e-t dialog shows the properties of the new program. 6ne of the most important
program properties of an ABAP program is its type. Arom the list provided/ we want
to select the type ?=-ecutable program? for our simple Cello&8orld program/ and
change or add no other properties. In particular/ ensure that the properties ?7nicode
chec5s active? (strict static type chec5s/ separation of byte and character string
processing$ and ?Ai-ed point arithmetic? (for decimal numbers the decimal separator
is ta5en into account in calculations$ should always be chec5ed. 2ogical ;atabases
option is no more used in ABAP 6b4ects. Press Save button.
,D
Introduction to ABAP Programming
G. 3reate 6b4ect ;irectory =ntry dialog appears/ clic5 save to continue. The 6b4ect
;irectory is a directory of all the *epository 6b4ects that ma5e up the SAP System.
8hen you create an ob4ect/ the corresponding ob4ect directory entry is also created.
". 9e-t dialog prompt for transport reBuest. The transport reBuest our pac5age belongs
to is already in the relevant field. Again 3onfirm it.
,G
Introduction to ABAP Programming
.. 9e-t the ABAP =ditor is appear/ where you write code. 3lic5 Les if you wanted to
chec5 the Buic5 start.
!. To configure the new ABAP =ditor go to 7tilities Settings Aront&=nd =ditor
(9ew$.
#. Lou can also double clic5 the program name to open ABAP =ditor.Lou can see the
framewor5 predefined by the ABAP 8or5bench. This synta- consists of a few lines
of comments/ and also contains an initial statement named *eport.
,"
Introduction to ABAP Programming
. To change the program. )o to the change mode by pressing the respective button:
Below the report&statement enter:
,. To format the source code. ABAP =ditor uses the Pretty Painter. To configure it go to
7tilities Settings Pretty Painter. 3hec5 Indent and 3onvert 7ppercase
+2owercase.
0. 3lic5 the Pretty Painter button in the ABAP =ditor and the format of statements
changes.
,.
Introduction to ABAP Programming
1. To chec5 the syntactic corrections/ select 3hec5 from the conte-t menu of the
program name in ob4ect list. 6r 3hec5 button from standard toolbar.
D. The error&free program must be activated. Select Activate function . ;uring The
error&free source code is converted to byte code that is stored in the database. After
activation program will be visible to every user using System Services
*eporting.
G. To run the program we press the icon: or =-ecute ;irect from conte-t menu
of program name or by pressing A..
". The e-pected %Cello 8orld( output appears in a special screen.
9ote: ABAP Programs can be e-ecuted by two ways. 7sing the =-ecute function or
transaction codes (SA0. and S=0.$. SA0. can be used only to e-ecute or run a program.
It is more recommended to use by Aunctional 3onsultants+7sers of the program to reduce
the ris5 of mista5enly modification or deletion of the program. S=0. is use to display an
ABAP =ditor screen where transaction is not limited only to program e-ecution but also
to display or modify the program code. SA0. can be used also by ABAPers to e-ecute
the program. Also to call the program from other program the use the S7B<IT R.
,!
Introduction to ABAP Programming
statement. 8ith addition A9; *=T7*9 specify the system returns to the caller after the
called program is terminated.
SA9: Call
S%9: Call
ABAP programs can also be called through transaction codes (transaction maintenance
S=!0$. To call transactions from other program use the statement 3A22
T*A9SA3TI69 R. and to abort the calling transaction use 2=AH= T*A9SA3TI69.
.. To display the %Cello 8orld% is message bo- change the code to:
0#
Introduction to ABAP Programming
As a result a dialog window greets the world. Instead of EIE try =/ I for type message.
-utput (ith $"pe ;I<
-utput (ith $"pe ;%<= message (ill be sho(n in status bar
Dissecting the Hello World Program
ABAP program consists of statements. Statements are composed of to5ens and
terminated by Period (.$. To5ens must be separated by at least one space. Possible to5ens
include Oeywords/ 6perands/ 6perators and Special 3haracters. In our e-ample
*=P6*T is the 5eyword and PAC8P is the operand. ABAP 5eyword determines the
category of the statement. (e.g. <odulari'ation/ 3ontrol/ 3all and 6perational
Statements$.
0
Introduction to ABAP Programming
=very standalone ABAP program/ that is/ all types of programs e-cept for so&called
include programs/ start with an introductory statement. In our first program/ the
introductory statement is *=P6*T. The *=P6*T 5eyword e-presses the fact that
historically e-ecutable program was once e-clusively used for reporting.
After the introductory statement/ every ABAP program follows a fi-ed program structure
that divides it into two parts:
a$ )lobal ;eclaration part
b$ Procedural part
)lobal declaration part directly follows the introductory statement. ;eclarative
statements can be used for definitions and declarations/ which will be visible and
applicable throughout the entire ABAP program. =-amples of ob4ects that can be
declared or defined here are data types/ classes/ interfaces/ data ob4ects and screens. Aor
larger programs/ these declarations are generally made in a special include program/ the
?top include/? which is supported by the ABAP 8or5bench and inserted at this position.
The ;ATA statement declares a data ob4ect msg of type string and initiali'es it to a start
value %Cello 8orld%.
After the global declaration part comes the procedural also 5nown as implementation
part/ in which the actual processing logic of the ABAP program is implemented. The
implementation part is divided into individual procedural units that are referred to as
Processing Bloc5s. =very ABAP statement that is not part of global declaration part
always belongs to e-actly one processing bloc5. Statements within processing bloc5 are
processed seBuentially. The arrangement of processing bloc5s in the implementation part
is not significant for program e-ecution. The order in which processing bloc5s are
e-ecuted is controlled by calls (from other processing bloc5$ or by the ABAP runtime
environment. =ach time a program is e-ecuted/ at least one processing bloc5 is called by
the runtime environment as a point of entry/ which/ in turn/ can call additional processing
bloc5s of same or other program. 8hen first processing bloc5 of a program is called/ the
entire program is loaded into the memory. 8hen the last processing bloc5 is terminated/
control is returned to the calling program or runtime environment. Processing bloc5s
canEt be nested.
To 5eep the program readable/ select a semantically relevant program structure and ma5e
the structure visible using comment lines. The following types of processing bloc5s are
available.
Procedures (methods/ subroutines and function modules with their own local
data area$
;ialog modules (processing bloc5s without local data$
=vent bloc5s (handle events of processes in the ABAP runtime environment$
0,
Introduction to ABAP Programming
STA*T&6A&S=2=3TI69 statement introduces a processing bloc5 which plays the same
role in e-ecutable programs as the main method in >ava program. That is/ when program
is e-ecuted/ the implementation of the bloc5 is automatically called.
The 8*IT= statement outputs a list and it is driven by the classic SAP ;ynpro
technology which should not be used to applications with state&of&the&art user interface.
Lou should use ;ynpro&based 7Is only in test&programs if you want to output (or input$
some values in a Buic5 and dirty way. Lou can compare the write&statement to the output
to the console in >ava.
3omment lines are introduced by an asteris5 S in the first position. To mar5 only the final
portion of a line as a comment/ you can use the character %.
-b.ect -riente! &ersion o >8ello Worl!? Program
. Select 3reate 3lass 2ibrary 3lass from the conte-t menu of PQ<yPac5age in
the *epository Browser. It will pop up the 3reate 3lass dialog.
,. Set the following fields in 3reate 3lass dialog.
9ame: PQ32QC8
3lass Type: 7sual ABAP 3lass
Brief ;escription: <y hello world class
Instantiation: Public
Ainal: 3hec5 (<eans that this class canEt be inherited$
00
Introduction to ABAP Programming
0. Press Save button and you will be presented with 3reate 6b4ect ;irectory =ntry
dialog/ clic5 save to continue.
1. 9e-t dialog prompt for transport reBuest. The transport reBuest our pac5age belongs
to is already in the relevant field. Again 3onfirm it.
D. In the 3lass Builder/ select the Attributes tab to define attribute for a class. An
attribute is a data ob4ect declared within the class. =nter the following values in
respective columns.
Attribute: msg
2evel: Instance Attribute
Hisibility: Private
Typing: Type
Associated Type: string
01
Introduction to ABAP Programming
G. 9e-t to define the method/ clic5 on <ethods tab. To define constructor push
3onstructor (AD$ button in class builder. To declare method/ enter the following in
respective columns write after the 369ST*73T6*.
<ethod: printQhello
2evel: Instance
Hisibility: Public
;escription: This method will print hello world message
". To implement the methods clic5 the Source 3ode function .
.. Type the following statement in constructor. <a5e sure that the cconstructor is
selected in the list. To switch between the class builder and editor select previous
button and ne-t button .
!. 9e-t type the following statement in printQhello method.
#. This concludes the definition of class in class library so chec5 and activate the class.
The dialog displays pending inactive ob4ects. 3lic5 3ontinue to activate.
0D
Introduction to ABAP Programming
. To consume this class/ letEs create the program of type Subroutine pool.
Note: Subroutine pool is a t%pe o" B. program1 #here local classes are created and
their public methods are connected to transaction codes&
,. *ight&clic5 on the pac5age PQ<yPac5age and choose 3reate @ Program.
0. =nter the name of the program we want to create PQ66QC8. ;eselect %8ith T6P
I932% (Top Include$ because we do not need a top include and confirm.
1. 9e-t dialog shows the properties of the new program. Arom the type list select the
type ?Subroutine Pool? change or add no other properties. In particular/ ensure that
the properties ?7nicode chec5s active? and ?Ai-ed point arithmetic? should always be
chec5ed. Press Save button.
0G
Introduction to ABAP Programming
D. 3reate 6b4ect ;irectory =ntry dialog appears/ clic5 save to continue.
G. 9e-t dialog prompt for transport reBuest. The transport reBuest our pac5age belongs
to is already in the relevant field. Again 3onfirm it.
". This will open the ABAP =ditor/ enter the following listing.
0"
Introduction to ABAP Programming
.. 9ow if you activate and =-ecute (A.$ the program. It wonEt wor5/ because subroutine
pool has no pre&defined starting point li5e STA*T&6A&S=2=3TI69 for e-ecutable
programs. To solve this problem we have to define the transaction code.
9ote: Transaction li5e the name %report% for e-ecutable program/ is historical in nature
and the reason for this conte-t is e-plained by the fact that a classical ABAP application
program generally e-ecuted a business transaction on the database table. Aor us the
transaction means the e-ecution of an ABAP program via %Transaction 3ode%. It is a
twenty&character name which is assigned to a screen or a method of an ABAP program
and is used for program e-ecution.
!. Select 3reate other($ Transaction from the conte-t menu of our pac5age in the
repository browser and fill the dialog window that appears.
Transaction 3ode: PQC8
Short Te-t: Cello 8orld
Start 6b4ect: <ethod of a class and Select 3ontinue.
0.
Introduction to ABAP Programming
,#. 6n ne-t screen maintain 66 transaction.
66 Transaction <odel: 7nchec5 (to fill the input fields$
3lass 9ame: 'QclQclient
<ethod: main
2ocal in Program: 3hec5
2ocal in Program: PQ66QC8
,. 3lic5 Save on standard toolbar.
,,. 3reate 6b4ect ;irectory =ntry dialog appears/ clic5 save to continue.
0!
Introduction to ABAP Programming
,0. 9e-t dialog prompt for transport reBuest. The transport reBuest our pac5age belongs
to is already in the relevant field. Again 3onfirm it.
,1. To run/ enter the ToPQC8 in the input field of the standard toolbar. +o runs the
program in new window/ in contrast to +n.
Dissecting the OO Hello World Program
The declaration part contains the declaration of local class 'QclQclient. The public section
show defines the public visibility of the static method main which is defined with
32ASS&<=TC6; statement.
The implementation part of local class must implement between 32ASS......
I<P2=<=9TATI69 and =9;32ASS. Between <=TC6; ... and =9;<=TC6; we
provide the implementation for method.
The main method is a user for our global class. The *=A T6 means that ob4 is a
reference variable which is pointing to 'QclQclient reference type or class. The 3*=AT=
6B>=3T creates the ob4 ob4ect. The selector &M is used for accessing an instance public
component.
1#
Introduction to ABAP Programming
ABAP Program $"pes
7nli5e >ava where programs are simply containers for classes/ there are different ABAP
programs types that play different roles on the application server ABAP. The program
type defines the basic technical attributes of a program/ that is/ which processing bloc5s a
program may contain how the program is handled and e-ecuted by the ABAP runtime
environment/ and whether it can wor5 with its own screens (Also 5nown as dynpros$ are
the most general type of user dialog in SAP applications before 9et8eaver. Lou do not
define them in ABAP programs/ but instead in the Screen Painter.$.
8hen you run an ABAP application program/ you must call at least the first processing
bloc5 from outside the program/ that is/ from the runtime environment. This processing
bloc5 can then either call further processing bloc5s or return control to the runtime
environment. 8hen you start an ABAP program/ the runtime environment starts a
processor (dependent on the program type$/ which calls the first ABAP processing bloc5.
The program can be started either by the user or by the system (for e-ample/ in
bac5ground processing$/ or through an e-ternal interface/ for e-ample/ for *emote
Aunction 3alls (*A3$.
There are seven program types from which you can choose: e-ecutable program/ module
pool/ function group/ class pool/ interface pool/ subroutine pool/ and include program.
Class Pools @ 1lobal Class
3lass pool is a container for e-actly one global class and more than one data types and
local ob4ect types (local classes and interfaces$. All the reusable code is programmed
here. A class pool is loaded into memory by using the global class/ for e-ample/ a public
method of global class can be called from another ABAP program or it can be lin5ed with
a transaction code. They are declared with the CLASS-POOL statement but as it is
created with 3lass Builder (S=,1$ of ABAP 8or5bench/ which means it is generally not
displayed as a single continues source code.
Interace Pools @ 1lobal Interace
Interface pool is a container for e-actly one global interface. The global interface can be
implemented in any global or local classes. They are introduced with the INTERFACE-
POOL statement. Interface pool is created in 3lass Builder (S=,1$ of the ABAP
8or5bench.
*unction 1roups @ *unction Pools
Aunction group contains a procedures (Aunction <odules$ processing bloc5. Aunction
groups and their function modules are the procedural predecessors of global classes with
public methods. Aunction groups (li5e e-e programs and module pools$ can contain
1
Introduction to ABAP Programming
dynpros as components/ which is not possible in class pools. If you reBuire wor5ing with
dynpros in ABAP 6b4ects then function groups is the first choice. Aunction groups are
also reBuired for *A3s. Lou can call function groups from methods but no more
functional coding should be created in function modulesK instead you should branch from
there into methods. Aunction pools are introduced with the FUNCTION-POOL statement
and maintained with Aunction Builder (S=0"$ of ABAP 8or5bench.
Subroutine Pools
Subroutines pool contains a subroutine processing bloc5s that can be called by other
programs. The use of subroutine is obsolete in ABAP 6b4ects. Cowever/ you can create
local classes in subroutine pools and connect their public methods to a transaction code.
A subroutine pool that contains a class with a main method that is connected to a
transaction code is very similar to >ava program. Subroutine pools are created using the
ABAP =ditor (S=0.$ of ABAP 8or5bench and are introduced with the PROGRAM
statement.
%Aecutable Programs
=-ecutable programs can contain all processing bloc5s supported in ABAP/ with the
e-ception of function modules/ and as many local classes as reBuired. =-ecutable
programs are often referred to as reports/ and why running an e-ecutable program is often
called reporting. Analogously/ the source code of an e-ecutable program starts with the
REPORT statement. 6nly e-ecutable programs can be called using their name. In ABAP
6b4ects/ e-ecutable should only be used if direct e-ecution using the name is important.
Aor technical point of view/ e-ecutable programs are currently only reBuired for
bac5ground processing. Today you should only handle the STA*T&6A&S=2=3TI69
event of the reporting (e-e program$ process and 4ump from the corresponding processing
bloc5 directly to a method of a local class. It is maintained directly in the ABAP =ditor
(S=0.$ of ABAP 8or5bench.
=-ecutable programs are only started with the SUBMIT statement. Although 9et8eaver
AS ABAP offers several ways to call e-ecutable programs by entering their name on the
screen/ the system still e-ecutes the SUBMIT statement in the bac5ground.
Mo!ule Pools
<odule pool acts as a container for dialog modules called by the dynpros flow logic.
<odule pools were originally designed for the dialog programming with dynpros. 8ith
the e-ception of reporting event bloc5s and function modules/ module pools can contain
all processing bloc5s supported in ABAP and as many local classes as reBuired. <odule
pools are no longer play a role in ABAP 6b4ects. Instead/ function groups should be used
as carriers of dynpros. <odule pools are introduced with the PROGRAM statement. It is
maintained directly in the ABAP =ditor (S=0.$ of ABAP 8or5bench.
1,
Introduction to ABAP Programming
$"pe 1roups
Type groups only contain declaration part for global data types and constants which can
be made visible in any ABAP program. Type groups are predecessor technology for
general type definitions in the ABAP ;ictionary and in global classes or interfaces. 9o
more type groups should be created in ABAP 6b4ects. Instead/ types and constants can be
published by global classes and interfaces. Type groups are introduced with the TYPE-
POOLS statement. It is maintained with ABAP ;ictionary (S=$ tool of the ABAP
8or5bench.
Inclu!e Programs
Include programs have no introductory program statement and/ unli5e all other program
types/ they do not represent independent compilation units with their own memory space.
Include programs provide a library function for ABAP source code and can be embedded
at any location in other ABAP programs using the INCLUDE statement. ;uring synta-
chec5 the INCLUDE statement is replaced by the source code of the include programs.
Include programs have no technical relationship to processing bloc5s. Cowever/ it is
preferable to separate logical program units/ such as the declaration part for global data/
and similar or individual processing bloc5s into independent include programs. They are
automatically generated by ABAP 8or5bench when you create programs such as class
pools or function pools. Lou can create your own include programs directly with the
ABAP =ditor (S=0.$ tool of ABAP 8or5bench.
Include programs ma5e large program much easier to handle/ as it can be transported
individually/ which allows/ individual methods or function modules to be processed
independently of their class pool or their function group.
The %T6P include( is designed for the global declaration part of an ABAP program. The
naming convention is that the name of top includes ends with %T6P(. 8hen you organi'e
program using include program/ all statements of global declaration part should be
included by the top include. It can be created automatically when you create an ABAP
program in the ABAP 8or5bench by simply selecting the corresponding chec5bo-.
Include programs should never be sued for multiple usage of source code in several
compilation units. Instead/ you can use global classes or interfaces. The reason for this
that the inclusion of an include program in several programs dramatically restricts both
their maintainability. Aurther more/ an include program that is included in several
programs is loaded several times into the program memory of the application server/ if
the programs are used in parallel. 8e recommend the declaration part of a local class or
processing bloc5 (method$. The names of include programs should correspond to those
that are proposed by the ABAP 8or5bench.
The following matri- shows all ABAP program types and their supported features.
10
Introduction to ABAP Programming
'ecommen!e! Program $"pes (ith ABAP -b.ects
7se class and interface pools for reusable code in global classes and interfaces.
Subroutine pools can serve as >ava&li5e programs in which you can call e-actly
one main method from outside.
The same applies for e-e programs as for subroutine/ though you can call them
using SUBMIT statement/ which is technically suitable for bac5ground processes.
7se function groups only where technically necessary/ that is/ as containers for
dynpros and for *A3&enabled function modules.
9ew module pools or type groups should no longer be created for programming
with ABAP 6b4ects.
11
Introduction to ABAP Programming
ABAP Program Processing Bloc+s
An ABAP program is embedded in a runtime environment provided by Application
Server ABAP. The runtime contains processors that e-ecute the ABAP programs. The
e-ecution of ABAP program is synonymous with a process in ABAP runtime
environment/ which controls the program by calling the processing bloc5s. Cowever
most of the concept of processors are primarily connected to procedural+event oriented
ABAP programming and has lost significance for modern ABAP 6b4ects. The following
types of processing bloc5s are available.
Procedures
;ialog <odules
=vent Bloc5s
Proce!ures
Procedure processing bloc5s have a local data area and can have a parameter interface.
Procedure can be in the form of <ethod/ Aunction <odules or Subroutines.
Methods
<ethod is a component of a class. 66 ABAP program is built from methods that are
organi'ed in classes. <ethod processing bloc5s can only be defined in class pools
program type. METHOD statement and concluded with the ENDMETHOD statement. Lou
call methods from ABAP programs using the CALL METHOD statement.
unction Modules
These are predecessors of methods for e-ternal procedure calls in the procedural
programming model. It is also called e-ternal procedure. Aunction modules can only be
created in function groups or function pools program type. Since many functions
(dynpros and *A3$ of an ABAP are still offered in function modules/ they can continue to
be called from methods. Aunction modules are introduced with the FUNCTION statement
and concluded with the ENDFUNCTION statement. Lou call function modules from
ABAP programs using the CALL FUNCTION statement.
Subroutines
These are predecessors of methods for internal procedure calls in the procedural
programming model. It is also called internal procedures. Subroutines are replaced
entirely by methods and should no longer be used. Instead you can create local classes for
internal modulari'ation in all program types that can contain operational code.
1D
Introduction to ABAP Programming
Subroutines are introduced with the FORM statement and concluded with the ENDFORM
statement. Lou call subroutines from ABAP programs using the PERFORM statement.
Dialog Mo!ules
;ialog <odules are processing bloc5s without a local data area and without a parameter
interface. They can only wor5 with global data from the declaration part of their ABAP
program/ which prevents data encapsulation. They can be used in ABAP programs that
support their own dynpros (e-ecutable programs/ function groups/ module pools$. ;ialog
modules processing bloc5s should contain little or no operational code other than method
calls. ;ialog modules are rarely needed nowadays. ;ialog modules are introduced with
the MODULE statement and concluded with the ENDMODULE statement. ;ialog modules
called from the screen flow logic (screen command MODULE$.
%vent Mo!ules
=ven <odules are processing bloc5s without a local data area and without a parameter
interface. They can only wor5 with global data from the declaration part of their ABAP
program/ which prevents data encapsulation. 3lassical ABAP programs and e-ecutable
programs particularly are event&oriented. =vent bloc5s are called through events which
are triggered by user actions on selection screens and lists or by the ABAP runtime
environment. ABAP 6b4ects has an e-plicit event concept where events are triggered by
a statement in methods and are handled by special methods (event handlers$. The events
bloc5s can be divided into:
Program Constructor !vent Block
;irectly after an e-ecutable program/ a module pool/ a function group or a subroutine
pool has been loaded/ a special processing bloc5 can be e-ecuted e-actly once. This
bloc5 can be used for global data initiali'ation. Therefore it resembles class constructor.
This processing bloc5 is defined as an event bloc5 using the event 5eyword LOAD-OF-
PROGRAM.
Selection Screen !vent Block
It is triggered by the screen selection processor of ABAP runtime environment during
selection screen processing. Selection screens are special dynpros.
"ist !vent Block
It is triggered by the list processor of the ABAP runtime environment during classical list
processing. In ABAP 6b4ects the creation and processing of classical lists is obsolete in
most cases.
1G
Introduction to ABAP Programming
#eporting !vent Block
It is triggered by the reporting processor of the ABAP runtime environment if an
e-ecutable program is e-ecuted. In ABAP 6b4ects you should only implement the
START-OF-SELECTION.
1"
Introduction to ABAP Programming
%lements o ABAP #anguage
Statements
=ach ABAP program is composed of one or more statements. =ach statement contains
one or more words separated by at least one space. The first word of a statement is the
5eyword. A statement can include one or more additions/ and always ends with a period.
The first 5eyword of statement determines the category of the statements. The different
statement categories are as follows:
Declarative Statements
These statements define data types or declare data ob4ects which are used by the other
statements in a program or routine. The collected declarative statements in a program or
subroutine ma5e up its declaration part. =-amples of declarative 5eywords: TYPES,
DATA, TABLES.
Modulari$ation Statements
These statements define the processing bloc5s in an ABAP program. =-amples of
modulari'ation 5eywords: START-OF-SELECTION, MODULE ... ENDMODULE.
Control Statements
Lou use these statements to control the flow of an ABAP program within a processing
bloc5 according to certain conditions. =-amples of control 5eywords: IF, WHILE,
CASE.
Call Statements
Lou use these statements to call processing bloc5s that you have already defined using
modulari'ation statements. The bloc5s you call can either be in the same ABAP program
or in a different program. =-amples of call 5eywords: PERFORM, CALL, SET
USER-COMMAND, SUBMIT, LEAVE TO.
1.
Introduction to ABAP Programming
Operational Statements
These 5eywords process the data that you have defined using declarative statements.
=-amples of operational 5eywords: WRITE, MOVE, ADD.
Database Statements
These statements use the database interface to access the tables in the central database
system. There are two 5inds of database statement in ABAP: 6pen SF2 and 9ative SF2.
-pen S0#: 6pen SF2 is a subset of the standard SF2!, language. It contains only ;ata
<anipulation 2anguage (;<2$ statements/ such as S=2=3T/ I9S=*T/ and ;=2=T=. It
does not contain any ;ata ;efinition 2anguage (;;2$ statements (such as 3*=AT=
TAB2= or 3*=AT= I9;=I$. Aunctions of this type are contained in the ABAP
;ictionary. ABAP programs that use only 6pen SF2 statements to access the database
are fully portable. The database interface converts the 6P=9 SF2 commands into
commands of the relevant database.
Native S0#: 9ative SF2 statements are passed directly from the database interface to
the database without first being converted. It allows you to ta5e advantage of all of your
databaseEs characteristics in your programs. In particular/ it allows you to use ;;2
operations. The ABAP ;ictionary uses 9ative SF2 for tas5s such as creating database
tables. In ordinary ABAP programs/ it is not worth using ;;2 statements/ since you
cannot then ta5e advantage of the central administration functions of the ABAP
;ictionary. ABAP programs that use 9ative SF2 statements are database&specific.
Chaine! Statements
The ABAP programming language allows you to concatenate consecutive statements
with an identical first part into a chain statement.
To concatenate a seBuence of separate statements/ write the identical part only once and
place a colon (:$ after it. After the colon/ write the remaining parts of the individual
statements/ separating them with commas. =nsure that you place a period (.$ after the last
part to inform the system where the chain ends.
Statement seBuence:
WRITE H!!"#.
WRITE $" $%#.
WRITE &"'!( ") ABAP#.
3hain statement:
WRITE* H!!"#,
$" $%#,
1!
Introduction to ABAP Programming
&"'!( ") ABAP#.
In a chain statement/ the first part (before the colon$ is not limited to the 5eyword of the
statements.
Statement seBuence:
SUM + SUM , -.
SUM + SUM , ..
SUM + SUM , /.
SUM + SUM , 0.
3hain statement:
SUM + SUM , * -, ., /, 0.
D#
Introduction to ABAP Programming
Data -b.ects an! Data $"pes
Data -b.ects
;ata ob4ect is a named memory that is structured according to a particular data type. ;ata
ob4ects are instances of data types. =ach ABAP data ob4ect has a set of attributes (field
length/ number of decimal places$ which it acBuires from its data type. ;ata ob4ects
reside in repository.
;ata ob4ects can be created by using declarative statements (DATA statement$ or
CREATE DATA statement. ;ata ob4ects that have been created using declarative
statements are assigned name and can be accessed through this name. ;ata ob4ects
created using CREATE DATA are not assigned a name (anonymous data ob4ects$ and can
be addressed only via reference variables/ similar to class instances.
DATA (1$1_"23 TYPE (1$1_$45 6LENGTH !78 6DECIMALS (98
VALUE :1!8 6READ-ONLY8.
The statement defines a (1$1_"23 data ob4ect of type (1$1_$45. LENGTH must be
used for incomplete types (p/c/n and -$ discussed later. The DECIMALS is used to define
the number of decimal places for pac5ed number type (p$. The VALUE addition defines
the initial value for data ob4ect (1$1_"23. READ-ONLY addition can be used to declare
an attribute in the public visibility section of a class (discussed in class section$ in such
away that its contents can not be changed from out side the class.
CREATE DATA (1$1_"23_') TYPE (1$1_$45 6LENGTH !78
6DECIMALS (98.
;ata ob4ects have three levels of visibility (a5a 3onte-t of ;ata 6b4ect$: global/ local/
and class. The visibility of a data ob4ect indicates from where in the program the data
ob4ect is accessible.
1lobal Data -b.ects: can be accessed from anywhere within the program. They are
declared in the declaration part of a program. The life cycle of global data ob4ect is bound
to the life cycle of its program in the internal session. In ABAP 6b4ects/ avoid using
program global data/ instead use global classes.
#ocal Data -b.ects: are accessible only from inside the methods or other procedures
(function modules/ subroutines$ in which they are defined. The life cycle of local data
ob4ect spans over the body of method or procedure.
Class #evel Data -b.ects: ;ata declarations in the declaration part of classes either
create instance attributes or static attributes. Instance attributes can b addressed in all
instance methods/ while static attributes can be addressed in all methods via their names.
D
Introduction to ABAP Programming
The life cycle of an instance attribute depends on the lifecycle of an ob4ect/ while the life
cycle of a static attribute depends on the life cycle of an internal session.
;ata ob4ects can be of the form: 2iterals/ Hariables/ 3onstants or Te-t Symbol.
"iterals
2iterals are not created by declarative statements. Instead/ they e-ist in the program
source code. 2i5e all data ob4ects/ they have attributes (field length/ number of decimal
places/ data type$/ but no name. They are therefore referred to as unnamed data ob4ects.
2iterals can be numeric or character. Aor e-ampleK ,0DG/ or %Cello 8orld(.
%ariables
Hariables are named data an ob4ect that you can declare statically (compile time$ using
declarative statements or dynamically while a program is running. They allow you to
store changeable data under a particular name within the memory area of a program. Lou
declare variables using the DATA, CLASS-DATA, STATICS, PARAMETERS,
SELECT-OPTIONS/ and RANGES statements.
Constants
3onstants are data ob4ects whose contents cannot be changed. Lou declare constants
using the CONSTANTS statement. Lou cannot define constants for XSTRINGS/
references/ internal tables/ or structures containing internal tables.
CONSTANT (1$1_"23 TYPE (1$1_$45 VALUE :1! ; <IS INITIAL=.
IS INITIAL is use to set a constant (1$1_"23 to its type specific initial value.
&e't Symbols
Te-t symbols are pointers to te-ts in the te-t pool of the ABAP program. The te-t pool
contains the te-t elements of the program/ several te-t pools can be defined in different
languages for a program. 8hen the program starts/ the corresponding data ob4ects are
generated from the te-ts stored in the te-t pool. They can be addressed using the name of
the te-t symbol. Te-t Symbols are maintained with Te-t =lement <aintenance (S=0,$ of
the ABAP 8or5bench. Te-t Symbols are lin5ed to the translation/ i.e. you can use te-t
symbols in places where you want to display te-ts from the program on the user interface/
without to bother about the logon language of specific user.
D,
Introduction to ABAP Programming
Data $"pes
;ata types specify the attributes of data ob4ects. ;ata type determines how the data is
stored in the memory/ and tells the ABAP statement how to handle it. ;ata types do not
occupy memory. The TYPE 5eyword defines the data type for data ob4ect as:
DATA $>$ TYPE 9 LENGTH -. VALUE H!!" W"'!(#.
Cere t-t data ob4ect is an instance of data type c with initial value %Cello 8orld(. In
ABAP we have the following data types.
!lementary Data &ypes
These are data types of fi-ed or variable length that are not made up of other types. There
are eight fi-ed length and two variable length elementary data types. The difference
between variable length data types and fi-ed length data types is that the length and the
memory space reBuired by data ob4ects of variable length data types can change
dynamically during runtime.
Lou can also define your own elementary data types in ABAP using the TYPES
statement. Lou base these on the predefined data types. This determines all of the
technical attributes of the new data type.
There are total # built&in elementary data types:
*iAe! #ength %lementar" Data $"pes
The %2ength( column indicates the minimum and ma-imum number of bytes or
characters that a data ob4ect can occupy. The interval is specified in length column
for 5/ 9/ 7 and > data types means that these data types are incomplete or generic
and it is reBuired to use the LENGTH addition to specify their length/ otherwise
you cannot use them to declare data types and data ob4ects. The other types ?/ )/
(/ and $ are not generic and complete/ you donEt need to specify LENGTH when
declare a data ob4ect or data type. In fact/ specifying length in this is forbidden.
;ata ob4ects that are declared using one of these eight data types are referred to as
static data ob4ects because the utili'ed memory space is statically (during
declaration$.
D0
Introduction to ABAP Programming
Data $"pe #ength
Stan!ar!
#ength
Initial &alue Meaning
Numeric Data $"pes
i 1 bytes # Integer
f . bytes # Aloating point
p &G bytes .bytes # Pac5ed number
Character Data $"pes
c
& GDD0D
characters
character UR.E
Te-t Aield
(Alpha numeric$
n
& GDD0D
characters
character :# R #:
9umeric Te-t
Aield (9umeric
characters$
d . characters U########:
;ate Aield
(Aormat:
LLLL<<;;$
t G characters :######:
Time Aield
(Aormat:
CC<<SS$$
8eAa!ecimal 4B"te5 Data $"pe
- &GDD0D bytes byte -:## R##:
Ce-adecimal
field
&ariable #ength %lementar" Data $"pes
Data $"pe #ength
Stan!ar!
#ength
Initial &alue Meaning
Character Data $"pes
string 3haracter Strings
-string Byte Strings
Comple' Data &ypes
3omple- data types are made up of other data types. 3omple- ;ata Types allow you to
manage and wor5 with semantically related datasets under a common name. There is nor
built&in comple- data types. A comple- data type must be constructed from e-isting
types. 3omple- data types can be structured types or table types.
D1
Introduction to ABAP Programming
#e(erence Data &ypes
*eference types describe data ob4ects (reference variables$ that contain references to
other ob4ects. There are types of data references (references to data ob4ects$ and ob4ect
references (references to instances of classes$.
DD
Introduction to ABAP Programming
Deining Data $"pes
There are two ways to define data types in ABAP:
Bound ;ata Type
Independent ;ata Type
Bound Data &ype
The data statement DATA creates a bound data type. That is a type defined only for that
particular data ob4ect and canEt be used for other data ob4ects.
DATA @AB TYPE 9 LENGTH .C VALUE H!!"#.
The above statement declares @AB data ob4ect of type 9 with length of ,# characters.
9ow these properties i.e. type and length is 4ust associated or bound with data ob4ect
@AB. If we try the following declarative statement.
DATA $>$ TYPE @AB VALUE W!9"@#.
Lou will get an error saying that type @AB is un5nown. This shows that the properties
li5e type and length is bound to @AB and you canEt use the TYPE addition to @AB to
define data ob4ects of type @AB.
The LIKE 5eyword is used to solve the above problem. Aor e-ample the following line is
e-ecuted without any errors.
DATA $>$ LIKE @AB VALUE W!9"@#.
The above line says that $>$ is a data ob4ect having same properties as that of @AB.
LIKE refers to predefined data ob4ects. But the problem with this method is we are
creating data ob4ects even for the purpose of defining data types i.e. LIKE similar to
TYPE also allocates memory space. As a result/ this would consume a lot of memory.
Aor this reason ABAP provides an independent data types.
)ndependent Data &ypes
Independent data types act as a template for data ob4ects/ similar to classes that can be
used for template for ob4ects. The TYPES 5eyword is used to define an independent data
types. The TYPES 5eyword creates data type and does not allocate memory space. The
synta- of TYPES is almost identical to the DATA statement but without data ob4ect
specific additions li5e length and value etc.
DG
Introduction to ABAP Programming
The TYPES statement for an independent character&li5e data type te-t of length ,# would
be as follows:
TYPES $>$ TYPE 9 LENGTH .C.
To declare data ob4ects of type te-t:
DATA $>$- TYPE $>$ VALUE W!9"@#.
DATA $>$. TYPE $>$ VALUE $" ABAP#.
This means/ that t-t and t-t, are of type te-t which in turn of type c and having length of
,#.
8ith so many different ways to declare data types/ the Buestion arises as to when you
should use which optionV
It is good programming style to create a self&defined data type only as an
independent type.
7se LIKE addition whenever your declaration is directly li5ed to a data ob4ect.
=-amples of this include au-iliary variables in procedures that must have the
same type as interface parameters or their components. This 5eeps your program
valid even if the data type of the data ob4ects changes.
In all other cases/ you should use the TYPE addition to directly reference
appropriate independent data types.
D"
Introduction to ABAP Programming
%lementar" Data $"pes 7sage
*umeric Data &ypes

Data $"pe i: i is a complete type/ used for integers/ having si'e of 1&bytes. 6ften
used for inde- or count variables. The default value is #.
DATA 9"D7$ TYPE ? VALUE C.
Data $"pe : f is a data type for binary floating point numbers. f is a complete
type. It is having .&bytes of si'e. It is consists of three components: the J+& sign/ a
G&digit mantissa and the e-ponent. <antissa contains the digits of the number/
while the e-ponent specifies the position of the decimal point. The default value is
#.

DATA 'AD!$ TYPE ).
Data $"pe p: p is incomplete type. It is pac5ed numbers in the Binary 3oded
;ecimals (B3;$ format with fi-ed number of decimal places. The number of
decimal places is defined during declaration of data type or data ob4ect using the
DECIMALS addition after TYPE. The default value is #. The type p is useful for
monetary amounts/ dimensions or weights etc.
DATA 7D@2' TYPE 5 DECIMALS . VALUE ./.
8ith SAP 9et8eaver ,##" new data type decfloatG and decfloat01 are
introduced to replace the f and p data types.
Data $"pe !ecloatBC: decfloatG is complete type. It is decimal floating point
number with G decimal places. It is having .&bytes of si'e. The default value is #.
DATA 7" TYPE (9)!"1$-E VALUE -..
Data $"pe !ecloat9D: decfloat01 is complete type. It is decimal floating point
numbers of this type are represented internally with 01 decimal places. It is
having G&bytes of si'e. The default value is #.
DATA 7" TYPE (9)!"1$/0 VALUE ./.
Character Data &ypes
Data $"pe c: c is a data type that can be used for any character string of fi-ed
length. c is incomplete data type for this purpose you must specify the length
property for this data type.
D.
Introduction to ABAP Programming
DATA $>$ _!?7 TYPE 9 LENGTH F..
$>$_!?7 + ABAP 5'"B'1@@?7B ?A )D7GH.
Data $"pe n: Type n is a special case of type c for numeric characters/ but not a
numeric data type. n is also incomplete data type. ;ata ob4ects of this type can
only contain numbers/ but these numbers can not be directly used to carry out
calculations. Typical use areas can be PIP codes/ Phone 9umbers/ P.6 Bo-
numbers etc.
DATA 5"A$1!_9"( TYPE 7 LENGTH I.
5"A$1!_9"( + .ICCC#.
Data $"pe !: d is data type for date information in the format/ YYYYMMDD. d is a
complete type. If data ob4ect of type d is used in the position of operands where a
numerical value is e-pected/ the date is regarded as a number that corresponds to
the number of days that have been passed since CCC-C-C-. 6ther operations
utili'e the character nature.
DATA $"(14 TYPE (.
$"(14 + A4-(1$D@.
$"(14 + $"(14 , ..
The A4-(1$D@ system field provides the system date/ after the calculation/ it
assign the date of day after tomorrow.
Data $"pe t: t is a data type for time information in the format/ HHMMSS. It is
complete data type. . If data ob4ect of type d is used in the position of operands
where a numerical value is e-pected/ the time is regarded as a number that
corresponds to the number of seconds that have been passed since midnight
CCCCCC. 6ther operations utili'e the character nature.
DATA 7"& TYPE $.
7"& + A4-DJ?$.
7"& + 7"& , /ECC.
The A4-DJ?$ system field provides the current time/ and then one hour is
added to the now data ob4ect.
Data $"pe A: - is a data type used for storing byte strings of fi-ed length. It is
incomplete data type. Type - data ob4ects can generally be used for byte&li5e
content where the fi-ed length is important.
DATA %> TYPE > LENGTH /.
%> + F/0IEAB#.
D!
Introduction to ABAP Programming
Data $"pe string: Type string is a data type that can be used for any characters
strings of variable length. The LENGTH addition is not allowed with string data
typeK however you can use the VALUE addition to initiali'e a string data ob4ect.
DATA $>$_A$' TYPE A$'?7B.
Data $"pe Astring: -string is a data type that can be used for any byte string of
variable length. The LENGTH and VALUE and addition is not allowed with -string
data type.
DATA $>$_>A$' TYPE >A$'?7B.
G#
Introduction to ABAP Programming
CompleA Data $"pes
3omple- data types can be structured types or table types.
Structured Data &ype
Structured data type is consists of a seBuence of other data types. The data ob4ect of a
structured data type is called structure. The units that ma5e up a structured type are called
structure components (fields$. The components of the structure can be elementary data
types/ a structure/ an internal table or a reference data type. Structures are used especially
to define the data at the interface of module pools and screens and to define the types of
function module parameters.
There are Alat/ nested and deep structures. A flat structure only references elementary
types. A nested structure references at least one further structure/ but not a table type. A
deep structure references at least one table type.
The BEGIN OF and END OF statements define the beginning and end of a structure as a
bound or independent type:
DATA* BEGIN OF A$'D9$D'_71@,
A$'D9$_9"@5- TYPE;LIKE K,
A$'D9$_9"@5. TYPE;LIKE K,
KKK
KKK
A$'D9$_9"@57 TYPE;LIKE K
END OF A$'D9$D'_71@.
TYPES* BEGIN OF A$'D9$D'_71@,
A$'D9$_9"@5- TYPE K,
A$'D9$_9"@5. TYPE K,
KKK
KKK
A$'D9$_9"@57 TYPEK
END OF A$'D9$D'_71@.
The addition of BEGIN OF and END OF statements define the beginning and end of a
structure called A$'D9$D'_71@. The colon and the commas indicate that we are
dealing with several DATA and TYPES statements. All the statements that lie in&between
G
Introduction to ABAP Programming
declare the components of the structure. A component that is structured itself is referred
to as a substructure. A structure that contains substructures is called nested structure.
The component of a structure can be accessed with structure component (&$. Aor nested
structures/ you must concatenate the structure names to access internal components.
G,
Introduction to ABAP Programming
The program produces the following out put.
Aor the street/ we created a separate structured type A$'$_A$'D9$ with components
71@ and 7". Aor the address/ we declare a structure 1(('AA_A$'D9$ as a data
ob4ect (everything we discussed for DATA also holds true for CLASS-DATA/ for
declaration of static attributes.$ and we declare the A$'$ component with type
A$'$_A$'D9$. The substructure 9?$4_A$'D9$ consists of two components
J?59"( and 71@.
Lou can integrate the components of a structure into another structure using the
INCLUDE statement as:
DATA BEGIN OF A$'D9$_-,
KK
INCLUDE STRUCTURE A$'D9$_. AS 71@
G0
Introduction to ABAP Programming
6RENAMING WITH SUFFIX AD))?>8.
KK
DATA END OF A$'D9$_-.
TYPES BEGIN OF A$'D9$_-,
KK
INCLUDE TYPE A$'D9$_. AS 71@
6RENAMING WITH SUFFIX AD))?>8.
KK
TYPES END OF A$'D9$_-.
The INCLUDE statement is not an addition to the TYPES or DATA statements. Instead/ it
interrupts the chained statement that must be restarted afterwards.
The components of A$'D9$_. will be transferred as components into the A$'D9$_-
structure. They can either be addressed commonly under the name 71@/ or individually
by their component names. The RENAMING addition can be used to avoid naming
conflicts.
G1
Introduction to ABAP Programming
The program produces the following out put.
All the components are allocated at the same level. 9aming conflicts between the name
components are avoided by the use of different endings. This type of structure definition
avoids comple- nested structures with long name chains.
&able &ypes
Table types represent the second comple- data type. The data ob4ects of table types are
internal tables. Internal tables are dynamic data ob4ects li5e stringsK internal tables are
internally managed by references. An internal table consists of a dynamic seBuence of
lines of the same data type (it can be thin5 of an arrays in >ava or 3W.9et$. The table type
GD
Introduction to ABAP Programming
describes the line type/ the table category and a table 5ey. The following synta- can be
used to declare the internal tables.
DATA $12_71@ TYPE;LIKE STANDARD;SORTED;HASHED TABLE
OF (1$1_$45;(1$1_"239$
WITH 6NON-8UNIQUE KEY 9"!-K9"!7.
TYPES $12_71@ TYPE STANDARD;SORTED;HASHED TABLE
OF (1$1_$45
WITH 6NON-8UNIQUE KEY 9"!-K9"!7.
The 5eywords STANDARD/ SORTED and HASHED define the table category.
S$ANDA'D $able: is managed internally by a table inde-. Access is possible via table
inde- or table 5ey. 8ith a 5ey access/ the response time is directly dependent on the
number of table entries. The 5ey of a standard table is always non&uniBue. This table
category is suited best whenever the individual entries can be accessed using the inde-.
S-'$%D $able: is managed internally by means of a table inde-/ too. They are always
sorted by the table 5ey and can be accessed via the table inde- or the table 5ey. 8ith a
5ey access/ the response time is logarithmically dependent on the number of table entries/
because the table is accessed via a binary search. The 5ey of sorted tables can be uniBue
or non&uniBue. This table category is suited whenever the table must already be sorted
when it is filled.
8AS8%D $able: is managed internally by a hash algorithm. Cashed tables can be
accessed only via the table 5ey. The response time is constant/ independent of the number
of table entries. The 5ey of hashed tables is always uniBue. This table category is suited
whenever the 5ey accesses represent the central operation on the table entries.
The (1$1_$45 and (1$1_"239$ represent the line type. The internal table can
contain any number of lines of the specified line type. Thus/ line type is fi-ed during
declaration/ but not the number of lines. Lou can use any line type/ elementary types/
reference types/ structures and even other internal tables.
The table 5ey is reBuired for the identification of table rows. An internal table has a
uniBue or non&uniBue table 5ey that can be defined by listing its components.
=-ample below demonstrates the usage of internal table.
GG
Introduction to ABAP Programming
After e-ecuting the loop will display five message bo-es as:
G"
Introduction to ABAP Programming
=-ample above declares a standard table 1''14 whose line type is elementary data type
i and whose 5ey consists of the DEFAULT KEY. DEFAULT KEY is build from all
columns of the internal table that have a character&type type (9/ (/ $/ 7/ >/ A$'?7B/
>A$'?7B$. The APPEND statement appends a new line to the end of the inde-ed internal
table. The A4-?7(> is a system field (System fields are filled according to the conte-t
by system runtime$ gets the particular record number. It acts li5e 2oop Iteration 3ounter.
'eerence Data $"pes
*eference types can contain a reference to other data ob4ects or to instances of classes.
Those data ob4ects are referred to as reference variables. ;epending on the type of ob4ect
that is referenced/ we spea5 of data reference variables or ob4ect reference variables that
can either contain data references or ob4ect references. The following synta- can be used
to declare the reference data types.
DATA ')_:1'?12! TYPE ;LIKE REF TO
(1$1_$45;(1$1_"239$.
G.
Introduction to ABAP Programming
TYPES ')_:1'?12! TYPE REF TO (1$1_$45.
DATA "23_') TYPE REF TO 9!1AA;?7$')19.
TYPES "23_') TYPE REF TO 9!1AA;?7$')19.
The first two statements create the reference variable for data reference. 9e-t two
statements create an ob4ect reference for class or interface. All of the data ob4ects that you
define in the declaration part of a program using statements such as DATA are created
statically/ and already e-ist when you start the program. To create a data ob4ect
dynamically during a program/ you need a reference variable and the following
statement:
CREATE DATA ')_:1'?12! TYPE ;LIKE
(1$1_$45;(1$1_"239$.
CREATE DATA ')_:1'?12! TYPE (1$1_$45.
The statements create a reference variable in the internal session of the current ABAP
program. After the statement/ the data reference in the data reference variable points to
the ob4ect.
The ob4ect component selector (-L$ can be used to access the components of the
reference variable. The dereferencing operator (-LM$ can be used to access the entire data
ob4ects that is referenced.
The following statements allow you to place a data reference to an e-isting data ob4ect in
a reference variable:
GET REFERENCE OF (1$1_"239$ INTO ')_:1'?12!.
=-ample below demonstrates the usage of reference variable and ob4ect references.
G!
Introduction to ABAP Programming
The program produces the following results.
The declaration section introduces the "23_') is an ob4ect reference to 9!A class/
while (1$1_')- and (1$1_'). are reference variables to "23_') and ?
respectively.
CREATE OBJECT statement allocates the reference "23_') which enable us to
access its attribute :1'. The GET REFERENCE OF statement gets the reference of
"23_') and places it into the (1$1_')- reference variable.
"#
Introduction to ABAP Programming
CREATE DATA statement creates a data ob4ect (1$1_'). dynamically. 6n ne-t line
through dereferencing operator (-LM$ we access the :1' attribute of "23_')
((1$1_')- is pointing to "23_')$ and assign to (1$1_').. After e-ecution it is
clear that both "23_') and (1$1_'). are pointing to same memory location.
1eneric Data $"pes
The generic data types allow the dynamic programming. By generic we mean that the
data type is determined during runtime. Table below lists the predefined generic types in
the first column/ while the second column describes the types they comprise. Lou can
assign a data ob4ect with a type from the second column to a formal parameter r field
symbol (Aield symbols are placeholders or symbolic names for other data ob4ects. Aield
symbols are similar to dereferenced pointers in 3$ that is typed with a generic type from
the first column.
1eneric $"pe $"pes Comprise!
any/ data All data types
cli5e
c/ d/ n/ t/ string/ and flat structures containing
character li5e components
cseBuence c and string (te-t li5e types$
-seBuence - and -string (byte li5e types$
any table All table types
sorted table Sorted tables
hashed table Cashed tables
inde- table Standard and Sorted tables
standard table/ table Standard tables
numeric i (b/s$/ p / f (numeric types$
c/ n/ p/ -
3orresponding built&in types with generic lengths
and decimal places
simple
c/ d/ f/ i (b/s$/ n/ p/ t/ string/ -/ -string/ and flat
structures containing character li5e components
If table type is defined using the TLP=S statement or if it is defined in the ABAP
;ictionary without specifying a 5ey/ this table type is also generic type.
*lat an! Deep Data $"pes
All data types in which the content of their data ob4ects represents actual wor5ing data
are referred to as flat data types. Thus all elementary data types of fi-ed length are flat
data types.
All data types in which content of their data ob4ects are references that point to wor5ing
data in different locations of the memory are referred to as deep data types. Thus
reference types and dynamic data ob4ects (strings and internal tables$ are deep data types.
"
Introduction to ABAP Programming
In assignment between deep data ob4ectsK for assignments between reference variables/
reference semantics applies i.e. only the references are copied/ but not the referenced
ob4ects. Aor assignment between dynamic data ob4ects (strings and internal tables$/ value
semantics applies i.e. the referenced ob4ect is copied and a new reference is created.
The memory reBuirement for deep data ob4ects is combination of a constant reBuirement
for the reference (. bytes$ and a dynamic reBuirement for actual ob4ects.
",

You might also like