Professional Documents
Culture Documents
ABAP - Sintaxa
ABAP - Sintaxa
ABAP Repository -> contine toate obiectele SAP din sistem independent de client
contine atat obiecte standard SAP cat si obiectele custom (create la cerinta
clientului
obiectele sunt disponibile in toti clientii sistemului
contine: programe, functii, definitii ale tabelelor, tipuri de date, clase etc.
ABAP Repository este impartit in functie de componenta de aplicatie (de ex
MM); aceste componente sun ierarhizate intr-o structura arborescenta (in
principiu pe module si sub-module; sub ele se afla pachetele)
In cadrul unei componente obiectele sunt impartite logic in pachete; fiecare
obiect trebuie sa fie atribuit unui pachet
Tool-uri de Workbench:
o ABAP Editor(SE38) – pentru editarea codului
o ABAP Dictionary(SE11) – pentru crearea si editarea obiectelor de baza de date(tabele,
elemente de date, domenii, table views etc)
o Screen painter(SE51) – utilizat pentru crearea layouturilor ecranelor folosite in
progamele ABAP
o Menu painter(SE41) – pentru configurarea meniurilor
o Function Builder(SE37) – pentru crearea si modificarea functiilor SAP(Function modules)
o Class Builder(SE24) – pentru lucrul cu clase si interfete globale (ABAP OO)
o Object Navigator(SE80) – ofera acces la toate cele de mai sus + obiecte de transport and
others
Crearea programelor ABAP
o Dezvoltarea progamelor ABAP se realizeaza in sistemul de dezvoltare, apoi se transporta
catre sistemele de Quality Assurance si Productiv cu ajutorul Transport
Organizer(SE09/SE10/SE01)
SINTAXA
Introductory Statements for Programs (In blue the most common ones)
Procedures
FUNCTION ... ENDFUNCTION Defines a function module
METHOD ... ENDMETHOD Defines a method
Dialog Modules
MODULE ... ENDMODULE Defines a dialog module
Event Blocks
AT LINE-SELECTION List Event
AT SELECTION-SCREEN Selection Screen Event
AT USER-COMMAND List Event
END-OF-PAGE List Event
END-OF-SELECTION Reporting Event
GET Reporting Event
INITIALIZATION Reporting Event
LOAD-OF-PROGRAM Program Constructor Event
START-OF-SELECTION Reporting Event
TOP-OF-PAGE List Event
Declarative Statements
Object Creation
Calling Programs
Control Structures
Program Interruption
Exception Handling
Assignments
Special Assignments
Setting References
Calculation Statements
CONVERT INTO TIME STAMP Converts date and time into time stamp
CONVERT TIME STAMP Converts a time stamp into data and time
GET TIME Fills the system fields for date and time
GET TIME STAMP Creates a time stamp
Internal Tables
Meshes
Open SQL
Native SQL
EXEC SQL ... ENDEXEC Defines an area for embedded Native SQL.
Data Clusters
File Interface
Program Parameters
SAP Memory
Language Environment
Program Editing
OLE Interface
User Dialogs
Dynpros
Selection Screens
Lists
Messages
Enhancements
Native SQL
EXIT FROM SQL Exits implicit cursor processing of Native SQL
Contexts
Internal Statements
Program Editing
External Interface
Operators
o ABAP contains the following operators:
Operators that perform special operations in operand positions:
Declaration operators
The declaration operators DATA and FIELD-SYMBOL declare variables or field
symbols in operand positions.
Constructor operators
The constructor operators NEW, VALUE, CONV, CORRESPONDING, CAST, REF,
EXACT, REDUCE, FILTER, COND, and SWITCH construct values for data objects of
specific data types in constructor expressions.
Assignment operators
The assignment operator = joins the source field and target field of an
assignment. In the case of assignments, the special casting operator ?= performs
a down cast. The operator = also joins actual parameters with formal
parameters, for example in procedure calls or when working with data clusters.
Arithmetic operators
The arithmetic operators +, -, *, /, DIV, MOD, and ** join two or more numeric
operands with an arithmetic expression. In addition, the characters + and - act
as plus/minus signs in arithmetic expressions.
Bit operators
The bit operators BIT-AND, BIT-OR, and BIT-XOR join two or more byte-like
operands with a bit expression. The bit operator BIT-NOT negates a byte-like
operand.
String operators
The string operator && chains two character-like operands to a string
expression.
Relational operators
Relational operators occur in relational expressions, which themselves are
components of logical expressions. The relational operators =, <>, <, >, <=,>=,
BETWEEN, and so on join two or more operands of any data type as a
comparison expression. There are additional relational operators for specific
data types. The predicate operator IS qualifies an operand.
Boolean operators
The Boolean operators AND, OR, and EQUIV join the results of individual logical
expressions with a logical expression. The result of a logical expression is either
true or false. The Boolean operator NOT negates the result of a logical
expression.
The type of an ABAP program determines (among other things) which declarations and processing
blocks a program can contain and how the program can be executed in the ABAP runtime environment.
The following table shows all program types for standalone programs (compilation units) and how the
attributes of the programs are affected by the type.
Text
Program Type Execution Global Declarations Processing Blocks Dynpros
Pools
Statement SUBMIT or a
Local interfaces and
Executable dynpro or selection All (except function
classes, all other Yes Yes
program screen is called using a modules)
declarative statements
transaction code
A global class from the
Call of a visible method class library, local
Class pool or a call using a interfaces and classes, Methods only No Yes
transaction code statements TYPES and
CONSTANTS
A function module is
Function called using CALL Local interfaces and All (except event
group or FUNCTION or a dynpro is classes, all other blocks for reporting Yes Yes
function pool called using a declarative statements events)
transaction code
A global interface from
Interface pool None None No No
the class library
All (except function
Local interfaces and
A dynpro is called using modules and event
Module pool classes, all declarative Yes Yes
a transaction code blocks for reporting
statements
events)
Event block LOAD-
External call of local Local interfaces and
Subroutine OF-PROGRAM,
procedures (subroutines classes, all other No Yes
pool subroutines,
or methods) declarative statements
methods
Type group or None Statements TYPES and None No No
type pool CONSTANTS
The second column of the table shows which category of execution the program type is designed for.
The third column shows which declarations can be made in the global declaration section of a program
with the specified type. The fourth column shows which processing blocks the program can contain. The
fifth indicates whether the program can support its own dynpros. The final column indicates whether
the program can create its own text pools.
The type of an ABAP program determines (among other things) which declarations and processing
blocks a program can contain and how the program can be executed in the ABAP runtime environment.
The following table shows all program types for standalone programs (compilation units) and how the
attributes of the programs are affected by the type.
Text
Program Type Execution Global Declarations Processing Blocks Dynpros
Pools
Statement SUBMIT or a
Local interfaces and
Executable dynpro or selection All (except function
classes, all other Yes Yes
program screen is called using a modules)
declarative statements
transaction code
A global class from the
Call of a visible method class library, local
Class pool or a call using a interfaces and classes, Methods only No Yes
transaction code statements TYPES and
CONSTANTS
A function module is
Function called using CALL Local interfaces and All (except event
group or FUNCTION or a dynpro is classes, all other blocks for reporting Yes Yes
function pool called using a declarative statements events)
transaction code
A global interface from
Interface pool None None No No
the class library
All (except function
Local interfaces and
A dynpro is called using modules and event
Module pool classes, all declarative Yes Yes
a transaction code blocks for reporting
statements
events)
Subroutine External call of local Local interfaces and Event block LOAD- No Yes
pool procedures (subroutines classes, all other OF-PROGRAM,
subroutines,
or methods) declarative statements
methods
Type group or Statements TYPES and
None None No No
type pool CONSTANTS
The second column of the table shows which category of execution the program type is designed for.
The third column shows which declarations can be made in the global declaration section of a program
with the specified type. The fourth column shows which processing blocks the program can contain. The
fifth indicates whether the program can support its own dynpros. The final column indicates whether
the program can create its own text pools.
The type of an ABAP program determines (among other things) which declarations and processing
blocks a program can contain and how the program can be executed in the ABAP runtime environment.
The following table shows all program types for standalone programs (compilation units) and how the
attributes of the programs are affected by the type.
Text
Program Type Execution Global Declarations Processing Blocks Dynpros
Pools
Statement SUBMIT or a
Local interfaces and
Executable dynpro or selection All (except function
classes, all other Yes Yes
program screen is called using a modules)
declarative statements
transaction code
A global class from the
Call of a visible method class library, local
Class pool or a call using a interfaces and classes, Methods only No Yes
transaction code statements TYPES and
CONSTANTS
A function module is
Function called using CALL Local interfaces and All (except event
group or FUNCTION or a dynpro is classes, all other blocks for reporting Yes Yes
function pool called using a declarative statements events)
transaction code
A global interface from
Interface pool None None No No
the class library
All (except function
Local interfaces and
A dynpro is called using modules and event
Module pool classes, all declarative Yes Yes
a transaction code blocks for reporting
statements
events)
Subroutine External call of local Local interfaces and Event block LOAD- No Yes
pool procedures (subroutines classes, all other OF-PROGRAM,
or methods) declarative statements subroutines,
methods
Type group or Statements TYPES and
None None No No
type pool CONSTANTS
The second column of the table shows which category of execution the program type is designed for.
The third column shows which declarations can be made in the global declaration section of a program
with the specified type. The fourth column shows which processing blocks the program can contain. The
fifth indicates whether the program can support its own dynpros. The final column indicates whether
the program can create its own text pools.
The data objects of the numeric data types are used to handle number values.
Properties
Initial
Type Value Range
Value
b 0 to 255 0
s -32,768 to +32,767 0
i -2,147,483,648 to +2,147,483,647 0
The valid length for packed numbers is between 1 and 16 bytes; two places are packed into
one byte, where the last byte only contains one place and the sign (the number of places
or digits is calculated from 2 * len-1); after the decimal separator, up to 14 decimal places
p are permitted. Depending on the field length len and the number of decimal places dec, 0
the following applies to the value range: (-10^(2len-1) +1) / (10^(+dec)) to (+10^(2len-1) -1)
/(10^(+dec)) in increments of 10^(-dec); any intermediate values are rounded (decimal);
invalid content produces undefined behavior.
decfl Decimal floating point numbers of this type are represented internally with 16 places in 0
accordance with the IEEE-754-2008 standard; valid values are numbers between 1E385(1E-
16 - 1) and -1E-383 for the negative range, 0 and +1E-383 to 1E385(1 - 1E-16) for the
oat1
positive range. Values lying between the ranges form the subnormal range and are
6
rounded; outside of the subnormal range, each 16-digit decimal number can be
represented precisely with a decimal floating point number of this type
Decimal floating point numbers of this type are represented internally with 34 places in
accordance with the IEEE-754-2008 standard; valid values are numbers between
decfl
1E6145(1E-34 - 1) and -1E-6143 for the negative range, 0 and +1E-6143 and 1E6145(1 - 1E-
oat3 0
34) for the positive range. Values lying between the ranges form the subnormal range and
4
are rounded; outside of the subnormal range, each 34-digit decimal number can be
represented precisely with such a decimal floating point number
Binary floating point numbers are represented internally in accordance with the IEEE-754
standard (double precision); in ABAP, 17 places are represented (one integer digit and 16
decimal places). Valid values are numbers between -1.7976931348623157E+308 and -
f 2.2250738585072014E-308 for the negative range and between +2.2250738585072014E- 0
308 and +1.7976931348623157E+308 for the positive range, plus 0. Both validity intervals
are extended in the direction of zero using subnormal numbers in accordance with the
IEEE-754 standard.
Predefined Numeric Types
The data objects of the numeric data types are used to handle number values.
Properties
Type Length Standard Length Name
b 1 byte 1-byte integer (internal)
s 2 byte 2-byte integer (internal)
i 4 byte 4-byte integer
p 1 to 16 bytes 8 byte Packed number
decfloat16 8 byte Decimal floating point number with 16 places
decfloat34 16 byte Decimal floating point number with 34 places
f 8 byte Binary floating point number with 17 places
T Value Range
b 0 to 255
s -32,768 to +32,767
i -2,147,483,648 to +2,147,483,647
The valid length for packed numbers is between 1 and 16 bytes; two places are packed into one byte,
where the last byte only contains one place and the sign (the number of places or digits is calculated
from 2 * len-1); after the decimal separator, up to 14 decimal places are permitted. Depending on the
p
field length len and the number of decimal places dec, the following applies to the value range: (-
10^(2len-1) +1) / (10^(+dec)) to (+10^(2len-1) -1) /(10^(+dec)) in increments of 10^(-dec); any
intermediate values are rounded (decimal); invalid content produces undefined behavior.
decfl Decimal floating point numbers of this type are represented internally with 16 places in accordance
with the IEEE-754-2008 standard; valid values are numbers between 1E385(1E-16 - 1) and -1E-383 for
oat1 the negative range, 0 and +1E-383 to 1E385(1 - 1E-16) for the positive range. Values lying between the
6 ranges form the subnormal range and are rounded; outside of the subnormal range, each 16-digit
decimal number can be represented precisely with a decimal floating point number of this type
Decimal floating point numbers of this type are represented internally with 34 places in accordance
decfl with the IEEE-754-2008 standard; valid values are numbers between 1E6145(1E-34 - 1) and -1E-6143
oat3 for the negative range, 0 and +1E-6143 and 1E6145(1 - 1E-34) for the positive range. Values lying
4 between the ranges form the subnormal range and are rounded; outside of the subnormal range, each
34-digit decimal number can be represented precisely with such a decimal floating point number
Binary floating point numbers are represented internally in accordance with the IEEE-754 standard
(double precision); in ABAP, 17 places are represented (one integer digit and 16 decimal places). Valid
values are numbers between -1.7976931348623157E+308 and -2.2250738585072014E-308 for the
f
negative range and between +2.2250738585072014E-308 and +1.7976931348623157E+308 for the
positive range, plus 0. Both validity intervals are extended in the direction of zero using subnormal
numbers in accordance with the IEEE-754 standard.
The following table shows the predefined generic ABAP types. A generic data type is an incomplete type
specification that includes multiple complete type specifications. With the exception of object, all
generic types can be used after TYPE for the typing of field symbols and formal parameters. When a data
object is assigned to generically typed field symbols using the statement ASSIGN, or to a formal
parameter in procedure calls, the system checks whether its concrete data type is compatible with it,
that is whether it is a subset of the generic type.
The only generic types that can be used after TYPE REF TO are data, for the generic typing of data
references, and object for the generic typing of object references.
Type Description
any Any data type
any table Internal table with any table category
c Text field with a generic length
clike Character-like (c, d, n, t, string, and character-like flat structures)
csequence Text-like (c, string)
data Any data type
decfloat Decimal floating point number (decfloat16, decfloat34)
hashed table Hashed table
index table Index table
n Numeric text with generic length
numeric Numeric (i (b, s), p, decfloat16, decfloat34, f)
object Any object type (root class of the inheritance hierarchy)
p Packed number with generic length and generic number of decimal places
Elementary data type including structured types with exclusively character-like flat
simple
components
sorted table Sorted table
standard table Standard table
table Standard table
x Byte field with generic length
xsequence Byte-like (x, xstring)
ABAP predefined data types such as Char, Date, Time, integer ABAP
Code
*& TITLE: ABAP predefined data types such as Char, Date, Time, integer
*&-------------------------------*
*& Report ZABAP_DATA_TYPES
*&-------------------------------*
*& Simple ABAP code to demonstrate the predefined ABAP data types.
*& Note you would usually have all the WRITE statements after all the data
*& declarations but just makes it clearer to put them together for this
example
*&-------------------------------*
REPORT ZABAP_DATA_TYPES.
*Type I (Integer)
*----------------
*This is the basic numeric integer type which only accepts whole numbers
DATA: ld_int type I.
ld_int = 200.
WRITE:/ ld_int.
*Type C (Character)
*------------------
*This is an alpha numeric text value of what ever lenght you specify up
*to the maximum length
DATA: ld_char type c, "length = 1
ld_char2(30) type c value 'Hello'. "length = 30
WRITE:/ ld_char2.
*Type D (Date)
*-------------
*This field stores a date value in the format YYYYMMDD
DATA: ld_date type d value '19991230',
ld_date2 type begda. "using a dictionary type
*Type N (Numeric)
*----------------
*This stores a numeric text value, fills any unused capacity with zeros
DATA: ld_numc type n, "1 char long
ld_numc2(10) type n value 1025. "30 chars long
WRITE:/ ld_numc2. "0000001025
*Type T (Time)
*-------------
*This stores a time value, the value is stored in seconds but displayed in
HHMMSS
DATA: ld_time type t value 1, "displayed as 00:00:01 i.e. 1 second
ld_time2 type t value 60, "displayed as 00:01:00 i.e. 1 minute
ld_time3 type t value 3661. "displayed as 01:01:01 i.e. 1 hour,1
minute & 1 second
WRITE:/ ld_time, "000001
/ ld_time2, "000100
/ ld_time3. "010101
*Type X (Hexadecimal)
*--------------------
*This stores a hexadecimal values, could be used for creating files and
inserting
*hexedecimal characters to insert tabs a new line
DATA: ld_hex type x value '09', "Tab
ld_hex2 type x value '0D'. "Carriage Return(new line)
WRITE:/ ld_hex,
/ ld_hex2.
**********************
*END-OF-SELECTION.
END-OF-SELECTION.