Sap Abap
Sap Abap
2025
Let's start with the high-level architecture of SAP system. The 3-tier
Client/Server architecture of a typical SAP system is depicted as follows.
The Presentation layer consists of any input device that can be used to
control SAP system. This could be a web browser, a mobile device and so on.
All the central processing takes place in Application server. The
Application server is not just one system in itself, but it can be multiple
instances of the processing system. The server communicates with
the Database layer that is usually kept on a separate server, mainly for
performance reasons and also for security. Communication happens between
each layer of the system, from the Presentation layer to the Database and
then back up the chain.
SAP ABAP Tutorial February 23,
2025
ABAP programs reside inside the SAP database. They execute under the
control of the runtime system that is a part of the SAP kernel. The run-time
system processes all ABAP statements, controlling the flow logic and
responding to user events.
So, unlike C++ and Java, ABAP programs are not stored in separate external
files. Inside the database, ABAP code exists in two forms −
Source code that can be viewed and edited with the ABAP workbench
tools.
Generated code, which is a binary representation. If you are familiar
with Java, this generated code is somewhat comparable with Java byte
code.
Hello ABAP
Let's get started with the common "Hello World" example.
Each ABAP statement starts with an ABAP keyword and ends with a period.
Keywords must be separated by at least one space. It does not matter
whether or not you use one or several lines for an ABAP statement.
You need to enter your code using the ABAP Editor that is a part of ABAP
Tools delivered with the SAP NetWeaver Application Server ABAP (also known
as ‘AS ABAP’).
‘AS ABAP’ is an application server with its own database, ABAP run-time
environment, and ABAP development tools such as ABAP Editor. The AS
ABAP offers a development platform that is independent of hardware,
operating system, and database.
Step 2 − On the initial screen of the editor, specify the name of your report
in the input field PROGRAM. You may specify the name as ZHELLO1. The
preceding Z is important for the name. Z ensures that your report resides in
the customer namespace.
Step 3 − You may type the report name in lower case letters, but the editor
will change it to upper case. So the names of ABAP objects are ‘Not’ case
sensitive.
Step 4 − After specifying the name of the report, click the CREATE button. A
popup window ABAP: PROGRAM ATTRIBUTES will pop up and you will provide
more information about your report.
Step 5 − Choose "Executable Program" as the report type, enter the title
“My First ABAP Report” and then select SAVE to continue. The CREATE
OBJECT DIRECTORY ENTRY window will pop up next. Select the button LOCAL
OBJECT and the popup will close.
You can complete your first report by entering the WRITE statement below
the REPORT statement, so that the complete report contains just two lines as
follows −
REPORT ZHELLO1.
WRITE 'Hello World'.
Starting the report is as simple as saving it. Click the ACTIVATION button (left
hand side next to the start icon) and start the report by using the icon
DIRECT PROCESSING or the F8 function key. The title "My First ABAP Report"
along with the output “Hello World” is displayed as well. Here is the output −
If you look at the field Program and double-click on the value ZHELLO1, the
ABAP editor will display the code for your report. This is called Forward
Navigation. Double clicking on an object's name opens that object in the
appropriate tool.
Login Screen
After you log on to SAP server, SAP login screen will prompt for User ID and
Password. You need to provide a valid user ID and Password and press Enter
(the user id and password is provided by system administrator). Following is
the login screen.
SAP ABAP Tutorial February 23,
2025
Toolbar Icon
Following is the SAP screen toolbar.
Title Bar − Title Bar displays the name of the application/business process
you are currently in.
ABAP Editor
You may just start the transaction SE38 (enter SE38 in Command Field) to
navigate to the ABAP Editor.
SAP ABAP Tutorial February 23,
2025
Following are the standard exit keys used in SAP as shown in the image.
Following are the options for checking, activating and processing the reports.
SAP ABAP Tutorial February 23,
2025
Log Off
It’s always a good practice to Exit from your ABAP Editor or/and logoff from
the SAP system after finishing your work.
SAP ABAP Tutorial February 23,
2025
The first non-comment line in a program begins with the word REPORT. The
Report will always be the first line of any executable program created. The
statement is followed by the program name which was created previously.
The line is then terminated with a full stop.
The syntax is −
[Statements…].
This allows the statement to take up as many lines in the editor as it needs.
For example, the REPORT may look like this −
REPORT Z_Test123_01.
On the line below the REPORT statement, just type this statement: Write
‘ABAP Tutorial’.
REPORT Z_Test123_01.
The ABAP editor converts all text to uppercase except text strings,
which are surrounded by single quotation marks.
Unlike some older programming languages, ABAP does not care where
a statement begins on a line. You may take advantage of this and
improve the readability of your program by using indentation to
indicate blocks of code.
ABAP has no restrictions on the layout of statements. That is, multiple
statements can be placed on a single line, or a single statement may
stretch across multiple lines.
Colon Notation
Consecutive statements can be chained together if the beginning of each
statement is identical. This is done with the colon (:) operator and commas,
which are used to terminate the individual statements, much as periods end
normal statements.
WRITE 'Hello'.
WRITE 'ABAP'.
WRITE 'World'.
WRITE: 'Hello',
'ABAP',
'World'.
Like any other ABAP statement, the layout doesn’t matter. This is an equally
correct statement −
Comments
Inline comments may be declared anywhere in a program by one of the two
methods −
Full line comments are indicated by placing an asterisk (*) in the first
position of the line, in which case the entire line is considered by the
SAP ABAP Tutorial February 23,
2025
Suppressing Blanks
The NO-ZERO command follows the DATA statement. It suppresses all
leading zeros of a number field containing blanks. The output is usually
easier for the users to read.
Example
REPORT Z_Test123_01.
50
Blank Lines
The SKIP command helps in inserting blank lines on the page.
Example
The message command is as follows −
SAP ABAP Tutorial February 23,
2025
SKIP number_of_lines.
The output would be several blank lines defined by the number of lines. The
SKIP command can also position the cursor on a desired line on the page.
This command is used to dynamically move the cursor up and down the
page. Usually, a WRITE statement occurs after this command to put output
on that desired line.
Inserting Lines
The ULINE command automatically inserts a horizontal line across the
output. It’s also possible to control the position and length of the line. The
syntax is pretty simple −
ULINE.
Example
The message command is as follows −
Messages
The MESSAGE command displays messages defined by a message ID
specified in the REPORT statement at the beginning of the program. The
message ID is a 2-character code that defines which set of 1,000 messages
the program will access when the MESSAGE command is used.
The messages are numbered from 000 to 999. Associated with each number
is a message text up to a maximum of 80 characters. When message
number is called, the corresponding text is displayed.
Following are the characters for use with the Message command −
Messa
Type Consequences
ge
The message appears and the application halts at its current point. If the program is ru
E Error
the job is canceled and the message is recorded in the job log.
The message appears and the user must press Enter for the application to continue. In
W Warning
message is recorded in the job log.
A pop-up window opens with the message text and the user must press Enter to conti
I Information
message is recorded in the job log.
A Abend This message class cancels the transaction that the user is currently using.
This provides an informational message at the bottom of the screen. The information
S Success
and it is just meant for user feedback. The message does not impede the program in a
X Abort This message aborts the program and generates an ABAP short dump.
Error messages are normally used to stop users from doing things they are
not supposed to do. Warning messages are generally used to remind the
users of the consequences of their actions. Information messages give the
users useful information.
Example
When we create a message for message the ID AB, the MESSAGE command -
MESSAGE E011 gives the following output −
Type Keyword
Byte field X
Text field C
Integer I
Floating point F
Packed number P
Text string STRING
Some of the fields and numbers can be modified using one or more names as
the following −
byte
numeric
character-like
The following table shows the data type, how much memory it takes to store
the value in memory, and the minimum and maximum value that could be
stored in such type of variables.
SAP ABAP Tutorial February 23,
2025
C 1 character 1 to 65535
F 8 bytes 2.2250738585072014E-308 to
1.7976931348623157E+308 positive or
negative
P 8 bytes [-10^(2len -1) +1] to [+10^(2len -1) 1]
(where len = fixed length)
STRING Variable Any alphanumeric characters
Example
REPORT YR_SEP_12.
DATA text_line TYPE C LENGTH 40.
text_line = 'A Chapter on Data Types'.
Write text_line.
variable length (text strings). Type STRING data objects should generally be
used for character-like content where fixed length is not important.
The DATE type is used for the storage of date information and can store
eight digits as shown above.
When the elementary types are grouped together, the data item can be
accessed as a grouped data item or the individual elementary type data
items (structure fields) can be accessed. The table types are better known as
arrays in other programming languages. Arrays can be simple or structure
arrays. In ABAP, arrays are called internal tables and they can be declared
and operated upon in many ways when compared to other programming
languages. The following table shows the parameters according to which
internal tables are characterized.
S.N
Parameter & Description
o.
Key
2 Specifies a field or a group of fields as a key of an internal table that identifies the table rows. A key con
types.
Access method
3
Describes how ABAP programs access individual table entries.
SAP ABAP Tutorial February 23,
2025
You must declare all variables before they can be used. The basic form of a
variable declaration is −
Here <f> specifies the name of a variable. The name of the variable can be
up to 30 characters long. <type> specifies the type of variable. Any data
type with fully specified technical attributes is known as <type>. The <val>
specifies the initial value of the of <f> variable. In case you define an
elementary fixed-length variable, the DATA statement automatically
populates the value of the variable with the type-specific initial value. Other
possible values for <val> can be a literal, constant, or an explicit clause,
such as Is INITIAL.
This chapter will explain various variable types available in ABAP. There are
three kinds of variables in ABAP −
Static Variables
Reference Variables
System Variables
SAP ABAP Tutorial February 23,
2025
Static Variables
Static variables are declared in subroutines, function modules, and
static methods.
The lifetime is linked to the context of the declaration.
With ‘CLASS-DATA’ statement, you can declare variables within the
classes.
The ‘PARAMETERS’ statement can be used to declare the elementary
data objects that are linked to input fields on a selection screen.
You can also declare the internal tables that are linked to input fields
on a selection screen by using ‘SELECT-OPTIONS’ statement.
You cannot use special characters such as "t" and "," to name
variables.
The name of the predefined data objects can’t be changed.
The name of the variable can’t be the same as any ABAP keyword or
clause.
The name of the variables must convey the meaning of the variable
without the need for further comments.
Hyphens are reserved to represent the components of structures.
Therefore, you are supposed to avoid hyphens in variable names.
The underscore character can be used to separate compound words.
REPORT ZTest123_01.
PARAMETERS: NAME(10) TYPE C,
CLASS TYPE I,
SCORE TYPE P DECIMALS 2,
CONNECT TYPE MARA-MATNR.
Reference Variables
The syntax for declaring reference variables is −
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 snippet, an object reference Oref and two data
reference variables Dref1 and Dref2 are declared.
Both data reference variables are fully typed and can be dereferenced
using the dereferencing operator →* at operand positions.
SAP ABAP Tutorial February 23,
2025
System Variables
ABAP system variables are accessible from all ABAP programs.
These fields are actually filled by the run-time environment.
The values in these fields indicate the state of the system at any given
point of time.
You can find the complete list of system variables in the SYST table in
SAP.
Individual fields of the SYST structure can be accessed by using either
“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.
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
SAP ABAP Tutorial February 23,
2025
SY-UNAME SAPUSER
SY-UZEIT 14:25:48
Numeric Literals
Number literals are sequences of digits which can have a prefixed sign. In
number literals, there are no decimal separators and no notation with
mantissa and exponent.
183.
-97.
+326.
Character Literals
Character literals are sequences of alphanumeric characters in the source
code of an ABAP program enclosed in single quotation marks. Character
literals enclosed in quotation marks have the predefined ABAP type C and
are described as text field literals. Literals enclosed in “back quotes” have
the ABAP type STRING and are described as string literals. The field length is
defined by the number of characters.
Note − In text field literals, trailing blanks are ignored, but in string literals
they are taken into account.
REPORT YR_SEP_12.
Write 'Tutorials Point'.
Write / 'ABAP Tutorial'.
REPORT YR_SEP_12.
Write `Tutorials Point `.
Write / `ABAP Tutorial `.
Tutorials Point
ABAP Tutorial
Note − When we try to change the value of the constant, a syntax or run-
time error may occur. Constants that you declare in the declaration part of a
class or an interface belong to the static attributes of that class or interface.
CONSTANTS Statement
We can declare the named data objects with the help of CONSTANTS
statement.
<f> specifies a name for the constant. TYPE <type> represents a constant
named <f>, which inherits the same technical attributes as the existing data
type <type>. VALUE <val> assigns an initial value to the declared constant
name <f>.
Note − We should use the VALUE clause in the CONSTANTS statement. The
clause ‘VALUE’ is used to assign an initial value to the constant during its
declaration.
SAP ABAP Tutorial February 23,
2025
REPORT YR_SEP_12.
CONSTANTS PQR TYPE P DECIMALS 4 VALUE '1.2356'.
Write: / 'The value of PQR is:', PQR.
The output is −
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.
Arithmetic Operators
Comparison Operators
Bitwise Operators
Character String Operators
SAP ABAP Tutorial February 23,
2025
Arithmetic Operators
Arithmetic operators are used in mathematical expressions in the same way
that they are used in algebra. The following list describes arithmetic
operators. Assume integer variable A holds 20 and variable B holds 40.
S.No
Arithmetic Operator & Description
.
+ (Addition)
1
Adds values on either side of the operator. Example: A + B will give 60.
− (Subtraction)
2
Subtracts right hand operand from left hand operand. Example: A − B will give -20.
* (Multiplication)
3
Multiplies values on either side of the operator. Example: A * B will give 800.
/ (Division)
4
Divides left hand operand by right hand operand. Example: B / A will give 2.
MOD (Modulus)
5
Divides left hand operand by right hand operand and returns the remainder. Example: B MOD A will
Example
REPORT YS_SEP_08.
DATA: A TYPE I VALUE 150,
B TYPE I VALUE 50,
Result TYPE I.
Result = A / B.
WRITE / Result.
Comparison Operators
Let’s discuss the various types of comparison operators for different
operands.
SAP ABAP Tutorial February 23,
2025
S.N
Comparison Operator & Description
o.
IS INITIAL
8 The condition becomes true if the contents of the variable have not changed and it has been automatical
Example (A IS INITIAL) is not true
IS NOT INITIAL
9
The condition becomes true if the contents of the variable have changed. Example (A IS NOT INITIAL
Note − If the data type or length of the variables does not match then
automatic conversion is performed. Automatic type adjustment is performed
for either one or both of the values while comparing two values of different
data types. The conversion type is decided by the data type and the
preference order of the data type.
Example 1
REPORT YS_SEP_08.
A is less than B
Example 2
REPORT YS_SEP_08.
DATA: A TYPE I.
IF A IS INITIAL.
WRITE: / 'A is assigned'.
ENDIF.
A is assigned.
Bitwise Operators
ABAP also provides a series of bitwise logical operators that can be used to
build Boolean algebraic expressions. The bitwise operators can be combined
in complex expressions using parentheses and so on.
SAP ABAP Tutorial February 23,
2025
S.N
Bitwise Operator & Description
o.
BIT-NOT
1 Unary operator that flips all the bits in a hexadecimal number to the opposite value. For instance, applyi
hexadecimal number having the bit level value 10101010 (e.g. 'AA') would give 01010101.
BIT-AND
2
This binary operator compares each field bit by bit using the Boolean AND operator.
BIT-XOR
3
Binary operator that compares each field bit by bit using the Boolean XOR (exclusive OR) operator.
BIT-OR
4
Binary operator that compares each field bit by bit using the Boolean OR operator.
For example, following is the truth table that shows the values generated
when applying the Boolean AND, OR, or XOR operators against the two bit
values contained in field A and field B.
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1
CO (Contains Only)
1
Checks whether A is solely composed of the characters in B.
3 CA (Contains ANY)
SAP ABAP Tutorial February 23,
2025
CS (Contains a String)
5
Checks whether A contains the character string B.
CP (Contains a Pattern)
7
It checks whether A contains the pattern in B.
Example
REPORT YS_SEP_08.
DATA: P(10) TYPE C VALUE 'APPLE',
Q(10) TYPE C VALUE 'CHAIR'.
IF P CA Q.
S.N
Loop Type & Description
o.
WHILE loop
1
Repeats a statement or group of statements when a given condition is true. It tests the condition before e
Do loop
2
The DO statement is useful for repeating particular task a specific number of times.
Nested loop
3
You may use one or more loops inside any another WHILE or DO loop.
o.
CONTINUE
1
Causes the loop to skip the remainder of its body and starts the next loop pass.
CHECK
2
If the condition is false, then the remaining statements after the CHECK are just ignored and the system
EXIT
3
Terminates the loop entirely and transfers execution to the statement immediately following the loop.
S.No
Statement & Description
.
IF Statement
1
An IF statement consists of a logical expression followed by one or more statements.
Nested IF Statement
3
You may use one IF or ELSEIF statement inside another IF or ELSEIF statement.
Creating Strings
The following declaration and initialization creates a string consisting of the
word 'Hello'. The size of the string is exactly the number of characters in the
word 'Hello'.
REPORT YT_SEP_15.
DATA my_Char(5) VALUE 'Hello'.
Write my_Char.
Hello
SAP ABAP Tutorial February 23,
2025
String Length
In order to find the length of character strings, we can use STRLEN
statement. The STRLEN () function returns the number of characters
contained in the string.
Example
REPORT YT_SEP_15.
DATA: title_1(10) VALUE 'Tutorials',
length_1 TYPE I.
CONCATENATE
1
Two strings are joined to form a third string.
CONDENSE
2
This statement deletes the space characters.
STRLEN
3
Used to find the length of a field.
REPLACE
4
Used to make replacements in characters.
SEARCH
5
To run searches in character strings.
SHIFT
6
Used to move the contents of a string left or right.
SPLIT
7
Used to split the contents of a field into two or more fields.
SAP ABAP Tutorial February 23,
2025
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).
CONDENSE spaced_title.
Write: / 'Condense with Gaps:', spaced_title.
Concatenation: TutorialsPoint
Concatenation with Space: Tutorials Point
Condense with Gaps: Tutorials Point Limited
Condense with No Gaps: TutorialsPointLimited
Note −
ABAP implicitly references the Gregorian calendar, valid across most of the
world. We can convert the output to country specific calendars. A date is a
time specified to a precise day, week or month with respect to a calendar. A
time is specified to a precise second or minute with respect to a day. ABAP
always saves time in 24-hour format. The output can have a country specific
format. Dates and time are usually interpreted as local dates that are valid in
the current time zone.
ABAP provides two built-in types to work with dates and time −
D data type
T data type
Both of these types are fixed-length character types that have the form
YYYYMMDD and HHMMSS, respectively.
Timestamps
In addition to these built-in types, the other two
types TIMESTAMP and TIMESTAMPL are being used in many standard
application tables to store a timestamp in the UTC format. Following table
shows the basic date and time types available in ABAP.
S.N
Data Type & Description
o.
D
1 A built-in fixed-length date type of the form YYYYMMDD. For example, the value 20100913 represen
2010.
2 T
SAP ABAP Tutorial February 23,
2025
A built-in fixed-length time type of the form HHMMSS. For example, the value 102305 represents time
REPORT YR_SEP_15.
DATA: date_1 TYPE D.
date_1 = SY-DATUM.
Write: / 'Present Date is:', date_1 DD/MM/YYYY.
The variable date_1 is assigned the value of the current system date SY-
DATUM. Next, we increment the date value by 6. In terms of a date
calculation in ABAP, this implies that we’re increasing the day component of
the date object by 6 days. The ABAP runtime environment is smart enough to
roll over the date value whenever it reaches the end of a month.
REPORT YR_SEP_15.
DATA: time_1 TYPE T.
time_1 = SY-UZEIT.
SAP ABAP Tutorial February 23,
2025
REPORT YR_SEP_12.
DATA: stamp_1 TYPE TIMESTAMP,
In the above example, we are displaying the timestamp using the TIME ZONE
addition of the WRITE statement. This addition formats the output of the
timestamp according to the rules for the time zone specified. The system
field SY-ZONLO is used to display the local time zone configured in the user’s
preferences.
SAP ABAP Tutorial February 23,
2025
S.N
Clause & Description
o.
LEFT-JUSTIFIED
1
Specifies that the output is left-justified.
CENTERED
2
Denotes that the output is centered.
RIGHT-JUSTIFIED
3
Specifies that the output is right-justified.
UNDER <g>
4
The output starts directly under the field <g>.
NO-GAP
5
Specifies that the blank after field <f> is rejected.
NO-ZERO
7
If a field contains only zeroes, then they are replaced by blanks.
S.N
Clause & Description
o.
NO-SIGN
1
Specifies that no leading sign is displayed on the screen.
EXPONENT <e>
2
Specifies that in type F (the floating point fields), the exponent is defined in <e>.
ROUND <r>
3
The type P fields (packed numeric data types) are first multiplied by 10**(-r) and then rounded off to a
CURRENCY <c>
4
Denotes that the formatting is done according to the currency <c> value that is stored in the TCURX da
UNIT <u>
5
Specifies that the number of decimal places is fixed according to the <u> unit as specified in the T006 d
DECIMALS <d>
6
Specifies that the number of digits <d> must be displayed after the decimal point.
For instance, the following table shows different formatting options for the
date fields −
Formatting Option
DD/MM/YY 13/01/15
MM/DD/YY 01/13/15
DD/MM/YYYY 13/01/2015
MM/DD/YYYY 01/13/2015
DDMMYY 130115
MMDDYY 011315
YYMMDD 150113
SAP ABAP Tutorial February 23,
2025
Here, DD stands for the date in two figures, MM stands for the month in two
figures, YY stands for the year in two figures, and YYYY stands for the year in
four figures.
Let’s take a look at an example of ABAP code that implements some of the
above formatting options −
REPORT ZTest123_01.
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 '__:__:__'.
Tutorials Point
Tutorials
Point
TutorialsPoint
112538
11:25:38
A TRY - CATCH block is placed around the code that might generate an
exception. Following is the syntax for using 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.
TRY − The TRY block contains the application coding whose exceptions are
to be handled. This statement block is processed sequentially. It can contain
further control structures and calls of procedures or other ABAP programs. It
is followed by one or more catch blocks.
Raising Exceptions
SAP ABAP Tutorial February 23,
2025
Catching Exceptions
Handlers are used to catch exceptions.
In the above code snippet, we are trying to divide Num1 by Num2 to get the
result in a float type variable.
Attributes of Exceptions
Here are the five attributes and methods of exceptions −
SAP ABAP Tutorial February 23,
2025
Textid
1
Used to define different texts for exceptions and also affects the result of the method get_text.
Previous
2
This attribute can store the original exception that allows you to build a chain of exceptions.
get_text
3
This returns the textual representation as a string as per the system language of the exception.
get_longtext
4
This returns the long variant of the textual representation of the exception as a string.
get_source_position
5
Gives the program name and line number reached where the exception was raised.
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.
CLEAR res_1.
ENDTRY.
DML part consists of query and update commands such as SELECT, INSERT,
UPDATE, DELETE, etc. and ABAP programs handle the DML part of SQL. DDL
part consists of commands such as CREATE TABLE, CREATE INDEX, DROP
TABLE, ALTER TABLE, etc. and ABAP Dictionary handles the DDL part of SQL.
SAP ABAP Tutorial February 23,
2025
ABAP Dictionary can be viewed as metadata (i.e. data about data) that
resides in the SAP database along with the metadata maintained by the
database. The Dictionary is used to create and manage data definitions and
to create Tables, Data Elements, Domains, Views and Types.
The Dictionary supports the definition of user-defined types and these types
are used in ABAP programs. They also define the structure of database
objects such as tables, views and indexes. These objects are created
automatically in the underlying database in their Dictionary definitions when
the objects are activated. The Dictionary also provides editing tools like
Search Help and locking tool like Lock Objects.
Dictionary Tasks
ABAP Dictionary achieves the following −
Example
SAP ABAP Tutorial February 23,
2025
Any complex user-defined type can be built from the 3 basic types in the
Dictionary. Customer data is stored in a structure ‘Customer’ with the
components Name, Address and Telephone as depicted in the following
image. Name is also a structure with components, First name and Last name.
Both of these components are elementary because their type is defined by a
data element.
The domain is assigned to the data element, which in turn is assigned to the
table fields or structure fields. For instance, the MATNR domain (CHAR
material number) is assigned to data elements such as MATNR_N, MATNN
and MATNR_D, and these are assigned to many table fields and structure
fields.
Creating Domains
Before you create a new domain, check whether any existing domains have
the same technical specifications required in your table field. If so, we are
supposed to use that existing domain. Let’s discuss the procedure for
creating the domain.
Step 2 − Select the radio button for Domain in the initial screen of the ABAP
Dictionary, and enter the name of the domain as shown in the following
screenshot. Click the CREATE button. You may create domains under the
customer namespaces, and the name of the object always starts with ‘Z’ or
‘Y’.
SAP ABAP Tutorial February 23,
2025
Step 3 − Enter the description in the short text field of the maintenance
screen of the domain. In this case, it is “Customer Domain”. Note − You
cannot enter any other attribute until you have entered this attribute.
Step 4 − Enter the Data Type, No. of Characters, and Decimal Places in the
Format block of the Definition tab. Press the key on Output Length and it
proposes and displays the output length. If you overwrite the proposed
output length, you may see a warning while activating the domain. You may
fill in the Convers. Routine, Sign and Lower Case fields if required. But these
are always optional attributes.
Step 5 − Select the Value Range tab. If the domain is restricted to having
only fixed values then enter the fixed values or intervals. Define the value
table if the system has to propose this table as a check table while defining a
foreign key for the fields referring to this domain. But all these are optional
attributes.
SAP ABAP Tutorial February 23,
2025
Step 6 − Save your changes. The Create Object Directory Entry pop-up
appears and asks for a package. You may enter the package name in which
you are working. If you do not have any package then you may create it in
the Object Navigator or you can save your domain using the Local Object
button.
Step 7 − Activate your domain. Click on the Activate icon (matchstick icon)
or press CTRL + F3 to activate the domain. A pop-up window appears, listing
the 2 currently inactive objects as shown in the following snapshot −
Step 8 − At this point, the top entry labeled ‘DOMA’ with the name ZSEP_18
is to be activated. As this is highlighted, click the green tick button. This
window disappears and the status bar will display the message ‘Object
activated’.
If error messages or warnings occurred when you activated the domain, the
activation log is displayed automatically. The activation log displays
information about activation flow. You can also call the activation log with
Utilities(M) → Activation log.
Step 2 − Select the radio button for Data type in the initial screen of the
ABAP Dictionary, and enter the name of the data element as shown below.
Step 3 − Click the CREATE button. You may create data elements under the
customer namespaces, and the name of the object always starts with ‘Z’ or
‘Y’.
SAP ABAP Tutorial February 23,
2025
Step 4 − Check the Data element radio button on the CREATE TYPE pop-up
that appears with three radio buttons.
Step 5 − Click the green checkmark icon. You are directed to the
maintenance screen of the data element.
Step 6 − Enter the description in the short text field of the maintenance
screen of the data element. In this case, it is “Customer Data
SAP ABAP Tutorial February 23,
2025
Element”. Note − You cannot enter any other attribute until you have
entered this attribute.
Step 7 − Assign the data element with the type. You can create an
elementary data element by checking elementary type or a reference data
element by checking Reference type. You can assign a data element to a
Domain or Predefined Type within Elementary Type and with Name of
Reference Type or Reference to Predefined Type within Reference Type.
Step 8 − Enter the fields for short text, medium text, long text, and heading
in the Field Label tab. You can press Enter and the length is automatically
generated for these labels.
SAP ABAP Tutorial February 23,
2025
Step 9 − Save your changes. The Create Object Directory Entry pop-up
appears and asks for a package. You may enter the package name in which
you are working. If you do not have any package then you may create it in
the Object Navigator or you can save your data element using the Local
Object button.
Step 10 − Activate your data element. Click the Activate icon (matchstick
icon) or press CTRL + F3 to activate the data element. A pop-up window
appears, listing the 2 currently inactive objects as shown in the following
screenshot.
Step 11 − At this point, the top entry labeled ‘DTEL’ with the name Z_CUST
is to be activated. As this is highlighted, click the green tick button. This
window disappears and the status bar will display the message ‘Object
activated’.
SAP ABAP Tutorial February 23,
2025
A table can contain one or more fields, each defined with its data type and
length. The large amount of data stored in a table is distributed among the
several fields defined in the table.
S.N
Elements & Description
o.
Field name
1 This is the name given to a field that can contain a maximum of 16 characters. The field name may be c
underscores. It must begin with a letter.
Key flag
2
Determines whether or not a field belongs to a key field.
Field type
3
Assigns a data type to a field.
Field length
4
The number of characters that can be entered in a field.
Decimal places
5
Defines the number of digits permissible after the decimal point. This element is used only for numeric
6 Short text
SAP ABAP Tutorial February 23,
2025
Step 3 − Click the Search Help icon beside the Delivery Class field. Select ‘A
[Application table (master and transaction data)]’ option.
Step 5 − Select the Fields tab. The screen containing the options related to
the Fields tab appears.
Step 6 − Enter the names of table fields in the Field column. A field name
may contain letters, digits, and underscores, but it must always begin with a
letter and must not be longer than 16 characters.
SAP ABAP Tutorial February 23,
2025
The fields that are to be created must also have data elements because they
take the attributes, such as data type, length, decimal places, and short text,
from the defined data element.
Step 7 − Select the Key column if you want the field to be a part of the table
key. Let’s create fields such as CLIENT, CUSTOMER, NAME, TITLE and DOB.
Step 8 − The first field is an important one and it identifies the client which
the records are associated with. Enter ‘Client’ as the Field and ‘MANDT’ as
the Data Element. The system automatically fills in the Data Type, Length,
Decimals and Short Description. The ‘Client’ field is made a key field by
checking the ‘Key’ box.
Step 9 − The next field is ‘Customer’. Check the box to make it a key field
and enter the new Data Element ‘ZCUSTNUM’. Click the Save button.
The ‘Definition’ tab opens automatically. The first field is ‘Data Type’.
SAP ABAP Tutorial February 23,
2025
Step 12 − Click inside the box and select ‘NUMC’ type from the drop-down
menu. Enter the number 8 in the ‘No. of characters’ field (a maximum of 8
characters) and enter 0 in ‘Decimal places’ area. The Output length of 8
must be selected and then press Enter. The ‘NUMC’ field’s description must
re-appear, confirming that this is a valid entry.
Step 15 − Press the back button to return to the table maintenance screen.
The Customer column has the correct Data Type, Length, Decimals and Short
Description. This indicates the successful creation of a Data element and also
the Domain used.
SAP ABAP Tutorial February 23,
2025
Similarly, we need to create three additional fields such as NAME, TITLE and
DOB.
Step 16 − Select ‘Technical settings’ from the toolbar. Choose APPL0 for the
‘Data class’ and the first size category 0 for the ‘Size’ category’ field. In case
of buffering options, ‘Buffering not allowed’ has to be selected.
Step 17 − Click Save. Go back to the table and Activate it. The following
screen appears.
SAP ABAP Tutorial February 23,
2025
Structures are useful for painting screen fields, and for manipulating data
that has a consistent format defined by a discrete number of fields.
A structure may have only a single record at run-time, but a table can have
many records.
Creating a Structure
Step 1 − Go to transaction SE11.
SAP ABAP Tutorial February 23,
2025
Step 2 − Click on the ‘Data type’ option on the screen. Enter the name
'ZSTR_CUSTOMER1' and click on Create button.
Step 3 − Select the option 'Structure' in the next screen and press Enter.
You can see 'Maintain / Change Structure' wizard.
Step 5 − Enter the Component (Field Name) and Component Type (Data
Element).
Note: Here the component names start with Z as per the SAP
recommendation. Let's use data elements that we have already created in
the database table.
Step 6 − You need to Save, Check and Activate after providing all the
components and component types.
We use projection view to mask unwanted fields and display only relevant
fields in a table. Projection views must be defined over a single transparent
table. A projection view contains exactly one table. We can't define selection
conditions for projection views.
Creating a View
Step 1 − Select the View radio button on the initial screen of ABAP
Dictionary. Enter the name of the view to be created and then click Create
button. We entered the name of the view as ZVIEW_TEST.
SAP ABAP Tutorial February 23,
2025
Step 2 − Select the projection view radio button while choosing view type
and click Copy button. The ‘Dictionary: Change View’ screen appears.
Step 3 − Enter a short description in the Short Description field and the
name of the table to be used in the Basis Table field as shown in the
following snapshot.
Step 6 − After clicking the Copy button, all the selected fields for the
projection view are displayed on the ‘Dictionary: Change View’ screen.
Step 8 − Save and Activate it. In the ‘Dictionary: Change View’ screen select
Utilities(M) > Contents to display the selection screen for ZVIEW_TEST.
Step 9 − Click the Execute icon. The output of the projection view appears
as shown in the following screenshot.
SAP ABAP Tutorial February 23,
2025
The table ZCUSTOMERS1 consists of 5 fields. Here the displayed fields are 3
(Client, Customer Number and Name) with 4 entries. Customer numbers are
from 100001 to 100004 with appropriate names.
Step 2 − The system will prompt for the search help type to be created.
Select the Elementary search help, which is default. The screen to create
elementary search help as shown in the following screenshot appears.
Step 4 − After the selection method is entered, the next field is the Dialog
type. This controls the appearance of the restrictive dialog box. There is a
drop-down list with three options. Let's select the option 'Display values
immediately'.
Step 5 − Next is the parameter area. For each Search help parameter or
field, these column fields have to be entered as per the requirements.
Search help parameter − This is a field from the source of data. The
fields from the table are listed in the selection list. The fields
participating in the search help would be entered, one field in each
row. Let's include the two fields CUSTOMER and NAME. How these two
fields participate is indicated in the rest of the columns.
Step 6 − Perform a consistency check and activate the search help. Press F8
to execute. The 'Test Search Help ZSRCH1' screen appears as shown in the
following screenshot.
Step 7 − Let's enter the number 100004 in the CUSTOMER's 'Ready for inp'
screen field. Press Enter.
used in SAP to avoid the inconsistency when data is inserted into or changed
in the database. Tables whose data records are to be locked must be defined
in a Lock Object, along with their key fields.
Lock Mechanism
Following are the two main functions accomplished with the lock mechanism
−
A lock request is first generated by the program. Then this request goes to
the Enqueue server and the lock is created in the lock table. The Enqueue
server sets the lock and the program is finally ready to access data.
SAP ABAP Tutorial February 23,
2025
Step 2 − Click ‘Lock Object’ radio button. Enter the name of lock object
starting with E and click the Create button. Here we use EZLOCK12.
Step 3 − Enter the short description field and click on Tables tab.
Step 4 − Enter the table name in Name field and select the lock mode as
Write Lock.
Step 5 − Click on Lock parameter tab, the following screen will appear.
SAP ABAP Tutorial February 23,
2025
Step 7 − Click Lock Modules and the following screen will open.
The key fields of a table included in a Lock Object are called lock arguments
and they are used as input parameters in function modules. These
arguments are used to set and remove the locks generated by the Lock
Object definition.
The processing blocks called from outside the program and from the
ABAP run-time environment (i.e., event blocks and dialog modules).
Processing blocks called from ABAP programs.
Apart from the modularization with processing blocks, source code modules
are used to modularize your source code through macros and include
programs.
Local Macros
Global Include programs
Subroutines
Function modules
We have program X with 3 different source code blocks. Each block has
the same ABAP statements. Basically, they are the same code blocks. To
make this code easier to maintain, we can encapsulate the code into a
subroutine. We can call this subroutine in our programs as many times as we
wish. A subroutine can be defined using Form and EndForm statements.
SAP ABAP Tutorial February 23,
2025
FORM <subroutine_name>.
<statements>
ENDFORM.
Example
Step 1 − Go to transaction SE80. Open the existing program and then right-
click on program. In this case, it is 'ZSUBTEST'.
Step 2 − Select Create and then select Subroutine. Write the subroutine
name in the field and then click the continue button. The subroutine name is
'Sub_Display' as shown in the following screenshot.
SAP ABAP Tutorial February 23,
2025
Step 3 − Write the code in FORM and ENDFORM statement block. The
subroutine has been created successfully.
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, activate and execute the program. The above code produces
the following output −
Subroutine Test:
This is Subroutine
Example
Go to transaction SE38. Create a new program ZMACRO_TEST along with the
description in the short text field, and also with appropriate attributes such
as Type and Status as shown in the following screenshot −
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.
A Macro Program
This is Macro 2
If all checkboxes are selected, the code produces the following output −
A Macro Program
The results of the search will be displayed in a new window. The function
modules are displayed in the lines with blue background and their function
groups in pink lines. You may look further at the function group ISOC by
using the Object Navigator screen (Transaction SE80). You can see a list of
function modules and also other objects held in the function group. Let's
SAP ABAP Tutorial February 23,
2025
Step 2 − Enter some code so that a parameter can be set up where a value
could be entered and passed on to the function module. The text element
text-001 here reads ‘Enter a Value’.
Step 3 − To write the code for this, use CTRL+F6. After this, a window
appears where ‘CALL FUNCTION’ is the first option in a list. Enter
'spell_amount' in the text box and click the continue button.
REPORT Z_SPELLAMOUNT.
data result like SPELL.
IF SY-SUBRC <> 0.
Write: 'Value returned is:', SY-SUBRC.
else.
Write: 'Amount in words is:', result-word.
ENDIF.
Step 6 − Save, activate and execute the program. Enter a value as shown in
the following screenshot and press F8.
INCLUDE <program_name>.
INCLUDE statement has the same effect as copying the source code of the
include program <program_name> into another program. As include
program can’t run independently, it has to be built into other programs. You
may also nest include programs.
Following are a couple of restrictions while writing the code for Include
programs −
PROGRAM Z_TOBEINCLUDED.
Write: / 'This program is started by:', SY-UNAME,
/ 'The Date is:', SY-DATUM,
/ 'Time is', SY-UZEIT.
Step 2 − Set the Type of the program to INCLUDE program, as shown in the
following screenshot.
SAP ABAP Tutorial February 23,
2025
Step 3 − Click the ‘Save’ button and save the program in a package named
ZINCL_PCKG.
REPORT Z_INCLUDINGTEST.
INCLUDE Z_TOBEINCLUDED.
The statements of Open SQL are converted to database specific SQL in the
Open SQL interface of the database interface. They are then transferred to
the database system and executed. Open SQL statements can be used to
access database tables that are declared in the ABAP Dictionary. The central
database of AS ABAP is accessed by default and also access to other
databases is possible via secondary database connections.
The DATA statement is used to declare a work area. Let's give this the name
'wa_customers1'. Rather than declaring one data type for this, several fields
that make up the table can be declared. The easiest way to do this is using
the LIKE statement.
INSERT Statement
The wa_customers1 work area is declared here LIKE the ZCUSTOMERS1
table, taking on the same structure without becoming a table itself. This
work area can only store one record. Once it has been declared, the INSERT
statement can be used to insert the work area and the record it holds into
the table. The code here will read as 'INSERT ZCUSTOMERS1 FROM
wa_customers1'.
The work area has to be filled with some data. Use the field names from the
ZCUSTOMERS1 table. This can be done by forward navigation, double
clicking the table name in the code or by opening a new session and using
the transaction SE11. The fields of the table can then be copied and pasted
into the ABAP editor.
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 if the record is
inserted correctly, the system will state this. If not, then the SY-SUBRC code
which will not equal zero will be displayed. Following is the code snippet −
IF SY-SUBRC = 0.
WRITE 'Record Inserted Successfully'.
ELSE.
WRITE: 'The return code is ', SY-SUBRC.
ENDIF.
Check the program, save, activate the code, and then test it. The output
window should display as 'Record Inserted Successfully'.
CLEAR Statement
CLEAR statement allows a field or variable to be cleared out for the insertion
of new data in its place, allowing it to be reused. CLEAR statement is
generally used in programs and it allows existing fields to be used many
times.
In the previous code snippet, the work area structure has been filled with
data to create a new record to be inserted into the ZCUSTOMERS1 table and
then a validation check is performed. If we want to insert a new record,
CLEAR statement must be used so that it can then be filled again with the
new data.
UPDATE Statement
If you want to update one or more existing records in a table at the same
time then use UPDATE statement. Similar to INSERT statement, a work area
is declared, filled with the new data that is then put into the record as the
program is executed. The record previously created with the INSERT
statement will be updated here. Just edit the text stored in the NAME and
TITLE fields. Then on a new line, the same structure as for the INSERT
statement is used, and this time by using the UPDATE statement as shown in
the following code snippet −
SAP ABAP Tutorial February 23,
2025
As UPDATE statement gets executed, you can view the Data Browser in the
ABAP Dictionary to see that the record has been updated successfully.
MODIFY Statement
MODIFY statement can be considered as a combination of the INSERT and
UPDATE statements. It can be used to either insert a new record or modify
an existing record. It follows a similar syntax to the previous two statements
in modifying the record from the data entered into a work area.
When this statement is executed, the key fields involved will be checked
against those in the table. If a record with these key field values already
exist, it will be updated. If not, then a new record will be created.
CLEAR wa_customers1.
In this example, CLEAR statement is used so that a new entry can be put into
the work area, and then customer (number) 100007 is added. Since this is a
new, unique key field value, a new record will be inserted, and another
validation check is executed.
When this is executed and the data is viewed in the Data Browser, a new
record will have been created for the customer number 100007 (RALPH).
To use a Native SQL statement, you have to precede it with the EXEC SQL
statement and end with ENDEXEC statement.
All SQL statements that are valid for the program interface of the
addressed database system can be listed between EXEC and
ENDEXEC, in particular the DDL (data definition language) statements.
These SQL statements are passed from the Native SQL interface to the
database system largely unchanged. The syntax rules are specified by
the database system, especially the case sensitivity rules for database
objects.
If the syntax allows a separator between individual statements, you
may include many Native SQL statements between EXEC and
ENDEXEC.
SAP specific Native SQL language elements can be specified between
EXEC and ENDEXEC. These statements are not passed directly from
the Native SQL interface to the database, but they are transformed
appropriately.
Example
SPFLI is a standard SAP Table that is used to store Flight schedule
information. This is available within R/3 SAP systems depending on the
version and release level. You can view this information when you enter the
Table name SPFLI into the relevant SAP transaction such as SE11 or SE80.
You can also view the data contained in this database table by using these
two transactions.
REPORT ZDEMONATIVE_SQL.
DATA: BEGIN OF wa,
connid TYPE SPFLI-connid,
cityfrom TYPE SPFLI-cityfrom,
cityto TYPE SPFLI-cityto,
END OF wa.
FROM SPFLI
WHERE carrid = :c1
ENDEXEC.
FORM loop_output.
WRITE: / wa-connid, wa-cityfrom, wa-cityto.
ENDFORM.
Data in an internal table is stored in rows and columns. Each row is called
a line and each column is called a field. In an internal table, all the records
have the same structure and key. The individual records of an internal table
are accessed with an index or a key. As internal table exists till the
associated program is being executed, the records of the internal table are
discarded when the execution of the program is terminated. So internal
tables can be used as temporary storage areas or temporary buffers where
data can be modified as required. These tables occupy memory only at run-
time and not at the time of their declaration.
Internal tables only exist when a program is running, so when the code is
written, the internal table must be structured in such a way that the program
can make use of it. You will find that internal tables operate in the same way
as structures. The main difference being that structures only have one line,
while an internal table can have as many lines as required.
tables, one can specify a non-unique key, allowing any number of non-unique
records to be stored, and allowing duplicate records to be stored if required.
The size of an internal table or the number of lines it contains is not fixed.
The size of an internal table changes according to the requirement of the
program associated with the internal table. But it is recommended to keep
internal tables as small as possible. This is to avoid the system running
slowly as it struggles to process enormous amounts of data.
Example
Assume that a user wants to create a list of contact numbers of various
customers from one or several large tables. The user first creates an internal
table, selects the relevant data from customer tables and then places the
data in the internal table. Other users can access and use this internal table
directly to retrieve the desired information, instead of writing database
queries to perform each operation during the run-time of the program.
Let’s create the fields on a new line. For instance, create ‘name’ which is
declared as LIKE ZCUSTOMERS1-name. Create another field called ‘dob’, LIKE
ZCUSTOMERS1-dob. It is useful initially to give the field names in internal
tables the same names as other fields that have been created elsewhere.
Finally, declare the end of the internal table with “END OF <internal_tab>.”
as shown in the following code −
You can also create an internal table as a local data type (a data type used
only in the context of the current program) by using the TYPES statement.
This statement uses the TYPE or LIKE clause to refer to an existing table.
Example
Step 1 − Open the ABAP Editor by executing the SE38 transaction code. The
initial screen of ABAP Editor appears.
Step 2 − In the initial screen, enter a name for the program, select the
Source code radio button and click the Create button to create a new
program.
REPORT ZINTERNAL_DEMO.
TYPES: BEGIN OF CustomerLine,
Cust_ID TYPE C,
Cust_Name(20) TYPE C,
END OF CustomerLine.
INSERT Statement
INSERT statement is used to insert a single line or a group of lines into an
internal table.
In this syntax, the INSERT statement inserts a new line in the internal_tab
internal table. A new line can be inserted by using the work_area_itab INTO
expression before the internal_tab parameter. When the work_area_itab INTO
expression is used, the new line is taken from the work_area_itab work area
and inserted into the internal_tab table. However, when the work_area_itab
INTO expression is not used to insert a line, the line is taken from the header
line of the internal_tab table.
When a new line is inserted in an internal table by using the INDEX clause,
the index number of the lines after the inserted line is incremented by 1. If
an internal table contains <index_num> - 1 lines, the new line is added at
the end of the table. When the SAP system successfully adds a line to an
internal table, the SY-SUBRC variable is set to 0.
Example
Following is a sample program that uses the insert 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.
SAP ABAP Tutorial February 23,
2025
ENDDO.
itable1-F1 = -96.
INSERT itable1 INDEX 2.
LOOP AT itable1.
Write / itable1-F1.
ENDLOOP.
Skip.
LOOP AT itable1.
Write / itable1-F1.
ENDLOOP.
1
96-
2
3
4
1
96-
2
78-
3
78-
4
In the above example, the DO loop appends 4 rows containing the numbers 1
through 4 to it. The header line component itable1-F1 has been assigned a
value of -96. Insert statement inserts the header line as new row into the
body before row 3. The existing row 3 becomes row 4 after the insert. The
LOOP AT statement retrieves those rows from the internal table that have an
F1 value greater than or equal to 3. Before each row, Insert statement
SAP ABAP Tutorial February 23,
2025
inserts a new row from the header line of it. Prior to the insert, the F1
component has been changed to contain -78.
After each insert statement is executed, the system re-indexes all rows
below the one inserted. This introduces overhead when you insert rows near
the top of a large internal table. If you need to insert a block of rows into a
large internal table, prepare another table with the rows to be inserted and
use insert lines instead.
When inserting a new row inside itable1 inside of a loop at itable1, it doesn’t
affect the internal table instantly. It actually becomes effective on the next
loop pass. While inserting a row after the current row, the table is re-indexed
at the ENDLOOP. The sy-tabix is incremented and the next loop processes
the row pointed to by sy-tabix. For instance, if you are in the second loop
pass and you insert a record before row 3. When endloop is executed, the
new row becomes row 3 and the old row 3 becomes row 4 and so on. Sy-
tabix is incremented by 1, and the next loop pass processes the newly
inserted record.
APPEND Statement
The APPEND statement is used to add a single row or line to an existing
internal table. This statement copies a single line from a work area and
inserts it after the last existing line in an internal table. The work area can be
either a header line or any other field string with the same structure as a line
of an internal table. Following is the syntax of the APPEND statement that is
used to append a single line in an internal table −
Appending lines to standard and sorted tables with a non-unique key works
regardless of whether the lines with the same key already exist in the table.
In other words, duplicate entries may occur. However, a run-time error
occurs if the user attempts to add a duplicate entry to a sorted table with a
SAP ABAP Tutorial February 23,
2025
unique key or if the user violates the sort order of a sorted table by
appending the lines to it.
Example
REPORT ZCUSLIST1.
DATA: BEGIN OF linv Occurs 0,
Name(20) TYPE C,
ID_Number TYPE I,
END OF linv.
Melissa 105467
To copy the records, we can use a SELECT statement to select all of the
records from the table and then use MOVE statement that will move the
records from the original table into the new internal table into the fields
where the names correspond.
Example
REPORT ZCUSLIST1.
TABLES: ZCUSTOMERS1.
DATA: BEGIN OF itab01 Occurs 0,
name LIKE ZCUSTOMERS1-name,
dob LIKE ZCUSTOMERS1-dob,
END OF itab01.
MARGARET 02.11.1994
The select loop fills each field one at a time, using the MOVE statement to
move the data from one table’s field to the other. In the above example,
MOVE statements were used to move the contents of the ZCUSTOMERS1
table to the corresponding fields in the internal table. You can accomplish
this action with just one line of code. You can use the MOVECORRESPONDING
statement.
It tells the system to move the data from the fields of ZCUSTOMERS1 to their
corresponding fields in itab01.
Example
REPORT ZCUSTOMERLIST.
TABLES: ZCUSTOMERS1.
DATA: Begin of itab01 occurs 0,
customer LIKE ZCUSTOMERS1-customer,
name LIKE ZCUSTOMERS1-name,
title LIKE ZCUSTOMERS1-title,
SAP ABAP Tutorial February 23,
2025
MARK 21.05.1981
JAMES 14.08.1977
AURIELE 19.06.1990
STEPHEN 22.07.1985
MARGARET 02.11.1994
This is made possible by the fact that both have matching field names. When
making use of this statement, you need to make sure that both fields have
matching data types and lengths. It has been done here with the LIKE
statement previously.
Here the entire line of the internal table is used as a search key. The
content of the entire line of the table is compared with the content of the
<internal_tab_field> field. If the values of the <internal_tab_field> field are
not compatible with the line type of the table, these values are converted
according to the line type of the table. The search key allows you to find
entries in internal tables that do not have a structured line type, that is,
where the line is a single field or an internal table type.
The following syntax of the READ statement is used to specify a work area or
field symbol by using the COMPARING clause −
When the COMPARING clause is used, the specified table fields <F1>,
<F2>....<Fn> of the structured line type are compared with the
corresponding fields of the work area before being transported. If the ALL
FIELDS clause is specified, the SAP system compares all the components.
When the SAP system finds an entry on the basis of a key, the value of the
SY-SUBRC variable is set to 0. In addition, the value of the SY-SUBRC variable
is set to 2 or 4 if the content of the compared fields is not the same or if the
SAP system cannot find an entry. However, the SAP system copies the entry
into the target work area whenever it finds an entry, regardless of the result
of the comparison.
Example
REPORT ZREAD_DEMO.
*/Creating an internal table
DATA: BEGIN OF Record1,
ColP TYPE I,
ColQ TYPE I,
END OF Record1.
DATA mytable LIKE HASHED TABLE OF Record1 WITH UNIQUE KEY ColP.
DO 6 Times.
Record1-ColP = SY-INDEX.
Record1-ColQ = SY-INDEX + 5.
INSERT Record1 INTO TABLE mytable.
ENDDO.
Record1-ColP = 4.
Record1-ColQ = 12.
SAP ABAP Tutorial February 23,
2025
SY-SUBRC = 2
4 9
In the above example, mytable is an internal table of the hashed table type,
with Record1 as the work area and ColP as the unique key. Initially, mytable
is populated with six lines, where the ColP field contains the values of the SY-
INDEX variable and the ColQ field contains (SY-INDEX + 5) values.
The Record1 work area is populated with 4 and 12 as values for the ColP and
ColQ fields respectively. The READ statement reads the line of the table after
comparing the value of the ColP key field with the value in the Record1 work
area by using the COMPARING clause, and then copies the content of the
read line in the work area. The value of the SY-SUBRC variable is displayed
as 2 because when the value in the ColP field is 4, the value in the ColQ is
not 12, but 9.
The delete operation is performed on the basis of a default key that could be
taken from the work area components.
You may also specify a table key explicitly in the DELETE TABLE statement
by using the following syntax −
In this syntax, <F1>, <F2>....<Fn> are the fields of an internal table and
<K1>, <K2>....<Kn> are the key fields of the table. The DELETE statement
is used to delete the records or lines of the <internal_table> table based on
the expressions <K1> = <F1>, <K2> = <F2>...<Kn> = <Fn>.
Note − If the data types of the <F1>, <F2>....<Fn> fields are not
compatible with the <K1>, <K2>...<Kn> key fields then the SAP system
automatically converts them into the compatible 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.
2 6
4 8
5 9
6 10
7 11
8 12
In this example, mytable has two fields, ColP and ColQ. Initially, mytable is
populated with eight lines, where the ColP contains the values 1, 2, 3, 4, 5, 6,
7 and 8. The ColQ contains the values 5, 6, 7, 8, 9, 10, 11 and 12 because
the ColP values are incremented by 4 every time.
The DELETE statement is used to delete the lines from mytable where the
value of the ColP key field is either 1 or 3. After deletion, the ColP field of
mytable contains the values 2, 4, 5, 6, 7 and 8, as shown in the output. The
ColQ field contains the values 6, 8, 9, 10, 11 and 12.
Programs are
Modularizatio
Programs can be divided into smaller programs known as functions. objects and th
n
into methods o
Data can be h
Data security Most of the functions share global data.
external sourc
As object orientation begins to take shape, each class assumes specific role
assignments. This division of labor helps to simplify the overall programming
model, allowing each class to specialize in solving a particular piece of the
problem at hand. Such classes have high cohesion and the operations of
each class are closely related in some intuitive way.
Has a state.
Has a unique identity.
May or may not display the behavior.
Each object has a unique identity that can be used to distinguish it from
other objects. Two objects may exhibit the same behavior and they may or
may not have the same state, but they never have the same identity. Two
persons may have the same name, age, and gender but they are not
identical. Similarly, the identity of an object will never change throughout its
lifetime.
Objects can interact with one another by sending messages. Objects contain
data and code to manipulate the data. An object can also be used as a user-
defined data type with the help of a class. Objects are also called variables of
the type class. After defining a class, you can create any number of objects
belonging to that class. Each object is associated with the data of the type
class with which it has been created.
Creating an Object
The object creation usually includes the following steps −
Example
REPORT ZDEMO_OBJECT.
CLASS Class1 Definition.
Public Section.
SAP ABAP Tutorial February 23,
2025
START-OF-SELECTION.
DATA: Class1 TYPE REF TO Class1.
CREATE Object: Class1.
Write:/ Class1->text1.
CALL METHOD: Class1->Display1.
ABAP Objects.
This is the Display method.
ENDCLASS.
A class definition starts with the keyword CLASS followed by the class name,
DEFINITION and the class body. The definition of a class can contain various
components of the class such as attributes, methods, and events. When we
declare a method in the class declaration, the method implementation must
be included in the class implementation. The following syntax shows how to
implement a class −
Attributes
Attributes are data fields of a class that can have any data type such as C, I,
F, and N. They are declared in the class declaration. These attributes can be
divided into 2 categories: instance and static attributes. An instance
attribute defines the instance specific state of an object. The states are
different for different objects. An instance attribute is declared by using the
DATA statement.
Static attributes define a common state of a class that is shared by all the
instances of the class. That is, if you change a static attribute in one object of
a class, the change is visible to all other objects of the class as well. A static
attribute is declared by using the CLASS-DATA statement.
Methods
A method is a function or procedure that represents the behavior of an
object in the class. The methods of the class can access any attribute of the
class. The definition of a method can also contain parameters, so that you
can supply the values to these parameters when methods are called. The
definition of a method is declared in the class declaration and implemented
in the implementation part of a class. The METHOD and ENDMETHOD
statements are used to define the implementation part of a method. The
following syntax shows how to implement a method −
SAP ABAP Tutorial February 23,
2025
METHOD <m_name>.
..........
..........
ENDMETHOD.
Components defined in the public visibility section can be accessed from any
context. By default all the members of a class would be private. Practically,
we define data in private section and related methods in public section so
that they can be called from outside of the class as shown in the following
program.
Example
Report ZAccess1.
CLASS class1 Definition.
PUBLIC Section.
Data: text1 Type char25 Value 'Public Data'.
Methods meth1.
PROTECTED Section.
Data: text2 Type char25 Value 'Protected Data'.
SAP ABAP Tutorial February 23,
2025
PRIVATE Section.
Data: text3 Type char25 Value 'Private Data'.
ENDCLASS.
Start-Of-Selection.
Data: Objectx Type Ref To class1.
Create Object: Objectx.
CALL Method: Objectx→meth1.
Write: / Objectx→text1.
Public Method:
Public Data
Protected Data
Private Data
Public Data
Static Attributes
A Static attribute is declared with the statement CLASS-DATA. All the objects
or instances can use the static attribute of the class. Static attributes are
accessed directly with the help of class name like class_name⇒name_1 =
'Some Text'.
Example
Following is a program where we want to print a text with line number 4 to 8
times. We define a class class1 and in the public section we declare CLASS-
DATA (static attribute) and a method. After implementing the class and
SAP ABAP Tutorial February 23,
2025
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.
Constructors
Constructors are special methods that are called automatically, either while
creating an object or accessing the components of a class. Constructor gets
triggered whenever an object is created, but we need to call a method to
trigger the general method. In the following example, we have declared two
public methods method1 and constructor. Both these methods have different
operations. While creating an object of the class, the constructor method
triggers its operation.
Example
Report ZConstructor1.
CLASS class1 Definition.
PUBLIC Section.
Methods: method1, constructor.
ENDCLASS.
Method constructor.
Write: / 'Constructor Triggered'.
SAP ABAP Tutorial February 23,
2025
EndMethod.
ENDCLASS.
Start-Of-Selection.
Data Object1 Type Ref To class1.
Create Object Object1.
Constructor Triggered
ME Operator in Methods
When you declare a variable of any type in public section of a class, you can
use it in any other implementation. A variable can be declared with an initial
value in public section. We may declare the variable again inside a method
with a different value. When we write the variable inside the method, the
system will print the changed value. To reflect the previous value of the
variable, we have to use ‘ME’ operator.
In this program, we have declared a public variable text1 and initiated with a
value. We have declared the same variable again, but instantiated with
different value. Inside the method, we are writing that variable with ‘ME’
operator to get the previously initiated value. We get the changed value by
declaring directly.
Example
Report ZMEOperator1.
CLASS class1 Definition.
PUBLIC Section.
ENDCLASS.
Start-Of-Selection.
Data objectx Type Ref To class1.
Create Object objectx.
CALL Method objectx→method1.
When creating a class, instead of writing completely new data members and
methods, the programmer can designate that the new class should inherit
the members of an existing class. This existing class is called the base
class or super class, and the new class is referred to as the derived
class or sub class.
Example
Report ZINHERITAN_1.
SAP ABAP Tutorial February 23,
2025
Start-of-selection.
Data: Parent Type Ref To Parent,
Child Type Ref To Child.
Create Object: Parent, Child.
Call Method: Parent→ParentM,
child→ChildM.
When deriving a class from a super class, it can be inherited through public,
protected or private inheritance. The type of inheritance is specified by the
access specifier as explained above. We hardly use protected or private
inheritance, but public inheritance is commonly used. The following rules are
applied while using different types of inheritance.
Example
SAP ABAP Tutorial February 23,
2025
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 executing F8, if we enter the values 9 and 10, the above code produces
the following output −
SAP ABAP Tutorial February 23,
2025
Redefinition Demo
29
Example
Report ZPolymorphism1.
CLASS class_prgm Definition Abstract.
PUBLIC Section.
Methods: prgm_type Abstract,
approach1 Abstract.
ENDCLASS.
PUBLIC Section.
Methods: prgm_type Redefinition,
approach1 Redefinition.
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.
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.
ABAP supports the properties of encapsulation and data hiding through the
creation of user-defined types called classes. As discussed earlier, a class
can contain private, protected and public members. By default, all items
defined in a class are private.
Encapsulation by Interface
Encapsulation actually means one attribute and method could be modified in
different classes. Hence data and method can have different form and logic
that can be hidden to separate class.
Example
The following program contains an Interface inter_1. We have declared
attribute and a method method1. We have also defined two classes like
Class1 and Class2. So we have to implement the method ‘method1’ in both
of the class implementations. We have implemented the method ‘method1’
differently in different classes. In the start-ofselection, we create two objects
Object1 and Object2 for two classes. Then, we call the method by different
objects to get the function declared in separate classes.
Report ZEncap1.
Interface inter_1.
Data text1 Type char35.
Methods method1.
EndInterface.
Start-Of-Selection.
Data: Object1 Type Ref To Class1,
Object2 Type Ref To Class2.
Designing Strategy
Most of us have learned through bitter experience to make class members
private by default unless we really need to expose them. That is just good
SAP ABAP Tutorial February 23,
2025
Interfaces are used when two similar classes have a method with the same
name, but the functionalities are different from each other. Interfaces might
appear similar to classes, but the functions defined in an interface are
implemented in a class to extend the scope of that class. Interfaces along
with the inheritance feature provide a base for polymorphism. This is
because a method defined in an interface can behave differently in different
classes.
INTERFACE <intf_name>.
DATA.....
CLASS-DATA.....
METHODS.....
CLASS-METHODS.....
ENDINTERFACE.
Note − All the methods of an interface are abstract. They are fully declared
including their parameter interface, but not implemented in the interface. All
the classes that want to use an interface must implement all the methods of
the interface. Otherwise, the class becomes an abstract class.
SAP ABAP Tutorial February 23,
2025
INTERFACE <intf_name>.
METHOD <intf_name~method_m>.
<statements>.
ENDMETHOD.
Example
Report ZINTERFACE1.
INTERFACE my_interface1.
Methods msg.
ENDINTERFACE.
Method add_number.
ADD 7 TO num.
EndMethod.
ENDCLASS.
PUBLIC Section.
INTERFACES my_interface1.
Methods speed1.
PRIVATE Section.
Data wheel1 Type I.
ENDCLASS.
Method speed1.
Add 4 To wheel1.
EndMethod.
ENDCLASS.
Start-Of-Selection.
Data object1 Type Ref To num_counter.
Create Object object1.
The number is 7
Total number of wheels is 4
Note − The add_number and speed1 methods are specific to the respective
classes.
SAP ABAP Tutorial February 23,
2025
An event of a class can trigger an event handler method of the same class by
using the RAISE EVENT statement. For an event, the event handler method
can be defined in the same or different class by using the FOR EVENT clause,
as shown in the following syntax −
Similar to the methods of a class, an event can have parameter interface but
it has only output parameters. The output parameters are passed to the
event handler method by the RAISE EVENT statement that receives them as
input parameters. An event is linked to its handler method dynamically in a
program by using the SET HANDLER statement.
Example
REPORT ZEVENT1.
CLASS CL_main DEFINITION.
PUBLIC SECTION.
DATA: num1 TYPE I.
METHODS: PRO IMPORTING num2 TYPE I.
EVENTS: CUTOFF.
ENDCLASS.
START-OF-SELECTION.
DATA: main1 TYPE REF TO CL_main.
DATA: eventhandler1 TYPE REF TO CL_eventhandler.
A classical report is created by using the output data in the WRITE statement
inside a loop. They do not contain any sub-reports. SAP also provides some
standard reports such as RSCLTCOP that is used to copy tables across clients
and RSPARAM that is used to display instance parameters.
These reports consist of only one screen as an output. We can use various
events such as INITIALIZATON & TOP-OF-PAGE to create a classical report,
SAP ABAP Tutorial February 23,
2025
and each event has its own importance during the creation of a classical
report. Each of these events is associated to a specific user action and is
triggered only when the user performs that action.
S.N
Event & Description
o.
INITIALIZATON
1
Triggered before displaying the selection screen.
AT SELECTION-SCREEN
2 Triggered after processing of the user input on the selection screen. This event verifies the user input pr
program. After processing the user input, the selection screen remains in the active mode.
START-OF-SELECTION
3 Triggered only after the processing of the selection screen is over; that is, when the user clicks the Exec
screen.
END-OF-SELECTION
4
Triggered after the last statement in the START-OF-SELECTON event is executed.
TOP-OF-PAGE
5
Triggered by the first WRITE statement to display the data on a new page.
END-OF-PAGE
6 Triggered to display the text at the end of a page in a report. Note, that this event is the last event while
combined with the LINE-COUNT clause of the REPORT statement.
Example
Let's create a classical report. We will display the information stored in the
standard database MARA (contains general material data) by using a
sequence of statements in ABAP editor.
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.
SAP ABAP Tutorial February 23,
2025
ULINE.
WRITE:/ 'CLASSICAL REPORT HAS BEEN CREATED' COLOR 7.
ULINE.
SKIP.
The above code produces the following output containing the general
material data from the standard table MARA −
Screens
Module pools
Subroutines
Menus
Transactions
The Toolset
Screens are made up of screen attributes, screen layout, fields and flow
logic. The module pool consists of modularized syntax that is placed inside
include programs of the dialog program. These modules can be invoked by
the flow logic, which is processed by the dialog processor.
Step 2 − Press Enter, choose ‘With TOP INCL’ and click the ‘Yes’ button.
Step 3 − Enter a name for your top include as ‘ZSCRTOP’ and click the
green tick mark.
Step 4 − Within the attributes screen, simply enter a title and click the save
button.
Step 2 − Enter a screen number as '0211' and click the green tick mark.
SAP ABAP Tutorial February 23,
2025
Step 3 − In the next screen, enter a short title, set to normal screen type
and click the save button on the top application toolbar.
Step 2 − Add a Text Field and enter some text such as "Hello World".
SAP ABAP Tutorial February 23,
2025
Creating Transaction
Step 1 − To create a transaction code for your program, simply right click
on the program name and choose the option Create → Transaction and enter
a transaction code as 'ZTRANEX'.
SAP ABAP Tutorial February 23,
2025
Step 2 − Enter the transaction text, program and screen you have just
created (ZSCREENEX & 0211), and tick the ‘SAPGUI for Windows’ checkbox
in the ‘GUI support’ section.
The tool allows you to modify forms by using simple graphical tools instead
of using any programming tool. It means that a user with no programming
knowledge can configure these forms with data for a business process
effortlessly.
In a Smart Form, data is retrieved from static and dynamic tables. The table
heading and subtotal are specified by the triggered events and the data is
then sorted before the final output. A Smart Form allows you to incorporate
graphics that can be displayed either as part of the form or as the
background. You can also suppress a background graphic if required while
taking a printout of a form.
Creating a Form
Let’s create a form by using the SAP Smart Forms tool. You will also learn
how to add a node in the Smart Form and test the form in this tutorial. Here
we begin with creating a copy of the SF_EXAMPLE_01 form. The
SF_EXAMPLE_01 form is a standard Smart Form available in the SAP system.
Step 1 − Smart Form Builder is the main interface used to build a Smart
Form. It is available on the initial screen of SAP Smart Forms. We need to
type the 'SMARTFORMS' transaction code in the Command field to open the
initial screen of SAP Smart Forms. In this screen, enter the form name,
SF_EXAMPLE_01, in the Form field.
Step 2 − Select Smart Forms → Copy or click the Copy icon to open the
Copy Form or Text dialog box.
Step 3 − In the Target Object field, enter a name for the new form. The
name must begin with the Y or Z letter. In this case, the name of the form is
'ZSMM1'.
SAP ABAP Tutorial February 23,
2025
Step 4 − Click the Continue icon or press the ENTER key in the Copy Form or
Text dialog box so that the ZSMM1 form is created as a copy of the
predefined form SF_EXAMPLE_01.
Step 5 − Click the Save icon. The name of the form is displayed in the Form
field on the initial screen of SAP Smart Forms.
Step 6 − Click the Create button on the initial screen of SAP Smart Forms.
The ZSMM1 form appears in Form Builder.
SAP ABAP Tutorial February 23,
2025
Step 7 − The first draft page is created with a MAIN window. All the
components of the new form are based on the SF_EXAMPLE_01 predefined
form. You can just click a node in the Navigation menu to view its content.
Step 2 − Modify the text in the Text field to 'My_Text' and the text in the
Meaning field to 'Text_Demo'. Enter the text 'Hello TutorialsPoint.....' in the
text-editing box in the center frame of Form Builder as shown in the
following snapshot −
SAP ABAP Tutorial February 23,
2025
Step 4 − Activate and test the node by clicking the Activate and Test icons,
respectively. The initial screen of Function Builder appears.
Step 5 − Activate and test the function module by clicking the Activate and
Execute icons. The parameters of the function module are displayed in the
initial screen of Function Builder.
Step 6 − Execute the function module by clicking the Execute icon. The
Print dialog box appears.
SAP ABAP Tutorial February 23,
2025
Step 7 − Specify the output device as 'LP01' and click the Print preview
button.
The SAP system comes with standard SAPscript forms that are delivered with
the SAP standard client (generally as client 000). Following are a few
examples of standard SAPscript forms delivered with client 000 −
SAP ABAP Tutorial February 23,
2025
RVORDER01
1
Sales Order Confirmation Form
RVDELNOTE
2
Packing List
RVINVOICE01
3
Invoice
MEDRUCK
4
Purchase Order
F110_PRENUM_CHCK
5
Prenumbered Check
Step 1 − Open the Form Painter. You may request the screen either by
navigating the SAP menu or by using the SE71 transaction code.
Step 2 − In the Form Painter, request screen, enter a name and language
for a SAPscript form in the Form and Language fields, respectively. Let’s
enter 'RVINVOICE01' and 'EN' respectively in these fields.
SAP ABAP Tutorial February 23,
2025
Step 3 − Select the Page Layout radio button in the Sub objects group box.
Step 5 − In the 'Copy Forms Between Clients' screen, enter the original
name of the form, 'RVINVOICE01', in the Form Name field, the number of the
source client '000' in the Source Client field, and the name of the target form
as 'ZINV_01' in the Target Form field. Make sure that other settings remain
unchanged.
SAP ABAP Tutorial February 23,
2025
Step 6 − Next, click the Execute icon in the 'Copy Forms Between Clients'
screen. The 'Create Object Directory Entry' dialog box appears. Click the
Save icon.
The ZINV_01 form is copied from the RVINVOICE01 form and displayed in the
'Copy Forms Between Clients screen' as depicted in the following snapshot −
SAP ABAP Tutorial February 23,
2025
Step 7 − Click the back icon twice and navigate back to the Form Painter:
Request screen, which contains the name of the copied form ZINV_01.
Step 8 − After clicking the Display button, the 'Form ZINV_01: Layout of
Page FIRST' window and the 'Form: Change Page Layout: ZINV_01' screen
appears as shown in the following screenshot.
SAP ABAP Tutorial February 23,
2025
Step 9 − The 'Form ZINV_01: Layout of Page FIRST' window shows the initial
layout of the form. The layout of the form contains five windows: HEADER,
ADDRESS, INFO, INFO1, and MAIN. The description of these windows can be
accessed in PC Editor.
For instance, by just selecting the MAIN window and clicking the Text icon in
the 'Form: Change Page Layout: ZINV_01' screen, you can view all the
margin values as shown in the following screenshot −
SAP ABAP Tutorial February 23,
2025
Step 2 − Get the program name from the popup screen. The program name
is 'SAPLMGMM'.
Step 3 − Go to transaction SE38, enter the program name and click Display.
Step 6 − After going to the ‘Find Exits’ screen, enter the package name we
got earlier and press F8 (Execute) button.
SAP ABAP Tutorial February 23,
2025
The above steps produce the following output with the list of exits available
in the Material Master Creation.
make some changes when standard SAP is not capable of fulfilling all the
requirements.
To be able to access what exits are available in each area of sales, go to IMG
using this path: IMG → Sales and Distribution → System Modifications → User
Exits. The documentation for each exit in the areas of SD is explained
thoroughly.
For instance, if you want to find user exits in Sales Document Processing
(contract, quotation or sales order), follow the path mentioned above and
continue to expand the node User Exits in Sales → User Exits. Click on icon
documentation to see all user exits available in Sales Document Processing.
S.No
User Exit & Description
.
USEREXIT_FIELD_MODIFICATION
1
Used to modify screen attributes.
USEREXIT_SAVE_DOCUMENT
2
Helps in performing operations when the user hits Save.
USEREXIT_SAVE_DOCUMENT_PREPARE
3
Very useful to check input fields, put any value in the field or show a popup to users and to confirm th
USEREXIT_MOVE_FIELD_TO_VBAK
4
Used when user header changes are moved to header work area.
USEREXIT_MOVE_FIELD_TO_VBAP
5
Used when user item changes are moved to SAP item work area.
A User Exit serves the same purpose as Customer Exits but they are
available only for the SD module. The exit is implemented as a call to a
Function Module. User Exits are modifications to SAP standard programs.
Example
REPORT ZUSEREXIT1.
TABLES:
TSTC, TSTCT,
TADIR, TRDIR, TFDIR, ENLFDIR,
MODSAPT, MODACT.
SAP ABAP Tutorial February 23,
2025
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
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.
SAP ABAP Tutorial February 23,
2025
SELECT *
FROM TADIR
INTO TABLE JTAB
SELECT SINGLE *
FROM TSTCT
WHERE sprsl EQ SY-LANGU AND
tcode EQ P_TCODE.
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.
WRITE:/(95) SY-ULINE.
DESCRIBE TABLE JTAB.
SAP ABAP Tutorial February 23,
2025
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.
While processing, enter the transaction code ‘ME01’ and press F8 (Execute)
button. The above code produces the following output −
SAP ABAP Tutorial February 23,
2025
You can also create filter BADIs, which means BADIs are defined on the basis
of filtered data that is not possible with enhancement techniques. The
concept of BADIs has been redefined in SAP Release 7.0 with the following
goals −
Advantages
SAP ABAP Tutorial February 23,
2025