Previous Topic: &SETBLNK

Next Topic: &SETVARS


&SETLENG

Sets the length of a variable.

&SETLENG length

&SETLENG is a built-in function and must be used to the right of an assignment statement.

The &SETLENG function forces a variable to a specific length.

If the specified length is less than the current length, the data within the variable will be truncated. If the specified length is greater than the current length of data in the variable, trailing blanks will be added.

If the variable does not exist (a null), then it is created and padded with blanks to the specified length.

Setting a length of zero causes the variable to be deleted (set to null).

Operands:

length

The new length for the target variable. This must be in the range 0 to the maximum length of the variable.

Examples: &SETLENG

&KEY = AAABBBCCC
&KEY = &SETLENG 5  -* &KEY is set to AAABB
&NAME = &SETLENG &NAMELEN

Notes:

The &SETLENG function is ideal for setting up keys of fixed length that are to be used in subsequent file processing and for setting fields to known lengths, perhaps to interface with other off-line systems.

Using &SETLENG can add trailing blanks to pad out existing data to the new length. If necessary, use the &TBLSTR function to remove these trailing blanks when no longer required.

If a series of variables are to be displayed in a tabular form (for example, in a report, or as message lines on a panel), the &OVERLAY statement is used instead.

If &CONTROL DBCS or DBCSN or DBCSP is in effect, &SETLENG is sensitive to the presence of DBCS data.