CENTERRIGHT

CENTERRIGHT returns a string that is the result of inserting string x in the center (or one position to the right of center) of a string with length y and padded on the left and on the right with the character z as needed.

Specifying a value for z is optional.

Read syntax diagramSkip visual syntax diagram
>>-+-CENTERRIGHT-+--(x,y-+----+-)------------------------------><
   '-CENTRERIGHT-'       '-,z-'     

x
Expression that is converted to character.
y
Expression that is converted to FIXED BINARY(31,0).
z
Optional expression. If specified, z must be CHARACTER(1) NONVARYING type.

Example

  dcl Source char value('Feel the Power');
  dcl Target20 char(20);
  dcl Target21 char(21);
 
  Target20 = centerright (Source, length(Target20), '*');
             /* '***Feel the Power***' - exactly centered */
 
  Target21 = centerright (Source, length(Target21), '*');
             /* '****Feel the Power***' - leaning right! */

If z is omitted, a blank is used as the padding character.






Published: 23 December 2018