Literals as Actual Parameters

Special rules apply to the assignment of literals to formal parameters. They allow you 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 it.

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). At takeover of a literal, a local data object is always generated, even if the formal parameter is defined for a transfer via reference.

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 execption occurs if the value range of the target is exceeded.

Checking Character Literals

Table 1 shows the requirements that a character literal must meet in order to be assigned to a formal parameter. These rules apply to both text field literals and string literals.

Table 1

Type Requirement
c If the formal parameter has a fixed length, the literal must not be longer than the length of the parameter itself. If the length is generic, the formal parameter inherits the length of the literal.
d The literal must be 8 characters long.
f The literal must contain a number in scientific notation (see Representation of numeric values in character fields).
i, b, s The literal must contain a number in mathematiscal or commercial notation (see representation of numeric values in character fields. From Release 6.10 onwards, the literal may not contain any decimal places.
n The literal may only contain digits. 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.
numeric The literal must contain a number in either mathematical or commercial notation. The formal parameter assumes data type p with length 16 and as many decimal places as are specified in the literal.
p The literal must contain a number in mathematical or commercial notation. If the formal parameter is generic, its length is set to 16. Before Release 6.10, the number of decimal places was automatically set to 0. Since Release 6.10, the parmaeter assumes the number of decimal places contained in the literal. If the program attribute fixed point arithmetic is set and the type of the formal parameter is fully specified, the number of decimal places in the literal must not exceed the number of decimal places in the formal parameter. If the fixed point arithmetic attribute is not set, the literal and the formal parameter must have the same number of decimal places. The above fixed point arithmetic conditions apply from Release 6.10 onwards.
string The literal can be of 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 the letters "A" to "F". If the formal parameter has a fixed length, the length of the literal may not be more than twice this length. If the formal parameter is generic, it assumes data type x. Its length is the number of bytes in the literal.
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 the letters "A" to "F". The formal parameter assumes the data type x. Its length is the number of bytes in the literal.

All other types have the same requirements of character literals as apply to other actual parameters. Generic formal parameters assume the type of the actual parameter. With the exception of formal parameters listed in table 1, character literals can only be passed to formal parameters with types c or string.

Checking Numeric Literals

Table 2 shows the requirements for numeric literals that are to be passed to typed formal parameters.

Table 2

Type Requirement
f All numeric literals are allowed.
i, b, s All numeric literals are allowed.
n The value of the literal may not be negative. If the formal parameter has a fixed length, the literal may not be longer than the formal parameter. If the length of the formal parameter is generic, the length will be set to 10 characters if the literal has data type i, and 31 if it has data type p.
p If the formal parameter is generic, its length is set to 16 with no decimal places. If the program attribute fixed point arithmetic is not set, the formal parameter may not have any decimal places, or the literal must have the value zero. This applies from Release 6.10 onwards.

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 of the types listed in table 2, numeric literals can only be passed to formal parameters with data types i or p.