Chapter 04 - ABAP Data Declarations
Chapter 04 - ABAP Data Declarations
Dec-2008
Objectives
The participants will be able to :
List ABAP elementary data types
Declaring variables
List user-defined data types
Use arithmetic expressions
List field-symbols
Dec-2008
C: Character Text
N: Numeric Text
I: Integer
D: Date
P: Packed #
T: Time
F: Floating Point #
X: Hexadecimal #
STRING
XSTRING
Dec-2008
C: Character Text
N: Numeric Text
I: Integer
D: Date
P: Packed #
T: Time
F: Floating Point #
X: Hexadecimal #
STRING
XSTRING
Dec-2008
Declaring Variables
DATA:
PLAYER(35) TYPE C,
NICKNAME(35),
POINTS
TYPE I,
GAMES
TYPE I
AVERAGE(5) TYPE P,
STARTER,
ACQUIRED TYPE D.
VALUE 10,
Dec-2008
Initial Values
C: (blank)
N: zeroes
I: zero
D: 00000000
P: zero
T: 000000
F: zeroes
X: 00
Dec-2008
DATA:
PLAYER(35) TYPE C,
NICKNAME(35)
POINTS
TYPE I
GAMES
TYPE I
AVERAGE(5) TYPE P
STARTER
ACQUIRED TYPE D
VALUE Dr. J,
VALUE 255,
VALUE 10,
VALUE 25.5,
VALUE Yes,
VALUE 19760610.
Dec-2008
DATA:
DATA:
PLAYER(35)
NICKNAME
ACQUIRED
Dec-2008
Declaring Constants
CONSTANTS: TEAM1(20)
TYPE C
VALUE 76ers,
TEAM2
TYPE TEAM1
VALUE Celtics,
TOT_GAMES TYPE I
VALUE 82.
Dec-2008
TYPES:
NAME(35)
TEAMS(20)
DATA:
PLAYER
NICKNAME
CONSTANTS: TEAM1
TEAM2
TYPE C,
TYPE C.
TYPE NAME VALUE Troy Aikman,
TYPE PLAYER.
TYPE TEAMS VALUE Cowboys,
TYPE TEAM1
VALUE Packers.
10
Dec-2008
11
Justification
C = defined length
C = left-justified
I = 12
I = right-justified
P = (2 * defined length) + 1
P = right-justified
F = 22
F = right-justified
N = defined length
N = left-justified
D = 10
D = left-justified
T =8
T = left-justified
X = (2 * defined length)
X = left-justified
Dec-2008
FLOAT
PACK
INT
TYPE F
TYPE P
TYPE I
VALUE 98.7654321E2,
VALUE 12,
VALUE 32.
WRITE: / FLOAT,
/ FLOAT EXPONENT 1 DECIMALS 3,
/ FLOAT EXPONENT 0 DECIMALS 2,
/ PACK,
/ PACK DECIMALS 1,
/ INT DECIMALS 2.
12
9.876543210000000E+03
987.654E+01
9876.54
12
12.0
32.00
Dec-2008
Demonstration
Declaring variables and constants.
13
Dec-2008
Practice
Declaring variables and constants.
14
Dec-2008
<field>.
<field>.
<value>.
<value>.
TITLE(25),
SALARY TYPE P,
CNVSALARY TYPE SALARY,
15
Dec-2008
Arithmetic Expressions
Operators
+ - * / **
DIV and MOD
Functions
SQRT, EXP, LOG,
SIN, COS, STRLEN, . . .
COUNTER = COUNTER + 1.
SALARY = BASE * BONUS_PERCENT.
LENGTH = STRLEN( NAME ).
ANSWER = ( 10 + SQRT( NUM1 ) ) / ( NUM2 - 10 ).
16
Dec-2008
Sub-Fields in ABAP
17
90 xx 1996
123456ABCD ----- 06/01/1996
Dec-2008
= 19621230.
= SY-DATUM.
18
Dec-2008
Demonstration
Assigning values to the fields and doing calculations.
19
Dec-2008
Practice
Assigning values to the fields and doing calculations.
20
Dec-2008
PARAMETERS:
NUM TYPE I,
NAME(20) DEFAULT AARON.
ADD 10 TO NUM.
WRITE: / NUM,
----,
NAME.
Selection Screen
21
Dec-2008
Selection Texts
Dec-2008
Demonstration
Creation of a selection screen and displaying the value in the report.
23
Dec-2008
Practice
Creation of a selection screen and displaying the value in the report.
24
Dec-2008
A field symbol is a
pointer that assumes a
fields address, not a
fields value.
12
32
12
32
Dec-2008
12
32
IBM Corporation 2013
Demonstration
Working with Field Symbols.
26
Dec-2008
Practice
Working with Field Symbols.
27
Dec-2008
FIELD-SYMBOLS <FSYMBOL>.
ASSIGN TEXT_LINE+2(5) TO <FSYMBOL>.
* this assigns 5 characters of text_line starting at
* position 3 to the field string.
WRITE: / Text Line =, TEXT_LINE.
ULINE.
WRITE: / Field Symbol=, <FSYMBOL>.
ULINE.
<FSYMBOL> = 1234567890.
WRITE: / Field Symbol =, <FSYMBOL>.
ULINE.
WRITE: / Text Line =, TEXT_LINE.
28
Dec-2008
FIELD
SY-UZEIT
Selection Screen
List
Dec-2008
Demonstration
Dynamic assignment with the Field Symbol.
30
Dec-2008
Practice
Dynamic assignment with the Field Symbol.
31
Dec-2008
Summary
DATA statement is used to declare a variable (or field) in an ABAP program
"LIKE" and "TYPE" statements are used to declare fields with reference to other
variables or fields
CONSTANTS statement is used to declare a constant
Text elements can be used to maintain a programs title and column headings,
selection texts, and text symbols. These text elements can be maintained in
multiple languages
A field symbol does not reserve space for the field, but points to the field
ASSIGN statement associates a field to a field symbol at runtime
The system carries out automatic type conversion if variables are not of the same
type
ABAP allows to display and change portions of a field by specifying an offset and
length
32
Dec-2008
Questions
What are the different types of data types?
What is a field symbol ? What is the advantage of using it in the program?
How to create a selection screen with the selection screen text?
33
Dec-2008