SAP Data types
Data types define the kind and size of data an ABAP variable holds. ABAP has a rich type system, built-in elementary types, dictionary types, and complex types, and using the right types is fundamental to correct, maintainable programs.
ABAP has elementary built-in types, c, string, n, i, p, f, d, t and x among them, and Dictionary types such as MATNR that carry a field's length and meaning from the ABAP Dictionary. Declare with DATA and TYPE. Amounts use packed p or currency types, never float, because float rounds money. Dictionary typing keeps custom code consistent with SAP.
- Watch out: Using float (f) for money, use packed/currency types.
Elementary built-in types
- Character: c (fixed char), string (variable), n (numeric text).
- Numeric: i (integer), p (packed decimal, for amounts), f (float), and modern int8/decfloat.
- Date/time: d (date, YYYYMMDD), t (time).
- Byte: x (hex), xstring.
Dictionary types
Rather than hard-coding lengths, ABAP encourages typing from the ABAP Dictionary, data elements and domains that define a field’s type, length and semantics centrally. Typing a variable as, say, MATNR (material number) gives it the correct, consistent definition used across SAP.
Declaring variables
DATA: lv_count TYPE i,
lv_amount TYPE p LENGTH 9 DECIMALS 2,
lv_matnr TYPE matnr, " dictionary type
lv_text TYPE string.Why types matter
Correct types prevent truncation, rounding and conversion errors, especially for amounts (use packed p or currency/quantity dictionary types, never float for money). Dictionary typing also keeps custom code consistent with SAP’s data model.
Common pitfalls
- Using float (f) for money, use packed/currency types.
- Hard-coding lengths instead of dictionary types.
- Character/numeric confusion causing conversion errors.