padright(X;Y)

Returns the given string with a certain number of characters, adding blanks at the end if necessary.

Syntax

padright(X;Y)

Input

Argument Type Description
X text The string on which to apply the function

A scalar value or the name of a column

Y integer The number of characters of the resultant string

Return Value

Returns the text string from the beginning of X up to the number of characters specified by Y. If Y is greater than the length of X, blanks are added to the end of the resultant string.

If X is N/A, the result is a string consisting of Y blank characters.

Sample Usage

value length padright(value;length)
'banana' 4 'bana'
'banana' 10 'banana'

Example

In the "Product Master" table (pub.demo.retail.prod), let's say we wanted to create a computed column that consisted of the department description (deptdesc) and the division description (divdesc) separated by a slash ("/"). We could do this by using the splice(X;Y) function and specifying the two column names in the list for the X parameter and the slash for the Y parameter.

<base table="pub.demo.retail.prod"/>
<willbe name="nopadding_result" label="Department/Division" 
 value="splice(deptdesc divdesc;'/')"/>

This would give us a column similar to the following:

However, let's say we wanted the division descriptions to line up evenly, so that our resultant column looks something like:

FOOTWEAR            /APPAREL           
SNACKS              /GROCERY
SNACKS              /GROCERY
TOOLS/AUTO          /DRY GOODS
TOOLS/AUTO          /DRY GOODS

We could use padright(X;Y) to add padding to the end of the department descriptions so that they are all the same length.

For our example, let's make all the department descriptions 20 characters in length. To do this, create a computed column and apply padright(X;Y) to the deptdesc column and specify 20 for the Y parameter:

<willbe name="padright_deptdesc" value="padright(deptdesc;20)"/>
This creates a new column whose department description values are all 20 characters in length, with extra blank spaces added to the end of those values that are less than 20 characters:
Note: Though the blank spaces do not appear in the new created column, they are part of the values in that column, which you will see in the following step.

Now, we can create a new computed column using the splice(X;Y) function again, but this time we will specify the new padright_deptdesc column instead of the deptdesc column in the list for the X parameter so that we get the padded strings.

<willbe name="padright_result" label="Department / Division" 
 value="splice(padright_deptdesc divdesc;'/')" format="width:40"/>
Note: We specify the display format attribute width to <willbe> so that the column width will accommodate the larger string length.

This results in a column that looks like:

Now, each department description is 20 characters in length, padded on the right with blanks, followed by a slash and then the associated division description. All of the division descriptions are neatly lined up.

However, what if we wanted to put some space after the slashes so that the division descriptions were not flush up against them? We could use the padleft(X;Y) function.

Additional Information

  • This function does not work with Unicode (UTF-8) strings.
  • For a Unicode-compliant alternative, consider strembed(X;N;P;Y;D).