ABAPbeginner
ABAP Data Types & Variables
Understanding elementary data types, structures, and how ABAP stores and validates typed data.
A data type tells ABAP what kind of value a variable holds — text, a number, a date — and how much space it needs. Getting the type wrong is one of the most common sources of bugs in ABAP, which is why interviewers ask about it early.
Think of ABAP types like shipping containers of fixed sizes — you must declare the container size before packing goods into it, and forcing an oversized item into a small container truncates it.
Key Concepts
1
ABAP has eight built-in types. They are worth learning by what they are for, not by their letters:
2
C text of a fixed length names, codes, descriptions
N digits stored as text postcodes, document numbers
I whole number counters, quantities
P decimal number, exact money, rates -- see below
F decimal number, approximate scientific values only
D date, stored as YYYYMMDD 8 characters
T time, stored as HHMMSS 6 characters
X raw bytes binary data3
Use P for money, never F. This is the rule interviewers most often test. F is a floating-point
type. It cannot store some decimal values exactly, so 0.1 + 0.2 does not give exactly 0.3. Over thousands
of rows, those tiny errors add up into a total that does not match the ledger. P stores decimals exactly,
which is why it exists.
PF
4
When you declare a P field you must say how many decimal places you want:
DATA lv_amount TYPE p LENGTH 8 DECIMALS 2. Forget DECIMALS and ABAP rounds to a whole number, silently.
PDECIMALS
5
N looks like a number and behaves like text. A field of type N holds digits, but ABAP treats it as
characters. Leading zeros are kept, which is what you want for a document number like 0000001234.
Arithmetic on it works, but it is slower and the result may surprise you. If you need to calculate with a
value, use I or P.
N0000001234IP
6
Fixed-length text pads with spaces. A C field of length 10 holding "SAP" actually holds "SAP"
followed by seven spaces. Comparisons ignore those trailing spaces; string operations may not. This is why
two values that look equal on screen can behave differently in code.
C
7
STRING and XSTRING grow as needed. Unlike C and X, they have no fixed length. Use them when the
size varies, such as a long description. They cost a little more memory management, so they are not the
default for short, known-length fields.
STRINGXSTRINGCX
8
Declare types once and reuse them. Instead of repeating TYPE p LENGTH 8 DECIMALS 2 everywhere,
define it in the ABAP Dictionary as a data element and refer to that. If the business later needs three
decimal places, you change it in one place. This is what interviewers mean when they ask about "using the
Dictionary properly".
TYPE p LENGTH 8 DECIMALS 2
9
What the interviewer is probing.1. "Which type would you use for an amount?" Probing: whether you know why F is dangerous.
Stalls: "A decimal type." Moves up: P with explicit DECIMALS, because F cannot hold some values
exactly and the rounding errors accumulate.
FPDECIMALS
10
2. "What is the difference between N and I?" Probing: text versus number. Stalls: "Both hold
numbers." Moves up: N is digits stored as text and keeps leading zeros; I is a real number for
arithmetic.
NI
11
3. "What happens if you leave out DECIMALS?" Probing: attention to the detail that bites. Stalls:
"It defaults sensibly." Moves up: it rounds to whole numbers, and nothing warns you.
DECIMALS
12
4. "When would you use STRING instead of C?" Probing: fixed versus variable length. Stalls:
"They are the same." Moves up: STRING grows as needed; C is fixed and pads with spaces.
STRINGC
13
5. "Why declare types in the Dictionary?" Probing: maintainability. Stalls: "It is the standard."
Moves up: one definition, reused everywhere, so a change to length or decimals happens in one place.