Skip to content

Pad Command

Obsolete

This command is replaced by the Pad function.

Purpose

To make a string a specified length by either truncating it on the right or appending spaces on the right.

Syntax

pad value to variable [length]

What It Does

The pad command moves data from value to variable to yield length characters in variable. If value is shorter than length, pad adds spaces to the right to make up a length of length in variable. If value is longer than length, pad truncates value on the right to produce a length of length in variable.

string country
number column_width
pad "France" to country 10
move 10 to column_width
pad "United States" to country column_width

In the example above, padding "France" to a length of 10 would produce "France" plus 4 spaces in the variable country. Padding "United States" to the same length would produce "United Sta" in country. In the second command, the number variable column_width is used to set the padded length to 10. In both cases, 10 is moved to the predefined variable strmark.

If length is left off, the value of the predefined variable strmark is used for the function. strmark is set by the last previous insert, left, mid, pos, replace, or sysdate command.

Notes

  • If you want to truncate strings that exceed a certain length but do not want to pad them when they are under that length, use the left command.

  • If length is less than 1, pad will output an empty string.

  • It is unnecessary to pad to a field since fields are automatically padded or truncated to the field length.

  • It is ineffectual to pad to a window since spaces are automatically stripped from the contents of windows.

  • The opposite of pad is trim, which removes trailing blanks. Trim, however, does not truncate strings.

  • Dates, numbers, and integers are suitable as values, but pad will not add spaces to the values of those types of variables as variables. It will, however, truncate them.

  • value and variable may both be the same string-type variable.