Sap Abap
Sap Abap
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.
Note, this tutorial will not go into extensive details on ABAP language
constructs (which become very boring to read ) but quickly introduce
key concepts to get you started so you can focus your attention on more
important topics.
Data
Initial field Valid field Initial
Typ Meaning
length length value
e
Numeric types
P 8 1 – 16 0 Packed number
Character types
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
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
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
Finally , here is where you will spent most of your time as a developer
creating / modifying programs. Transaction SE38
SAP ABAP Data Dictionary (SE11)
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
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)
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.
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.
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
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 more other tables
It is tailored to the needs of a specific application
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
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
Need of Modularization
Use of Macros
Use of include files
Subroutines
Function Modules
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.
Syntax
DEFINE <macro_name>
'Macro Statements
END-OF-DEFINITION
Macros can use Parameters &N where N = 1,2,3…
Example:-
DATA: number1 TYPE I VALUE 1.
DEFINE increment.
ADD 1 to &1.
WRITE &1.
END-OF-DEFINITION.
Increment number1.
WRITE number1.
Output: 2
Include Programs
Include 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 to use in different programs.
Syntax
Include <include program Name>
Points to Note
Example:
INCLUDE ZILX0004.
================================
PROGRAM ZRPM0001.
INCLUDE ZILX0004.
Subroutines
Subroutines 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-
FORM <Subroutine> [<pass>].
<Statement block>.
ENDFORM.
<Subroutine> = Name of the subroutine
Types of Subroutines
1. Internal
Subroutine defined in same program being called.
Can access all the data objects declared in the main ABAP/4
program.
2. External
Subroutine defined outside the program being called.
Need to use the <pass> option or declare data objects in
common parts of memory.
Calling a Subroutine
Internal Subroutines
PERFORM <subroutine> [<pass>]
<subroutine> = Name of the subroutine
External Subroutines
PERFORM <subroutine>(<Program>) [<pass>].
Function Modules
Function Modules are general purpose ABAP/4 routines that anyone can
use. Infact , there are a large number of standard function Modules
available.
Syntax-
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 that function group
[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]
[OTHERS = ro]].
Function Groups
Function 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