0% found this document useful (0 votes)
10 views

3 - ABAP Programming Part2

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

3 - ABAP Programming Part2

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 58

ABAP Programming Part1

1
Introduction to ABAP Editor

▪ ABAP editor is a tool for ABAP coding.

▪ It is one of the main tool of the ABAP workbench.

▪ The transaction code for ABAP editor is SE38.

▪ Any customized program must start with Z or Y as first alphabet.

▪ A statement is a sequence of words that ends with a period.

▪ In the ABAP editor, the keywords appear in blue color.

2
Functionalities of ABAP Editor

▪ Save - Ctrl + S

▪ Syntax check - Ctrl + F2

▪ Activation - Ctrl + F3

▪ Execute - F8

▪ Display/change - Ctrl+ F1

▪ Display object list - Ctrl + Shift + F5

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.

▪ The shortcut of pretty printer is Shift + F1.

▪ The various functionalities of pretty printer are as follows:

 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

person reading the program to understand it.

▪ 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

remaining content in the line is a comment.

5
Functionalities of ABAP Editor - Comments(Contd.)

▪ Shortcut to comment out lines - Ctrl + ,

▪ Shortcut to uncomment lines - Ctrl + .

6
Data Types

▪ Data types are templates for creating data objects.

▪ A data type defines the technical attributes of data objects.

▪ Data types do not use any memory space.

▪ Data types can be defined independently in the ABAP program or in ABAP dictionary.

7
Data Objects

▪ A data object is an instance of a data type.

▪ A data object holds the contents or data.

▪ It occupies the memory space based upon the data type specified.

▪ Example - DATA lv_empid(20) TYPE n.

lv_empid = 10.

▪ In the above example, DATA = keyword , lv_empid is the name of the data object,

TYPE = keyword , n(numeric) = is a data type of that data object.


8
Categories of Data Types
Categories of Data Types

▪ There are three categories of data types.

1. Elementary types

2. Complex types

3. Reference types

9
Elementary Types

▪ They are predefined data types.

▪ They are single data types. They are not composed of other data types.

▪ Elementary datatypes are of 2 types:

1. Fixed length data types - C(character) , N(numeric) , I(Integer) , P(packed number) ,

F(floating point) , D(date), T(time) , X(hexadecimal).

2. Variable length data types - String , Xstring.

1
0
Complex Data Types

▪ There is no pre-defined complex data type in ABAP.

▪ They are the combination of elementary data types.

▪ There are 2 types of complex data types.

1. Structure type

2. Table type

1
1
Reference Data Types

▪ There is no pre-defined reference data type.

▪ It describes data objects that contain references to other objects.

▪ They are of 2 types of reference data type.

1. Data reference

2. Object reference

1
2
Reference Data Types(Contd.)

▪ Example : DATA lo_object TYPE REF TO zclass.

▪ In the above syntax - DATA = keyword , lo_object = name of data object, TYPE REF TO =

keyword , zclass = name of already existing class.

1
3
Types of Data Objects

▪ The Data objects are of 2 types.

1. Literals(unnamed data objects)

2. Named data objects

1
4
Literals(Unnamed Data Objects)

▪ Literals don’t have any name that’s why they are called as unnamed data objects.

▪ They are fully defined by their value.

▪ There are 2 types of literals.

1. Numeric literals - Numeric literals have sequence of numbers. Examples - 123 , -4567

etc.

2. Character literals - Character literals are sequences of alphanumeric characters in single

quotation marks. Examples - ‘Test 123’ , ‘SAP ABAP’ etc.


1
5
Named Data Objects

▪ Data objects that have a name are called as named data objects.

▪ The various types of named data objects are as follows :

1. Variables

2. Constants

3. Text symbols

1
6
Variables

▪ Variables are data objects whose contents can be changed.

▪ Variables are declared using the DATA, CLASS-DATA, STATICS, PARAMETERS, SELECT-

OPTIONS, and RANGES keyword.

▪ Example - DATA lv_empid(20) TYPE n.

lv_empid = 10.

lv_empid = 20.

1
7
Constants

▪ Constants are data objects whose contents can not be changed.

▪ Constants are declared using the CONSTANTS keyword.

▪ Example - CONSTANTS lc_pi TYPE P DECIMALS 3 VALUE ‘3.141’.

1
8
Text Symbols

▪ A text symbol is a data object that is not declared in the program itself.

▪ It is defined as a part of the text elements of the program.

1
9
Character and Numeric Data Types

▪ The C(character) , N(numeric), D(date), T(time) are considered as character(non-

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.

▪ Example - Data: number TYPE I VALUE 1,

name(25) TYPE c VALUE 'Leena’.

WRITE: 'The Number is ‘, number.

WRITE: / 'The Name is ', name.

▪ We can use ‘ /’ in write statement to denotes a new line.

2
1
Chain Operator

▪ The chain operator is ‘:’.

▪ It is used to combine the statements.

▪ Statement sequence - WRITE var1.

WRITE var2.

WRITE var3.

▪ CHAIN statement : WRITE : var1 , var2 , var3.

2
2
Conditional Statements

▪ Conditional statements allows us to execute a block of code if a certain condition is met.

▪ The various conditional statements are as follows:

 IF statement

 CASE statement

2
3
IF Statement

Various options of IF Statement


▪ It is a conditional statement.

▪ Every if statement ends with endif.

▪ We provide multiple conditions using elseif.

▪ Multiple statements blocks are there,

depends upon the condition one block executes.

▪ If none of the If and elseif conditions

are satisfied, it goes to else part.


2
4
CASE Statement

CASE Statement
▪ It is a conditional statement.

▪ Every case statement ends with endcase.

▪ Multiple statements blocks are there,

depends upon the condition one block

executes.

▪ If none of the conditions are satisfied,

it goes to others part.


2
5
Difference between Case & IF

▪ If we have multiple IF conditions , IF check all the conditions, until it gets a true

condition whereas in CASE , it directly jumps to the true condition.

▪ Case is performance effective as compared to IF.

2
6
Loop

▪ Loop allows us to execute a group of statements multiple times.

▪ The various loops are as follows:

 Do loop

 While loop.

 Loop at <itab> where itab stands for Internal table.

2
7
Do Loop

▪ Do loop is called as a unconditional loop.

▪ Every do loop ends with enddo.

▪ Syntax : Do <n> TIMES.

<statement block>.

ENDDO.

2
8
While Loop

▪ While loop is called as a conditional loop.

▪ Every while loop ends with endwhile.

▪ Syntax : WHILE<condition>.

<statement block>.

ENDWHILE.

2
9
Loop Statements

▪ Exit - is used to exit from the loop.

▪ Continue - skip the current processing of the record and then process the next record in

the loop statement.

▪ Check - if the check condition is not true, loop will skip the current loop pass and move

to next loop pass.

3
0
System Variables

▪ System variables are pre-defined variables in SAP.

▪ SYST is the structure for the system fields.

▪ All system fields are addressed using SY field name.

▪ The various system variables are as follows :

 SY-SUBRC - System variable for return code (successful = 0, not successful = other than

0).

 SY-TABIX - It returns the current line index inside a loop.


3
1
System Variables(Contd.)

 SY-INDEX - It returns the current line index inside do and while Loop.

 SY-DATUM - System variable for current date (internal format - yyyymmdd).

 SY-UNAME - It returns the logon name of the user.

 SY-UZEIT - It returns the current system time(internal format - hhmmss)

 SY-UCOMM - System variable for user command.

3
2
String

▪ A string is a collection of characters.

▪ String is an elementary data type of variable length.

 Imp point : String operations are applicable to data objects having

C(character),N(numeric),D(date),T(time) and string data types.

3
3
String Operations - Concatenate

▪ The purpose of concatenate is to combine the strings.

▪ Syntax : CONCATENATE <c1> --------<cn> INTO <c> SEPERATED BY <s>.

▪ In the above syntax : CONCATENATE = keyword , <c1>-------<cn> = individual strings ,

INTO = keyword , <c> = final result string , SEPERATED BY = keyword, <s> = separator.

3
4
String Operations - Split

▪ The purpose of split is to divide the strings.

▪ For split, separator is compulsory.

▪ Syntax : SPLIT <string> AT <separator> INTO <f1> <f2> <f3>…. .

▪ In the above syntax : SPLIT = keyword , <string> = string which we need to split, AT =

keyword, <separator> = any delimiter , INTO = keyword , <f1> <f2><f3>---- = individual

strings.

3
5
String Operations - Condense

▪ The purpose of condense is to remove the leading and trailing spaces and convert a

sequence of spaces into a single space.

▪ Syntax : CONDENSE <c>.

▪ 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.

▪ Syntax : CONDENSE<c> NO-GAPS.

▪ In the above syntax : CONDENSE = keyword , <c> = string which we want to condense ,

NO-GAPS = keyword.

3
7
String Operations - Strlen

▪ The purpose of strlen is to provide the string length.

▪ Syntax : len = strlen( string ).

▪ In the above syntax : len = variable name which returns the length of the string, strlen =

pre-defined operation , string = string whose length needs to be calculated.

3
8
String Operations - Find

▪ The purpose of find is to find a particular pattern in a string.

▪ Syntax : FIND <pattern> IN <str> .

▪ In the above syntax : FIND = keyword , <pattern> = is the sequence of characters we are

looking for , IN = keyword , <str> = is the string that is being searched.

3
9
String Operations - Translate

▪ The purpose of translate is to convert the string to upper case or lower case.

▪ Syntax : TRANSLATE <string> TO UPPER CASE/ LOWER CASE.

▪ In the above syntax : TRANSLATE = keyword , <string> = the string which needs to be

converted , TO = keyword , UPPER CASE/LOWER CASE = keyword.

4
0
String Operations - Translate Using Pattern

▪ We can translate a text based upon specific pattern also.

▪ Syntax : TRANSLATE <string> USING <pattern> .

▪ In the above syntax : TRANSLATE = keyword , <string> = the string which needs to be

converted , USING = keyword, pattern = contains letter pairs.

4
1
String Operations - Shift

▪ The purpose of shift is to shift the contents of a string.

▪ It shifts the string by a number of places.

▪ Syntax : SHIFT <string> BY n PLACES <mode>. (by default mode is left)

▪ In the above syntax : SHIFT = keyword , string = string which needs to be shifted, BY =

keyword , n = number , PLACES = keyword , <mode> = left/right/circular.

4
2
String Operations - Substring Processing

▪ Substring is a part of the string or small set of characters from the string.

▪ Depends upon the requirement we need to process the substring.

▪ Syntax : Target_variable = Source_variable[+][starting position of substring](length of

the substring).

4
3
String Comparison Operators

▪ String comparison operators are used to compare the strings.

▪ String comparison operators are applicable to data objects having

C(character),N(numeric),D(date),T(time) and string data types.

▪ The system variable SY-FDPOS plays an important role in string comparison.

▪ The various string comparison operators are as follows:

 CO(contains only)

 CN(contains not only)


4
4
String Comparison Operators(Contd.)

 CA(contains any)

 NA(contains not any)


Microsoft Excel
Worksheet

 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

▪ Internal table is a temporary storage of data on application layer.

▪ Internal table stores any number of records at run time.

▪ A very important use of internal tables is for storing and formatting data from a

database table within a program.

4
6
Work Area In Internal Tables

▪ Work area is also a temporary storage of data on application layer.

▪ Work area are single rows of data.

▪ It is used to process the data in an internal table, one line at a time.

4
7
Types of Internal Tables

▪ Internal table is of 3 types. Refer the attached sheet for the comparison and related

questions on the types of internal tables.


Comparison of Internal Tables

1. Standard internal table


Microsoft Excel
Worksheet

2. Sorted internal table

3. Hashed internal table

4
8
Internal Table With Header Line

▪ In case of internal table with header line, there is an implicit(internal) work area.

▪ The name of the work area is same as that of internal table.

▪ To clearly identify the internal table use brackets after the internal table name(<itab>[]).

▪ CLEAR <itab>[] - Clear the contents of internal table.

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

internal table without header line.

▪ In case of internal table without header line, there is an explicit(external) work area.

▪ We declare an explicit work area.

▪ The name of the internal table is different from as that of work area.

▪ CLEAR <itab> - Clear the contents of internal table.

5
0
Internal Table Operations

▪ Append - It is used to insert data at the last of the internal table.

▪ Delete - It is used to delete the records from the internal table.

▪ Modify - It is used to modify the records of the Internal table.

▪ 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.

▪ Clear , Refresh - It is used to clear the contents of the internal table.

5
1
Internal Table Operations(Contd.)

▪ Collect - It is used to make sum of numeric field values based upon unique character

(non-numeric) field values. The C(character) , N(numeric), D(date), T(time) are

considered as character(non-numeric) data types. The I(Integer) , P(packed decimal),

F(floating point) are considered as numeric data types.

▪ 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

specify the keyword descending.


5
2
Internal Table Operations(Contd.)

▪ Describe table - It returns the number of records in the internal table.

Syntax : DESCRIBE TABLE <itab> LINES <lv_lines>.

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

▪ Selection screen is also called as Input screen.

▪ With the help of selection screen user provides a input to the program.

▪ There are 2 ways to provide the input to the program.

 Parameters

 Select-options

5
4
Parameters

▪ Parameters are used to pass the single input.

▪ The various parameters variations are as follows:

 PARAMETERS <p> ...... DEFAULT <f> ......

 PARAMETERS <p> ...... OBLIGATORY ......

 PARAMETERS <p> ...... AS CHECKBOX ......

 PARAMETERS <p> ...... RADIOBUTTON GROUP <radi>......

5
5
Select-Options

▪ Select-options are used to pass a range of inputs.

▪ The various Select-options variations are as follows:

 SELECT-OPTIONS <seltab> FOR <f> ... DEFAULT <g> [TO <h>]

 SELECT-OPTIONS <seltab> FOR <f> ... NO-EXTENSION

 SELECT-OPTIONS <seltab> FOR <f> ... NO INTERVALS

 SELECT-OPTIONS <seltab> FOR <f> ... OBLIGATORY

5
6
Select-Options(Contd.)

▪ A select-option has 4 parts.

1. Sign - I/E(include/exclude)

2. Option - Relational operator( EQ, BT, LT etc.)

3. Low - Low value

4. High - High value

5
7
Thank You

5
8

You might also like