ABAP - Data Types and Variables

Data Types and Variables

ABAP provides a set of built-in data types. In addition, every structure, table, view or data element defined in the ABAP Dictionary can be used to type a variable. Also, object classes and interfaces can be used as types.

The built-in data types are:

Type Description
I Integer (4-bytes)
P Packed decimal
F Floating point
N Character numeric
C Character
D Date
T Time
X Hexadecimal (raw byte)
STRING Variable-length string
XSTRING Variable-length raw byte array

Date variables or constants (type D) contain the number of days since January 1, 1 AD. Time variables or constants (type T) contain the number of seconds since midnight. A special characteristic of both types is that they can be accessed both as integers and as character strings (with internal format "YYYYMMDD" for dates and "hhmmss" for times), which makes date/time handling very easy. For example, the code snippet below calculates the last day of the previous month (note: SY-DATUM is a system-defined variable containing the current date):

DATA LAST_EOM TYPE D. "last end-of-month date * Start from today's date LAST_EOM = SY-DATUM. * Set characters 6 and 7 (0-relative) of the YYYYMMDD string to "01", * giving the first day of the current month LAST_EOM+6(2) = '01'. * Subtract one day LAST_EOM = LAST_EOM - 1. WRITE: 'Last day of previous month was', LAST_EOM.

All ABAP variables must be explicitly declared in order to be used. Normally all declarations are placed at the top of the code module (program, subroutine, function) before the first executable statement; this placement is a convention and not an enforced syntax rule. The declaration consists of the name, type, length (where applicable), additional modifiers (e.g. the number of implied decimals for a packed decimal field) and optionally an initial value:

* Primitive types: DATA: COUNTER TYPE I, VALIDITY TYPE I VALUE 60, TAXRATE(3) TYPE P DECIMALS 1, LASTNAME(20) TYPE C, DESCRIPTION TYPE STRING. * Dictionary types: DATA: ORIGIN TYPE COUNTRY. * Internal table: DATA: T_FLIGHTS TYPE TABLE OF FLIGHTINFO, T_LOOKUP TYPE HASHED TABLE OF FLT_LOOKUP. * Objects: DATA: BOOKING TYPE REF TO CL_FLT_BOOKING.

Notice the use of the colon to chain together consecutive DATA statements.

Read more about this topic:  ABAP

Famous quotes containing the words data, types and/or variables:

    Mental health data from the 1950’s on middle-aged women showed them to be a particularly distressed group, vulnerable to depression and feelings of uselessness. This isn’t surprising. If society tells you that your main role is to be attractive to men and you are getting crow’s feet, and to be a mother to children and yours are leaving home, no wonder you are distressed.
    Grace Baruch (20th century)

    As for types like my own, obscurely motivated by the conviction that our existence was worthless if we didn’t make a turning point of it, we were assigned to the humanities, to poetry, philosophy, painting—the nursery games of humankind, which had to be left behind when the age of science began. The humanities would be called upon to choose a wallpaper for the crypt, as the end drew near.
    Saul Bellow (b. 1915)

    The variables of quantification, ‘something,’ ‘nothing,’ ‘everything,’ range over our whole ontology, whatever it may be; and we are convicted of a particular ontological presupposition if, and only if, the alleged presuppositum has to be reckoned among the entities over which our variables range in order to render one of our affirmations true.
    Willard Van Orman Quine (b. 1908)