SAP ABAP Training - ABAP Language

An ABAP statement always begins with a keyword and ends with a period. There is a little quirk caused by using the period as a statement terminator, floating point numbers must be enclosed in single quotes as if they were strings. Otherwise the period would be treated as a statement terminator and you would receive an error. This was probably not a big issue when the language was originally developed since in Germany commas are used as the decimal separator.

In ABAP, any line that has an asterisks (*) in the first column is considered a comment line. To place a comment at the end of a line you must use double quotes ("). Multi-line comments are not supported.

ABAP is a typed language, meaning that variables and their types' must be declared before they can be used. There are elementary or simple variables, structure variables which contain simple variables, and internal tables which contains structure variables.

Since keywords are determined by position there is no technical restriction on using them as variable names, but best practices dictate that this should not be done. The only restriction on variables is that they cannot be longer than thirty characters. SAP has ten standard variable types. Of these types there are two categories: complete and incomplete. Complete variable types are completely defined by themselves, whereas incomplete variable types need some additional information to be properly defined. Incomplete variables must have some sort of specification on the length of the variable.
  • D -- an 8 character date (complete)
  • T -- a 6 character time (complete)
  • I -- a 4 character integer (complete)
  • F -- an 8 character float (complete)
  • STRING -- a string of characters (complete)
  • XSTRING -- a hexadecimal string (complete)
  • C -- characters (incomplete)
  • N -- numeral (incomplete)
  • X -- hexadecimal (incomplete)
  • P -- packed number (incomplete)
It is possible to define local variable types in an ABAP program, but these are only valid within the program in which they are defined. The data dictionary (transaction code SE11) must be used to define custom variables types if a broader scope is desired. To define a local type within an ABAP program the following syntax is used:
TYPES my_new_type TYPE C LENGTH 5.
The default value for numeric variables is zero (0), and the default for character types is space ( ). Strings do not have an initial length, so the default value is not space. To set a default value the value keyword is used, this is shown in the following constant declaration. Below that are two variable declaration statements.
DATA my_float TYPE F VALUE '12.34'.
DATA: my_integer TYPE I VALUE 1234,
my_characters TYPE C(3) VALUE '123'.
When making variable assignments in ABAP, SAP tries to convert the source type into the destination type. SAP has 62 conversion rules that it follows when doing this. There are two methods for making variable assignments. In both of the examples below variable_two is assigned to variable_one:
MOVE v_two TO v_one.
v_one = v_two.
In order to reset a variable to it's default value ABAP provides the CLEAR keyword.
CLEAR my_variable.
For arithmetic expressions ABAP provides the COMPUTE keyword, however it's use is optional. Compute supports the following operators: +, -, *, /, ** (exponentiation), DIV (division without remainder), MOD (remainder of division).
COMPUTE my_v = another_v * 5 / 100.
my_v = another_v * 5 / 100.
Published: 2009-01-17