Download - 1-Introduction to ABAP
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 1/17
Introduction to ABAP
ABAP stands for Advanced Business Application Programming. It is a programming
language for developing applications for the SAP R/3 system.
The latest version of ABAP is called ABAP Objects and supports object-oriented
programming. SAP will run applications written using ABAP/4, the earlier ABAP
version, as well as applications using ABAP Objects.
Data Types
Syntax to declare a variable in ABAP -
DATA Variable_Name Type Variable_Type
Example:
DATA employee_number Type I.
The following is a list of Data Types supported by ABAP
Data
Type
Initial field
length
Valid field
length
Initial
value
Meaning
Numeric types
I 4 4 0 Integer (whole number)
F 8 8 0 Floating point number
P 8 1 - 16 0 Packed number
Character types
C 1 1 - 65535 ' ... ' Text field(alphanumeric
characters)
D 8 8 '00000000' Date field(Format:
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 2/17
YYYYMMDD)
N 1 1 - 65535 '0 ... 0' Numeric text field(numeric
characters)
T 6 6 '000000' Time field(format:
HHMMSS)
Hexadecimal type
X 1 1 - 65535 X'0 ... 0' Hexadecimal field
Processing Data - Assigning Values
a=16.
move 16 to a.
write a to b.
- Arithmetic Operations
compute a = a*100.
Control Statements
Following control statements can be used - - If ... EndIf Loop
if [not] exp [ and / or [not] exp ].
........
[elseif exp.
.......]
[else.
.......]
Endif.
- Case statement
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 3/17
Case variable.
when value1.
.........
when value2.
.........
[ when others.
.........]
Endcase.
Do.
-While loop
While <logical expression>.
.....
.....
Endwhile.
- Do loop
Do <n> times.
.....
.....
Enddo.
Logical Operator
A list of logical operators
GE or >=
GT or >
LE or <=
LT or <
EQ or =
NE or <>
ABAP/4 Editor
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 4/17
Finally, here is where you will spend most of your time as a developer creating /
modifying programs. Transaction SE38
ABAP Data Dictionary TutorialA data dictionary is a central source of information for the data in a information
management system. Its main function is to support the creation and management of
data definitions (or "metadata").
What is Data dictionary used for?
Management of data definitions
Provision of information for evaluations Support for software development
Support for documentation
Ensuring that data definitions are flexible and up-to-date
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 5/17
Objects in the ABAP Dictionary resided on three levels that support their re-usability.
These levels are:
1. Tables and structures
2. Data elements
3. Domains
Let’s look into them in detail -
Domains
Describes the technical characteristics of a table field
Specifies a value range which describes allowed data values for the fields
Fields referring to the same domain (via the data elements assigned to them)
are changed when a change is made to the domain
Ensures consistency
Ex. Purchasing document number (EBELN)
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 6/17
Data Elements
Describes the role played by a field in a technical context
Fields of same semantic meaning can refer to the same data element
Contains the field information
Ex. Purchasing document number (EBELN)
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 7/17
Tables
Represent the Database Tables where data actually resides.
Tables can be defined independently of the database in the ABAP Dictionary.
The fields of the table are defined with their (database-independent) SAP
ABAP data types and lengths.
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 8/17
Structures
Are record declarations that do NOT correspond to a Database Table.
Just like user-defined data type.
Defined like a table and can then be addressed from ABAP programs.
Structures contain data only during the runtime of a program.
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 9/17
Aggregated Objects of ABAP Dictionary
Aggregated means consisting of several components. In the ABAP Dictionary,
aggregated objects are objects which come from several different transparent tables.
1. Views
2. Search Help
3. Lock Objects
Lets look into them in detail
Views
Views in SAP _ ABAP are used to summarize data which is distributed among
several tables
The data of a view is not actually physically stored. The data of a view is
instead derived from one or moreother tables
It is tailored to the needs of a specific application
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 10/17
Search Help
A Search help is a tool to help you search for data records in the system
An efficient and user-friendly search assists users where the key of a record is
unknown
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 11/17
Lock Objects Simultaneous accessing of the same data record by two users in the SAP
system is synchronized by a lock mechanism.
Locks are set and released by calling certain function modules. These function
modules are generated automatically from the definition of so-called lock objects in
the ABAP/4 Dictionary
Function modules : Enqueue_<obj name> - to lock the table dequeue_<obj name> -
to release the lock
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 12/17
Important Transactions
SE11 : Data Dictionary Initial Screen (SE12 Display only)
SE13 : ABAP Dictionary : Technical Settings
SE14 : Database Utility
SE15 : Repository Information System
SE16 : Data Browser
SE17 : General table Display
SE55 : Table View Maintenance
SM30 : Table Maintenance
Modularity in ABAP:Macro,Include,Subroutines,Function
Modules & GroupsWhen you modularize source code, you place a sequence of ABAPstatements in a
module. Then, instead of placing all of the statements in your main program, you just
call the module.When the program is generated, the source code in the modularization
unit is treated as though it were actually physically present in the main program.
Need of Modularization
Improve the structure of the program.
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 13/17
Easy to read the code
Easy to maintain the code
Avoid redundancy and promotes code reuse
Various Modularization Techniques
Use of Macros
Use of include files
Subroutines
Function Modules
Let’s look into each of them in detail :
SAP- ABAP MacroIf you want to reuse the same set of statements more than once in a program, you can
include them in a macro. You can only use a macro within the program in which it is defined, and it can only be
called in lines of the program following its definition.
Macros can be useful for long calculations or complex WRITE statements.
Syntax
1
23
4
5
DEFINE <macro_name>
'Macro Statements
END-OF-DEFINITION
Macros can use Parameters & N where N = 1,2,3...
Example:-
1
2
34
5
6
7
8
9
10
11
12
13
DATA: number1 TYPE I VALUE 1.
DEFINE increment.
ADD 1 to &1.
WRITE &1.
END-OF-DEFINITION.
Increment number1.
WRITE number1.
Output: 2
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 14/17
Include ProgramsInclude Programs are solely for modularizing source code, and have no parameter
interface. Include programs allow you to use the same source code in different
programs. They can be useful if you have lengthy data declarations that you want touse in different programs.
Syntax
1 Include <include program Name>
Points to Note
Include programs cannot call themselves.
Include programs must contain complete statements.
Example:
1
2
3
4
5
6
7
8
9
INCLUDE ZILX0004.
WRITE: / 'User', SY-UNAME,/ 'Date', SY-DATUM.
================================
PROGRAM ZRPM0001.
INCLUDE ZILX0004.
SubroutinesSubroutines are procedures that you can define in any ABAP program and also call
from any program. Subroutines are normally called internally, that is, they contain
sections of code or algorithms that are used frequently locally. If you want a function
to be reusable throughout the system, use a function module.
Syntax-
12
3
4
5
FORM <Subroutine> [<pass>].
<Statement block>.
ENDFORM.
<Subroutine> = Name of the subroutine
<pass> = Parameters being passed
Types of Subroutines
1.
Internalo
Subroutine defined in same program being called.
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 15/17
o Can access all the data objects declared in the main ABAP/4 program.
2. External
o Subroutine defined outside the program being called.
o Need to use the <pass> option or declare data objects in common parts
of memory.
Calling a Subroutine I nternal Subroutines
1 PERFORM <subroutine> [<pass>]
<subroutine> = Name of the subroutine
<pass> = Parameters being passed
Data declared in main program is automatically available.
External Subroutines
1
2
3
4
5
6
7
PERFORM <subroutine>(<Program>) [<pass>].
PERFORM <subroutine> (<Program>) [<pass>] [IF FOUND].
PERFORM (<subroutine>) IN PROGRAM (<Program>) [<pass>] [IF FOUND].
PERFORM <index> OF <subroutine1> <subroutine2> <subroutine3> [<pass>].
Points to Note
Nested calls are allowed in subroutines (i.e. PERFORM within a FORM ...ENDFORM ).
Recursive calls are also possible.
To define local data, use the DATA statement after FORM . Each time you
enter the subroutine, the data is recreated (with an initial value) and released at the
end (from the stack).
To define global data used within a subroutine, use the LOCAL statement after
FORM . The values are saved when you enter the subroutine and then released at
the end (from the stack)
Function ModulesFunction Modules are general purpose ABAP/4 routines that anyone can use. Infact ,
there are a large number of standard function Modules available.
Function Modules are organized into Function Groups: Collections of logically related
functions. A Function module always belongs to a Function Group.
Syntax-
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 16/17
1
2
3
4
5
FUNCTION <function module>
<Statements>
ENDFUNCTION.
Important information Associated with Function Module
Administration
Import/Changing/Export parameters.
Table Parameters/Exceptions.
Documentation
Source code - L<fgrp>U01 . <fgrp> is the Function Group
Global Data - L<fgrp>TOP .Global data for the function group- Accessible
across function modules in the function group.
Main Program - SAPL<fgrp> . Contains the list of all the include files for thatfunction group
Call a Function Module
To call a function module, use the CALL FUNCTION statement:
1
2
3
4
56
7
8
9
10
11
12
13
CALL FUNCTION <module>
[EXPORTING f1 = a 1.... f n = a n]
[IMPORTING f1 = a 1.... f n = a n]
[CHANGING f1 = a 1.... f n = a n]
[TABLES f1 = a 1.... f n = a n]
[EXCEPTIONS e1 = r 1.... e n = r n [ERROR_MESSAGE = r E]
[OTHERS = ro]].
Function GroupsFunction groups are containers for function modules. Infact, there are a large number
of standard Function Groups. All of the function modules in a function group can
access the global data of the group.
Like executable programs (type 1) and module pools (type M), function groups can
contain screens, selection screens, and lists.
Points to Note
Function Groups cannot be executed.
The name of a function group can be up to 26 characters long.
7/21/2019 1-Introduction to ABAP
http://slidepdf.com/reader/full/1-introduction-to-abap 17/17
When you create a function group or function module, the main program and
include programs are generated automatically.
Function groups encapsulate data.
How to create a Function Group
1. Goto Transaction SE80.
2. Select Program in the DropDown.
3. Write the name of the Function Group That you want to create. Generally User
made Function groups start with "Z". e.g. - <Z_FUNCTION_GROUP_NAME> .
Hit Enter Key.
4. Note that The TOP Include is create by default if the user checks the option of
creating a TOP include.
How to create a Function Module
1. Create a function Group (say " ZCAL").
2. Create a function module, set the attributes like (Function group, Application,
Short Text and Process Type) and Save.
3. Include file " LZCALU01" will have source code of first function module.
4.
Include file " LZCALTOP " will have global data.
5. Main program "SAPLZCAL" contains
o
Global data Include file " LZCALTOP "o Function modules include file " LZCALUXX "
o User defined Include files " LZCALF ..", " LZCALO.." and " LZCALI .."
6. Define interface parameters and Exceptions
7. Write the source code
8. Activate Function Module
9. Testing the Function Module - Single Test & Debugging
10. Documenting and Releasing a Function Module