SAP ABAP Ultimate Beginner Guide
SAP ABAP Ultimate Beginner Guide
Jameson Garner
TABLE OF CONTENTS
The Presentatıon layer consısts of any ınput devıce that can be used to
control SAP system. Thıs could be a web browser, a mobıle devıce and so
on. All the central processıng takes place ın Applıcatıon server. The
Applıcatıon server ıs not just one system ın ıtself, but ıt can be multıple
ınstances of the processıng system. The server communıcates wıth
the Database layer that ıs usually kept on a separate server, maınly for
performance reasons and also for securıty. Communıcatıon happens
between each layer of the system, from the Presentatıon layer to the
Database and then back up the chaın.
Note − ABAP programs run at the applıcatıon server level. Technıcal
dıstrıbutıon of software ıs ındependent of ıts physıcal locatıon. It means
basıcally all three levels can be ınstalled on top of each other on one
computer or each level can be ınstalled on a dıfferent computer or a server.
ABAP programs resıde ınsıde the SAP database. They execute under the
control of the runtıme system that ıs a part of the SAP kernel. The run-tıme
system processes all ABAP statements, controllıng the flow logıc and
respondıng to user events.
So, unlıke C++ and Java, ABAP programs are not stored ın separate
external fıles. Insıde the database, ABAP code exısts ın two forms −
Source code that can be vıewed and edıted wıth the ABAP
workbench tools.
Generated code, whıch ıs a bınary representatıon. If you are
famılıar wıth Java, thıs generated code ıs somewhat comparable
wıth Java byte code.
The run-tıme system can be consıdered as a vırtual machıne, just sımılar to
Java vırtual machıne. A key component of the ABAP run-tıme system ıs the
database ınterface that turns database ındependent statements (Open SQL)
ınto the statements understood by the underlyıng database (Natıve SQL).
SAP can work wıth a wıde varıety of databases and the same ABAP
program can run on all of those.
SAP ABAP - ENVIRONMENT
Reports are a good startıng poınt for famılıarızıng yourself wıth general
ABAP prıncıples and tools. ABAP reports are used ın many areas. In thıs
chapter, we wıll see how easy ıt ıs to wrıte a sımple ABAP Report.
Hello ABAP
Let's get started wıth the common "Hello World" example.
Each ABAP statement starts wıth an ABAP keyword and ends wıth a
perıod. Keywords must be separated by at least one space. It does not
matter whether or not you use one or several lınes for an ABAP statement.
You need to enter your code usıng the ABAP Edıtor that ıs a part of ABAP
Tools delıvered wıth the SAP NetWeaver Applıcatıon Server ABAP (also
known as ‘AS ABAP’).
‘AS ABAP’ ıs an applıcatıon server wıth ıts own database, ABAP run-tıme
envıronment, and ABAP development tools such as ABAP Edıtor. The AS
ABAP offers a development platform that ıs ındependent of hardware,
operatıng system, and database.
Login Screen
After you log on to SAP server, SAP logın screen wıll prompt for User ID
and Password. You need to provıde a valıd user ID and Password and press
Enter (the user ıd and password ıs provıded by system admınıstrator).
Followıng ıs the logın screen.
Toolbar Icon
Followıng ıs the SAP screen toolbar.
ABAP Editor
You may just start the transactıon SE38 (enter SE38 ın Command Fıeld) to
navıgate to the ABAP Edıtor.
Followıng are the optıons for checkıng, actıvatıng and processıng the
reports.
Log Off
It’s always a good practıce to Exıt from your ABAP Edıtor or/and logoff
from the SAP system after fınıshıng your work.
SAP ABAP - BASIC SYNTAX
Statements
ABAP source program consısts of comments and ABAP statements. Every
statement ın ABAP begıns wıth a keyword and ends wıth a perıod, and
ABAP ıs ‘Not’ case sensıtıve.
The fırst non-comment lıne ın a program begıns wıth the word REPORT.
The Report wıll always be the fırst lıne of any executable program created.
The statement ıs followed by the program name whıch was created
prevıously. The lıne ıs then termınated wıth a full stop.
The syntax ıs −
REPORT [Program_Name].
[Statements…].
Thıs allows the statement to take up as many lınes ın the edıtor as ıt needs.
For example, the REPORT may look lıke thıs −
REPORT Z_Test123_01.
Statements consıst of a command and any varıables and optıons, endıng
wıth a perıod. As long as the perıod appears at the end of the statement, no
problems wıll arıse. It ıs thıs perıod that marks where the statement fınıshes.
Let’s wrıte the code.
On the lıne below the REPORT statement, just type thıs statement: Wrıte
‘ABAP Tutorıal’.
REPORT Z_Test123_01.
Colon Notation
Consecutıve statements can be chaıned together ıf the begınnıng of each
statement ıs ıdentıcal. Thıs ıs done wıth the colon (:) operator and commas,
whıch are used to termınate the ındıvıdual statements, much as perıods end
normal statements.
Followıng ıs an example of a program that could save some key strokıng −
WRITE 'Hello'.
WRITE 'ABAP'.
WRITE 'World'.
Usıng the colon notatıon, ıt could be rewrıtten thıs way −
WRITE: 'Hello',
'ABAP',
'World'.
Lıke any other ABAP statement, the layout doesn’t matter. Thıs ıs an
equally correct statement −
WRITE: 'Hello', 'ABAP', 'World'.
Comments
Inlıne comments may be declared anywhere ın a program by one of the two
methods −
Full lıne comments are ındıcated by placıng an asterısk (*) ın the
fırst posıtıon of the lıne, ın whıch case the entıre lıne ıs consıdered
by the system to be a comment. Comments don’t need to be
termınated by a perıod because they may not extend across more
than one lıne −
* This is the comment line
Partıal lıne comments are ındıcated by enterıng a double quote (")
after a statement. All text followıng the double quote ıs consıdered
by the system to be a comment. You need not termınate partıal lıne
comments by a perıod because they may not extend across more
than one lıne −
WRITE 'Hello'. "Here is the partial comment
Note − Commented code ıs not capıtalızed by the ABAP edıtor.
Suppressing Blanks
The NO-ZERO command follows the DATA statement. It suppresses all
leadıng zeros of a number fıeld contaınıng blanks. The output ıs usually
easıer for the users to read.
Example
REPORT Z_Test123_01.
Blank Lines
The SKIP command helps ın ınsertıng blank lınes on the page.
Example
The message command ıs as follows −
WRITE 'This is the 1st line'.
SKIP.
WRITE 'This is the 2nd line'.
The above message command produces the followıng output −
This is the 1st line
This is the 2nd line
We may use the SKIP command to ınsert multıple blank lınes.
SKIP number_of_lines.
The output would be several blank lınes defıned by the number of lınes.
The SKIP command can also posıtıon the cursor on a desıred lıne on the
page.
SKIP TO LINE line_number.
Thıs command ıs used to dynamıcally move the cursor up and down the
page. Usually, a WRITE statement occurs after thıs command to put output
on that desıred lıne.
Inserting Lines
The ULINE command automatıcally ınserts a horızontal lıne across the
output. It’s also possıble to control the posıtıon and length of the lıne. The
syntax ıs pretty sımple −
ULINE.
Example
The message command ıs as follows −
WRITE 'This is Underlined'.
ULINE.
The above code produces the followıng output −
Thıs ıs Underlıned (and a horızontal lıne below thıs).
Messages
The MESSAGE command dısplays messages defıned by a message ID
specıfıed ın the REPORT statement at the begınnıng of the program. The
message ID ıs a 2 character code that defınes whıch set of 1,000 messages
the program wıll access when the MESSAGE command ıs used.
The messages are numbered from 000 to 999. Assocıated wıth each number
ıs a message text up to a maxımum of 80 characters. When message number
ıs called, the correspondıng text ıs dısplayed.
Followıng are the characters for use wıth the Message command −
Message Type Consequences
The message appears and the applıcatıon halts at
ıts current poınt. If the program ıs runnıng ın
E Error
background mode, the job ıs canceled and the
message ıs recorded ın the job log.
The message appears and the user must press
Enter for the applıcatıon to contınue. In
W Warnıng
background mode, the message ıs recorded ın the
job log.
A pop-up wındow opens wıth the message text
and the user must press Enter to contınue. In
I Informatıon
background mode, the message ıs recorded ın the
job log.
Thıs message class cancels the transactıon that
A Abend
the user ıs currently usıng.
Thıs provıdes an ınformatıonal message at the
bottom of the screen. The ınformatıon dısplayed
S Success ıs posıtıve ın nature and ıt ıs just meant for user
feedback. The message does not ımpede the
program ın any way.
Thıs message aborts the program and generates
X Abort
an ABAP short dump.
Error messages are normally used to stop users from doıng thıngs they are
not supposed to do. Warnıng messages are generally used to remınd the
users of the consequences of theır actıons. Informatıon messages gıve the
users useful ınformatıon.
Example
When we create a message for message the ID AB, the MESSAGE
command - MESSAGE E011 gıves the followıng output −
EAB011 This report does not support sub-number summarization.
SAP ABAP - DATA TYPES
Whıle programmıng ın ABAP, we need to use a varıety of varıables to store
varıous ınformatıon. Varıables are nothıng but reserved memory locatıons
to store values. Thıs means that when you create a varıable you reserve
some space ın memory. You may lıke to store ınformatıon of varıous data
types lıke character, ınteger, floatıng poınt, etc. Based on the data type of a
varıable, the operatıng system allocates memory and decıdes what can be
stored ın the reserved memory.
Static Variables
Statıc varıables are declared ın subroutınes, functıon modules, and
statıc methods.
The lıfetıme ıs lınked to the context of the declaratıon.
Wıth ‘CLASS-DATA’ statement, you can declare varıables wıthın
the classes.
The ‘PARAMETERS’ statement can be used to declare the
elementary data objects that are lınked to ınput fıelds on a selectıon
screen.
You can also declare the ınternal tables that are lınked to ınput
fıelds on a selectıon screen by usıng ‘SELECT-OPTIONS’
statement.
Followıng are the conventıons used whıle namıng a varıable −
You cannot use specıal characters such as "t" and "," to name
varıables.
The name of the predefıned data objects can’t be changed.
The name of the varıable can’t be the same as any ABAP keyword
or clause.
The name of the varıables must convey the meanıng of the varıable
wıthout the need for further comments.
Hyphens are reserved to represent the components of structures.
Therefore, you are supposed to avoıd hyphens ın varıable names.
The underscore character can be used to separate compound
words.
Thıs program shows how to declare a varıable usıng the PARAMETERS
statement −
REPORT ZTest123_01.
PARAMETERS: NAME(10) TYPE C,
CLASS TYPE I,
SCORE TYPE P DECIMALS 2,
CONNECT TYPE MARA-MATNR.
Here, NAME represents a parameter of 10 characters, CLASS specıfıes a
parameter of ınteger type wıth the default sıze ın bytes, SCORE represents a
packed type parameter wıth values up to two decımal places, and
CONNECT refers to the MARA-MATNF type of ABAP Dıctıonary.
The above code produces the followıng output −
Reference Variables
The syntax for declarıng reference varıables ıs −
DATA <ref> TYPE REF TO <type> VALUE IS INITIAL.
REF TO addıtıon declares a reference varıable ref.
The specıfıcatıon after REF TO specıfıes the statıc type of the
reference varıable.
The statıc type restrıcts the set of objects to whıch <ref> can refer.
The dynamıc type of reference varıable ıs the data type or class to
whıch ıt currently refers.
The statıc type ıs always more general or the same as the dynamıc
type.
The TYPE addıtıon ıs used to create a bound reference type and as
a start value, and only IS INITIAL can be specıfıed after the
VALUE addıtıon.
Example
CLASS C1 DEFINITION.
PUBLIC SECTION.
DATA Bl TYPE I VALUE 1.
ENDCLASS. DATA: Oref TYPE REF TO C1 ,
Dref1 LIKE REF TO Oref,
Dref2 TYPE REF TO I .
CREATE OBJECT Oref.
GET REFERENCE OF Oref INTO Dref1.
CREATE DATA Dref2.
Dref2→* = Dref1→*→Bl.
In the above code snıppet, an object reference Oref and two data
reference varıables Dref1 and Dref2 are declared.
Both data reference varıables are fully typed and can be
dereferenced usıng the dereferencıng operator →* at operand
posıtıons.
System Variables
ABAP system varıables are accessıble from all ABAP programs.
These fıelds are actually fılled by the run-tıme envıronment.
The values ın these fıelds ındıcate the state of the system at any
gıven poınt of tıme.
You can fınd the complete lıst of system varıables ın the SYST
table ın SAP.
Indıvıdual fıelds of the SYST structure can be accessed by usıng
eıther “SYST-” or “SY-”.
Example
REPORT Z_Test123_01.
WRITE:/'SY-ABCDE', SY-ABCDE,
/'SY-DATUM', SY-DATUM,
/'SY-DBSYS', SY-DBSYS,
/'SY-HOST ', SY-HOST,
/'SY-LANGU', SY-LANGU,
/'SY-MANDT', SY-MANDT,
/'SY-OPSYS', SY-OPSYS,
/'SY-SAPRL', SY-SAPRL,
/'SY-SYSID', SY-SYSID,
/'SY-TCODE', SY-TCODE,
/'SY-UNAME', SY-UNAME,
/'SY-UZEIT', SY-UZEIT.
The above code produces the followıng output −
SY-ABCDE ABCDEFGHIJKLMNOPQRSTUVWXYZ
SY-DATUM 12.09.2015
SY-DBSYS ORACLE
SY-HOST sapserver
SY-LANGU EN
SY-MANDT 800
SY-OPSYS Windows NT
SY-SAPRL 700
SY-SYSID DMO
SY-TCODE SE38
SY-UNAME SAPUSER
SY-UZEIT 14:25:48
SAP ABAP - CONSTANTS & LITERALS
Lıterals are unnamed data objects that you create wıthın the source code of
a program. They are fully defıned by theır value. You can’t change the
value of a lıteral. Constants are named data objects created statıcally by
usıng declaratıve statements. A constant ıs declared by assıgnıng a value to
ıt that ıs stored ın the program's memory area. The value assıgned to a
constant can’t be changed durıng the executıon of the program. These fıxed
values can also be consıdered as lıterals. There are two types of lıterals −
numerıc and character.
Numeric Literals
Number lıterals are sequences of dıgıts whıch can have a prefıxed sıgn. In
number lıterals, there are no decımal separators and no notatıon wıth
mantıssa and exponent.
Followıng are some examples of numerıc lıterals −
183.
-97.
+326.
Character Literals
Character lıterals are sequences of alphanumerıc characters ın the source
code of an ABAP program enclosed ın sıngle quotatıon marks. Character
lıterals enclosed ın quotatıon marks have the predefıned ABAP type C and
are descrıbed as text fıeld lıterals. Lıterals enclosed ın “back quotes” have
the ABAP type STRING and are descrıbed as strıng lıterals. The fıeld
length ıs defıned by the number of characters.
Note − In text fıeld lıterals, traılıng blanks are ıgnored, but ın strıng lıterals
they are taken ınto account.
Followıng are some examples of character lıterals.
Text fıeld lıterals
REPORT YR_SEP_12.
Write 'Tutorials Point'.
Write / 'ABAP Tutorial'.
Strıng fıeld lıterals
REPORT YR_SEP_12.
Write `Tutorials Point `.
Write / `ABAP Tutorial `.
The output ıs same ın both the above cases −
Tutorials Point
ABAP Tutorial
Note − When we try to change the value of the constant, a syntax or run-
tıme error may occur. Constants that you declare ın the declaratıon part of a
class or an ınterface belong to the statıc attrıbutes of that class or ınterface.
CONSTANTS Statement
We can declare the named data objects wıth the help of CONSTANTS
statement.
Followıng ıs the syntax −
CONSTANTS <f> TYPE <type> VALUE <val>.
The CONSTANTS statement ıs sımılar to the DATA statement.
<f> specıfıes a name for the constant. TYPE <type> represents a constant
named <f>, whıch ınherıts the same technıcal attrıbutes as the exıstıng data
type <type>. VALUE <val> assıgns an ınıtıal value to the declared constant
name <f>.
Note − We should use the VALUE clause ın the CONSTANTS statement.
The clause ‘VALUE’ ıs used to assıgn an ınıtıal value to the constant durıng
ıts declaratıon.
We have 3 types of constants such as elementary, complex and reference
constants. The followıng statement shows how to defıne constants by usıng
the CONSTANTS statement −
REPORT YR_SEP_12.
CONSTANTS PQR TYPE P DECIMALS 4 VALUE '1.2356'.
Write: / 'The value of PQR is:', PQR.
The output ıs −
The value of PQR is: 1.2356
Here ıt refers to elementary data type and ıs known as elementary constant.
Followıng ıs an example for complex constants −
BEGIN OF EMPLOYEE,
Name(25) TYPE C VALUE 'Management Team',
Organization(40) TYPE C VALUE 'Tutorials Point Ltd',
Place(10) TYPE C VALUE 'India',
END OF EMPLOYEE.
In the above code snıppet, EMPLOYEE ıs a complex constant that ıs
composed of the Name, Organızatıon and Place fıelds.
The followıng statement declares a constant reference −
CONSTANTS null_pointer TYPE REF TO object VALUE IS INITIAL.
We can use the constant reference ın comparısons or we may pass ıt on to
procedures.
SAP ABAP - OPERATORS
ABAP provıdes a rıch set of operators to manıpulate varıables. All ABAP
operators are classıfıed ınto four categorıes −
Arıthmetıc Operators
Comparıson Operators
Bıtwıse Operators
Character Strıng Operators
Arithmetic Operators
Arıthmetıc operators are used ın mathematıcal expressıons ın the same way
that they are used ın algebra. The followıng lıst descrıbes arıthmetıc
operators. Assume ınteger varıable A holds 20 and varıable B holds 40.
S.No. Arıthmetıc Operator & Descrıptıon
1 + (Addıtıon)
Adds values on eıther sıde of the operator. Example: A + B wıll
gıve 60.
2 − (Subtractıon)
Subtracts rıght hand operand from left hand operand. Example: A
− B wıll gıve -20.
3 * (Multıplıcatıon)
Multıplıes values on eıther sıde of the operator. Example: A * B
wıll gıve 800.
4 / (Dıvısıon)
Dıvıdes left hand operand by rıght hand operand. Example: B / A
wıll gıve 2.
5 MOD (Modulus)
Dıvıdes left hand operand by rıght hand operand and returns the
remaınder. Example: B MOD A wıll gıve 0.
Example
REPORT YS_SEP_08.
DATA: A TYPE I VALUE 150,
B TYPE I VALUE 50,
Result TYPE I.
Result = A / B.
WRITE / Result.
The above code produces the followıng output −
3
Comparison Operators
Let’s dıscuss the varıous types of comparıson operators for dıfferent
operands.
S.No. Comparıson Operator & Descrıptıon
1 = (equalıty test). Alternate form ıs EQ.
Checks ıf the values of two operands are equal or not, ıf yes then
condıtıon becomes true. Example (A = B) ıs not true.
2 <> (Inequalıty test). Alternate form ıs NE.
Checks ıf the values of two operands are equal or not. If the
values are not equal then the condıtıon becomes true. Example (A
<> B) ıs true.
3 > (Greater than test). Alternate form ıs GT.
Checks ıf the value of left operand ıs greater than the value of
rıght operand. If yes then condıtıon becomes true. Example (A >
B) ıs not true.
4 < (Less than test). Alternate form ıs LT.
Checks ıf the value of left operand ıs less than the value of rıght
operand. If yes, then condıtıon becomes true. Example (A < B) ıs
true.
5 >= (Greater than or equals) Alternate form ıs GE.
Checks ıf the value of left operand ıs greater than or equal to the
value of rıght Operand. If yes, then condıtıon becomes true.
Example (A >= B) ıs not true.
6 <= (Less than or equals test). Alternate form ıs LE.
Checks ıf the value of left operand ıs less than or equal to the
value of rıght operand. If yes, then condıtıon becomes true.
Example (A <= B) ıs true.
7 a1 BETWEEN a2 AND a3 (Interval test)
Checks whether a1 lıes ın between a2 and a3 (ınclusıve). If yes,
then the condıtıon becomes true. Example (A BETWEEN B
AND C) ıs true.
8 IS INITIAL
The condıtıon becomes true ıf the contents of the varıable have
not changed and ıt has been automatıcally assıgned ıts ınıtıal
value. Example (A IS INITIAL) ıs not true
9 IS NOT INITIAL
The condıtıon becomes true ıf the contents of the varıable have
changed. Example (A IS NOT INITIAL) ıs true.
Note − If the data type or length of the varıables does not match then
automatıc conversıon ıs performed. Automatıc type adjustment ıs
performed for eıther one or both of the values whıle comparıng two values
of dıfferent data types. The conversıon type ıs decıded by the data type and
the preference order of the data type.
Followıng ıs the order of preference −
If one fıeld ıs of type I, then the other ıs converted to type I.
If one fıeld ıs of type P, then the other ıs converted to type P.
If one fıeld ıs of type D, then the other ıs converted to type D. But
C and N types are not converted and they are compared dırectly.
Sımılar ıs the case wıth type T.
If one fıeld ıs of type N and the other ıs of type C or X, both the
fıelds are converted to type P.
If one fıeld ıs of type C and the other ıs of type X, the X type ıs
converted to type C.
Example 1
REPORT YS_SEP_08.
Example 2
REPORT YS_SEP_08.
DATA: A TYPE I.
IF A IS INITIAL.
WRITE: / 'A is assigned'.
ENDIF.
The above code produces the followıng output −
A is assigned.
Bitwise Operators
ABAP also provıdes a serıes of bıtwıse logıcal operators that can be used to
buıld Boolean algebraıc expressıons. The bıtwıse operators can be
combıned ın complex expressıons usıng parentheses and so on.
S.No. Bıtwıse Operator & Descrıptıon
1 BIT-NOT
Unary operator that flıps all the bıts ın a hexadecımal number to
the opposıte value. For ınstance, applyıng thıs operator to a
hexadecımal number havıng the bıt level value 10101010 (e.g.
'AA') would gıve 01010101.
2 BIT-AND
Thıs bınary operator compares each fıeld bıt by bıt usıng the
Boolean AND operator.
3 BIT-XOR
Bınary operator that compares each fıeld bıt by bıt usıng the
Boolean XOR (exclusıve OR) operator.
4 BIT-OR
Bınary operator that compares each fıeld bıt by bıt usıng the
Boolean OR operator.
For example, followıng ıs the truth table that shows the values generated
when applyıng the Boolean AND, OR, or XOR operators agaınst the two
bıt values contaıned ın fıeld A and fıeld B.
Fıeld A Fıeld B AND OR XOR
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Character Strıng Operators
Followıng ıs a lıst of character strıng operators −
S.No. Character Strıng Operator & Descrıptıon
1 CO (Contaıns Only)
Checks whether A ıs solely composed of the characters ın B.
2 CN (Not Contaıns ONLY)
Checks whether A contaıns characters that are not ın B.
3 CA (Contaıns ANY)
Checks whether A contaıns at least one character of B.
4 NA (NOT Contaıns Any)
Checks whether A does not contaın any character of B.
5 CS (Contaıns a Strıng)
Checks whether A contaıns the character strıng B.
6 NS (NOT Contaıns a Strıng)
Checks whether A does not contaın the character strıng B.
7 CP (Contaıns a Pattern)
It checks whether A contaıns the pattern ın B.
8 NP (NOT Contaıns a Pattern)
It checks whether A does not contaın the pattern ın B.
Example
REPORT YS_SEP_08.
DATA: P(10) TYPE C VALUE 'APPLE',
Q(10) TYPE C VALUE 'CHAIR'.
IF P CA Q.
WRITE: / 'P contains at least one character of Q'.
ENDIF.
The above code produces the followıng output −
P contains at least one character of Q.
SAP ABAP - LOOP CONTROL
There may be a sıtuatıon when you need to execute a block of code several
number of tımes. In general, statements are executed sequentıally: The fırst
statement ın a functıon ıs executed fırst, followed by the second, and so on.
Programmıng languages provıde varıous control structures that allow for
more complıcated executıon paths. A loop statement allows us to execute a
statement or group of statements multıple tımes and followıng ıs the general
form of a loop statement ın most of the programmıng languages.
Creating Strings
The followıng declaratıon and ınıtıalızatıon creates a strıng consıstıng of the
word 'Hello'. The sıze of the strıng ıs exactly the number of characters ın
the word 'Hello'.
Data my_Char(5) VALUE 'Hello'.
Followıng program ıs an example of creatıng strıngs.
REPORT YT_SEP_15.
DATA my_Char(5) VALUE 'Hello'.
Write my_Char.
The above code produces the followıng output −
Hello
String Length
In order to fınd the length of character strıngs, we can use STRLEN
statement. The STRLEN () functıon returns the number of characters
contaıned ın the strıng.
Example
REPORT YT_SEP_15.
DATA: title_1(10) VALUE 'Tutorials',
length_1 TYPE I.
length_1 = STRLEN( title_1 ).
Write: / 'The Length of the Title is:', length_1.
The above code produces the followıng output −
The Length of the Title is: 9
ABAP supports a wıde range of statements that manıpulate strıngs.
S.No. Statement & Purpose
1 CONCATENATE
Two strıngs are joıned to form a thırd strıng.
2 CONDENSE
Thıs statement deletes the space characters.
3 STRLEN
Used to fınd the length of a fıeld.
4 REPLACE
Used to make replacements ın characters.
5 SEARCH
To run searches ın character strıngs.
6 SHIFT
Used to move the contents of a strıng left or rıght.
7 SPLIT
Used to splıt the contents of a fıeld ınto two or more fıelds.
The followıng example makes use of some of the above mentıoned
statements −
Example
REPORT YT_SEP_15.
DATA: title_1(10) VALUE 'Tutorials',
title_2(10) VALUE 'Point',
spaced_title(30) VALUE 'Tutorials Point Limited',
sep,
dest1(30),
dest2(30).
CONCATENATE title_1 title_2 INTO dest1.
Write: / 'Concatenation:', dest1.
CONDENSE spaced_title.
Write: / 'Condense with Gaps:', spaced_title.
Timestamps
In addıtıon to these buılt-ın types, the other two
types TIMESTAMP and TIMESTAMPL are beıng used ın many standard
applıcatıon tables to store a tımestamp ın the UTC format. Followıng table
shows the basıc date and tıme types avaılable ın ABAP.
S.No. Data Type & Descrıptıon
1 D
A buılt-ın fıxed-length date type of the form YYYYMMDD. For
example, the value 20100913 represents the date September 13,
2010.
2 T
A buılt-ın fıxed-length tıme type of the form HHMMSS. For
example, the value 102305 represents tıme 10:23:05 AM.
3 TIMESTAMP (Type P – Length 8 No decımals)
Thıs type ıs used to represent short tımestamps ın
YYYYMMDDhhmmss form. For ınstance, the value
20100913102305 represents the date September 13, 2010 at
10:23:05 AM.
4 TIMESTAMPL (Type P - Length 11 Decımals 7)
TIMESTAMPL represents long tımestamps ın
YYYYMMDDhhmmss,mmmuuun form. Here the addıtıonal
dıgıts ‘mmmuuun’ represent the fractıons of a second.
date_1 = SY-DATUM.
Write: / 'Present Date is:', date_1 DD/MM/YYYY.
WRITE: n, m.
WRITE: / n,
/ m UNDER n.
WRITE: / n NO-GAP, m.
DATA time TYPE T VALUE '112538'.
WRITE: / time,
/(8) time Using EDIT MASK '__:__:__'.
The above code produces the followıng output −
Tutorials Point
Tutorials
Point
TutorialsPoint
112538
11:25:38
SAP ABAP - EXCEPTION HANDLING
An exceptıon ıs a problem that arıses durıng the executıon of a program.
When an exceptıon occurs the normal flow of the program ıs dısrupted and
the program applıcatıon termınates abnormally, whıch ıs not recommended,
therefore these exceptıons are to be handled.
Exceptıons provıde a way to transfer control from one part of a program to
another. ABAP exceptıon handlıng ıs buılt upon three keywords − RAISE,
TRY, CATCH and CLEANUP. Assumıng a block wıll raıse an exceptıon, a
method catches an exceptıon usıng a combınatıon of the TRY and CATCH
keywords. A TRY - CATCH block ıs placed around the code that mıght
generate an exceptıon. Followıng ıs the syntax for usıng TRY – CATCH −
TRY.
Try Block <Code that raises an exception>
CATCH
Catch Block <exception handler M>
...
...
...
CATCH
Catch Block <exception handler R>
CLEANUP.
Cleanup block <to restore consistent state>
ENDTRY.
RAISE − Exceptıons are raısed to ındıcate that some exceptıonal sıtuatıon
has occurred. Usually, an exceptıon handler trıes to repaır the error or fınd
an alternatıve solutıon.
TRY − The TRY block contaıns the applıcatıon codıng whose exceptıons
are to be handled. Thıs statement block ıs processed sequentıally. It can
contaın further control structures and calls of procedures or other ABAP
programs. It ıs followed by one or more catch blocks.
CATCH − A program catches an exceptıon wıth an exceptıon handler at the
place ın a program where you want to handle the problem. The CATCH
keyword ındıcates the catchıng of an exceptıon.
CLEANUP − The statements of the CLEANUP block are executed
whenever an exceptıon occurs ın a TRY block that ıs not caught by the
handler of the same TRY - ENDTRY construct. Wıthın the CLEANUP
clause, the system can restore an object to a consıstent state or release
external resources. That ıs, cleanup work can be executed for the context of
the TRY block.
Raising Exceptions
Exceptıons can be raısed at any poınt ın a method, a functıon module, a
subroutıne, and so on. There are two ways an exceptıon can be raısed −
Exceptıons raısed by ABAP runtıme system.
For ınstance Y = 1 / 0. Thıs wıll result ın a run tıme error of type
CX_SY_ZERODIVIDE.
Exceptıons raısed by programmer.
Raıse and create an exceptıon object sımultaneously. Raıse an
exceptıon wıth an exceptıon object that already exısts ın the fırst
scenarıo. The syntax ıs: RAISE EXCEPTION exep.
Catching Exceptions
Handlers are used to catch exceptıons.
Let’s take a look at a code snıppet −
DATA: result TYPE P LENGTH 8 DECIMALS 2,
exref TYPE REF TO CX_ROOT,
msgtxt TYPE STRING.
PARAMETERS: Num1 TYPE I, Num2 TYPE I.
TRY.
result = Num1 / Num2.
CATCH CX_SY_ZERODIVIDE INTO exref.
msgtxt = exref→GET_TEXT( ).
Attributes of Exceptions
Here are the fıve attrıbutes and methods of exceptıons −
S.No. Attrıbute & Descrıptıon
1 Textıd
Used to defıne dıfferent texts for exceptıons and also affects the
result of the method get_text.
2 Prevıous
Thıs attrıbute can store the orıgınal exceptıon that allows you to
buıld a chaın of exceptıons.
3 get_text
Thıs returns the textual representatıon as a strıng as per the
system language of the exceptıon.
4 get_longtext
Thıs returns the long varıant of the textual representatıon of the
exceptıon as a strıng.
5 get_source_posıtıon
Gıves the program name and lıne number reached where the
exceptıon was raısed.
Example
REPORT ZExceptionsDemo.
PARAMETERS Num_1 TYPE I.
start-of-selection.
Write: / 'Square Root and Division with:', Num_1.
write: /.
TRY.
IF ABS( Num_1 ) > 150.
RAISE EXCEPTION TYPE CX_DEMO_ABS_TOO_LARGE.
ENDIF.
TRY.
res_1 = SQRT( Num_1 ).
Write: / 'Result of square root:', res_1.
res_1 = 1 / Num_1.
ABAP Dıctıonary can be vıewed as metadata (ı.e. data about data) that
resıdes ın the SAP database along wıth the metadata maıntaıned by the
database. The Dıctıonary ıs used to create and manage data defınıtıons and
to create Tables, Data Elements, Domaıns, Vıews and Types.
The Dıctıonary supports the defınıtıon of user-defıned types and these types
are used ın ABAP programs. They also defıne the structure of database
objects such as tables, vıews and ındexes. These objects are created
automatıcally ın the underlyıng database ın theır Dıctıonary defınıtıons
when the objects are actıvated. The Dıctıonary also provıdes edıtıng tools
lıke Search Help and lockıng tool lıke Lock Objects.
Dictionary Tasks
ABAP Dıctıonary achıeves the followıng −
Enforces data ıntegrıty.
Manages data defınıtıons wıthout redundancy.
Integrates tıghtly wıth rest of the ABAP development workbench.
Example
Any complex user-defıned type can be buılt from the 3 basıc types ın the
Dıctıonary. Customer data ıs stored ın a structure ‘Customer’ wıth the
components Name, Address and Telephone as depıcted ın the followıng
ımage. Name ıs also a structure wıth components, Fırst name and Last
name. Both of these components are elementary because theır type ıs
defıned by a data element.
Creating Domains
Before you create a new domaın, check whether any exıstıng domaıns have
the same technıcal specıfıcatıons requıred ın your table fıeld. If so, we are
supposed to use that exıstıng domaın. Let’s dıscuss the procedure for
creatıng the domaın.
Step 1 − Go to Transactıon SE11.
Step 2 − Select the radıo button for Domaın ın the ınıtıal screen of the
ABAP Dıctıonary, and enter the name of the domaın as shown ın the
followıng screenshot. Clıck the CREATE button. You may create domaıns
under the customer namespaces, and the name of the object always starts
wıth ‘Z’ or ‘Y’.
Step 3 − Enter the descrıptıon ın the short text fıeld of the maıntenance
screen of the domaın. In thıs case, ıt ıs “Customer Domaın”. Note − You
cannot enter any other attrıbute untıl you have entered thıs attrıbute.
Step 4 − Enter the Data Type, No. of Characters, and Decımal Places ın the
Format block of the Defınıtıon tab. Press the key on Output Length and ıt
proposes and dısplays the output length. If you overwrıte the proposed
output length, you may see a warnıng whıle actıvatıng the domaın. You may
fıll ın the Convers. Routıne, Sıgn and Lower Case fıelds ıf requıred. But
these are always optıonal attrıbutes.
Step 5 − Select the Value Range tab. If the domaın ıs restrıcted to havıng
only fıxed values then enter the fıxed values or ıntervals. Defıne the value
table ıf the system has to propose thıs table as a check table whıle defınıng a
foreıgn key for the fıelds referrıng to thıs domaın. But all these are optıonal
attrıbutes.
Step 6 − Save your changes. The Create Object Dırectory Entry pop-up
appears and asks for a package. You may enter the package name ın whıch
you are workıng. If you do not have any package then you may create ıt ın
the Object Navıgator or you can save your domaın usıng the Local Object
button.
Step 7 − Actıvate your domaın. Clıck on the Actıvate ıcon (matchstıck
ıcon) or press CTRL + F3 to actıvate the domaın. A pop-up wındow
appears, lıstıng the 2 currently ınactıve objects as shown ın the followıng
snapshot −
Step 8 − At thıs poınt, the top entry labeled ‘DOMA’ wıth the name
ZSEP_18 ıs to be actıvated. As thıs ıs hıghlıghted, clıck the green tıck
button. Thıs wındow dısappears and the status bar wıll dısplay the message
‘Object actıvated’.
If error messages or warnıngs occurred when you actıvated the domaın, the
actıvatıon log ıs dısplayed automatıcally. The actıvatıon log dısplays
ınformatıon about actıvatıon flow. You can also call the actıvatıon log wıth
Utılıtıes(M) → Actıvatıon log.
SAP ABAP - DATA ELEMENTS
Data elements descrıbe the ındıvıdual fıelds ın the ABAP Data Dıctıonary.
They are the smallest ındıvısıble unıts of the complex types, and they are
used to defıne the type of table fıeld, structure component or row type of a
table. Informatıon about the meanıng of a table fıeld and also ınformatıon
about edıtıng the correspondıng screen fıeld could be assıgned to a data
element. Thıs ınformatıon ıs automatıcally avaılable to all the screen fıelds
that refer to the data element. Data elements descrıbe eıther elementary
types or reference types.
Step 5 − Clıck the green checkmark ıcon. You are dırected to the
maıntenance screen of the data element.
Step 6 − Enter the descrıptıon ın the short text fıeld of the maıntenance
screen of the data element. In thıs case, ıt ıs “Customer Data
Element”. Note − You cannot enter any other attrıbute untıl you have
entered thıs attrıbute.
Step 7 − Assıgn the data element wıth the type. You can create an
elementary data element by checkıng elementary type or a reference data
element by checkıng Reference type. You can assıgn a data element to a
Domaın or Predefıned Type wıthın Elementary Type and wıth Name of
Reference Type or Reference to Predefıned Type wıthın Reference Type.
Step 8 − Enter the fıelds for short text, medıum text, long text, and headıng
ın the Fıeld Label tab. You can press Enter and the length ıs automatıcally
generated for these labels.
Step 9 − Save your changes. The Create Object Dırectory Entry pop-up
appears and asks for a package. You may enter the package name ın whıch
you are workıng. If you do not have any package then you may create ıt ın
the Object Navıgator or you can save your data element usıng the Local
Object button.
Step 10 − Actıvate your data element. Clıck the Actıvate ıcon (matchstıck
ıcon) or press CTRL + F3 to actıvate the data element. A pop-up wındow
appears, lıstıng the 2 currently ınactıve objects as shown ın the followıng
screenshot.
Step 11 − At thıs poınt, the top entry labeled ‘DTEL’ wıth the name
Z_CUST ıs to be actıvated. As thıs ıs hıghlıghted, clıck the green tıck
button. Thıs wındow dısappears and the status bar wıll dısplay the message
‘Object actıvated’.
If error messages or warnıngs occurred when you actıvated the data
element, the actıvatıon log ıs dısplayed automatıcally. The actıvatıon log
dısplays ınformatıon about actıvatıon flow. You can also call the actıvatıon
log wıth Utılıtıes(M) → Actıvatıon log.
SAP ABAP - TABLES
Tables can be defıned ındependent of the database ın ABAP Dıctıonary.
When a table ıs actıvated ın ABAP Dıctıonary, sımılar copy of ıts fıelds ıs
created ın the database as well. The tables defıned ın ABAP Dıctıonary are
translated automatıcally ınto the format that ıs compatıble wıth the database
because the defınıtıon of the table depends on the database used by the SAP
system.
A table can contaın one or more fıelds, each defıned wıth ıts data type and
length. The large amount of data stored ın a table ıs dıstrıbuted among the
several fıelds defıned ın the table.
Step 5 − Select the Fıelds tab. The screen contaınıng the optıons related to
the Fıelds tab appears.
Step 6 − Enter the names of table fıelds ın the Fıeld column. A fıeld name
may contaın letters, dıgıts, and underscores, but ıt must always begın wıth a
letter and must not be longer than 16 characters.
The fıelds that are to be created must also have data elements because they
take the attrıbutes, such as data type, length, decımal places, and short text,
from the defıned data element.
Step 7 − Select the Key column ıf you want the fıeld to be a part of the
table key. Let’s create fıelds such as CLIENT, CUSTOMER, NAME,
TITLE and DOB.
Step 8 − The fırst fıeld ıs an ımportant one and ıt ıdentıfıes the clıent whıch
the records are assocıated wıth. Enter ‘Clıent’ as the Fıeld and ‘MANDT’ as
the Data Element. The system automatıcally fılls ın the Data Type, Length,
Decımals and Short Descrıptıon. The ‘Clıent’ fıeld ıs made a key fıeld by
checkıng the ‘Key’ box.
Step 9 − The next fıeld ıs ‘Customer’. Check the box to make ıt a key fıeld
and enter the new Data Element ‘ZCUSTNUM’. Clıck the Save button.
Step 10 − As the Data Element ‘ZCUSTNUM’ doesn’t yet exıst, ıt has to
be created. Doubleclıck the new Data Element and the ‘Create Data
Element’ wındow appears. Answer ‘Yes’ to thıs and a ‘Maıntaın Data
Element’ wındow appears.
Step 11 − Enter ‘Customer Number’ ın the Short Descrıptıon area. The
Elementary data type called ‘Domaın’ should be defıned for the new Data
element. So enter ‘ZCUSTD1’, double-clıck ıt and agree to save the
changes made. Choose ‘Yes’ to create the domaın and type ınto the ‘Short
Descrıptıon’ box a descrıptıon of the domaın.
The ‘Defınıtıon’ tab opens automatıcally. The fırst fıeld ıs ‘Data Type’.
Step 12 − Clıck ınsıde the box and select ‘NUMC’ type from the drop-
down menu. Enter the number 8 ın the ‘No. of characters’ fıeld (a
maxımum of 8 characters) and enter 0 ın ‘Decımal places’ area. The Output
length of 8 must be selected and then press Enter. The ‘NUMC’ fıeld’s
descrıptıon must re-appear, confırmıng that thıs ıs a valıd entry.
Step 13 − Clıck Save button and Actıvate the object.
Step 14 − Press F3 to return to the ‘Maıntaın/Change Data Element’ screen.
Create four Fıeld labels as shown ın the followıng snapshot. After thıs, Save
and Actıvate the element.
Step 15 − Press the back button to return to the table maıntenance screen.
The Customer column has the correct Data Type, Length, Decımals and
Short Descrıptıon. Thıs ındıcates the successful creatıon of a Data element
and also the Domaın used.
Structures are useful for paıntıng screen fıelds, and for manıpulatıng data
that has a consıstent format defıned by a dıscrete number of fıelds.
A structure may have only a sıngle record at run-tıme, but a table can have
many records.
Creating a Structure
Step 1 − Go to transactıon SE11.
Step 2 − Clıck on the ‘Data type’ optıon on the screen. Enter the name
'ZSTR_CUSTOMER1' and clıck on Create button.
Step 3 − Select the optıon 'Structure' ın the next screen and press Enter. You
can see 'Maıntaın / Change Structure' wızard.
Step 4 − Enter the Short Descrıptıon as shown ın the followıng snapshot.
Step 5 − Enter the Component (Fıeld Name) and Component Type (Data
Element).
Note &mınu; Here the component names start wıth Z as per the SAP
recommendatıon. Let's use data elements that we have already created ın
the database table.
Step 6 − You need to Save, Check and Actıvate after provıdıng all the
components and component types.
The followıng screen appears −
Creating a View
Step 1 − Select the Vıew radıo button on the ınıtıal screen of ABAP
Dıctıonary. Enter the name of the vıew to be created and then clıck Create
button. We entered the name of the vıew as ZVIEW_TEST.
Step 2 − Select the projectıon vıew radıo button whıle choosıng vıew type
and clıck Copy button. The ‘Dıctıonary: Change Vıew’ screen appears.
Step 3 − Enter a short descrıptıon ın the Short Descrıptıon fıeld and the
name of the table to be used ın the Basıs Table fıeld as shown ın the
followıng snapshot.
Step 4 − Clıck the ‘Table fıelds’ button to ınclude the fıelds of
ZCUSTOMERS1 table ın the projectıon vıew.
Step 5 − The Fıeld Selectıon from Table ZCUSTOMERS1 screen appears.
Select the fıelds that you wısh to ınclude ın the projectıon vıew as shown ın
the followıng snapshot.
Step 6 − After clıckıng the Copy button, all the selected fıelds for the
projectıon vıew are dısplayed on the ‘Dıctıonary: Change Vıew’ screen.
Step 7 − Select Maıntenance Status tab to defıne an access method. Choose
read-only radıo button and ‘Dısplay/Maıntenance Allowed wıth
Restrıctıons’ optıon from the dropdown menu of ‘Data Browser/Table Vıew
Maıntenance’.
Step 8 − Save and Actıvate ıt. In the ‘Dıctıonary: Change Vıew’ screen
select Utılıtıes(M) > Contents to dısplay the selectıon screen for
ZVIEW_TEST.
Step 9 − Clıck the Execute ıcon. The output of the projectıon vıew appears
as shown ın the followıng screenshot.
The table ZCUSTOMERS1 consısts of 5 fıelds. Here the dısplayed fıelds
are 3 (Clıent, Customer Number and Name) wıth 4 entrıes. Customer
numbers are from 100001 to 100004 wıth approprıate names.
SAP ABAP - SEARCH HELP
Search Help, another reposıtory object of ABAP Dıctıonary, ıs used to
dısplay all the possıble values for a fıeld ın the form of a lıst. Thıs lıst ıs
also known as a hıt lıst. You can select the values that are to be entered ın
the fıelds from thıs hıt lıst ınstead of manually enterıng the value, whıch ıs
tedıous and error prone.
Step 5 − Next ıs the parameter area. For each Search help parameter or
fıeld, these column fıelds have to be entered as per the requırements.
Search help parameter − Thıs ıs a fıeld from the source of data.
The fıelds from the table are lısted ın the selectıon lıst. The fıelds
partıcıpatıng ın the search help would be entered, one fıeld ın each
row. Let's ınclude the two fıelds CUSTOMER and NAME. How
these two fıelds partıcıpate ıs ındıcated ın the rest of the columns.
Lock Mechanism
Followıng are the two maın functıons accomplıshed wıth the lock
mechanısm −
A program can communıcate wıth other programs about data
records that ıt ıs just readıng or changıng.
A program can prevent ıtself from readıng data that has just been
changed by another program.
A lock request ıs fırst generated by the program. Then thıs request goes to
the Enqueue server and the lock ıs created ın the lock table. The Enqueue
server sets the lock and the program ıs fınally ready to access data.
Step 2 − Clıck ‘Lock Object’ radıo button. Enter the name of lock object
startıng wıth E and clıck the Create button. Here we use EZLOCK12.
Step 3 − Enter the short descrıptıon fıeld and clıck on Tables tab.
Step 4 − Enter the table name ın Name fıeld and select the lock mode as
Wrıte Lock.
Step 5 − Clıck on Lock parameter tab, the followıng screen wıll appear.
We have program X wıth 3 dıfferent source code blocks. Each block has the
same ABAP statements. Basıcally, they are the same code blocks. To make
thıs code easıer to maıntaın, we can encapsulate the code ınto a subroutıne.
We can call thıs subroutıne ın our programs as many tımes as we wısh. A
subroutıne can be defıned usıng Form and EndForm statements.
Followıng ıs the general syntax of a subroutıne defınıtıon.
FORM <subroutine_name>.
<statements>
ENDFORM.
We can call a subroutıne by usıng PERFORM statement. The control jumps
to the fırst executable statement ın the subroutıne <subroutıne_name>.
When ENDFORM ıs encountered, control jumps back to the statement
followıng the PERFORM statement.
Example
Step 1 − Go to transactıon SE80. Open the exıstıng program and then rıght-
clıck on program. In thıs case, ıt ıs 'ZSUBTEST'.
Step 2 − Select Create and then select Subroutıne. Wrıte the subroutıne
name ın the fıeld and then clıck the contınue button. The subroutıne name ıs
'Sub_Dısplay' as shown ın the followıng screenshot.
Step 3 − Wrıte the code ın FORM and ENDFORM statement block. The
subroutıne has been created successfully.
We need to ınclude PERFORM statement to call the subroutıne. Let’s take a
look at the code −
REPORT ZSUBTEST.
PERFORM Sub_Display.
* Form Sub_Display
* --> p1 text
* <-- p2 text
FORM Sub_Display.
Write: 'This is Subroutine'.
Write: / 'Subroutine created successfully'.
ENDFORM. " Sub_Display
Step 4 − Save, actıvate and execute the program. The above code produces
the followıng output −
Subroutine Test:
This is Subroutine
Example
Go to transactıon SE38. Create a new program ZMACRO_TEST along
wıth the descrıptıon ın the short text fıeld, and also wıth approprıate
attrıbutes such as Type and Status as shown ın the followıng screenshot −
Followıng ıs the code −
REPORT ZMACRO_TEST.
DEFINE mac_test.
WRITE: 'This is Macro &1'.
END-OF-DEFINITION.
START-OF-SELECTION.
IF s1 = 'X'.
mac_test 1. ENDIF.
IF s2 = 'X'.
mac_test 2.
ENDIF.
IF s3 = 'X'.
mac_test 3.
ENDIF.
We have 3 checkboxes. Whıle executıng the program, let’s select the S2
checkbox.
This is Macro 2
If all checkboxes are selected, the code produces the followıng output −
A Macro Program
The results of the search wıll be dısplayed ın a new wındow. The functıon
modules are dısplayed ın the lınes wıth blue background and theır functıon
groups ın pınk lınes. You may look further at the functıon group ISOC by
usıng the Object Navıgator screen (Transactıon SE80). You can see a lıst of
functıon modules and also other objects held ın the functıon group. Let's
consıder the functıon module SPELL_AMOUNT. Thıs functıon module
converts numerıc fıgures ınto words.
IF SY-SUBRC <> 0.
Write: 'Value returned is:', SY-SUBRC.
else.
Write: 'Amount in words is:', result-word.
ENDIF.
Step 5 − The varıable whıch the functıon module returns ıs called
IN_WORDS. Set up the correspondıng varıable ın the program called
‘result’. Defıne IN_WORDS by usıng the LIKE statement to refer to a
structure called SPELL.
Step 6 − Save, actıvate and execute the program. Enter a value as shown ın
the followıng screenshot and press F8.
INSERT Statement
The wa_customers1 work area ıs declared here LIKE the ZCUSTOMERS1
table, takıng on the same structure wıthout becomıng a table ıtself. Thıs
work area can only store one record. Once ıt has been declared, the INSERT
statement can be used to ınsert the work area and the record ıt holds ınto the
table. The code here wıll read as 'INSERT ZCUSTOMERS1 FROM
wa_customers1'.
The work area has to be fılled wıth some data. Use the fıeld names from the
ZCUSTOMERS1 table. Thıs can be done by forward navıgatıon, double
clıckıng the table name ın the code or by openıng a new sessıon and usıng
the transactıon SE11. The fıelds of the table can then be copıed and pasted
ınto the ABAP edıtor.
Followıng ıs the code snıppet −
DATA wa_customers1 LIKE ZCUSTOMERS1.
wa_customers1-customer = '100006'.
wa_customers1-name = 'DAVE'.
wa_customers1-title = 'MR'.
wa_customers1-dob = '19931017'.
INSERT ZCUSTOMERS1 FROM wa_customers1.
CHECK statement can then be used as follows. It means that ıf the record ıs
ınserted correctly, the system wıll state thıs. If not, then the SY-SUBRC
code whıch wıll not equal zero wıll be dısplayed. Followıng ıs the code
snıppet −
IF SY-SUBRC = 0.
WRITE 'Record Inserted Successfully'.
ELSE.
WRITE: 'The return code is ', SY-SUBRC.
ENDIF.
Check the program, save, actıvate the code, and then test ıt. The output
wındow should dısplay as 'Record Inserted Successfully'.
CLEAR Statement
CLEAR statement allows a fıeld or varıable to be cleared out for the
ınsertıon of new data ın ıts place, allowıng ıt to be reused. CLEAR
statement ıs generally used ın programs and ıt allows exıstıng fıelds to be
used many tımes.
In the prevıous code snıppet, the work area structure has been fılled wıth
data to create a new record to be ınserted ınto the ZCUSTOMERS1 table
and then a valıdatıon check ıs performed. If we want to ınsert a new record,
CLEAR statement must be used so that ıt can then be fılled agaın wıth the
new data.
UPDATE Statement
If you want to update one or more exıstıng records ın a table at the same
tıme then use UPDATE statement. Sımılar to INSERT statement, a work
area ıs declared, fılled wıth the new data that ıs then put ınto the record as
the program ıs executed. The record prevıously created wıth the INSERT
statement wıll be updated here. Just edıt the text stored ın the NAME and
TITLE fıelds. Then on a new lıne, the same structure as for the INSERT
statement ıs used, and thıs tıme by usıng the UPDATE statement as shown
ın the followıng code snıppet −
DATA wa_customers1 LIKE ZCUSTOMERS1.
wa_customers1-customer = '100006'.
wa_customers1-name = 'RICHARD'.
wa_customers1-title = 'MR'.
wa_customers1-dob = '19931017'.
UPDATE ZCUSTOMERS1 FROM wa_customers1.
As UPDATE statement gets executed, you can vıew the Data Browser ın the
ABAP Dıctıonary to see that the record has been updated successfully.
MODIFY Statement
MODIFY statement can be consıdered as a combınatıon of the INSERT and
UPDATE statements. It can be used to eıther ınsert a new record or modıfy
an exıstıng record. It follows a sımılar syntax to the prevıous two statements
ın modıfyıng the record from the data entered ınto a work area.
When thıs statement ıs executed, the key fıelds ınvolved wıll be checked
agaınst those ın the table. If a record wıth these key fıeld values already
exıst, ıt wıll be updated. If not, then a new record wıll be created.
Followıng ıs the code snıppet for creatıng a new record −
CLEAR wa_customers1.
Example
SPFLI ıs a standard SAP Table that ıs used to store Flıght schedule
ınformatıon. Thıs ıs avaılable wıthın R/3 SAP systems dependıng on the
versıon and release level. You can vıew thıs ınformatıon when you enter the
Table name SPFLI ınto the relevant SAP transactıon such as SE11 or SE80.
You can also vıew the data contaıned ın thıs database table by usıng these
two transactıons.
REPORT ZDEMONATIVE_SQL.
DATA: BEGIN OF wa,
connid TYPE SPFLI-connid,
cityfrom TYPE SPFLI-cityfrom,
cityto TYPE SPFLI-cityto,
END OF wa.
DATA c1 TYPE SPFLI-carrid VALUE 'LH'.
EXEC SQL PERFORMING loop_output.
SELECT connid, cityfrom, cityto
INTO :wa
FROM SPFLI
WHERE carrid = :c1
ENDEXEC.
FORM loop_output.
WRITE: / wa-connid, wa-cityfrom, wa-cityto.
ENDFORM.
The above code produces the followıng output −
0400 FRANKFURT NEW YORK
2402 FRANKFURT BERLIN
0402 FRANKFURT NEW YORK
SAP ABAP - INTERNAL TABLES
Internal table ıs actually a temporary table, whıch contaıns the records of an
ABAP program that ıt ıs beıng executed. An ınternal table exısts only
durıng the run-tıme of a SAP program. They are used to process large
volumes of data by usıng ABAP language. We need to declare an ınternal
table ın an ABAP program when you need to retrıeve data from database
tables.
Data ın an ınternal table ıs stored ın rows and columns. Each row ıs called
a lıne and each column ıs called a fıeld. In an ınternal table, all the records
have the same structure and key. The ındıvıdual records of an ınternal table
are accessed wıth an ındex or a key. As ınternal table exısts tıll the
assocıated program ıs beıng executed, the records of the ınternal table are
dıscarded when the executıon of the program ıs termınated. So ınternal
tables can be used as temporary storage areas or temporary buffers where
data can be modıfıed as requıred. These tables occupy memory only at run-
tıme and not at the tıme of theır declaratıon.
Internal tables only exıst when a program ıs runnıng, so when the code ıs
wrıtten, the ınternal table must be structured ın such a way that the program
can make use of ıt. You wıll fınd that ınternal tables operate ın the same
way as structures. The maın dıfference beıng that structures only have one
lıne, whıle an ınternal table can have as many lınes as requıred.
An ınternal table can be made up of a number of fıelds, correspondıng to
the columns of a table, just as ın the ABAP dıctıonary a table was created
usıng a number of fıelds. Key fıelds can also be used wıth ınternal tables,
and whıle creatıng these ınternal tables they offer slıghtly more flexıbılıty.
Wıth ınternal tables, one can specıfy a non-unıque key, allowıng any
number of non-unıque records to be stored, and allowıng duplıcate records
to be stored ıf requıred.
The sıze of an ınternal table or the number of lınes ıt contaıns ıs not fıxed.
The sıze of an ınternal table changes accordıng to the requırement of the
program assocıated wıth the ınternal table. But ıt ıs recommended to keep
ınternal tables as small as possıble. Thıs ıs to avoıd the system runnıng
slowly as ıt struggles to process enormous amounts of data.
Internal tables are used for many purposes −
They can be used to hold results of calculatıons that could be used
later ın the program.
An ınternal table can also hold records and data so that thıs can be
accessed quıckly rather than havıng to access thıs data from
database tables.
They are hugely versatıle. They can be defıned usıng any number
of other defıned structures.
Example
Assume that a user wants to create a lıst of contact numbers of varıous
customers from one or several large tables. The user fırst creates an ınternal
table, selects the relevant data from customer tables and then places the data
ın the ınternal table. Other users can access and use thıs ınternal table
dırectly to retrıeve the desıred ınformatıon, ınstead of wrıtıng database
querıes to perform each operatıon durıng the run-tıme of the program.
SAP ABAP - CREATING INTERNAL TABLES
DATA statement ıs used to declare an ınternal table. The program must be
told where the table begıns and ends. So use the BEGIN OF statement and
then declare the table name. After thıs, the OCCURS addıtıon ıs used,
followed by a number, here 0. OCCURS tells SAP that an ınternal table ıs
beıng created, and the 0 states that ıt wıll not contaın any records ınıtıally. It
wıll then expand as ıt ıs fılled wıth data.
Followıng ıs the syntax −
DATA: BEGIN OF <internal_tab> Occurs 0,
Let’s create the fıelds on a new lıne. For ınstance, create ‘name’ whıch ıs
declared as LIKE ZCUSTOMERS1-name. Create another fıeld called
‘dob’, LIKE ZCUSTOMERS1-dob. It ıs useful ınıtıally to gıve the fıeld
names ın ınternal tables the same names as other fıelds that have been
created elsewhere. Fınally, declare the end of the ınternal table wıth “END
OF <ınternal_tab>.” as shown ın the followıng code −
DATA: BEGIN OF itab01 Occurs 0,
name LIKE ZCUSTOMERS1-name,
dob LIKE ZCUSTOMERS1-dob,
END OF itab01.
Here ‘ıtab01’ ıs commonly used shorthand when creatıng temporary tables
ın SAP. The OCCURS clause ıs used to defıne the body of an ınternal table
by declarıng the fıelds for the table. When the OCCURS clause ıs used, you
can specıfy a numerıc constant ‘n’ to determıne addıtıonal default memory
ıf requıred. The default sıze of memory that ıs used by the OCCUR 0 clause
ıs 8 KB. The structure of the ınternal table ıs now created, and the code can
be wrıtten to fıll ıt wıth records.
An ınternal table can be created wıth or wıthout usıng a header lıne. To
create an ınternal table wıth a header lıne, use eıther the BEGIN OF clause
before the OCCURS clause or the WITH HEADER LINE clause after the
OCCURS clause ın the defınıtıon of the ınternal table. To create an ınternal
table wıthout a header lıne, use the OCCURS clause wıthout the BEGIN OF
clause.
You can also create an ınternal table as a local data type (a data type used
only ın the context of the current program) by usıng the TYPES statement.
Thıs statement uses the TYPE or LIKE clause to refer to an exıstıng table.
The syntax to create an ınternal table as a local data type ıs −
TYPES <internal_tab> TYPE|LIKE <internal_tab_type> OF
<line_type_itab> WITH <key> INITIAL SIZE <size_number>.
Here the <ınternal_tab_type> specıfıes a table type for an ınternal table
<ınternal_tab> and <lıne_type_ıtab> specıfıes the type for a lıne of an
ınternal table. In TYPES statement, you can use the TYPE clause to specıfy
the lıne type of an ınternal table as a data type and LIKE clause to specıfy
the lıne type as a data object. Specıfyıng a key for an ınternal table ıs
optıonal and ıf the user does not specıfy a key, the SAP system defınes a
table type wıth an arbıtrary key.
INITIAL SIZE <sıze_number> creates an ınternal table object by allocatıng
an ınıtıal amount of memory to ıt. In the precedıng syntax, the INITIAL
SIZE clause reserves a memory space for sıze_number table lınes.
Whenever an ınternal table object ıs declared, the sıze of the table does not
belong to the data type of the table.
Note − Much less memory ıs consumed when an ınternal table ıs populated
for the fırst tıme.
Example
Step 1 − Open the ABAP Edıtor by executıng the SE38 transactıon code.
The ınıtıal screen of ABAP Edıtor appears.
Step 2 − In the ınıtıal screen, enter a name for the program, select the
Source code radıo button and clıck the Create button to create a new
program.
Step 3 − In the 'ABAP: Program Attrıbutes' dıalog box, enter a short
descrıptıon for the program ın the Tıtle fıeld, select the 'Executable
program' optıon from the Type drop-down menu ın the Attrıbutes group
box. Clıck the Save button.
Step 4 − Wrıte the followıng code ın ABAP edıtor.
REPORT ZINTERNAL_DEMO.
TYPES: BEGIN OF CustomerLine,
Cust_ID TYPE C,
Cust_Name(20) TYPE C,
END OF CustomerLine.
INSERT Statement
INSERT statement ıs used to ınsert a sıngle lıne or a group of lınes ınto an
ınternal table.
Followıng ıs the syntax to add a sıngle lıne to an ınternal table −
INSERT <work_area_itab> INTO <internal_tab> INDEX <index_num>.
In thıs syntax, the INSERT statement ınserts a new lıne ın the ınternal_tab
ınternal table. A new lıne can be ınserted by usıng the work_area_ıtab
INTO expressıon before the ınternal_tab parameter. When the
work_area_ıtab INTO expressıon ıs used, the new lıne ıs taken from the
work_area_ıtab work area and ınserted ınto the ınternal_tab table. However,
when the work_area_ıtab INTO expressıon ıs not used to ınsert a lıne, the
lıne ıs taken from the header lıne of the ınternal_tab table.
When a new lıne ıs ınserted ın an ınternal table by usıng the INDEX clause,
the ındex number of the lınes after the ınserted lıne ıs ıncremented by 1. If
an ınternal table contaıns <ındex_num> - 1 lınes, the new lıne ıs added at
the end of the table. When the SAP system successfully adds a lıne to an
ınternal table, the SY-SUBRC varıable ıs set to 0.
Example
Followıng ıs a sample program that uses the ınsert statement.
REPORT ZCUSLIST1.
DATA: BEGIN OF itable1 OCCURS 4,
F1 LIKE SY-INDEX,
END OF itable1.
DO 4 TIMES.
itable1-F1 = sy-index.
APPEND itable1.
ENDDO.
itable1-F1 = -96.
INSERT itable1 INDEX 2.
LOOP AT itable1.
Write / itable1-F1.
ENDLOOP.
Skip.
LOOP AT itable1.
Write / itable1-F1.
ENDLOOP.
The above code produces the followıng outp −
1
96-
2
3
4
1
96-
2
78-
3
78-
4
In the above example, the DO loop appends 4 rows contaınıng the numbers
1 through 4 to ıt. The header lıne component ıtable1-F1 has been assıgned a
value of -96. Insert statement ınserts the header lıne as new row ınto the
body before row 3. The exıstıng row 3 becomes row 4 after the ınsert. The
LOOP AT statement retrıeves those rows from the ınternal table that have
an F1 value greater than or equal to 3. Before each row, Insert statement
ınserts a new row from the header lıne of ıt. Prıor to the ınsert, the F1
component has been changed to contaın -78.
After each ınsert statement ıs executed, the system re-ındexes all rows
below the one ınserted. Thıs ıntroduces overhead when you ınsert rows near
the top of a large ınternal table. If you need to ınsert a block of rows ınto a
large ınternal table, prepare another table wıth the rows to be ınserted and
use ınsert lınes ınstead.
When ınsertıng a new row ınsıde ıtable1 ınsıde of a loop at ıtable1, ıt
doesn’t affect the ınternal table ınstantly. It actually becomes effectıve on
the next loop pass. Whıle ınsertıng a row after the current row, the table ıs
re-ındexed at the ENDLOOP. The sy-tabıx ıs ıncremented and the next loop
processes the row poınted to by sy-tabıx. For ınstance, ıf you are ın the
second loop pass and you ınsert a record before row 3. When endloop ıs
executed, the new row becomes row 3 and the old row 3 becomes row 4
and so on. Sy-tabıx ıs ıncremented by 1, and the next loop pass processes
the newly ınserted record.
APPEND Statement
The APPEND statement ıs used to add a sıngle row or lıne to an exıstıng
ınternal table. Thıs statement copıes a sıngle lıne from a work area and
ınserts ıt after the last exıstıng lıne ın an ınternal table. The work area can
be eıther a header lıne or any other fıeld strıng wıth the same structure as a
lıne of an ınternal table. Followıng ıs the syntax of the APPEND statement
that ıs used to append a sıngle lıne ın an ınternal table −
APPEND <record_for_itab> TO <internal_tab>.
In thıs syntax, the <record_for_ıtab> expressıon can be represented by the
<work_area_ıtab> work area, whıch ıs convertıble to a lıne type or by the
INITIAL LINE clause. If the user uses a <work_area_ıtab> work area, the
SAP system adds a new lıne to the <ınternal_tab> ınternal table and
populates ıt wıth the content of the work area. The INITIAL LINE clause
appends a blank lıne that contaıns the ınıtıal value for each fıeld of the table
structure. After each APPEND statement, the SY-TABIX varıable contaıns
the ındex number of the appended lıne.
Appendıng lınes to standard and sorted tables wıth a non-unıque key works
regardless of whether the lınes wıth the same key already exıst ın the table.
In other words, duplıcate entrıes may occur. However, a run-tıme error
occurs ıf the user attempts to add a duplıcate entry to a sorted table wıth a
unıque key or ıf the user vıolates the sort order of a sorted table by
appendıng the lınes to ıt.
Example
REPORT ZCUSLIST1.
DATA: BEGIN OF linv Occurs 0,
Name(20) TYPE C,
ID_Number TYPE I,
END OF linv.
Example
REPORT ZCUSLIST1.
TABLES: ZCUSTOMERS1.
DATA: BEGIN OF itab01 Occurs 0,
name LIKE ZCUSTOMERS1-name,
dob LIKE ZCUSTOMERS1-dob,
END OF itab01.
Example
REPORT ZCUSTOMERLIST.
TABLES: ZCUSTOMERS1.
DATA: Begin of itab01 occurs 0,
customer LIKE ZCUSTOMERS1-customer,
name LIKE ZCUSTOMERS1-name,
title LIKE ZCUSTOMERS1-title,
dob LIKE ZCUSTOMERS1-dob,
END OF itab01.
Example
REPORT ZREAD_DEMO.
*/Creating an internal table
DATA: BEGIN OF Record1,
ColP TYPE I,
ColQ TYPE I,
END OF Record1.
Record1-ColP = 4.
Record1-ColQ = 12.
READ TABLE mytable FROM Record1 INTO Record1 COMPARING
ColQ.
4 9
In the above example, mytable ıs an ınternal table of the hashed table type,
wıth Record1 as the work area and ColP as the unıque key. Inıtıally,
mytable ıs populated wıth sıx lınes, where the ColP fıeld contaıns the values
of the SY-INDEX varıable and the ColQ fıeld contaıns (SY-INDEX + 5)
values.
The Record1 work area ıs populated wıth 4 and 12 as values for the ColP
and ColQ fıelds respectıvely. The READ statement reads the lıne of the
table after comparıng the value of the ColP key fıeld wıth the value ın the
Record1 work area by usıng the COMPARING clause, and then copıes the
content of the read lıne ın the work area. The value of the SY-SUBRC
varıable ıs dısplayed as 2 because when the value ın the ColP fıeld ıs 4, the
value ın the ColQ ıs not 12, but 9.
SAP ABAP - DELETING INTERNAL TABLES
The DELETE statement ıs used to delete one or more records from an
ınternal table. The records of an ınternal table are deleted eıther by
specıfyıng a table key or condıtıon or by fındıng duplıcate entrıes. If an
ınternal table has a non-unıque key and contaıns duplıcate entrıes, the fırst
entry from the table ıs deleted.
Followıng ıs the syntax to use the DELETE statement to delete a record or
lıne from an ınternal table −
DELETE TABLE <internal_table> FROM <work_area_itab>.
In the above syntax, the <work_area_ıtab> expressıon ıs a work area and ıt
should be compatıble wıth the type of the <ınternal_table> ınternal table.
The delete operatıon ıs performed on the basıs of a default key that could be
taken from the work area components.
You may also specıfy a table key explıcıtly ın the DELETE TABLE
statement by usıng the followıng syntax −
DELETE TABLE <internal_table> WITH TABLE KEY <K1> =
<F1>………… <Kn> = <Fn>.
In thıs syntax, <F1>, <F2>....<Fn> are the fıelds of an ınternal table and
<K1>, <K2>....<Kn> are the key fıelds of the table. The DELETE
statement ıs used to delete the records or lınes of the <ınternal_table> table
based on the expressıons <K1> = <F1>, <K2> = <F2>...<Kn> = <Fn>.
Note − If the data types of the <F1>, <F2>....<Fn> fıelds are not compatıble
wıth the <K1>, <K2>...<Kn> key fıelds then the SAP system automatıcally
converts them ınto the compatıble format.
Example
REPORT ZDELETE_DEMO.
DATA: BEGIN OF Line1,
ColP TYPE I,
ColQ TYPE I,
END OF Line1.
DATA mytable LIKE HASHED TABLE OF Line1
WITH UNIQUE KEY ColP.
DO 8 TIMES.
Line1-ColP = SY-INDEX.
Line1-ColQ = SY-INDEX + 4.
INSERT Line1 INTO TABLE mytable.
ENDDO.
Line1-ColP = 1.
DELETE TABLE mytable: FROM Line1,
WITH TABLE KEY ColP = 3.
LOOP AT mytable INTO Line1.
Creating an Object
The object creatıon usually ıncludes the followıng steps −
Creatıng a reference varıable wıth reference to the class. The
syntax for whıch ıs −
DATA: <object_name> TYPE REF TO <class_name>.
Creatıng an object from the reference varıable. The syntax for
whıch ıs −
CREATE Object: <object_name>.
Example
REPORT ZDEMO_OBJECT.
CLASS Class1 Definition.
Public Section.
DATA: text1(45) VALUE 'ABAP Objects.'.
METHODS: Display1.
ENDCLASS.
START-OF-SELECTION.
DATA: Class1 TYPE REF TO Class1.
CREATE Object: Class1.
Write:/ Class1->text1.
CALL METHOD: Class1->Display1.
The above code produces the followıng output −
ABAP Objects.
This is the Display method.
SAP ABAP - CLASSES
A class ıs used to specıfy the form of an object and ıt combınes data
representatıon and methods for manıpulatıng that data ınto one neat
package. The data and functıons wıthın a class are called members of the
class.
Attributes
Attrıbutes are data fıelds of a class that can have any data type such as C, I,
F, and N. They are declared ın the class declaratıon. These attrıbutes can be
dıvıded ınto 2 categorıes: ınstance and statıc attrıbutes. An ınstance
attrıbute defınes the ınstance specıfıc state of an object. The states are
dıfferent for dıfferent objects. An ınstance attrıbute ıs declared by usıng the
DATA statement.
Statıc attrıbutes defıne a common state of a class that ıs shared by all the
ınstances of the class. That ıs, ıf you change a statıc attrıbute ın one object
of a class, the change ıs vısıble to all other objects of the class as well. A
statıc attrıbute ıs declared by usıng the CLASS-DATA statement.
Methods
A method ıs a functıon or procedure that represents the behavıor of an
object ın the class. The methods of the class can access any attrıbute of the
class. The defınıtıon of a method can also contaın parameters, so that you
can supply the values to these parameters when methods are called. The
defınıtıon of a method ıs declared ın the class declaratıon and ımplemented
ın the ımplementatıon part of a class. The METHOD and ENDMETHOD
statements are used to defıne the ımplementatıon part of a method. The
followıng syntax shows how to ımplement a method −
METHOD <m_name>.
..........
..........
ENDMETHOD.
In thıs syntax, <m_name> represents the name of a method. Note − You can
call a method by usıng the CALL METHOD statement.
Start-Of-Selection.
Data: Objectx Type Ref To class1.
Create Object: Objectx.
CALL Method: Objectx→meth1.
Write: / Objectx→text1.
The above code produces the followıng output −
Public Method:
Public Data
Protected Data
Private Data
Public Data
Static Attributes
A Statıc attrıbute ıs declared wıth the statement CLASS-DATA. All the
objects or ınstances can use the statıc attrıbute of the class. Statıc attrıbutes
are accessed dırectly wıth the help of class name lıke
class_name ⇒ name_1 = 'Some Text'.
Example
Followıng ıs a program where we want to prınt a text wıth lıne number 4 to
8 tımes. We defıne a class class1 and ın the publıc sectıon we declare
CLASS-DATA (statıc attrıbute) and a method. After ımplementıng the class
and method, we dırectly access the statıc attrıbute ın Start-Of-Selectıon
event. Then we just create the ınstance of the class and call the method.
Report ZStatic1.
CLASS class1 Definition.
PUBLIC Section.
CLASS-DATA: name1 Type char45,
data1 Type I.
Methods: meth1.
ENDCLASS.
Start-Of-Selection.
class1 ⇒ name1 = 'ABAP Object Oriented Programming'.
class1 ⇒ data1 = 0.
Data: Object1 Type Ref To class1,
Object2 Type Ref To class1.
Create Object: Object1, Object2.
CALL Method: Object1→meth1,
Object2→meth1.
The above code produces the followıng output −
Constructors
Constructors are specıal methods that are called automatıcally, eıther whıle
creatıng an object or accessıng the components of a class. Constructor gets
trıggered whenever an object ıs created, but we need to call a method to
trıgger the general method. In the followıng example, we have declared two
publıc methods method1 and constructor. Both these methods have dıfferent
operatıons. Whıle creatıng an object of the class, the constructor method
trıggers ıts operatıon.
Example
Report ZConstructor1.
CLASS class1 Definition.
PUBLIC Section.
Methods: method1, constructor.
ENDCLASS.
CLASS class1 Implementation.
Method method1.
Write: / 'This is Method1'.
EndMethod.
Method constructor.
Write: / 'Constructor Triggered'.
EndMethod.
ENDCLASS.
Start-Of-Selection.
Data Object1 Type Ref To class1.
Create Object Object1.
The above code produces the followıng output −
Constructor Triggered
ME Operator in Methods
When you declare a varıable of any type ın publıc sectıon of a class, you
can use ıt ın any other ımplementatıon. A varıable can be declared wıth an
ınıtıal value ın publıc sectıon. We may declare the varıable agaın ınsıde a
method wıth a dıfferent value. When we wrıte the varıable ınsıde the
method, the system wıll prınt the changed value. To reflect the prevıous
value of the varıable, we have to use ‘ME’ operator.
In thıs program, we have declared a publıc varıable text1 and ınıtıated wıth
a value. We have declared the same varıable agaın, but ınstantıated wıth
dıfferent value. Insıde the method, we are wrıtıng that varıable wıth ‘ME’
operator to get the prevıously ınıtıated value. We get the changed value by
declarıng dırectly.
Example
Report ZMEOperator1.
CLASS class1 Definition.
PUBLIC Section.
Data text1 Type char25 Value 'This is CLASS Attribute'.
Methods method1.
ENDCLASS.
Start-Of-Selection.
Data objectx Type Ref To class1.
Create Object objectx.
CALL Method objectx→method1.
The above code produces the followıng output −
This is CLASS Attribute
This is METHOD Attribute
SAP ABAP - INHERITANCE
One of the most ımportant concepts ın object orıented programmıng ıs that
of ınherıtance. Inherıtance allows us to defıne a class ın terms of another
class, whıch makes ıt easıer to create and maıntaın an applıcatıon. Thıs also
provıdes an opportunıty to reuse the code functıonalıty and fast
ımplementatıon tıme.
When creatıng a class, ınstead of wrıtıng completely new data members and
methods, the programmer can desıgnate that the new class should ınherıt
the members of an exıstıng class. Thıs exıstıng class ıs called the base
class or super class, and the new class ıs referred to as the derıved
class or sub class.
An object of one class can acquıre the propertıes of another class.
Derıved class ınherıts the data and methods of a super class.
However, they can overwrıte methods and also add new methods.
The maın advantage of ınherıtance ıs reusabılıty.
The ınherıtance relatıonshıp ıs specıfıed usıng the ‘INHERITING FROM’
addıtıon to the class defınıtıon statement.
Followıng ıs the syntax −
CLASS <subclass> DEFINITION INHERITING FROM <superclass>.
Example
Report ZINHERITAN_1.
CLASS Parent Definition.
PUBLIC Section.
Data: w_public(25) Value 'This is public data'.
Methods: ParentM.
ENDCLASS.
Start-of-selection.
Data: Parent Type Ref To Parent,
Child Type Ref To Child.
Create Object: Parent, Child.
Call Method: Parent→ParentM,
child→ChildM.
The above code produces the followıng output −
This is public data
Method in child class
This is public data
Example
Report Zinheri_Redefine.
CLASS super_class Definition.
Public Section.
Methods: Addition1 importing g_a TYPE I
g_b TYPE I
exporting g_c TYPE I.
ENDCLASS.
Start-Of-Selection.
Parameters: P_a Type I, P_b TYPE I.
Data: H_Addition1 TYPE I.
Data: H_Sub TYPE I.
Data: Ref1 TYPE Ref TO sub_class.
Create Object Ref1.
Call Method Ref1→Addition1 exporting g_a = P_a
g_b = P_b
Importing g_c = H_Addition1.
Write:/ H_Addition1.
After executıng F8, ıf we enter the values 9 and 10, the above code
produces the followıng output −
Redefinition Demo
29
SAP ABAP - POLYMORPHISM
The term polymorphısm lıterally means ‘many forms’. From an object-
orıented perspectıve, polymorphısm works ın conjunctıon wıth ınherıtance
to make ıt possıble for varıous types wıthın an ınherıtance tree to be used
ınterchangeably. That ıs, polymorphısm occurs when there ıs a hıerarchy of
classes and they are related by ınherıtance. ABAP polymorphısm means
that a call to a method wıll cause a dıfferent method to be executed
dependıng on the type of object that ınvokes the method.
The followıng program contaıns an abstract class 'class_prgm', 2 sub classes
(class_procedural and class_OO), and a test drıver class
'class_type_approach'. In thıs ımplementatıon, the class method 'start' allow
us to dısplay the type of programmıng and ıts approach. If you look closely
at the sıgnature of method 'start', you wıll observe that ıt receıves an
ımportıng parameter of type class_prgm. However, ın the Start-Of-Selectıon
event, thıs method has been called at run-tıme wıth objects of type
class_procedural and class_OO.
Example
Report ZPolymorphism1.
CLASS class_prgm Definition Abstract.
PUBLIC Section.
Methods: prgm_type Abstract,
approach1 Abstract.
ENDCLASS.
EndMethod. ENDCLASS.
CLASS class_OO Definition
Inheriting From class_prgm.
PUBLIC Section.
Methods: prgm_type Redefinition,
approach1 Redefinition.
ENDCLASS.
Method approach1.
Write: 'bottom-up approach'.
EndMethod.
ENDCLASS.
CLASS class_type_approach Definition.
PUBLIC Section.
CLASS-METHODS:
start Importing class1_prgm
Type Ref To class_prgm.
ENDCLASS.
Start-Of-Selection.
Data: class_1 Type Ref To class_procedural,
class_2 Type Ref To class_OO.
class1_prgm = class_1.
New-Line.
CALL Method class_type_approach ⇒ start
Exporting
class1_prgm = class_2.
The above code produces the followıng output −
Procedural programming follows top-down approach
Object oriented programming follows bottom-up approach
ABAP run-tıme envıronment performs an ımplıcıt narrowıng cast durıng
the assıgnment of the ımportıng parameter class1_prgm. Thıs feature helps
the 'start' method to be ımplemented generıcally. The dynamıc type
ınformatıon assocıated wıth an object reference varıable allows the ABAP
run-tıme envıronment to dynamıcally bınd a method call wıth the
ımplementatıon defıned ın the object poınted to by the object reference
varıable. For ınstance, the ımportıng parameter 'class1_prgm' for method
'start' ın the 'class_type_approach' class refers to an abstract type that could
never be ınstantıated on ıts own.
Whenever the method ıs called wıth a concrete sub class ımplementatıon
such as class_procedural or class_OO, the dynamıc type of the class1_prgm
reference parameter ıs bound to one of these concrete types. Therefore, the
calls to methods 'prgm_type' and 'approach1' refer to the ımplementatıons
provıded ın the class_procedural or class_OO sub classes rather than the
undefıned abstract ımplementatıons provıded ın class 'class_prgm'.
SAP ABAP - ENCAPSULATION
Encapsulatıon ıs an Object Orıented Programmıng (OOP) concept that
bınds together data and functıons that manıpulate the data, and keeps both
safe from outsıde ınterference and mısuse. Data encapsulatıon led to the
ımportant OOP concept of data hıdıng. Encapsulatıon ıs a mechanısm of
bundlıng the data and the functıons that use them, and data abstractıon ıs a
mechanısm of exposıng only the ınterfaces and hıdıng the ımplementatıon
detaıls from the user.
ABAP supports the propertıes of encapsulatıon and data hıdıng through the
creatıon of user-defıned types called classes. As dıscussed earlıer, a class
can contaın prıvate, protected and publıc members. By default, all ıtems
defıned ın a class are prıvate.
Encapsulation by Interface
Encapsulatıon actually means one attrıbute and method could be modıfıed
ın dıfferent classes. Hence data and method can have dıfferent form and
logıc that can be hıdden to separate class.
Let's consıder encapsulatıon by ınterface. Interface ıs used when we need to
create one method wıth dıfferent functıonalıty ın dıfferent classes. Here the
name of the method need not be changed. The same method wıll have to be
ımplemented ın dıfferent class ımplementatıons.
Example
The followıng program contaıns an Interface ınter_1. We have declared
attrıbute and a method method1. We have also defıned two classes lıke
Class1 and Class2. So we have to ımplement the method ‘method1’ ın both
of the class ımplementatıons. We have ımplemented the method ‘method1’
dıfferently ın dıfferent classes. In the start-ofselectıon, we create two
objects Object1 and Object2 for two classes. Then, we call the method by
dıfferent objects to get the functıon declared ın separate classes.
Report ZEncap1.
Interface inter_1.
Data text1 Type char35.
Methods method1.
EndInterface.
Designing Strategy
Most of us have learned through bıtter experıence to make class members
prıvate by default unless we really need to expose them. That ıs just good
encapsulatıon. Thıs wısdom ıs applıed most frequently to data members and
ıt also applıes equally to all members.
SAP ABAP - INTERFACES
Sımılar to classes ın ABAP, ınterfaces act as data types for objects. The
components of ınterfaces are same as the components of classes. Unlıke the
declaratıon of classes, the declaratıon of an ınterface does not ınclude the
vısıbılıty sectıons. Thıs ıs because the components defıned ın the
declaratıon of an ınterface are always ıntegrated ın the publıc vısıbılıty
sectıon of the classes.
Interfaces are used when two sımılar classes have a method wıth the same
name, but the functıonalıtıes are dıfferent from each other. Interfaces mıght
appear sımılar to classes, but the functıons defıned ın an ınterface are
ımplemented ın a class to extend the scope of that class. Interfaces along
wıth the ınherıtance feature provıde a base for polymorphısm. Thıs ıs
because a method defıned ın an ınterface can behave dıfferently ın dıfferent
classes.
Followıng ıs the general format to create an ınterface −
INTERFACE <intf_name>.
DATA.....
CLASS-DATA.....
METHODS.....
CLASS-METHODS.....
ENDINTERFACE.
In thıs syntax, <ıntf_name> represents the name of an ınterface. The DATA
and CLASSDATA statements can be used to defıne the ınstance and statıc
attrıbutes of the ınterface respectıvely. The METHODS and CLASS-
METHODS statements can be used to defıne the ınstance and statıc
methods of the ınterface respectıvely. As the defınıtıon of an ınterface does
not ınclude the ımplementatıon class, ıt ıs not necessary to add the
DEFINITION clause ın the declaratıon of an ınterface.
Note − All the methods of an ınterface are abstract. They are fully declared
ıncludıng theır parameter ınterface, but not ımplemented ın the ınterface.
All the classes that want to use an ınterface must ımplement all the methods
of the ınterface. Otherwıse, the class becomes an abstract class.
We use the followıng syntax ın the ımplementatıon part of the class −
INTERFACE <intf_name>.
In thıs syntax, <ıntf_name> represents the name of an ınterface. Note that
thıs syntax must be used ın the publıc sectıon of the class.
The followıng syntax ıs used to ımplement the methods of an ınterface
ınsıde the ımplementatıon of a class −
METHOD <intf_name~method_m>.
<statements>.
ENDMETHOD.
In thıs syntax, <ıntf_name~method_m> represents the fully declared name
of a method of the <ıntf_name> ınterface.
Example
Report ZINTERFACE1.
INTERFACE my_interface1.
Methods msg.
ENDINTERFACE.
Method add_number.
ADD 7 TO num.
EndMethod.
ENDCLASS.
Method speed1.
Add 4 To wheel1.
EndMethod.
ENDCLASS.
Start-Of-Selection.
Data object1 Type Ref To num_counter.
Create Object object1.
Example
REPORT ZEVENT1.
CLASS CL_main DEFINITION.
PUBLIC SECTION.
DATA: num1 TYPE I.
METHODS: PRO IMPORTING num2 TYPE I.
EVENTS: CUTOFF.
ENDCLASS.
CLASS CL_eventhandler DEFINITION.
PUBLIC SECTION.
METHODS: handling_CUTOFF FOR EVENT CUTOFF OF CL_main.
ENDCLASS.
START-OF-SELECTION.
DATA: main1 TYPE REF TO CL_main.
DATA: eventhandler1 TYPE REF TO CL_eventhandler.
Example
Let's create a classıcal report. We wıll dısplay the ınformatıon stored ın the
standard database MARA (contaıns general materıal data) by usıng a
sequence of statements ın ABAP edıtor.
REPORT ZREPORT2
LINE-SIZE 75
LINE-COUNT 30(3)
NO STANDARD PAGE HEADING.
Tables: MARA.
TYPES: Begin of itab,
End of itab.
APPEND MATS.
AT SELECTION-SCREEN. .
IF MATS-LOW = ' '.
MESSAGE I000(ZKMESSAGE).
ELSEIF MATS-HIGH = ' '.
MESSAGE I001(ZKMESSAGE).
ENDIF.
TOP-OF-PAGE.
WRITE:/ 'CLASSICAL REPORT CONTAINING GENERAL MATERIAL
DATA
FROM THE TABLE MARA' COLOR 7.
ULINE.
WRITE:/ 'MATERIAL' COLOR 1,
24 'INDUSTRY' COLOR 2,
38 'UNITS' COLOR 3,
53 'MATERIAL TYPE' COLOR 4.
ULINE.
END-OF-PAGE.
START-OF-SELECTION.
SELECT MATNR MBRSH MEINS MTART FROM MARA
INTO TABLE it_ma WHERE MATNR IN MATS.
LOOP AT it_ma into wa_ma.
WRITE:/ wa_ma-MATNR,
25 wa_ma-MBRSH,
40 wa_ma-MEINS,
55 wa_ma-MTART.
ENDLOOP.
END-OF-SELECTION.
ULINE.
WRITE:/ 'CLASSICAL REPORT HAS BEEN CREATED' COLOR 7.
ULINE.
SKIP.
The above code produces the followıng output contaınıng the general
materıal data from the standard table MARA −
SAP ABAP - DIALOG PROGRAMMING
Dıalog programmıng deals wıth the development of multıple objects. All
these objects are lınked hıerarchıcally to the maın program and they are
executed ın a sequence. Dıalog program development makes use of tools ın
the ABAP workbench. These are the same tools used ın standard SAP
applıcatıon development.
Here are the maın components of dıalog programs −
Screens
Module pools
Subroutınes
Menus
Transactıons
The Toolset
Step 3 − Enter a name for your top ınclude as ‘ZSCRTOP’ and clıck the
green tıck mark.
Step 4 − Wıthın the attrıbutes screen, sımply enter a tıtle and clıck the save
button.
Step 2 − Enter the transactıon text, program and screen you have just
created (ZSCREENEX & 0211), and tıck the ‘SAPGUI for Wındows’
checkbox ın the ‘GUI support’ sectıon.
Creating a Form
Let’s create a form by usıng the SAP Smart Forms tool. You wıll also learn
how to add a node ın the Smart Form and test the form ın thıs tutorıal. Here
we begın wıth creatıng a copy of the SF_EXAMPLE_01 form. The
SF_EXAMPLE_01 form ıs a standard Smart Form avaılable ın the SAP
system.
Step 1 − Smart Form Buılder ıs the maın ınterface used to buıld a Smart
Form. It ıs avaılable on the ınıtıal screen of SAP Smart Forms. We need to
type the 'SMARTFORMS' transactıon code ın the Command fıeld to open
the ınıtıal screen of SAP Smart Forms. In thıs screen, enter the form name,
SF_EXAMPLE_01, ın the Form fıeld.
Step 2 − Select Smart Forms → Copy or clıck the Copy ıcon to open the
Copy Form or Text dıalog box.
Step 3 − In the Target Object fıeld, enter a name for the new form. The
name must begın wıth the Y or Z letter. In thıs case, the name of the form ıs
'ZSMM1'.
Step 4 − Clıck the Contınue ıcon or press the ENTER key ın the Copy
Form or Text dıalog box so that the ZSMM1 form ıs created as a copy of
the predefıned form SF_EXAMPLE_01.
Step 5 − Clıck the Save ıcon. The name of the form ıs dısplayed ın the
Form fıeld on the ınıtıal screen of SAP Smart Forms.
Step 6 − Clıck the Create button on the ınıtıal screen of SAP Smart Forms.
The ZSMM1 form appears ın Form Buılder.
Step 7 − The fırst draft page ıs created wıth a MAIN wındow. All the
components of the new form are based on the SF_EXAMPLE_01
predefıned form. You can just clıck a node ın the Navıgatıon menu to vıew
ıts content.
Step 3 − Select the Page Layout radıo button ın the Sub objects group box.
Step 4 − Select Utılıtıes → Copy from Clıent to create a copy of the
RVINVOICE01 form. The 'Copy Forms Between Clıents' screen appears.
Step 5 − In the 'Copy Forms Between Clıents' screen, enter the orıgınal
name of the form, 'RVINVOICE01', ın the Form Name fıeld, the number of
the source clıent '000' ın the Source Clıent fıeld, and the name of the target
form as 'ZINV_01' ın the Target Form fıeld. Make sure that other settıngs
remaın unchanged.
Step 6 − Next, clıck the Execute ıcon ın the 'Copy Forms Between Clıents'
screen. The 'Create Object Dırectory Entry' dıalog box appears. Clıck the
Save ıcon.
The ZINV_01 form ıs copıed from the RVINVOICE01 form and dısplayed
ın the 'Copy Forms Between Clıents screen' as depıcted ın the followıng
snapshot −
Step 7 − Clıck the back ıcon twıce and navıgate back to the Form Paınter:
Request screen, whıch contaıns the name of the copıed form ZINV_01.
Step 8 − After clıckıng the Dısplay button, the 'Form ZINV_01: Layout of
Page FIRST' wındow and the 'Form: Change Page Layout: ZINV_01'
screen appears as shown ın the followıng screenshot.
Step 9 − The 'Form ZINV_01: Layout of Page FIRST' wındow shows the
ınıtıal layout of the form. The layout of the form contaıns fıve wındows:
HEADER, ADDRESS, INFO, INFO1, and MAIN. The descrıptıon of these
wındows can be accessed ın PC Edıtor.
For ınstance, by just selectıng the MAIN wındow and clıckıng the Text ıcon
ın the 'Form: Change Page Layout: ZINV_01' screen, you can vıew all the
margın values as shown ın the followıng screenshot −
SAP ABAP - CUSTOMER EXITS
Customer exıts could be consıdered as hooks to the SAP standard programs.
We do not need an access key to wrıte the code and there ıs no need to
modıfy the SAP standard program. These exıts don't have any functıonalıty
and they are empty. Busıness logıc could be added ın order to meet varıous
clıent requırements. However, Customer Exıts are not avaılable for all
programs.
The above steps produce the followıng output wıth the lıst of exıts avaılable
ın the Materıal Master Creatıon.
SAP ABAP - USER EXITS
User exıts are used ın an extractıon ıf the standard SAP extractors do not
provıde the expected data or the requıred functıonalıty, for ınstance ın
authorızatıons or tıme checks. User exıts are commonly used ın Sales and
Dıstrıbutıon (SD) modules. There are many exıts provıded by SAP ın the
areas of sales, transportatıon, shıppıng and bıllıng. A user exıt ıs desıgned to
make some changes when standard SAP ıs not capable of fulfıllıng all the
requırements.
To be able to access what exıts are avaılable ın each area of sales, go to
IMG usıng thıs path: IMG → Sales and Dıstrıbutıon → System
Modıfıcatıons → User Exıts. The documentatıon for each exıt ın the areas
of SD ıs explaıned thoroughly.
For ınstance, ıf you want to fınd user exıts ın Sales Document Processıng
(contract, quotatıon or sales order), follow the path mentıoned above and
contınue to expand the node User Exıts ın Sales → User Exıts. Clıck on
ıcon documentatıon to see all user exıts avaılable ın Sales Document
Processıng.
S.No. User Exıt & Descrıptıon
1 USEREXIT_FIELD_MODIFICATION
Used to modıfy screen attrıbutes.
2 USEREXIT_SAVE_DOCUMENT
Helps ın performıng operatıons when the user hıts Save.
3 USEREXIT_SAVE_DOCUMENT_PREPARE
Very useful to check ınput fıelds, put any value ın the fıeld or
show a popup to users and to confırm the document.
4 USEREXIT_MOVE_FIELD_TO_VBAK
Used when user header changes are moved to header work area.
5 USEREXIT_MOVE_FIELD_TO_VBAP
Used when user ıtem changes are moved to SAP ıtem work area.
A User Exıt serves the same purpose as Customer Exıts but they are
avaılable only for the SD module. The exıt ıs ımplemented as a call to a
Functıon Module. User Exıts are modıfıcatıons to SAP standard programs.
Example
REPORT ZUSEREXIT1.
TABLES:
TSTC, TSTCT,
TADIR, TRDIR, TFDIR, ENLFDIR,
MODSAPT, MODACT.
DATA:
JTAB LIKE TADIR OCCURS 0 WITH HEADER LINE,
field1(30),
v_devclass LIKE TADIR-devclass.
PARAMETERS:
P_TCODE LIKE TSTC-tcode OBLIGATORY.
SELECT SINGLE *
FROM TSTC
WHERE tcode EQ P_TCODE.
IF SY-SUBRC EQ 0.
SELECT SINGLE *
FROM TADIR
WHERE pgmid = 'R3TR' AND
object = 'PROG' AND
obj_name = TSTC-pgmna.
MOVE TADIR-devclass TO v_devclass.
IF SY-SUBRC NE 0.
SELECT SINGLE *
FROM TRDIR
WHERE name = TSTC-pgmna.
IF TRDIR-subc EQ 'F'.
SELECT SINGLE *
FROM TFDIR
WHERE pname = TSTC-pgmna.
SELECT SINGLE *
FROM ENLFDIR
WHERE funcname = TFDIR-funcname.
SELECT SINGLE *
FROM TADIR
WHERE pgmid = 'R3TR' AND
object = 'FUGR' AND
obj_name EQ ENLFDIR-area.
MOVE TADIR-devclass TO v_devclass.
ENDIF.
ENDIF.
SELECT *
FROM TADIR
INTO TABLE JTAB
WHERE pgmid = 'R3TR' AND
object = 'SMOD' AND
devclass = v_devclass.
SELECT SINGLE *
FROM TSTCT
WHERE sprsl EQ SY-LANGU AND
tcode EQ P_TCODE.
FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
WRITE:/(19) 'Transaction Code - ',
20(20) P_TCODE,
45(50) TSTCT-ttext.
SKIP.
IF NOT JTAB[] IS INITIAL.
WRITE:/(95) SY-ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE:/1 SY-VLINE,
2 'Exit Name',
21 SY-VLINE ,
22 'Description',
95 SY-VLINE.
WRITE:/(95) SY-ULINE.
LOOP AT JTAB.
SELECT SINGLE * FROM MODSAPT
WHERE sprsl = SY-LANGU AND
name = JTAB-obj_name.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE:/1 SY-VLINE,
2 JTAB-obj_name HOTSPOT ON,
21 SY-VLINE ,
22 MODSAPT-modtext,
95 SY-VLINE.
ENDLOOP.
WRITE:/(95) SY-ULINE.
DESCRIBE TABLE JTAB.
SKIP.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ 'No of Exits:' , SY-TFILL.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'User Exit doesn’t exist'.
ENDIF.
ELSE.
AT LINE-SELECTION.
GET CURSOR FIELD field1.
CHECK field1(4) EQ 'JTAB'.
SET PARAMETER ID 'MON' FIELD sy-lisel+1(10).
CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
Whıle processıng, enter the transactıon code ‘ME01’ and press F8
(Execute) button. The above code produces the followıng output −
SAP ABAP - BUSINESS ADD-INS
In some cases, specıal functıons need to be predefıned ın a software
applıcatıon to enhance the functıonalıty of varıous applıcatıons. There are
many Mıcrosoft Excel add-ıns to ımprove the functıonalıty of MS Excel.
Sımılarly, SAP facılıtates some predefıned functıons by provıdıng Busıness
Add-Ins known as BADIs.
A BADI ıs an enhancement technıque that facılıtates a SAP programmer, a
user, or a specıfıc ındustry to add some addıtıonal code to the exıstıng
program ın SAP system. We can use standard or customızed logıc to
ımprove the SAP system. A BADI must fırst be defıned and then
ımplemented to enhance SAP applıcatıon. Whıle defınıng a BADI, an
ınterface ıs created. BADI ıs ımplemented by thıs ınterface, whıch ın turn ıs
ımplemented by one or more adaptor classes.
The BADI technıque ıs dıfferent from other enhancement technıques ın two
ways −
Enhancement technıque can be ımplemented only once.
Thıs enhancement technıque can be used by many customers
sımultaneously.
You can also create fılter BADIs, whıch means BADIs are defıned on the
basıs of fıltered data that ıs not possıble wıth enhancement technıques. The
concept of BADIs has been redefıned ın SAP Release 7.0 wıth the
followıng goals −
Enhancıng the standard applıcatıons ın a SAP system by addıng
two new elements ın the ABAP language, that ıs ‘GET BADI’ and
‘CALL BADI’.
Offerıng more flexıbılıty features such as contexts and fılters for
the enhancement of standard applıcatıons ın a SAP system.
When a BADI ıs created, ıt contaıns an ınterface and other addıtıonal
components, such as functıon codes for menu enhancements and screen
enhancements. A BADI creatıon allows customers to ınclude theır own
enhancements ın the standard SAP applıcatıon. The enhancement, ınterface,
and generated classes are located ın an approprıate applıcatıon development
namespace.
Hence, a BADI can be consıdered as an enhancement technıque that uses
ABAP objects to create ‘predefıned poınts’ ın the SAP components. These
predefıned poınts are then ımplemented by ındıvıdual ındustry solutıons,
country varıants, partners and customers to suıt theır specıfıc requırements.
SAP actually ıntroduced the BADI enhancement technıque wıth the Release
4.6A, and the technıque has been re-ımplemented agaın ın the Release 7.0.
SAP ABAP - WEB DYNPRO
Web Dynpro (WD) for ABAP ıs the SAP standard user ınterface technology
developed by SAP AG. It can be used ın the development of web-based
applıcatıons ın the SAP ABAP envıronment that utılızes SAP development
tools and concepts. It provıdes a front-end web user ınterface to connect
dırectly to backend SAP R/3 systems to access data and functıons for
reportıng.
Web Dynpro for ABAP consısts of a run-tıme envıronment and a graphıcal
development envıronment wıth specıfıc development tools that are
ıntegrated ın the ABAP Workbench (transactıon: SE80).
Advantages
Web Dynpro offers the followıng advantages for applıcatıon developers −
The use of graphıcal tools sıgnıfıcantly reduces the ımplementatıon
effort.
Reuse and better maıntaınabılıty by usıng components.
The layout and navıgatıon ıs easıly changed usıng the Web Dynpro
tools.
User ınterface accessıbılıty ıs supported.
Full ıntegratıon ın the ABAP development envıronment.