Overview
WRITE Statement
Operators
ABAP Basics Elementary Data Types and
Variables
Structured Datatypes and Work
areas
Control Structures
Branching
Looping
1
Overview
Workbench
Transactions
Syntax Rules
Types of Programs
Naming Conventions
2
orkbench Transactions
Workbench Transactions allows Developers to work Workbench Transactions
with various Development Objects like Tables, Views, Data Dictionary – SE11
Search Helps, Programs, Function Modules, Classes etc. ABAP Editor – SE38
Screen Painter – SE51
Menu Painter – SE41
Development Objects Integrated with ABAP Workbench so Function Builder – SE37
that we can Create and Maintain development Objects Class Builder – SE24
It allows Forward Navigation Object Navigator – SE80
Layout Editor – SE71 / SMARTFORMS
Data Browser – SE16/SE16N
3
Syntax Rules
General ABAP Statement Syntax
ABAP Statement consist of Operators and Operands. Generally ABAP Statement starting with Keyword and
Ending with Period
Ex: Print Text on Output Screen
WRITE ‘Welcome to ABAP’.
Ex: Check if A is greater than B
IF a > b.
ELSE.
ENDIF.
Sometimes Only Operators and Operands exists in the Statement
Ex: Move Value in the Variable B to Variables A
A = B.
4
Syntax Rules Contd..
ABAP Statement can Span Multiple Lines
Ex: Write a Select Command to get the Material Master for given Material
SELECT *
FROM mara
INTO TABLE it_mara
WHERE matnr = p_matnr.
Types of Statements
Declarative or Definitive Statements
Note: In the above example SELECT spans multiple Lines.
Blocked/Procedural Statements
ABAP Code is not case sensitive Executable Statements
Ex: Declare Variable to hold the Employee Name
Comments
DATA emp_name TYPE char10.
DATA EMP_NAME TYPE char10.
Multiple Statements can be written in Single Line. But Its not recommended
Ex: Display ‘Hello World’ ‘Welcome to ABAP’ text in the Output
WRITE ‘Hello World’. WRITE ‘Welcome to ABAP’.
5
Syntax Rules Contd.. Declarative
Statements
Declarative statement allows to declare Program Header, User Defined Type etc
Few Examples
REPORT Header of Executable Program
PROGRAMHeader of Module Pool
FUNCTION-POOL Header of Function Group
TYPES To Declare User Defined Types
DATA To Declare Variables | Work Areas | Internal Tables
6
Syntax Rules Contd.. Blocked/Procedural
Statements
Statements which encloses some other statements called as Blocked or Procedural Statements
Directly Executable:
IF..ENDIF
CASE..ENDCASE
LOOP..ENDLOOP
DO..ENDDO
Callable Blocks
FORM..ENDFORM
FUNCTION..ENDFORM
METHOD..ENDMETHOD
Replicable Blocks
INCLUDE
7
Syntax Rules Contd.. Executable
Statements
Every Statement which will be executed and produces some result generally called as Executable Statement
Ex: WRITE
WRITE Statement writes text to Output Screen
Ex: Assignment Operator
Assignment Operator allows to move data from Right Operand to Left Operand
Ex: SELECT
SELECT commands is an Open SQL Command to get the data from the Database Table | View | Internal Table(7.5)
Ex: CALL METHOD | CALL FUNCTION | PERFORM
These are used to call the Callable Blocks
8
Syntax Rules Contd.. Chained Statements
Chained statement allows Developer to group several Statements which are starting with Same Keyword
Symbols to be used for Chaining
‘:’ should be used after the Keyword
‘,’ has to be used to separate the Statements
Ex: Individual Statements with out Chain Operator Ex: Statements using Chain Operator
Output Output
9
Syntax Rules Contd.. Comments
Comments helps to add the short/Long description to the Source code so that Other Developers can easily
understand. Comments will not be executed by the Runtime
Types of Comments
‘*’ Should be specified at the first column so that entire line will be commented
‘”’ can be specified at any position in the line so that subsequent part can be commented
Short Cut to comment/Uncomment the entire line or Multiple Lines
Select all the lines to be commented and press Ctrl + <
Select all the lines to be un commented and Press Ctrl + >
10
Types of Programs
Following are the Different Program Types
1 – Executable Programs
M – Module pool Programming
I – Include Programs
F – Function Group | Function Pool
S – Subroutine Pool
K – Class Pool
J – Interface Pool
T – Type Pool
11
Types of Programs: Executable Programs –
Type ‘1’
Executable Programs also called Report Programs
Features:
Can directly execute in SE38/SA38 transaction.
Transaction code is optional for executing the Report programs
Generally contains Selection screen for Input and List Screen or Custom Container for Output List
Example:
MMBE – Material Stock Details
MB51 – List of Material Documents
ME2M – List of Purchase Orders for Material
Transaction used to create Report Programs
SE38 – ABAP Editor
SE41 and SE51 – GUI status and Screen Painter
SE93 – Create transaction Code (Optional)
General Naming Convention: R* | YR* | ZR*
12
Types of Programs: Dialog or Module Pool Programs –
Type ‘M’
Module pool Programs: Also called dialog programs or transaction programs. Type – M
Features:
Non executable programs
Transaction code is required to run Module pool programs
These program may contains one to many screens
Example:
ME21N – Create Purchase Order
VA01 – Create Sales Order
VL01N – Create Delivery
Transaction used to create Report Programs
SE38 – ABAP Editor
SE51 – Screen Painter to design the screens
SE41 – GUI status ( Menu Bar, Standard Tool Bar & Application Tool Bar)
SE93 – Create Transaction code
General Naming Convention: SAPM* | SAPZM* | SAPYM*
13
Types of Programs: Include Programs – Type ‘I’
Features:
Include programs are not executable programs
Include programs are used for modularization purpose
We will create Include programs for Readability and Reusability purpose
Transaction used to create Report Programs
SE38 – ABAP Editor
We can call the Include program in other Program using INCLUDE Statement
INCLUDE <include_program_name>
General Naming Convention: I* | ZI* | YI*
14
Types of Programs: Function Group – Type ‘F’
Features:
It is a complex program to hold logically related function module
Every function module should be part of one function group
Function Group and Function Modules are not executable programs
Function Modules created for Reusability purpose
Transaction used to create Report Programs
SE37 – Function Builder
We can call the Function Module in other Program using CALL FUNCTION Statement
CALL FUNCTION <function_module_name>
<Parameters>
15
Types of Programs: Others
There are few other types of Programs which help us in developments
Subroutine Pool:
Class Pool
Interface Pool
Type Pool
16
Naming Conventions
General naming standards for defining various objects in the Program
TBD
17
WRITE
Basic Syntax
Position and Size
Additional Features
18
WRITE
WRITE statement is used to print static text or content of variable on screen. It creates a Screen
called List Screen and Display text on the Output Screen
WRITE {[AT] [/][pos][(len|*|**)]} dobj
[UNDER other_dobj]
[NO-GAP]
[int_format_options]
[ext_format_options]
[list_elements]
[QUICKINFO info].
19
WRITE- Example
Text specified in the WRITE Statement will be displayed in the Output continuously
Ex: Display SAP ABAP Demo and ‘Welcome to ABAP World’ text in the Output
ew line '/' character initiates output on next line.
: Display SAP ABAP Demo and ‘Welcome to ABAP World’ text in the Output in Different lines
Specify Location from where output should start printing and Length of the output.
Display SAP ABAP Demo from 5th Position onwards and ‘Welcome to ABAP World’ from 5th Position and 10 Characters
t in the Output in Different lines
20
Operators
Assignment
Operators
Arithmetic
Operators
Initial Check
Others
21
rithmetic Operators
Operator Description
Equal: True, if the content of operand1 matches the content of
=, EQ operand2.
Not Equal: True, if the content of operand1 does not match the
<>, NE content of operand2.
Lower Than: True, if the content of operand1 is smaller than the
<, LT content of operand2.
Greater Than: True, if the content of operand1 is greater than the
>, GT content of operand2.
Lower Equal: True, if the content of operand1 is lower than or equal
<=, LE to the content of operand2.
Greater Equal: True, if the content of operand1 is greater than or
>=, GE equal to the content of operand2
22
gical and Special Operators
Between:
A logical expression with the language element BETWEEN checks where an interval belongs
Syntax ... operand [NOT] BETWEEN operand1 AND operand2...
IS
It is Logical expressions with the language element IS check the state of an operand.
IN
In a logical expression with language element IN, the conditions of a selection table are checked.
AND, OR, NOT
The Boolean operators AND & OR link, in each case, multiple logical expression, while the operator NOT
negates a logical expression. Logical expressions can be explicitly bracketed with ( ).
Note: example will be available in further sections
23
Elementary Data
Types and Variables
Built in Types
Data Elements
User Defined Types
Class Types
24
mentary Data Types and Variables
Elementary data types are used to declare variables which hold single value at a time
Types of Elementary Types
Built In Data Type
Data Elements
Table Fields
User Defined Types Employee E01
Number
Types from Class/Interface Gross Amount 2000
Address 10th Street, Down Town, Moline
25
mentary Data Types: Built in Types
Type Length Standard length Description
1 byte integer
B 1 Byte (internal)
C 1 to 65,535 characters 1 character Text field
Cursor as i As i Database cursor
D 8 characters Date field
F 8 bytes Floating point number
I 4 bytes 4 byte integer
N 1 to 65,535 characters 1 character Numeric text
P 1 to 16 bytes 8 bytes Packed number
String Variable Text string
2 byte integer
S 2 bytes (internal)
T 6 characters Time field
X 1 to 65,535 bytes 1 byte Byte field
xstring Variable Byte string
26
ntary Data Types: Declare Variables based on Built in Types
Following example to demonstrates how
to
Declare variables using built-in types
Populate values to the variables
Display values
Output
27
ntary Data Types: Declare Variables based on Data Elements
Following example to demonstrates how
to
Declare variables using Data Elements
Populate values to the variables
Display values
Output
28
ntary Data Types: Declare Variables based on Table Fields
Following example to demonstrates how
to
Declare variables using Table Fields
Populate values to the variables
Display values
Output
29
entary Data Types: User Defined Elementary Types
We can declare our own data types using TYPES
statement. Structures, Tables, Data elements defined in
Data Dictionary will be used as data types to declare
variables.
Following example demonstrates how to
Declare user defined Type
use User Defined Type to Declare Variables
Output
30
Structured Type and
Work areas
Dictionary Types
User Defined Types
Class Types
31
Overview
Structured data types are composed of several simple data types or other structure data type. Structured Data
Types are used to declare work areas which holds group of values
Following are the Structure Types used to declare work areas
Tables
Dictionary Structures
User Defined Structures Custome
CUST1
r
Types from Classes/Interfaces Customer
Mr. ABCD
Name
Countr US
y A
Address 8th Street Down Town
32
ured Types: Declare Work Area using Database Tables
Following example demonstrates How to
Declare Work Area using Database Table
How Populate values to Each Field of the Work Area
How to Access
Output
33
ured Types: Declare Work Area using Dictionary Structure
Following example demonstrates How to
Declare Work Area using Dictionary Structure
How Populate values to Each Field of the Work Area
Dictionary Structure Progra
m
34
ured Types: Declare Work Area using User Defined Structure
Following example demonstrates How to
Declare Work Area using User Defined Structure
How Populate values to Each Field of the Work Area Declare Work area for User Defined Type
How to Access and Populate Values
Declare user define Type
35
Control Structures
Branching
IF..ENDIF
CASE..ENDCASE
Looping
DO..ENDDO
WHILE..ENDWHI
LE
36
Overview
Control structures allows to control the flow of execution by Branch - Selection
defining the statement in blocks. Control structures can be Condition
True
nested. Statement blocks in control structures can themselves
Conditi
contain control structures.
False
Block of Statements
on
Two kinds of control structures
Branch (selection)
Loop (iteration)
Loop - Iteration
Condition Condition
Block of
True False
statements
37
Branching
Branching Control structures allow the developer to group of the logically related statements and specify
condition only when those block of statements will be executed.
Following are the conditional statements
Condition Based
IF..ENDIF
COND # Constructor Operator
Constant Based
CASE..ENDCASE
SWITCH #
38
ranching: IF..ENDIF
Simple IF
IF..ENDIF is conditional branching statement. One are many condition
IF..ELSE
conditions can be added in the IF Block.
Condition
Syntax:
IF <Condtion>.
“ Block of Statemetns
ELSEIF <Condtion>
“ Block of Statement IF..ELSE Ladder
…
ELSE.
…
ENDIF>
39
ranching: COND#|Type
COND Constructor operator is new ABAP syntax for Conditional statement.
Syntax
... COND type( [let_exp]
WHEN log_exp1 THEN [let_exp] result1
[ WHEN log_exp2 THEN [let_exp] result2 ]
...
[ ELSE [let_exp] resultn ] ) ...
Example
40
ranching: CASE…ENDCASE
CASE..ENDCASE is Constant based Branching
statement.
Syntax:
CASE <Operand>
WHEN <Value>.
“ Block of Statements
WHEN <Value>
“ Block of Statements
..
WHEN OTHERS.
“ Block of Statemetns
ENDCASE.
New syntax introduced in ABAP7.4 for Branching called
SWITCH
Syntax:
Operand = SWITCH <Type|#>( Operand
WHEN
<Value> THEN <Expression>
WHEN
<value> THEN <Expression> …).
41
Looping
Looping Control structures allow the developer to group of the logically related statements and these block
statements executed repeatedly until some number if times or as long as condition is true.
Following are the conditional statements
Condition Based
WHILE..ENDWHILE
Constant Based
DO..ENDO
EXIT is a control Break statement and whenever it encounter by the system, it will come out of current processing
block. Its generally used inside DO..ENDO, WHILE..ENDWHILE and LOOP..ENDLOOP
42
Looping: DO..ENDO
DO..ENDDO constant based Looping control structure.
DO..ENDDO having two kinds of loops.
Finite Loops
Infinite Loops
Finite Loops
Finite Loops: Loop will be executed some fixed number of Times
Syntax:
DO number_of TIMES.
“ Block of Statements
ENDDO.
Output
43
Looping: DO..ENDO
Infinite Loops: Loop will be executed infinite number of times. Exit condition must be inside the DO..ENDDO block
Syntax:
DO.
“ Block of Statements
“ Exit Condition
ENDDO.
Output
Infinite Loops
44
ooping: WHILE..ENDWHILE
WHILE..ENDWHILE conditional based looping control Structure. Condition evaluated first. If it results true then
block of statements executed. Statements inside the WHILE..ENDWHILE block executed as long as condition
evaluated TRUE.
Syntax
WHILE <Logica_Exp>
“ Block of Statements.
ENDWHILE.
Example Output
45