3 - ABAP Programming Part2
3 - ABAP Programming Part2
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
Character and Numeric Data Types
▪ The I(Integer) , P(packed decimal), F(floating point) are considered as numeric data
types.
2
0
Write Statement
▪ The basic ABAP statement for displaying data on the screen is write.
2
1
Chain Operator
WRITE var2.
WRITE var3.
2
2
Conditional Statements
IF statement
CASE statement
2
3
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
6
Loop
Do loop
While loop.
2
7
Do Loop
<statement block>.
ENDDO.
2
8
While Loop
▪ Syntax : WHILE<condition>.
<statement block>.
ENDWHILE.
2
9
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
3
0
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
2
String
3
3
String Operations - Concatenate
INTO = keyword , <c> = final result string , SEPERATED BY = keyword, <s> = separator.
3
4
String Operations - Split
▪ In the above syntax : SPLIT = keyword , <string> = string which we need to split, AT =
strings.
3
5
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
6
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
7
String Operations - Strlen
▪ In the above syntax : len = variable name which returns the length of the string, strlen =
3
8
String Operations - Find
▪ In the above syntax : FIND = keyword , <pattern> = is the sequence of characters we are
3
9
String Operations - Translate
▪ The purpose of translate is to convert the string to upper case or lower case.
▪ In the above syntax : TRANSLATE = keyword , <string> = the string which needs to be
4
0
String Operations - Translate Using Pattern
▪ In the above syntax : TRANSLATE = keyword , <string> = the string which needs to be
4
1
String Operations - Shift
▪ In the above syntax : SHIFT = keyword , string = string which needs to be shifted, BY =
4
2
String Operations - Substring Processing
▪ Substring is a part of the string or small set of characters from the string.
the substring).
4
3
String Comparison Operators
CO(contains only)
CA(contains any)
CS(contains string)
NS(contains no string)
CP(contains pattern)
NP(contains no pattern)
▪ Refer the attached sheet for the detailed explanation of string comparison operators.
4
5
Internal Tables
▪ A very important use of internal tables is for storing and formatting data from a
4
6
Work Area In Internal Tables
4
7
Types of Internal Tables
▪ Internal table is of 3 types. Refer the attached sheet for the comparison and related
4
8
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
9
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.
5
0
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.
5
1
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
3
Selection Screen
▪ With the help of selection screen user provides a input to the program.
Parameters
Select-options
5
4
Parameters
5
5
Select-Options
5
6
Select-Options(Contd.)
1. Sign - I/E(include/exclude)
5
7
Thank You
5
8