ABAP Data Types and Literals
Elementary types, packed decimals, string vs char, and when to use TYPES vs DATA.
Explanation
ABAP has generic types (C, N, D, T, P, I, F, STRING, XSTRING) and complete types you declare with TYPES/DATA. STRING is dynamic-length; C(n) is fixed. P (packed) is used for currency/quantity with DECIMALS. NUMC preserves leading zeros. Always TYPES first, then DATA โฆ TYPE โ never use LIKE against dictionary structures in new code.
Code example
TYPES: BEGIN OF ty_line, matnr TYPE matnr, menge TYPE p LENGTH 13 DECIMALS 3, END OF ty_line.DATA lt_lines TYPE STANDARD TABLE OF ty_line WITH EMPTY KEY.Real project scenario
In an invoice interface, using STRING for material numbers instead of MATNR broke conversion exits and produced leading-zero mismatches against MARA.
Common mistakes
Using I for currency amounts; declaring C(1024) instead of STRING; missing DECIMALS on P types.
Best practices
Use dictionary types (MATNR, KUNNR, WAERS) so conversion exits and F4 help work automatically.
Interview angle
Interviewers ask why P is preferred for money and what CONVERSION EXIT ALPHA does.