ABAP predefined data types such as Char, Date, Time, integer



Simple ABAP code to demonstrate the ABAP predefined data types such as Char, Date, Time, integer. 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

ABAP code list to demonstrate data types

*&-------------------------------*
*& Report  ZABAP_DATA_TYPES
*&-------------------------------*
*&-------------------------------*
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 F (Floating point number)

This is a numeric value with decimal places used for calculation results

DATA: ld_float  type f.
ld_float = ld_int / 22.
WRITE:/ ld_float.

Type P (Packed number)

This is a numeric value with decimals places, packed data types also allow you to define the number of decimal places

DATA: ld_packed type p decimals 2 value '88.345'.
WRITE:/ ld_packed. "notice because it is only 2 decimal places the value is rounded

Type C (Character)

This is an alphanumeric text value of whatever length 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

ld_date2 = sy-datum. "set value to today's date
*Although the value is stored in YYYYMMDD it is displayed in a different
*format either based on the users setting or specifying the output i.e.
WRITE:/ ld_date2 DD/MM/YYYY,
      / ld_date2 DDMMYY."etc

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 value could be used for creating files and inserting hexadecimal 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.

About the Author se80