Sunteți pe pagina 1din 16

ABAP Language Basics

ABAP (Advanced Business Application Programming) the propriety language of SAP; has
basically procedure oriented constructs. When it was created, (in the 1970s) there was no
OOPS technology application. The OOPS constructs in ABAP were incorporated sometime in
the beginning of the millennia. It is an interpreter driven language. Its limited repertoire of
statements and features at the time SAP R/3 release; (in 1992) have grown considerably.
The ABAP source programs are stored in the SAP database. The complied run time version,
much akin to the JAVA byte code is also stored in the SAP database. The maintenance of
ABAP source programs can be done only in the SAP environment i.e. you have to be logged in
into SAP to create, edit ABAP programs.
Again, the ABAP programs can only be executed in the SAP environment. The execution of
ABAP requires the ABAP run time environment, only available when you are logged in into SAP.
The SAP installation consists of a database server, one or more application servers and many
presentation servers. An ABAP run time code is extracted from the database, loaded into the
RAM of application server and executes in the application server and presentation server for
interaction with the user.
The ABAP run time environment is part of work processes, the work processes are in turn
components of the application server which is called the NetWeaver Application Server (AS)
ABAP.















ABAP Run Time Environment


NetWeaver Application Server - ABAP


Work Processes


ABAP Processor


Screen Processor


Database Interface





Database Management System


Database


ABAP Data TYPES


Data TYPES





Elementary TYPES Complex TYPES Reference TYPES

Structure Data
TYPES Reference

Table Object
TYPES Reference

Fixed Length Class
Reference
TYPE C
Interface
TYPE D Reference
Character types
TYPE N

TYPE T

TYPE F

TYPE I Numeric types

TYPE P

TYPE X (Hexadecimal)

Variable Length

TYPE STRING

TYPE XSTRING (Hexadecimal)



I. Elementary TYPES
In the Elementary TYPES, the Fixed Length (TYPES C, D, N, T, F, I, P, X) means that
either the length of this TYPE in inherently fixed (TYPES D, F, I, T) or while declaring a
data item; length in bytes is specified for that data item, the length of this data item
remains fixed all through its existence.
In the Variable Length, (TYPES STRING and XSTRING) the length of a data item is not
specified while declaring it, it varies during the execution of program as you assign data to it.
The bunching of Elementary TYPES as Character types is for the TYPES which store one
Unicode character/2 bytes.(16 bit Unicode) The bunching as Numeric types is for the TYPES
on which you can perform normal arithmetic operations. You can perform arithmetic operations
on elementary TYPE N, but it is not very advisable. You can perform date arithmetic on
elementary TYPE D, and time arithmetic on elementary TYPE T.

Data
TYPE

Initial
Size
(Bytes)
Valid
Size
(Bytes)
Initial
Value
Description
C 1 1-65535 SPACE Text, characters (alphanumeric - characters)
N 1 1-65535 '000
Numeric text, one decimal digit/byte. Will
accept only decimal digits 0-9. (Used for
assigning codes like employee code. Not to be
normally used in arithmetic)
D 8 8 00000000 Date, one digit/byte (format: YYYYMMDD)
T 6 6 '000000' Time, one digit/byte (format: HHMMSS)
X 1 1-65535 X'00'
Hexadecimal, two hexadecimal digits stored per
byte.

P

8

1 16

0
Packed number, two decimal digits per byte,
Maximum number of 31 digits. Half byte /
nibble taken up by the sign. Up to 14 digits
are allowed after the decimal. Used for
currencies, Quantities etc.
I 4 4 0
Integer (whole number) Number range +2
31
-1
to -2
31

F 8 8 0
Floating point number, Maximum value 10
307
.

Minimum value 10
-308
. The accuracy range is
approximately 15 decimals, depending on the
floating point arithmetic of the hardware
platform.


Data
TYPE

Initial
Size
(Bytes)
Valid
Size
(Bytes)
Initial
Value
Description
STRING 0
Like TYPE C, but the length changes at run
time as per the data stored in it.
XSTRING 0
Like TYPE X, but the length changes at run
time as per the data stored in it.
ABAP Elementary Data TYPES
The data TYPES D, F, I, and T are predefined in all respects including the size, but the data
TYPES C, N, P, and X can have additional specifications. For example, you can define /
specify the size of these data TYPES in the program in bytes, when data declaration is done.
For TYPE F and P, you can specify the number of decimals with the data declaration.
The Initial Size column specifies the default length a data item will assume, if its length is
not specified while declaring a data item.
ABAP elementary TYPES mapping with DDIC TYPES:

ABAP Elementary TYPES

DDIC TYPES

C CHAR
N NUMC
D DATS
T TIMS
X No exact mapping TYPE
P DEC
I INT4
F FLTP
STRING STRING
XSTRING No exact mapping TYPE


Complex TYPES
The Complex TYPES are categorized into the (a) Structure TYPES and (b) Table TYPES.

(a) In the Structure TYPES, Elementary TYPES, Structure TYPES (Structure embedded in a
Structure) are grouped together. Only the grouping of Elementary TYPES will be considered.
The grouping involving Structures (Structure/s embedded in a Structure nested Structures)
are an advanced feature beyond the scope of this course. When the Elementary TYPES are
grouped together, the data item can be accessed/addressed as a grouped data item or the
individual Elementary TYPES data items (fields of the Structure) can be accessed/addressed.

(b) The Table TYPES are what are called arrays in other programming languages. Arrays can
either be simple or Structure arrays. The arrays are called internal tables in ABAP. In
ABAP, the arrays / internal tables can be declared and operated upon in many more ways
than in other programming languages.

III. Reference TYPES (Discussion in OOPS context)
The Reference TYPES are used to refer to instances of classes, interfaces and run time data
items.

The ABAP OOPS Run Time Type Services (RTTS) enables declaration of data items at run
time. A reference variable of TYPE Data Reference is used to refer to instances of the run
time data items.

When an instance of a class is created, a reference variable of TYPE Class Reference is
used.

When an instance of an interface is created, a reference variable of TYPE Interface
Reference is used.

Either of the reference variables Class Reference or Interface Reference would be
categorized as Object Reference.

Discussion in OOPS context is over!


Data Objects in ABAP Programs
In an ABAP program, you can work with four kinds of data objects:
1) Internal data objects

Internal data objects are declared in a particular ABAP program. They do not have any
existence outside the particular program. Internal data objects are assigned RAM. Internal
data objects further categorization:

Literals (constants defined as part of a statement/command)
Variables
Constants

2) External data objects

External data objects exist independent of ABAP programs. You cannot work with them
directly, but you can copy them to internal data objects and write them back when you
have finished. External data objects can be used globally throughout the system
environment.
ABAP stores external data objects in tables defined in the DDIC. To access this data from
within a program, you declare the tables in the program with the TABLES or DATA
statement.

3) System-defined data objects

Besides user-defined data objects, some data objects are defined automatically by the
system. Some of the system defined data objects - SPACE, SY-SUBRC, SY-DATUM, SY-
UZEIT, SY-TCODE.

4) Special data objects

ABAP also includes some data objects with special features, namely:
- PARAMETERS
PARAMETERS are variables which are linked to a selection screen. They can accept values
after an ABAP program is started (inputting).
- Selection criteria - SELECT-OPTIONS
Selection criteria are special internal tables used to specify value ranges. They are also
linked to a selection screen. Set of values are accepted after a program is started (ranges
of values inputting).
All the data objects you want to work with in the programs, (except system data objects,
literal data objects) have to be declared. While declaring the data objects, you must assign
attributes to it. The most important of these attributes is the data TYPE.(except for TABLE
data object) In ABAP, you can either use predefined data TYPES similar to other program
languages, or user-defined data types.

The user-defined data TYPES in ABAP provide you with a powerful tool since they allow for
great flexibility in programming. They range from elementary TYPES (e.g. character strings
of a given length) to very complex structures (e.g. nested structures).

Assigning user-defined data TYPES to data objects allow you to work with precisely the data
objects you require. User-defined data TYPES can be used in the same way as predefined
data TYPES. You can declare them locally within a program or store them globally in the
ABAP Dictionary. (DDIC object: Type Group)

There are three hierarchical levels of data TYPES and objects:
program-independent data, defined in the ABAP Dictionary
internal data used globally in one program
data used locally in a procedure (subroutine, function module)

ABAP Program Components

ABAP programs are maintained in transaction code SE38

An ABAP program consists of five sub objects (see SE38 screen radio buttons) :-

1) Source code (source lines)
2) Variants (will be covered later), requires knowledge of Internal Tables and Selection
Screen.
3) Attributes (mandatory: Title, Type, (program type) and Package (local object/$TMP)
4) Documentation (no separate documentation in course of our exercises. Will comment
source lines profusely, making them self-documentary as well as self-explanatory)
5) Text elements, these in turn consist of (i) Text Symbols (ii) Selection Texts (will be
covered later)

The attributes (item 3) of an ABAP program consists of:

Title, equivalent of short description you were entering when creating DDIC objects.
Original language, logged in language code when the program was created (maintained by
the system)
Created, date of program creation, user id. (Maintained by the system)
Last changed by, last date of change, user id. (Maintained by the system)

Program Attributes area

o Type, program type is mandatory. A drop down list is available with the following
options:

Executable program program which can be executed.
Include Program the lines of these programs can be incorporated in other
programs.
Module Pool it contains screen flow logic modules.
Function group it contains function modules, which are generic routines. Cannot
be created in ABAP editor. (SE38) Is to be created in SE37, SE80
Subroutine Pool it contains external subroutines
Interface pool it contains interfaces. Cannot be created in ABAP editor. (SE38)
Is to be created in SE24.
Class pool it contains classes. Cannot be created in ABAP editor. (SE38) Is to
be created in SE24.
Type Pool it contains user defined TYPES. Cannot be created in ABAP editor.
(SE38) Is to be created in SE11.

XSLT Program. Cannot be created in ABAP editor. (SE38) Is to be created in
SE80.

o Status, this is optional program categorization. A drop down list is available with the
following options:

SAP Standard Production Program
Customer Production Program
System Program
Test Program

o Application, an optional entry. You can assign a program to an application. A drop
down list is available.

o Authorization Group, an optional entry. Authorization is a security feature. A pop-up
(F4) is available.

o Package, any object created in ABAP Workbench environment is to be assigned a
package. We are designating all our objects as local i.e. not transportable to other
implementation environments. We are assigning the SAP delivered package $TMP.

o Logical database, an optional entry. Logical database is basically a data retrieval re-
usable object. A Logical database created can be used by multiple programs
(programs which are retrieving similar data from almost the same database tables)
saving the effort of data retrieval in the programs using the Logical database. Works
slow. Still used in HR Module.

o Selection screen, an optional entry. Maintained by the system or goes along with the
Logical database. Will be covered in Chapter VII

o Editor lock checkbox, enabling this prevents other user ids. From editing the
program.

o Fixed point arithmetic check box, enabled by default. In business applications, you
perform mostly fixed point arithmetic not floating point arithmetic.

o Unicode checks active checkbox, to enable the program syntax checks relating to
Unicode.

o Start using variant check box, will be covered in Chapter VII.
ABAP Editors

ABAP Program Structure
Declaration Part - Global Data, Selection Screens and Local Classes
All global data declaration statements. (Global in the context of a program) Global data is
accessible in all internal processing blocks. You define it using declarative statements that
appear before the first processing block, in dialog modules, or in event blocks. You cannot
declare local data in dialog modules or event blocks.
All selection screen definitions.
All local class definitions (CLASS DEFINITION statement).
Data declaration statements made in procedures (methods, subroutines, function modules)
form the declaration part for local data in those processing blocks. This data is only
existent, accessible in the procedure in which it is declared.
Container for Processing Blocks
The second part of an ABAP program contains all of the processing blocks for the program.
The following types of processing blocks exist:
Dialog modules (no local data area, whatever data declared treated as global)
Event blocks (no local data area, whatever data declared treated as global)
Procedures (methods, subroutines and function modules with their own local data
definitions).

Basic Arithmetic Operations
===========================
Operator Meaning
-------- -------------
+ Addition
- Subtraction
* Multiplication
/ Division
DIV Integer division
MOD Remainder of integer division
** Exponeniation/Powers

Instead of using operators in mathematical expressions,
we can perform basic arithmetic operations with the
keywords ADD, SUBTRACT, MULTIPLY, and DIVIDE.


Functions for all numeric data types
====================================
Function Result
-------- ------------------
ABS Absolute value of argument.
SIGN Sign of argument:
1 X > 0
SIGN( X) = 0 if X = 0
-1 X < 0

CEIL Smallest integer value not smaller
than the argument.

FLOOR Largest integer value not larger
than the argument.

TRUNC Integer part of argument.

FRAC Fraction part of argument.


Assignments
==========
To assign the value of a data object <f1> to a variable
<f2>, use the following statement:

MOVE <f1> TO <f2>.

or the equivalent statement

<f2> = <f1>.

Assigning Values with WRITE TO

As well as the MOVE statement, which converts the
value of the source field into the data type of the
target field, there is also a statement WRITE TO,
which converts the contents of the source field
into a field with type C.

WRITE <f1> TO <f2> [<option>].

To reset a variable <f> to the appropriate initial value for
its type, use the statement

CLEAR <f>.
String Operations
TRANSLATE <c> TO UPPER CASE.
TRANSLATE <c> TO LOWER CASE.

CONDENSE <c> [NO-GAPS].
<n> = STRLEN( <c> ).
CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].
SPLIT <c> AT <s> INTO result1 result2 ...
SEARCH <c> FOR <str> STARTING AT <pos1> ending <pos2>.

INTERNAL FLOW CONTROL
=====================


CONDITION STATEMENTS
====================

**
IF <condition>.
.....
.....
ELSE.
.....
.....
ENDIF.

**
IF <condition>.
.....
.....
ELSEIF <condition>.
.....
.....
ENDIF.

**
IF <condition>.
.....
.....
IF <condition>.
.....
.....
ENDIF.
.....
.....
ENDIF.

CONDITIONAL OPERARORS
=====================

=, EQ Equal to
<>, NE Not equal to
>, GT Greater than
<, LT Less than
>=, GE Greater than or equal to
<=, LE Less than or equal to
CP CONTAINS PATTERN
NP DOES NOT CONTAIN PATTERN

****************************************************************
TESTING MUTUALLY EXCLUSIVE CONDITIONS (CASE)
============================================

CASE <var>.

WHEN f11.
.....
WHEN f21.
.....
.....
WHEN OTHERS.
.....
.....
ENDCASE.

****************************************************************

LOOPING CONSTRUCTS
==================

UNCONDITIONAL LOOP.
-------------------

**

DO.
.....
.....
IF <condition>.
EXIT.
ENDIF.
.....
IF <condition>.
CONTINUE.
ENDIF.
.....
ENDDO.

CONDITIONAL LOOPS.
------------------

**

DO <n> TIMES.
.....
IF <condition>.
CONTINUE.
ENDIF.
.....
ENDDO

**

WHILE <condition>.
.....
IF <condition>.
CONTINUE.
ENDIF.
.....
ENDWHILE.


NESTED LOOPS.
-------------

**

DO.
.....
.....
DO.
.....
IF <condition>.
EXIT.
ENDIF.
ENDDO.
.....
IF <condition>.
EXIT.
ENDIF.
.....
ENDDO.

**

DO <n> TIMES.
.....
DO <m> TIMES.
.....
.....
ENDDO.
.....
.....
ENDDO.

**

WHILE <condition>.
.....
DO.
.....
IF <condition>.
EXIT.
ENDIF.
.....
.....
ENDDO.
.....
.....
ENDWHILE.

SY-INDEX GIVES PASS NO OF CURRENT LOOP
---------------------------------------

S-ar putea să vă placă și