3 ABAP Programming
3 ABAP Programming
1
Introduction to ABAP Editor
2
Functionalities of ABAP Editor
▪ Save - Ctrl + S
▪ Activation - Ctrl + F3
▪ Execute - F8
▪ Display/change - Ctrl+ F1
3
Functionalities of ABAP Editor - Pretty Printer
▪ The use of pretty printer is used to format the ABAP code. It makes the code more
readable.
Indentation
Convert uppercase/lowercase
4
Functionalities of ABAP Editor - Comments
▪ A comment is an explanation that is added to the source code of a program to help the
▪ Comments are ignored when the program is generated by the ABAP compiler.
▪ The * character at the start of a program line indicates that the entire line is a comment.
▪ The " character, which can be entered at any position in the line, indicates that the
5
Functionalities of ABAP Editor - Comments(Contd.)
6
Data Types
▪ Data types can be defined independently in the ABAP program or in ABAP dictionary.
7
Data Objects
▪ It occupies the memory space based upon the data type specified.
lv_empid = 10.
▪ In the above example, DATA = keyword , lv_empid is the name of the data object,
1. Elementary types
2. Complex types
3. Reference types
9
Elementary Types
▪ They are single data types. They are not composed of other data types.
1
0
Complex Data Types
1. Structure type
2. Table type
1
1
Reference Data Types
1. Data reference
2. Object reference
1
2
Reference Data Types(Contd.)
▪ In the above syntax - DATA = keyword , lo_object = name of data object, TYPE REF TO =
1
3
Types of Data Objects
1
4
Literals(Unnamed Data Objects)
▪ Literals don’t have any name that’s why they are called as unnamed data objects.
1. Numeric literals - Numeric literals have sequence of numbers. Examples - 123 , -4567
etc.
▪ Data objects that have a name are called as named data objects.
1. Variables
2. Constants
3. Text symbols
1
6
Variables
▪ Variables are declared using the DATA, CLASS-DATA, STATICS, PARAMETERS, SELECT-
lv_empid = 10.
lv_empid = 20.
1
7
Constants
1
8
Text Symbols
▪ A text symbol is a data object that is not declared in the program itself.
1
9
Write Statement
▪ The basic ABAP statement for displaying data on the screen is write.
2
0
Chain Operator
WRITE var2.
WRITE var3.
2
1
Conditional Statements
IF statement
CASE statement
2
2
IF Statement
CASE Statement
▪ It is a conditional statement.
executes.
▪ If we have multiple IF conditions , IF check all the conditions, until it gets a true
2
5
Loop
Do loop
While loop.
2
6
Do Loop
<statement block>.
ENDDO.
2
7
While Loop
▪ Syntax : WHILE<condition>.
<statement block>.
ENDWHILE.
2
8
Loop Statements
▪ Continue - skip the current processing of the record and then process the next record in
▪ Check - if the check condition is not true, loop will skip the current loop pass and move
2
9
System Variables
SY-SUBRC - System variable for return code (successful = 0, not successful = other than
0).
SY-INDEX - It returns the current line index inside do and while Loop.
3
1
String
3
2
String Operations - Concatenate
INTO = keyword , <c> = final result string , SEPERATED BY = keyword, <s> = separator.
3
3
String Operations - Split
▪ In the above syntax : SPLIT = keyword , <string> = string which we need to split, AT =
strings.
3
4
String Operations - Condense
▪ The purpose of condense is to remove the leading and trailing spaces and convert a
▪ In the above syntax : CONDENSE = keyword , <c> = string which we want to condense.
3
5
String Operations - Condense No-gaps
▪ To remove the entire spaces the addition no-gaps is used with condense.
▪ In the above syntax : CONDENSE = keyword , <c> = string which we want to condense ,
NO-GAPS = keyword.
3
6
String Operations - Strlen
▪ In the above syntax : len = variable name which returns the length of the string, strlen =
3
7
String Operations - Find
▪ In the above syntax : FIND = keyword , <pattern> = is the sequence of characters we are
3
8
String Operations - Translate
▪ The purpose of translate is to covert the string to upper case or lower case.
▪ In the above syntax : TRANSLATE = keyword , <string> = the string which needs to be
3
9
String Operations - Translate Using Pattern
▪ In the above syntax : TRANSLATE = keyword , <string> = the string which needs to be
4
0
String Operations - Shift
▪ In the above syntax : SHIFT = keyword , string = string which needs to be shifted, BY =
4
1
String Operations - Substring Processing
▪ Substring is a part of the string or small set of characters from the string.
the substring).
4
2
Internal Tables
▪ A very important use of internal tables is for storing and formatting data from a
4
3
Work Area In Internal Tables
4
4
Types of Internal Tables
4
5
Types of Internal Tables
4
6
Internal Table With Header Line
▪ In case of internal table with header line, there is an implicit(internal) work area.
▪ To clearly identify the internal table use brackets after the internal table name(<itab>[]).
Imp point : In case of internal table with header line, CLEAR <itab> clears the work area, not
the internal table. If you want to clear the internal table use brackets after the internal table
name.
4
7
Internal Table Without Header Line
▪ We can avoid the confusion of internal table with header line by using the concept of
▪ In case of internal table without header line, there is an explicit(external) work area.
▪ The name of the internal table is different from as that of work area.
4
8
Internal Table Operations
▪ Loop - It is used to read the records one by one from the internal table.
▪ Read table - It is used to read the first matching record from the internal table.
4
9
Internal Table Operations(Contd.)
▪ Collect - It is used to make sum of numeric field values based upon unique character
▪ Sort - It is to sort the internal table. If we are not specifying anything, then by default It
sorts in the ascending order. If we want to sort in descending order, then we need to
In the above syntax : DESCRIBE TABLE = keyword, <itab> = name of the internal table ,
LINES = keyword, <lv_lines> = local variable which returns the number of records.
5
1
Selection Screen
▪ With the help of selection screen user provides a input to the program.
Parameters
Select-options
5
2
Parameters
5
3
Select-Options
5
4
Select-Options(Contd.)
1. Sign - I/E(include/exclude)
5
5
Classical Reports
▪ Reports are programs that read data from the database, processes the data and displays
▪ SAP ABAP classical reports are the most basic ABAP reports in which we displayed the
5
6
Open SQL
▪ It is of 2 types.
5
7
Open SQL Queries
▪ This query fetches data from database table ztordh_88, based upon the select-options
s_ono.
5
8
Open SQL Queries(Contd.)
▪ This query fetches data from database table ztordh_88, based upon the parameter
p_ono.
5
9
Open SQL Queries - For All Entries In
▪ When we fetch the data from multiple tables, ‘For All Entries In’ is the best alternative.
6
0
Open SQL Queries - Join
▪ With the help of join, we can read from more than one table in a single select
statement.
Use of Join to Fetch Data From Multiple Tables
6
1
Best Performance Practices/Guidelines
▪ Never use * in the query. Fetch the data of only those columns which are required.
sequence.
▪ Where condition column sequence needs to be same as that of data dictionary column
sequence.
▪ For traditional databases avoid using JOIN, use FOR ALL ENTRIES IN.
▪ For fetching data from foreign key tables/dependent tables - check for sy-subrc or
▪ For multiple conditions, use CASE conditional statement rather than IF conditional
statement.
6
3
Best Performance Practices/Guidelines(Contd.)
6
4
Message Class
S(success/status),W(warning), X(exit).
6
5
Message Class(Contd.)
▪ In the above syntax - MESSAGE = keyword , E = error message type , 000 is message
6
6
Transaction Code
6
7
Classical Report Events
▪ Classical reports are the most basic ABAP reports in which we display the output using
WRITE statement.
▪ The example of specific actions are mouse click, pressing a key etc. The example of
6
8
Classical Report Events(Contd.)
▪ The same concept of events is applicable to classical reports. Some events trigger by
specific user action and some events trigger at specific occurrence in classical reports.
Initialization
At selection-screen
Start-of-selection
End-of-selection
6
9
Classical Report Events(Contd.)
Top-of-page
End-of-page
At selection-screen output
At selection-screen on <field>
7
0
Initialization
▪ The purpose of this event is to assign the default values to parameters and select-
options.
7
1
AT Selection-Screen
▪ This event calls when user performs some action (enter, click etc.) on to the selection
screen.
7
2
Start-of-Selection
▪ This event calls when user clicks execute button on the selection screen.
7
3
End-of-Selection
▪ This event calls when selection process ends or after the last statement in the START-OF-
7
4
Top-of-Page
▪ This event calls when the first write statement occurs in a program for
a page.
▪ The purpose of this event is to provide title/header at the beginning of a new page.
7
5
End-of-Page
▪ This event calls when the last write statement occurs in a program for
a page.
▪ The purpose of this event is to provide footer or some information at the end of a new
page.
▪ Example: LINE-COUNT 5(2), It means the total number of lines on a page is 5 and out of
▪ The purpose of this event is to modify the selection screen before it is displayed.
7
7
Initialization and AT Selection-Screen Output Comparison
▪ Initialization event calls only first time before displaying the selection screen whereas at
selection-screen output event calls every time before displaying a selection screen.
7
8
AT Selection-Screen and AT Selection-Screen Output Comparison
▪ AT selection-screen event calls when user performs some action (enter, click etc.) on to
the selection screen whereas at selection-screen output event calls before displaying
the selection-screen.
▪ AT selection-screen event is equal to PAI( Process After Input) of module pool whereas
▪ The purpose of this event is to provide value help for an input field.
8
0
AT Selection-Screen On Help Request For <Field>
8
1
AT Selection-Screen On <Field>
▪ This event calls when user performs some action (enter, click etc.) on to the selection
screen.
▪ This event is used to validate a particular input field present on the selection screen.
8
2
AT Selection-Screen and AT Selection-Screen On <Field> Comparison
screen on <field> event is to validate a particular input field present on the selection
screen.
▪ In case of at selection-screen event to highlight a wrong input field the explicit logic is
required, whereas in at selection screen on <field> the wrong input field highlighted
automatically.
8
3
AT Selection-Screen and AT Selection-Screen On <Field> Comparison
▪ In case of at selection-screen event all input fields remain enable after the wrong input
whereas in case of at selection-screen on <field> event the wrong input field remain
8
4
Interactive Classical Report Events
▪ In classical report we only display the output on basic list . There is no interaction with
the output.
▪ In Interactive classical report is one we interact with the output on basic list and it take
us to secondary list.
▪ Basic list is the list which is generated at first by our ABAP program.
▪ The secondary lists are generated by further navigation or user selection from the basic
list.
8
5
Interactive Classical Report Events(Contd.)
At line-selection
At user-command
8
6
AT Line-Selection
▪ When user double clicks on the line or select a line and press F2 or select a line and click
8
7
AT User-Command
▪ When user clicks on the functions created using pf-status, at that time at user-command
event triggers.
▪ The system variable sy-ucomm is used to capture the value of function code.
8
8
Top-of-Page During Line-Selection
▪ This event calls when the first WRITE statement occurs in a program
▪ The purpose of this event is to provide title/header at the beginning of a new page on
secondary list.
8
9
Interactive Classical Reports Statements - HIDE
interactive reporting.
▪ The above statement places the contents of the variable <f> into the
9
0
Interactive Classical Reports Statements - HIDE(Contd.)
▪ We can consider hide area as a table which stores the field name, field
9
1
Interactive Classical Reports Statements - Working of HIDE
▪ The user selects a line for which data has been stored in the HIDE
area.
▪ The runtime system jumps to the point in the HIDE area where data for
this
line is stored.
▪ The runtime system then inserts all values stored for the selected line
9
2
Interactive Classical Reports Statements - GET CURSOR
▪ In interactive classical reports, GET CURSOR statement is used to create secondary lists
▪ The parameter FIELD provides the name of an output field. The parameter VALUE
▪ In the above syntax - the field name and field value will be returned in to variables
▪ HIDE statement responds for a particular line whereas GET CURSOR statement responds
▪ HIDE statement is used to store the line with line number in the hide area whereas GET
▪ With HIDE statement, we can not display secondary lists based upon Individual field
name and field value whereas with GET CURSOR statement we can display secondary
lists based upon the Individual field name and field value.
9
4
System Variables in Interactive Classical Report Events
▪ The various system variables used in interactive classical report events are as follows:
SY-LISEL - It is a system variable which returns the contents of the selected line.
SY-LSIND - It is a system variable which returns the index of the displayed list. For the
basic list SY-LSIND = 0 and for the secondary lists SY-LSIND > 0.
9
5
Control Break Statements
▪ Control break statements are used to control loop or we can say they are used to control
AT FIRST
AT LAST
AT NEW <fieldname>
AT END OF <fieldname>
9
7
Types of Control Break Statements
AT FIRST - It triggers for the first row/first record/first iteration of the internal table in
loop.
AT LAST - It triggers for the last row/last record/last iteration of the internal table in
loop.
AT NEW <fieldname> - It triggers for the new/first record of a group having the same
9
8
Types of Control Break Statements(Contd.)
AT END OF <fieldname> - It triggers for the end/last record of a group having the same
9
9
Control Break Statements With SUM Statement
▪ SUM statement can only be used in loop- endloop statement and needs to be applied in
▪ SUM calculates the sum of all numeric fields to the right of the current group key.
▪ The sum is for all rows of the current group and assign it to the corresponding fields of
the workarea.
1
0
Control Break Statements - Important Points
▪ Always sort the internal table based upon the fieldname used in AT NEW<fieldname> or
AT END OF <fieldname>.
▪ The event AT NEW <fieldname> and AT END OF <fieldname> also triggers if the value of
other fields change which are present on the left hand side of specified fieldname. If we
fieldname only , then we need to take specified fieldname at the first position in the
internal table.
1
0
Control Break Statements - Important Points
▪ Whenever AT FIRST and AT LAST control break events triggers all character field values
character fields on the right hand side of specified fieldname converted to **** and
Solution : Store the values in a temporary work area before any of the control break
event triggers.
1
0
Database Operations
▪ Database operations deals with database tables. The various database operations are as
follows:
Update - Update is used to update the existing records in the database tables.
Delete - Delete is used to delete the existing records from database tables.
1
0
Database Operations(Contd.)
Modify - It works for both - insert + update. For existing records - It acts as update, for
1
0
Thank You
1
0