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)
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.
TYPES my__type TYPE P LENGTH 3 DECIMALS 2.
CONSTANTS my_const TYPE STRING VALUE 'my val'.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:
DATA my_float TYPE F VALUE '12.34'.
DATA: my_integer TYPE I VALUE 1234,
my_characters TYPE C(3) VALUE '123'.
MOVE v_two TO v_one.In order to reset a variable to it's default value ABAP provides the CLEAR keyword.
v_one = v_two.
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.