SAP ABAP

参考英文原版教程请移步 Tutorialspoint

一、Numeric Literals

  1. Sequences of digits
  2. can have a prefixed sign
  3. No decimal separators
  4. No notation with mantissa and exponent
1
2
3
183.
-97.
+326.

二、Character Literals

  1. Sequences of alphanumeric characters
  2. Enclosed in single quotation marks
  3. Quotation marks mean type C and text field literals
  4. “back quotes” mean type STRING and string literals

Text field literals

1
2
3
REPORT YR_SEP_12.
Write 'Tutorials Point'.
Write / 'ABAP Tutorial'.

String field literals

1
2
3
REPORT YR_SEP_12.
Write `Tutorials Point `.
Write / `ABAP Tutorial `.

The output is same in both the above cases

1
2
Tutorials Point
ABAP Tutorial

Note − When we try to change the value of the constant, a syntax or run-time error may occur. Constants that you declare in the declaration part of a class or an interface belong to the static attributes of that class or interface.

三、CONSTANTS Statements

1
CONSTANT <f> TYPE <type> VALUE <val>.

Note − We should use the VALUE clause in the CONSTANTS statement. The clause ‘VALUE’ is used to assign an initial value to the constant during its declaration.

Elementary constant

1
2
3
REPORT YR_SEP_12.
CONSTANTS PQR TYPE P DECIMALS 4 VALUE '1.2356'.
Write: / 'The value of PQR is:', PQR.

The output is

1
The value of PQR is: 1.2356

Complex constant

1
2
3
4
5
BEGIN OF EMPLOYEE,
Name(25) TYPE C VALUE 'Management Team',
Organization(40) TYPE C VALUE 'Tutorials Point Ltd',
Place(10) TYPE C VALUE 'India',
END OF EMPLOYEE.

Reference constant

1
CONSTANTS null_pointer TYPE REF TO object VALUE IS INITIAL.