Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
ABAP
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==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. <!-- Deleted image removed: [[Image:Data types.gif|thumb|525px|none|Data and Types]] --> The built-in data types are: {| class="wikitable" |- ! Type !! Description |- | I || Integer |- | 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 can be used for date and time handling. 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): <syntaxhighlight lang="abap"> 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. </syntaxhighlight> All ABAP variables have to be explicitly [[Declaration (computer science)|declared]] in order to be used. They can be declared either with individual statements and explicit typing or, since ABAP 7.40, inline with [[type inference|inferred typing]]. === Explicitly typed declaration === 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: <syntaxhighlight lang="abap"> * 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. </syntaxhighlight> Notice the use of the colon to chain together consecutive DATA statements. === Inline declaration === Since ABAP 7.40,<ref>{{Cite web |title=DATA - Inline Declaration |url=https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abendata_inline.htm |website=help.sap.com}}</ref> variables can be declared inline with the following syntax: <syntaxhighlight lang="abap"> DATA(variable_name) = 'VALUE'. </syntaxhighlight> For this type of declaration it must be possible to infer the type statically, e.g. by [[method signature]] or database table structure. This syntax is also possible in OpenSQL statements: <syntaxhighlight lang="abap"> SELECT * FROM ekko into @DATA(lt_ekko) WHERE ebeln EQ @lv_ebeln. </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)