Sap Abap Quick Guide
Sap Abap Quick Guide
Sap Abap Quick Guide
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.
Note ABAP programs run at the application server level. Technical distribution of software is independent of its physical location. It
means basically all three levels can be installed on top of each other on one computer or each level can be installed on a different computer
or a server.
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.
The run-time system can be considered as a virtual machine, just similar to Java virtual machine. A key component of the ABAP run-time
system is the database interface that turns database independent statements (Open SQL) into the statements understood by the
underlying database (Native SQL). SAP can work with a wide variety of databases and the same ABAP program can run on all of those.
Reports are a good starting point for familiarizing yourself with general ABAP principles and tools. ABAP reports are used in many areas. In
this chapter, we will see how easy it is to write a simple ABAP Report.
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.
The customer namespace includes all objects with the prefix Y or Z. It is always used when customers or partners create objects (like a
report) to differentiate these objects from objects of SAP and to prevent name conflicts with objects.
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
As long as you do not activate a new report or activate a change to an existing report, it is not relevant to their users. This is important in a
central development environment where you may work on objects that other developers use in their projects.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 2/93
9/18/2017 SAP ABAP Quick Guide
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.
Toolbar Icon
Following is the SAP screen toolbar.
Standard Toolbar Most standard functions such as Top of Page, End of Page, Page Up, Page Down and Save are available in this
toolbar.
Title Bar Title Bar displays the name of the application/business process you are currently in.
Command Field We can start an application without navigating through the menu transactions and some logical codes are assigned to
business processes. Transaction codes are entered in the command field to directly start the application.
ABAP Editor
You may just start the transaction SE38 (enter SE38 in Command Field) to navigate to the ABAP Editor.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 3/93
9/18/2017 SAP ABAP Quick Guide
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 4/93
9/18/2017 SAP ABAP Quick Guide
Log Off
Its always a good practice to Exit from your ABAP Editor or/and logoff from the SAP system after finishing your work.
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
REPORT [Program_Name].
[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.
Statements consist of a command and any variables and options, ending with a period. As long as the period appears at the end of the
statement, no problems will arise. It is this period that marks where the statement finishes.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 5/93
9/18/2017 SAP ABAP Quick Guide
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 doesnt 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 system to be a comment. Comments dont need to be terminated by a period because they may not extend across more
than one line
Partial line comments are indicated by entering a double quote (") after a statement. All text following the double quote is
considered by the system to be a comment. You need not terminate partial line comments by a period because they may not
extend across more than one line
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 6/93
9/18/2017 SAP ABAP Quick Guide
Blank Lines
The SKIP command helps in inserting blank lines on the page.
Example
The message command is as follows
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. Its 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
The message appears and the application halts at its current point. If the program is running in background mode, the
E Error
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 background mode, the message is
W Warning
recorded in the job log.
A pop-up window opens with the message text and the user must press Enter to continue. In background mode, the
I Information
message is recorded in the job log.
A Abend This message class cancels the transaction that the user is currently using.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 7/93
9/18/2017 SAP ABAP Quick Guide
S Success This provides an informational message at the bottom of the screen. The information displayed is positive in nature and it
is just meant for user feedback. The message does not impede the program in any way.
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
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.
C 1 character 1 to 65535
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 8/93
9/18/2017 SAP ABAP Quick Guide
Example
REPORT YR_SEP_12.
DATA text_line TYPE C LENGTH 40.
text_line = 'A Chapter on Data Types'.
Write text_line.
In this example, we have a character string of type C with a predefined length 40. STRING is a data type that can be used for any character
string of 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.
2 Key
Specifies a field or a group of fields as a key of an internal table that identifies the table rows. A key contains the fields of
elementary types.
3 Access method
Reference types are used to refer to instances of classes, interfaces, and run-time data items. The ABAP OOP run-time type services (RTTS)
enables declaration of data items at run-time.
You must declare all variables before they can be used. The basic form of a variable declaration is
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 9/93
9/18/2017 SAP ABAP Quick Guide
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.
In the above code snippet, d1 is a variable of C type, d2 is a variable of d1 type, and minimum_value is a variable of ABAP integer type I.
This chapter will explain various variable types available in ABAP. There are three kinds of variables in ABAP
Static Variables
Reference Variables
System Variables
Static Variables
Static variables are declared in subroutines, function modules, and static methods.
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 variable cant 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.
This program shows how to declare a variable using 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 specifies a parameter of integer type with the default size in bytes, SCORE
represents a packed type parameter with values up to two decimal places, and CONNECT refers to the MARA-MATNF type of ABAP
Dictionary.
Reference Variables
The syntax for declaring reference variables is
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 10/93
9/18/2017 SAP ABAP Quick Guide
The specification after REF TO specifies the static type of the reference variable.
The static type restricts the set of objects to which <ref> can refer.
The dynamic type of reference variable is the data type or class to which it currently refers.
The static type is always more general or the same as the dynamic type.
The TYPE addition is used to create a bound reference type and as a start value, and only IS INITIAL can be specified after the
VALUE addition.
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.
System Variables
ABAP system variables are accessible from all ABAP programs.
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
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.
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.
We have 3 types of constants such as elementary, complex and reference constants. The following statement shows how to define
constants by using 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 is
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 12/93
9/18/2017 SAP ABAP Quick Guide
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 snippet, EMPLOYEE is a complex constant that is composed of the Name, Organization and Place fields.
Arithmetic Operators
Comparison Operators
Bitwise Operators
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.
1 + (Addition)
Adds values on either side of the operator. Example: A + B will give 60.
2 (Subtraction)
Subtracts right hand operand from left hand operand. Example: A B will give -20.
3 * (Multiplication)
Multiplies values on either side of the operator. Example: A * B will give 800.
4 / (Division)
Divides left hand operand by right hand operand. Example: B / A will give 2.
5 MOD (Modulus)
Divides left hand operand by right hand operand and returns the remainder. Example: B MOD A will give 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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 13/93
9/18/2017 SAP ABAP Quick Guide
Comparison Operators
Lets discuss the various types of comparison operators for different operands.
Checks if the values of two operands are equal or not, if yes then condition becomes true. Example (A = B) is not true.
Checks if the values of two operands are equal or not. If the values are not equal then the condition becomes true. Example (A
<> B) is true.
Checks if the value of left operand is greater than the value of right operand. If yes then condition becomes true. Example (A >
B) is not true.
Checks if the value of left operand is less than the value of right operand. If yes, then condition becomes true. Example (A < B)
is true.
Checks if the value of left operand is greater than or equal to the value of right Operand. If yes, then condition becomes true.
Example (A >= B) is not true.
Checks if the value of left operand is less than or equal to the value of right operand. If yes, then condition becomes true.
Example (A <= B) is true.
Checks whether a1 lies in between a2 and a3 (inclusive). If yes, then the condition becomes true. Example (A BETWEEN B AND
C) is true.
8 IS INITIAL
The condition becomes true if the contents of the variable have not changed and it has been automatically assigned its initial
value. Example (A IS INITIAL) is not true
9 IS NOT INITIAL
The condition becomes true if the contents of the variable have changed. Example (A IS NOT INITIAL) is true.
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.
If one field is of type D, then the other is converted to type D. But C and N types are not converted and they are compared directly.
Similar is the case with type T.
If one field is of type N and the other is of type C or X, both the fields are converted to type P.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 14/93
9/18/2017 SAP ABAP Quick Guide
If one field is of type C and the other is of type X, the X type is converted to type C.
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.
1 BIT-NOT
Unary operator that flips all the bits in a hexadecimal number to the opposite value. For instance, applying this operator to a
hexadecimal number having the bit level value 10101010 (e.g. 'AA') would give 01010101.
2 BIT-AND
This binary operator compares each field bit by bit using the Boolean AND operator.
3 BIT-XOR
Binary operator that compares each field bit by bit using the Boolean XOR (exclusive OR) operator.
4 BIT-OR
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
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 15/93
9/18/2017 SAP ABAP Quick Guide
S.No. Character String Operator & Description
1 CO (Contains Only)
3 CA (Contains ANY)
5 CS (Contains a String)
7 CP (Contains a Pattern)
Example
REPORT YS_SEP_08.
DATA: P(10) TYPE C VALUE 'APPLE',
Q(10) TYPE C VALUE 'CHAIR'.
IF P CA Q.
Programming languages provide various control structures that allow for more complicated execution paths. A loop statement allows us to
execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the
programming languages.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 16/93
9/18/2017 SAP ABAP Quick Guide
ABAP programming language provides the following types of loop to handle looping requirements.
1 WHILE loop
Repeats a statement or group of statements when a given condition is true. It tests the condition before executing the loop body.
2 Do loop
The DO statement is useful for repeating particular task a specific number of times.
3 Nested loop
You may use one or more loops inside any another WHILE or DO loop.
1 CONTINUE
Causes the loop to skip the remainder of its body and starts the next loop pass.
2 CHECK
If the condition is false, then the remaining statements after the CHECK are just ignored and the system starts the next loop
pass.
3 EXIT
Terminates the loop entirely and transfers execution to the statement immediately following the loop.
Following is the general form of a typical decision-making structure found in most of the programming languages
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 17/93
9/18/2017 SAP ABAP Quick Guide
1 IF Statement
An IF statement consists of a logical expression followed by one or more statements.
3 Nested IF Statement
You may use one IF or ELSEIF statement inside another IF or ELSEIF statement.
We use data type C variables for holding alphanumeric characters, with a minimum of 1 character and a maximum of 65,535 characters. By
default, these are aligned to the left.
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
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 18/93
9/18/2017 SAP ABAP Quick Guide
length_1 = STRLEN( title_1 ).
Write: / 'The Length of the Title is:', length_1.
1 CONCATENATE
2 CONDENSE
3 STRLEN
4 REPLACE
5 SEARCH
6 SHIFT
7 SPLIT
The following example makes use of some of the above mentioned 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).
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 19/93
9/18/2017 SAP ABAP Quick Guide
The CONDENSE statement removes blank spaces between the fields, but leaving only 1 characters space.
NO-GAPS is an optional addition to the CONDENSE statement that removes all spaces.
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.
1 D
A built-in fixed-length date type of the form YYYYMMDD. For example, the value 20100913 represents the date September 13,
2010.
2 T
A built-in fixed-length time type of the form HHMMSS. For example, the value 102305 represents time 10:23:05 AM.
This type is used to represent short timestamps in YYYYMMDDhhmmss form. For instance, the value 20100913102305 represents
the date September 13, 2010 at 10:23:05 AM.
TIMESTAMPL represents long timestamps in YYYYMMDDhhmmss,mmmuuun form. Here the additional digits mmmuuun
represent the fractions of a second.
REPORT YR_SEP_15.
DATA: date_1 TYPE D.
date_1 = SY-DATUM.
Write: / 'Present Date is:', date_1 DD/MM/YYYY.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 20/93
9/18/2017 SAP ABAP Quick Guide
date_1 = date_1 + 06.
Write: / 'Date after 6 Days 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 were 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.
Time calculations work similar to date calculations. The following code increments the current system time by 75 seconds using basic time
arithmetic.
REPORT YR_SEP_15.
DATA: time_1 TYPE T.
time_1 = SY-UZEIT.
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 users preferences.
The WRITE statement is a formatting statement used to display data on a screen. There are different formatting options for the WRITE
statement. The syntax of the WRITE statement is
In this syntax, <format> represents the output format specification, which can be a forward slash (/) that indicates the display of the
output starting from a new line. In addition to the forward slash, the format specification includes a column number and column length. For
example, the WRITE/04 (6) statement shows that a new line begins with column 4 and the column length is 6, whereas the WRITE 20
statement shows the current line with column 20. The parameter <f> represents a data variable or numbered text.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 21/93
9/18/2017 SAP ABAP Quick Guide
S.No. Clause & Description
1 LEFT-JUSTIFIED
2 CENTERED
3 RIGHT-JUSTIFIED
4 UNDER <g>
5 NO-GAP
Denotes the specification of the format template <m>. Using No EDIT Mask: This specifies that the format template specified in
the ABAP Dictionary is deactivated.
7 NO-ZERO
1 NO-SIGN
2 EXPONENT <e>
Specifies that in type F (the floating point fields), the exponent is defined in <e>.
3 ROUND <r>
The type P fields (packed numeric data types) are first multiplied by 10**(-r) and then rounded off to an integer value.
4 CURRENCY <c>
Denotes that the formatting is done according to the currency <c> value that is stored in the TCURX database table.
5 UNIT <u>
Specifies that the number of decimal places is fixed according to the <u> unit as specified in the T006 database table for type P.
6 DECIMALS <d>
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 22/93
9/18/2017 SAP ABAP Quick Guide
Formatting Option Example
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
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.
Lets 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
Exceptions provide a way to transfer control from one part of a program to another. ABAP exception handling is built upon three keywords
RAISE, TRY, CATCH and CLEANUP. Assuming a block will raise an exception, a method catches an exception using a combination of the
TRY and CATCH keywords. 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.
RAISE Exceptions are raised to indicate that some exceptional situation has occurred. Usually, an exception handler tries to repair the
error or find an alternative solution.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 23/93
9/18/2017 SAP ABAP Quick Guide
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.
CATCH A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The
CATCH keyword indicates the catching of an exception.
CLEANUP The statements of the CLEANUP block are executed whenever an exception occurs in a TRY block that is not caught by the
handler of the same TRY - ENDTRY construct. Within the CLEANUP clause, the system can restore an object to a consistent state or release
external resources. That is, cleanup work can be executed for the context of the TRY block.
Raising Exceptions
Exceptions can be raised at any point in a method, a function module, a subroutine, and so on. There are two ways an exception can be
raised
For instance Y = 1 / 0. This will result in a run time error of type CX_SY_ZERODIVIDE.
Raise and create an exception object simultaneously. Raise an exception with an exception object that already exists in the first
scenario. The syntax is: RAISE EXCEPTION exep.
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.
Divide by zero exception. Handlers catch CX_SY_CONVERSION_NO_NUMBER exception and also the CX_SY_ZERODIVIDE
exception. Here the GET_TEXT( ) method of the exception class is used to get the description of the exception.
Attributes of Exceptions
Here are the five attributes and methods of exceptions
1 Textid
Used to define different texts for exceptions and also affects the result of the method get_text.
2 Previous
This attribute can store the original exception that allows you to build a chain of exceptions.
3 get_text
This returns the textual representation as a string as per the system language of the exception.
4 get_longtext
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 24/93
9/18/2017 SAP ABAP Quick Guide
This returns the long variant of the textual representation of the exception as a string.
5 get_source_position
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.
In this example, if the number is greater than 150, the exception CX_DEMO_ABS_TOO_LARGE is raised. The above code produces the
following output for the number 160.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 25/93
9/18/2017 SAP ABAP Quick Guide
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.
Data elements describe an elementary type by defining the data type, length and possibly decimal places.
Various objects in the Dictionary environment can be referenced in ABAP programs. The Dictionary is known as the global area. The objects
in the Dictionary are global to all ABAP programs and the data in ABAP programs can be declared by reference to these Dictionary global
objects.
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 26/93
9/18/2017 SAP ABAP Quick Guide
Example
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 type of component Address is defined by a structure whose components are also structures, and the Telephone component is defined
by a table type because a customer can have more than one telephone number. Types are used in ABAP programs and also to define the
types of interface parameters of function modules.
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. Lets 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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 27/93
9/18/2017 SAP ABAP Quick Guide
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.
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 28/93
9/18/2017 SAP ABAP Quick Guide
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 29/93
9/18/2017 SAP ABAP Quick Guide
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
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 30/93
9/18/2017 SAP ABAP Quick Guide
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.
If error messages or warnings occurred when you activated the data element, 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.
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.
1 Field name
This is the name given to a field that can contain a maximum of 16 characters. The field name may be composed of digits,
letters, and underscores. It must begin with a letter.
2 Key flag
3 Field type
4 Field length
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 31/93
9/18/2017 SAP ABAP Quick Guide
5 Decimal places
Defines the number of digits permissible after the decimal point. This element is used only for numeric data types.
6 Short text
Step 3 Click the Search Help icon beside the Delivery Class field. Select A [Application table (master and transaction data)] option.
Step 4 Select the Display/Maintenance Allowed option from the Data Browser/Table view Maintenance drop-down menu. The
Dictionary: Maintenance Table screen appears.
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.
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. Lets 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.
Step 10 As the Data Element ZCUSTNUM doesnt yet exist, it has to be created. Doubleclick the new Data Element and the Create Data
Element window appears. Answer Yes to this and a Maintain Data Element window appears.
Step 11 Enter Customer Number in the Short Description area. The Elementary data type called Domain should be defined for the new
Data element. So enter ZCUSTD1, double-click it and agree to save the changes made. Choose Yes to create the domain and type into
the Short Description box a description of the domain.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 32/93
9/18/2017 SAP ABAP Quick Guide
The Definition tab opens automatically. The first field is Data Type.
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
fields description must re-appear, confirming that this is a valid entry.
Step 14 Press F3 to return to the Maintain/Change Data Element screen. Create four Field labels as shown in the following snapshot.
After this, Save and Activate the element.
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.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 33/93
9/18/2017 SAP ABAP Quick Guide
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.
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).
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 34/93
9/18/2017 SAP ABAP Quick Guide
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.
Step 7 As this 'ZSTR_CUSTOMER1' is highlighted, click the green tick button. This window disappears and the status bar will display the
message Active.
Data related to an application object is distributed among multiple tables by using database views. They use the inner join condition to join
the data of different tables. A maintenance view is used to display and modify the data stored in an application object. Every maintenance
view has a maintenance status associated with it.
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.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 35/93
9/18/2017 SAP ABAP Quick Guide
Step 4 Click the Table fields button to include the fields of ZCUSTOMERS1 table in the projection view.
Step 5 The Field Selection from Table ZCUSTOMERS1 screen appears. Select the fields that you wish to include in the projection view 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 7 Select Maintenance Status tab to define an access method. Choose read-only radio button and Display/Maintenance Allowed with
Restrictions option from the dropdown menu of Data Browser/Table View Maintenance.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 36/93
9/18/2017 SAP ABAP Quick Guide
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 3 In the selection method, we need to indicate whether our source of data is a table or a view. In our case it happens to be a table.
The table is ZCUSTOMERS1. It is selected from a selection list.
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.
Import This field is a checkbox for indicating whether a Search help parameter is an import parameter. The export or import is
with reference to the search help.
Export This field is a checkbox for indicating whether a Search help parameter is an export parameter. The export will be
transfer of field values from the selection list to screen fields.
LPos Its value controls the physical position of Search help parameter or field in the selection list. If you enter a value 1, the field
will appear in the first position in the selection list and so on.
SPos It controls the physical position of Search Help parameter or field in the restrictive dialog box. If you enter a value of 1, the
field will appear in the first position in the restrictive dialog box and so on.
Data element Every Search Help parameter or field by default is assigned a data element that was assigned to it in the source
of data (Table or View). This data element name appears in display mode.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 37/93
9/18/2017 SAP ABAP Quick Guide
Step 7 Let's enter the number 100004 in the CUSTOMER's 'Ready for inp' screen field. Press Enter.
Lock Mechanism
Following are the two main functions accomplished with the lock mechanism
A program can communicate with other programs about data records that it is just reading or changing.
A program can prevent itself from reading data that has just been changed by another program.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 38/93
9/18/2017 SAP ABAP Quick Guide
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.
Step 6 Save and activate. Automatically 2 function modules will generate. To check function modules, we can use Go to Lock Modules.
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.
distractions.
In SAP ABAP environment, modularization involves the organization of programs into modular units, also known as logical blocks. It
reduces redundancy and increases program readability even as you are creating it and subsequently during the maintenance cycle.
Modularization also enables reusability of the same code again. ABAP has made it necessary for developers to modularize, i.e. organizing
the programs relatively more, than in the OOPS-based languages that have relatively more built-in modular features. Once a small,
modularized section of code is complete, debugged and so on, it does not subsequently have to be returned to, and developers can then
move on and focus on other issues.
ABAP programs are made up of processing blocks known as modularizing processing blocks. They are
The processing blocks called from outside the program and from the ABAP run-time environment (i.e., event blocks and dialog
modules).
Apart from the modularization with processing blocks, source code modules are used to modularize your source code through macros and
include programs.
Local Macros
Subroutines
Function modules
Modularizing a source code means placing a sequence of ABAP statements in a module. The modularized source code can be called in a
program as per the requirement of the user. Source code modules enhance the readability and understandability of ABAP programs.
Creating individual source code modules also prevents one from having to repeatedly write the same statements again and again that in
turn makes the code easier to understand for anyone going through it for the first time.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 40/93
9/18/2017 SAP ABAP Quick Guide
FORM <subroutine_name>.
<statements>
ENDFORM.
We can call a subroutine by using PERFORM statement. The control jumps to the first executable statement in the subroutine
<subroutine_name>. When ENDFORM is encountered, control jumps back to the statement following the PERFORM statement.
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.
Step 3 Write the code in FORM and ENDFORM statement block. The subroutine has been created successfully.
We need to include PERFORM statement to call the subroutine. Lets 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, activate and execute the program. The above code produces the following output
Subroutine Test:
This is Subroutine
Hence, using subroutines makes your program more function-oriented. It splits the program's task into sub-functions, so that each
subroutine is responsible for one subfunction. Your program becomes easier to maintain as changes to functions often only have to be
implemented in the subroutine.
Macros are designed based on placeholders. Placeholder works like pointers in C language. You can define a macro within the
DEFINE...END-OF-DEFINITION statement.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 41/93
9/18/2017 SAP ABAP Quick Guide
It is necessary to define a macro first before invoking it. The <param1>. replaces the placeholders &1...in the ABAP statements contained
in the macro definition.
The maximum number of placeholders in a macro definition is nine. That is, when a program is executed, the SAP system replaces the
macro by appropriate statements and the placeholders &1, &2,.&9 are replaced by the parameters param1, param2,....param9. We may
invoke a macro within another macro, but not the same macro.
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.
We have 3 checkboxes. While executing the program, lets select the S2 checkbox.
A Macro Program
This is Macro 2
If all checkboxes are selected, the code produces the following output
A Macro Program
Function modules are sub-programs that contain a set of reusable statements with importing and exporting parameters. Unlike Include
programs, function modules can be executed independently. SAP system contains several predefined function modules that can be called
from any ABAP program. The function group acts as a kind of container for a number of function modules that would logically belong
together. For instance, the function modules for an HR payroll system would be put together into a function group.
To look at how to create function modules, the function builder must be explored. You can find the function builder with transaction code
SE37. Just type a part of a function module name with a wild card character to demonstrate the way function modules can be searched for.
Type *amount* and then press the F4 key.
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 consider the function module
SPELL_AMOUNT. This function module converts numeric figures into words.
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.
Step 4 Some code is generated automatically. But we need to enhance the IF statement to include a code to WRITE a message to the
screen to say "The function module returned a value of: sy-subrc and add the ELSE statement so as to write the correct result out when
the function module is successful. Here, a new variable must be set up to hold the value returned from the function module. Let's call this
as 'result'.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 43/93
9/18/2017 SAP ABAP Quick Guide
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 5 The variable which the function module returns is called IN_WORDS. Set up the corresponding variable in the program called
result. Define IN_WORDS by using the LIKE statement to refer to a structure called SPELL.
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 cant 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
Step 1 Create the program (Z_TOBEINCLUDED) to be included in ABAP Editor. Code to be included in ABAP Editor is
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 44/93
9/18/2017 SAP ABAP Quick Guide
Step 3 Click the Save button and save the program in a package named ZINCL_PCKG.
Step 4 Create another program where the program Z_TOBEINCLUDED has to be used. Here we have created another program named
Z_INCLUDINGTEST and assigned the type for the program as Executable program.
Step 5 The coding for Z_INCLUDINGTEST program includes the Z_TOBEINCLUDED program with the help of the INCLUDE statement as
shown in the following code.
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.
Whenever any of these statements are used in an ABAP program, it is important to check whether the action executed has been successful.
If one tries to insert a record into a database table and it is not inserted correctly, it is very essential to know so that the appropriate action
can be taken in the program. This can done using a system field that has already been used, that is SY-SUBRC. When a statement is
executed successfully, the SY-SUBRC field will contain a value of 0, so this can be checked for and one can continue with the program if it
appears.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 45/93
9/18/2017 SAP ABAP Quick Guide
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
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).
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 46/93
9/18/2017 SAP ABAP Quick Guide
In native SQL, mainly database-specific SQL statements can be used. These are transferred unchanged from the native SQL interface to a
database system and executed. The full SQL language scope of the relevant database can be used and the addressed database tables do
not have to be declared in the ABAP Dictionary. There is also a small set of SAP specific Native SQL statements that are handled in a
specific way by the native SQL interface.
To use a Native SQL statement, you have to precede it with the EXEC SQL statement and end with ENDEXEC statement.
These statements define an area in an ABAP program where one or more Native SQL statements can be listed. The statements entered are
passed to the Native SQL interface and then processed as follows
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 47/93
9/18/2017 SAP ABAP Quick Guide
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.
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.
An internal table can be made up of a number of fields, corresponding to the columns of a table, just as in the ABAP dictionary a table was
created using a number of fields. Key fields can also be used with internal tables, and while creating these internal tables they offer slightly
more flexibility. With internal 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.
They can be used to hold results of calculations that could be used later in the program.
An internal table can also hold records and data so that this can be accessed quickly rather than having to access this data from
database tables.
They are hugely versatile. They can be defined using any number of other defined structures.
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 48/93
9/18/2017 SAP ABAP Quick Guide
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.
Lets 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
Here itab01 is commonly used shorthand when creating temporary tables in SAP. The OCCURS clause is used to define the body of an
internal table by declaring the fields for the table. When the OCCURS clause is used, you can specify a numeric constant n to determine
additional default memory if required. The default size of memory that is used by the OCCUR 0 clause is 8 KB. The structure of the internal
table is now created, and the code can be written to fill it with records.
An internal table can be created with or without using a header line. To create an internal table with a header line, use either the BEGIN OF
clause before the OCCURS clause or the WITH HEADER LINE clause after the OCCURS clause in the definition of the internal table. To
create an internal table without a header line, use the OCCURS clause without the BEGIN OF clause.
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.
Here the <internal_tab_type> specifies a table type for an internal table <internal_tab> and <line_type_itab> specifies the type for a line
of an internal table. In TYPES statement, you can use the TYPE clause to specify the line type of an internal table as a data type and LIKE
clause to specify the line type as a data object. Specifying a key for an internal table is optional and if the user does not specify a key, the
SAP system defines a table type with an arbitrary key.
INITIAL SIZE <size_number> creates an internal table object by allocating an initial amount of memory to it. In the preceding syntax, the
INITIAL SIZE clause reserves a memory space for size_number table lines. Whenever an internal table object is declared, the size of the
table does not belong to the data type of the table.
Note Much less memory is consumed when an internal table is populated for the first time.
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.
Step 3 In the 'ABAP: Program Attributes' dialog box, enter a short description for the program in the Title field, select the 'Executable
program' option from the Type drop-down menu in the Attributes group box. Click the Save button.
REPORT ZINTERNAL_DEMO.
TYPES: BEGIN OF CustomerLine,
Cust_ID TYPE C,
Cust_Name(20) TYPE C,
END OF CustomerLine.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 49/93
9/18/2017 SAP ABAP Quick Guide
In this example, mytable is an internal table and a unique key is defined on the Cust_ID field.
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.
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 50/93
9/18/2017 SAP ABAP Quick Guide
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 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 doesnt 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
In this syntax, the <record_for_itab> expression can be represented by the <work_area_itab> work area, which is convertible to a line
type or by the INITIAL LINE clause. If the user uses a <work_area_itab> work area, the SAP system adds a new line to the <internal_tab>
internal table and populates it with the content of the work area. The INITIAL LINE clause appends a blank line that contains the initial
value for each field of the table structure. After each APPEND statement, the SY-TABIX variable contains the index number of the appended
line.
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 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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 51/93
9/18/2017 SAP ABAP Quick Guide
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 tables 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,
dob LIKE ZCUSTOMERS1-dob,
END OF itab01.
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.
In this syntax, the <work_area_itab> expression represents a work area that is compatible with the line type of the <internal_table> table.
We can specify a search key, but not a table key, within the READ statement by using the WITH KEY clause, as shown in the following
syntax
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 52/93
9/18/2017 SAP ABAP Quick Guide
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.
READ TABLE mytable FROM Record1 INTO Record1 COMPARING ColQ.
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.
Following is the syntax to use the DELETE statement to delete a record or line from an internal table
In the above syntax, the <work_area_itab> expression is a work area and it should be compatible with the type of the <internal_table>
internal table. 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
DELETE TABLE <internal_table> WITH TABLE KEY <K1> = <F1> <Kn> = <Fn>.
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 53/93
Example
9/18/2017 SAP ABAP Quick Guide
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.
As solutions are designed in terms of real-world objects, it becomes much easier for programmers and business analysts to exchange ideas
and information about a design that uses a common domain language. These improvements in communication help to reveal hidden
requirements, identify risks, and improve the quality of software being developed. The object-oriented approach focuses on objects that
represent abstract or concrete things of the real world. These objects are defined by their character and properties that are represented by
their internal structure and their attributes (data). The behavior of these objects is described by methods (i.e. functionality).
Modularization Programs can be divided into smaller programs known as Programs are organized into classes and objects and the
functions. functionalities are embedded into methods of a class.
Data security Most of the functions share global data. Data can be hidden and cant be accessed by external sources.
Extensibility This is more time consuming to modify and extend the New data and functions can be added effortlessly as and when
existing functionality. required.
ABAP was initially developed as a procedural language (just similar to earlier procedural programming language like COBOL). But ABAP has
now adapted the principles of object oriented paradigms with the introduction of ABAP Objects. The object-oriented concepts in ABAP such
as class, object, inheritance, and polymorphism, are essentially the same as those of other modern object-oriented languages such as Java
or C++.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 54/93
9/18/2017 SAP ABAP Quick Guide
An object is a pattern or instance of a class. It represents a real-world entity such as a person or a programming entity like variables and
constants. For example, accounts and students are examples of real-world entities. But hardware and software components of a computer
are examples of programming entities.
Has a state.
The state of an object can be described as a set of attributes and their values. For example, a bank account has a set of attributes such as
Account Number, Name, Account Type, Balance, and values of all these attributes. The behavior of an object refers to the changes that
occur in its attributes over a period of time.
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
Creating a reference variable with reference to the class. The syntax for which is
Creating an object from the reference variable. The syntax for which is
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 55/93
9/18/2017 SAP ABAP Quick Guide
ABAP Objects.
This is the Display method.
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
Note Implementation of a class contains the implementation of all its methods. In ABAP Objects, the structure of a class contains
components such as attributes, methods, events, types, and constants.
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
METHOD <m_name>.
..........
..........
ENDMETHOD.
In this syntax, <m_name> represents the name of a method. Note You can call a method by using the CALL METHOD statement.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 56/93
9/18/2017 SAP ABAP Quick Guide
The attributes and methods declared in Public section in a class can be accessed by that class and any other class, sub-class of the
program.
When the attributes and methods are declared in Protected section in a class, those can be accessed by that class and sub classes
(derived classes) only.
When the attributes and methods are declared in Private section in a class, those can be accessed by only that class and not by any
other class.
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'.
PRIVATE Section.
Data: text3 Type char25 Value 'Private Data'.
ENDCLASS.
Start-Of-Selection.
Data: Objectx Type Ref To class1.
Create Object: Objectx.
CALL Method: Objectxmeth1.
Write: / Objectxtext1.
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_namename_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 method, we directly access the static attribute in
Start-Of-Selection event. Then we just create the instance 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.
class1name1 = 'ABAP Object Oriented Programming'.
class1data1 = 0.
Data: Object1 Type Ref To class1,
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 57/93
9/18/2017 SAP ABAP Quick Guide
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'.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 58/93
9/18/2017 SAP ABAP Quick Guide
Method method1.
Start-Of-Selection.
Data objectx Type Ref To class1.
Create Object objectx.
CALL Method objectxmethod1.
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.
Derived class inherits the data and methods of a super class. However, they can overwrite methods and also add new methods.
The inheritance relationship is specified using the INHERITING FROM addition to the class definition statement.
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: ParentParentM,
childChildM.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 59/93
9/18/2017 SAP ABAP Quick Guide
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.
Public Inheritance When deriving a class from a public super class, public members of the super class become public members
of the sub class and protected members of the super class become protected members of the sub class. Super class's private
members are never accessible directly from a sub class, but can be accessed through calls to the public and protected members of
the super class.
Protected Inheritance When deriving from a protected super class, public and protected members of the super class become
protected members of the sub class.
Private Inheritance When deriving from a private super class, public and protected members of the super class become private
members of the sub class.
The redefinition statement for the inherited method must be in the same section as the definition of the original method.
If you redefine a method, you do not need to enter its interface again in the subclass, but only the name of the method.
Within the redefined method, you can access components of the direct super class using the super reference.
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 Ref1Addition1 exporting g_a = P_a
g_b = P_b
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 60/93
9/18/2017 SAP ABAP Quick Guide
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
Redefinition Demo
29
The following program contains an abstract class 'class_prgm', 2 sub classes (class_procedural and class_OO), and a test driver class
'class_type_approach'. In this implementation, the class method 'start' allow us to display the type of programming and its approach. If you
look closely at the signature of method 'start', you will observe that it receives an importing parameter of type class_prgm. However, in the
Start-Of-Selection event, this method has been called at run-time with 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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 61/93
9/18/2017 SAP ABAP Quick Guide
CALL Method class1_prgmapproach1.
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_approachstart
Exporting
class1_prgm = class_2.
ABAP run-time environment performs an implicit narrowing cast during the assignment of the importing parameter class1_prgm. This
feature helps the 'start' method to be implemented generically. The dynamic type information associated with an object reference variable
allows the ABAP run-time environment to dynamically bind a method call with the implementation defined in the object pointed to by the
object reference variable. For instance, the importing parameter 'class1_prgm' for method 'start' in the 'class_type_approach' class refers
to an abstract type that could never be instantiated on its own.
Whenever the method is called with a concrete sub class implementation such as class_procedural or class_OO, the dynamic type of the
class1_prgm reference parameter is bound to one of these concrete types. Therefore, the calls to methods 'prgm_type' and 'approach1'
refer to the implementations provided in the class_procedural or class_OO sub classes rather than the undefined abstract implementations
provided in class 'class_prgm'.
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.
Let's consider encapsulation by interface. Interface is used when we need to create one method with different functionality in different
classes. Here the name of the method need not be changed. The same method will have to be implemented in different class
implementations.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 62/93
9/18/2017 SAP ABAP Quick Guide
CLASS Class1 Implementation.
Method inter_1~method1.
inter_1~text1 = 'Class 1 Interface method'.
Write / inter_1~text1.
EndMethod.
ENDCLASS.
Start-Of-Selection.
Data: Object1 Type Ref To Class1,
Object2 Type Ref To Class2.
Encapsulated classes do not have a lot of dependencies on the outside world. Moreover, the interactions that they do have with external
clients are controlled through a stabilized public interface. That is, an encapsulated class and its clients are loosely coupled. For the most
part, classes with well-defined interfaces can be plugged into another context. When designed correctly, encapsulated classes become
reusable software assets.
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 encapsulation. This wisdom is applied most frequently to data members and it also applies equally to all members.
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.
In this syntax, <intf_name> represents the name of an interface. The DATA and CLASSDATA statements can be used to define the instance
and static attributes of the interface respectively. The METHODS and CLASS-METHODS statements can be used to define the instance and
static methods of the interface respectively. As the definition of an interface does not include the implementation class, it is not necessary
to add the DEFINITION clause in the declaration of an interface.
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.
INTERFACE <intf_name>.
In this syntax, <intf_name> represents the name of an interface. Note that this syntax must be used in the public section of the class.
The following syntax is used to implement the methods of an interface inside the implementation of a class
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 63/93
9/18/2017 SAP ABAP Quick Guide
METHOD <intf_name~method_m>.
<statements>.
ENDMETHOD.
In this syntax, <intf_name~method_m> represents the fully declared name of a method of the <intf_name> interface.
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.
The number is 7
Total number of wheels is 4
In the above example, my_interface1 is the name of an interface that contains the 'msg' method. Next, two classes, num_counter and
drive1 are defined and implemented. Both these classes implement the 'msg' method and also specific methods that define the behavior of
their respective instances, such as the add_number and speed1 methods.
Note The add_number and speed1 methods are specific to the respective classes.
In a normal method call, a calling program determines which method of an object or a class needs to be called. As fixed handler method is
not registered for every event, in case of event handling, the handler method determines the event that needs to be triggered.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 64/93
9/18/2017 SAP ABAP Quick Guide
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.
When an event is triggered, appropriate event handler methods are supposed to be executed in all the handling classes.
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, 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.
1 INITIALIZATON
2 AT SELECTION-SCREEN
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 65/93
9/18/2017 SAP ABAP Quick Guide
Triggered after processing of the user input on the selection screen. This event verifies the user input prior to the execution of a
program. After processing the user input, the selection screen remains in the active mode.
3 START-OF-SELECTION
Triggered only after the processing of the selection screen is over; that is, when the user clicks the Execute icon on the selection
screen.
4 END-OF-SELECTION
5 TOP-OF-PAGE
Triggered by the first WRITE statement to display the data on a new page.
6 END-OF-PAGE
Triggered to display the text at the end of a page in a report. Note, that this event is the last event while creating a report, and
should be 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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 66/93
9/18/2017 SAP ABAP Quick Guide
ENDLOOP.
END-OF-SELECTION.
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
Dialog programs should be developed by the object browser (transaction: SE80) so that all objects become linked to the main program
without having to explicitly point each object. Advanced navigation techniques enhance the process of moving from one object to the other.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 67/93
9/18/2017 SAP ABAP Quick Guide
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.
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".
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 68/93
9/18/2017 SAP ABAP Quick Guide
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'.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 69/93
9/18/2017 SAP ABAP Quick Guide
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.
Some examples of standard Smart Forms available in SAP system are as follows
SF_EXAMPLE_01 represents an invoice with a table output for flight booking for a customer.
SF_EXAMPLE_03 specifies an invoice similar to SF_EXAMPLE_02, but one in which several customers can be selected in an
application program.
Creating a Form
Lets 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'.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 70/93
9/18/2017 SAP ABAP Quick Guide
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.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 71/93
9/18/2017 SAP ABAP Quick Guide
Step 1 Open a form in the change mode of the SAP Form Builder screen and right-click the Main Window option in the First Page node
and select Create Text from the context menu.
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
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.
Step 7 Specify the output device as 'LP01' and click the Print preview button.
The SAPscript tool of the SAP system can be used to build and manage business forms such as invoices and purchase orders. The SAPscript
tool provides numerous templates that simplify the designing of a business form to a great extent.
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
1 RVORDER01
2 RVDELNOTE
Packing List
3 RVINVOICE01
Invoice
4 MEDRUCK
Purchase Order
5 F110_PRENUM_CHCK
Prenumbered Check
Content This can be either text (business data) or graphics (company logo).
Layout This is defined by a set of windows in which the form content appears.
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. Lets enter 'RVINVOICE01' and 'EN' respectively in these fields.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 73/93
9/18/2017 SAP ABAP Quick Guide
Step 3 Select the Page Layout radio button in the Sub objects group box.
Step 4 Select Utilities Copy from Client to create a copy of the RVINVOICE01 form. The 'Copy Forms Between Clients' screen appears.
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.
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 74/93
9/18/2017 SAP ABAP Quick Guide
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.
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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 75/93
9/18/2017 SAP ABAP Quick Guide
Step 1 Go to transaction MM01 and identify the program name of MM01 by going to Menu bar System Status as shown in the
above screenshot.
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 4 Navigate to Go to Properties and find out the package of this program name.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 76/93
9/18/2017 SAP ABAP Quick Guide
Step 5 Go to transaction code SMOD that is usually used to identify customer exits. Navigate to Utilities Find (or) you may directly
press Ctrl + F on the transaction code SMOD.
Step 6 After going to the Find Exits screen, enter the package name we got earlier and press F8 (Execute) button.
The above steps produce the following output with the list of exits available in the Material Master Creation.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 77/93
9/18/2017 SAP ABAP Quick Guide
provided by SAP in the areas of sales, transportation, shipping and billing. A user exit is designed to 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.
1 USEREXIT_FIELD_MODIFICATION
2 USEREXIT_SAVE_DOCUMENT
3 USEREXIT_SAVE_DOCUMENT_PREPARE
Very useful to check input fields, put any value in the field or show a popup to users and to confirm 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 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.
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.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 78/93
9/18/2017 SAP ABAP Quick Guide
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
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.
SKIP.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ 'No of Exits:' , SY-TFILL.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'User Exit doesnt 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
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 79/93
9/18/2017 SAP ABAP Quick Guide
A BADI is an enhancement technique that facilitates a SAP programmer, a user, or a specific industry to add some additional code to the
existing program in SAP system. We can use standard or customized logic to improve the SAP system. A BADI must first be defined and
then implemented to enhance SAP application. While defining a BADI, an interface is created. BADI is implemented by this interface, which
in turn is implemented by one or more adaptor classes.
The BADI technique is different from other enhancement techniques in two ways
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
Enhancing the standard applications in a SAP system by adding two new elements in the ABAP language, that is GET BADI and
CALL BADI.
Offering more flexibility features such as contexts and filters for the enhancement of standard applications in a SAP system.
When a BADI is created, it contains an interface and other additional components, such as function codes for menu enhancements and
screen enhancements. A BADI creation allows customers to include their own enhancements in the standard SAP application. The
enhancement, interface, and generated classes are located in an appropriate application development namespace.
Hence, a BADI can be considered as an enhancement technique that uses ABAP objects to create predefined points in the SAP
components. These predefined points are then implemented by individual industry solutions, country variants, partners and customers to
suit their specific requirements. SAP actually introduced the BADI enhancement technique with the Release 4.6A, and the technique has
been re-implemented again in the Release 7.0.
Web Dynpro for ABAP consists of a run-time environment and a graphical development environment with specific development tools that
are integrated in the ABAP Workbench (transaction: SE80).
Web Dynpro is the SAP NetWeaver programming model for user interfaces.
All Web Dynpro applications are structured as per the Model View Controller (MVC) programming model.
The model defines an interface to the main system and the Web Dynpro application can have an access to system data.
The view is responsible for showing the data in the web browser.
The controller resides between the view and the model. The controller formats the model data to be displayed in the view. It
processes the user entries made by the user and returns them to the model.
Advantages
Web Dynpro offers the following advantages for application developers
The layout and navigation is easily changed using the Web Dynpro tools.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 81/93
9/18/2017 SAP ABAP Quick Guide
At least one Web Dynpro window is contained in each Web Dynpro component. The Web Dynpro window embeds all the views that are
displayed within the front-end web application. The window is processed in the window editors of the ABAP Workbench.
Note
The component view displays all the administrative details for the application including the description, the name of the person who
created it, the creation date, and the assigned development package.
The Web Dynpro application is the independent object in the object list of the ABAP Workbench. The interaction between the
window and the application is created by the interface view of a given window.
Advertisements
Google
Cloud
Platform.
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 82/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 83/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 84/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 85/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 86/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 87/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 88/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 89/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 90/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 91/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 92/93
9/18/2017 SAP ABAP Quick Guide
https://www.tutorialspoint.com/sap_abap/sap_abap_quick_guide.htm 93/93