Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Declarations →  Typing →  Checking Typing 

Literals as Actual Parameters

Special rules apply to the assignment of literals to formal parameters. They make it possible to assign character literals of type c and string or numeric literals of type i and p to formal parameters whose type would not normally allow this.

If the formal parameter has a generic type, the non-specified type attributes are defined by the contents of the specified literal (see table 1). When a literal is bound, the pass is always executed as pass by value, even if pass by reference is defined for the formal parameter.

If a literal meets the type requirements of the parameter, its contents are assigned to the formal parameter according to the relevant conversion rules for elementary data types. However, in contrast to the normal application of these rules, a non-catchable exception is raised if the value range of the target is exceeded.

Other versions: 7.31 | 7.40 | 7.54

Checking Character Literals

The following table shows the requirements that character literals must meet to be assigned to typed formal parameters. These rules apply to both text field literals and text string literals.

Typing Requirement
c If the formal parameter has a fixed length, the length of the literal may not exceed this length. If the length is generic, the formal parameter inherits the length of the literal.
d The literal must be eight characters long.
decfloat, decfloat16, decfloat34 The literal must contain a number in mathematical,commercial, orscientific notation.If generic typing with decfloat is used, the formal parameter contains the data type decfloat34.
f The literal must contain a number in scientific notation.
i, int8, (b, s) The literal must contain a number in mathematical orcommercial notation. The literal may not contain anydecimal places.
n The literal may only contain digits. If the formal parameter has a fixed length, the length of theliteral may not exceed this length. If the length is generic, the formal parameter inherits the length of the literal.
numeric The literal must contain a number in mathematical orcommercial notation. The formal parameter inherits the data type p, length 16, and the decimal spaces specified in the literal.
p The literal must contain a number in mathematical orcommercial notation.If a generic formal parameter is used, the length is set to 16. The number of decimal spaces is set to the number of spaces specified in the literal. If theprogram attributeFixed Point Arithmetic is activated in the called procedure, the numberof decimal places in the literal for a fully typed formal parameter must be less than or equal to thenumber of decimal places in the formal parameter. If the attribute Fixed PointArithmetic is deactivated in the called procedure, the number in the literal must have exactly the same number of decimal places as the formal parameter.
string The literal can have any length.
t The literal must be six characters long.
x The literal may only contain valid hexadecimal characters, that is the digits "0" to "9" and theletters "A" to "F". If the formal parameter has a fixed length, the length of the literal may not bemore than twice this length. If the length is generic, the number of bytes specified in the literal determines the length of the formal parameter.
xstring The literal may only contain valid hexadecimal characters, that is the digits "0" to "9" and the letters "A" to "F".
xsequence The literal may only contain valid hexadecimal characters, that is the digits "0" to "9" and theletters "A" to "F". The formal parameter inherits the data type x. Its length is the number of bytes in the literal.
utclong The literal can be a left-aligned character-like representationof a time stamp, like "yyyy-mm-ddThh:mm:ss.fffffff", or it can contain only blanks.

All other types have the same requirements of character literals as apply to other actual parameters. Generic formal parameters inherit the type of the actual parameter. With the exception of formal parameters listed in the table above, character literals can only be passed to formal parameters whose typings include the data types c or string.


Notes

  • Character literals that are passed to actual parameters can be joined using the literal operator &. The rules described above apply here. However, if a join with the chaining operator && is used, the actual parameter is a string expression of type string and the formal parameter must be typed accordingly.

  • The requirements in the table above do not fully exclude the case where character literals are passed to actual parameters that do not match their value range. An exception is raised in this case.

Checking Numeric Literals

The following table shows the requirements that numeric literals must meet to be assigned to typed formal parameters.

Typing Requirement
f All numeric literals are allowed.
decfloat, decfloat16, decfloat34 All numeric literals are allowed. If generic typing with decfloat is used, the formal parameter contains the data type decfloat34.
i, int8, (b, s) All numeric literals are allowed.
n The value of the literal must not be negative. If the formal parameter has a fixed length, the numberof digits may not exceed this length. If the length is generic and the literal has the data type i, the length of the formal parameter is set to 10. If the literal has the data type p, the length is set to 31.
p If a generic formal parameter is used, the length is set to 16 and the number of decimal spacesis set to 0. If the program attribute Fixed Point Arithmetic is deactivated, the formal parameter cannot have any decimal places or the literal must have the value 0.

All other types have the same requirements of numeric literals as of other actual parameters. Generic formal parameters inherit the type of the actual parameters. With the exception of formal parameters listed in the table above, numeric literals can only be passed to formal parameters whose typings include the data types i or p.


Note

The requirements in the table above do not fully exclude the case where numeric literals are passed to actual parameters that do not match their value range. An exception is raised in this case.