Data Types





ABAP Data Types 

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:
TypeDescription
IInteger (4-bytes)
PPacked decimal
FFloating point
NCharacter numeric
CCharacter
DDate
TTime
XHexadecimal (raw byte)
STRINGVariable-length string
XSTRINGVariable-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.


In ABAP/4, we can declare data by command DATA.

Type      Description  Initial Value C Character Space D Date ’00000000’
F Floating Point 0.0
I Integer 0
N Numeric Text ’0’
P Packed Decimal 0
T Time ’000000’
X Hexadecimals X00


No comments:

Post a Comment