Specifying an alignment item – L / R / C


An alignment item is used to left-justify, right-justify, or center, the result string.  Recall from the discussion above that the result string is built up, a piece at a time, in a left-to-right manner.  When an alignment item is encountered in the mapping string, it is applied to the result string as it exists at that point in time.  Thus, to align the ‘final’ result string in a certain way, you would place the alignment item last (right-most) in the mapping string.


Because the action of an alignment item is applied to the result string and not to the source string, the mapping string can contain additional column-reference operands to the right of an alignment item, since the data characters in the source string remain undisturbed in their original locations.


An alignment item consists of the letter L, R or C followed by an alignment specification.  


Alignment is always performed with respect to some specified field length.  That is, when you left justify a string, it is done within some given area, say, a length of 9.  If your original data is longer than 9, the excess is trimmed off, while if it is shorter, the data is padded on the other side.


Suppose you have a result string with some blanks on each side of it, and you wanted this string to be left justified in its current size.  You do this by omitting the length, or by specifying a length of 0.  When this is done, the result string is effectively first trimmed of leading and trailing blanks (or other character you specify), and then left-justified within a field that is the size that the result string originally was before it got trimmed.


For example, if the result string contains '°xy°' and you use a command of L or L0, (noting that the result string is initially of length 4) the string is first trimmed to 'xy', and then left-justified within a length of 4, to produce 'xy°°', the same as if the command had been specified as L4.  (The “°” symbol represents one blank.)


When alignment causes padding to occur, the default pad character is a blank.  You can optionally specify a different padding character as a literal value.


No spaces or characters not part of the syntax can appear within a single alignment item, unless appearing inside of quotes as a literal pad-character value.


In the discussion below, the command L for left-justifying is used as an example to make the explanation easier to follow; the same rules apply to R and C.  A literal length of 3 or 9 is used for similar reasons, to make the examples easier to read.  An example of an optional padding character of 'x' is shown, where 'x' can be any single character.



Syntax of an alignment item:


{ L | R | C }  [ pad-character ]  field-size


L | R | C:


L, R or C refer to Left-justifying, Right-justifying, or Centering, respectively.


Pad-character:


Any single character in quotes, as described above under Inserted text.  The pad character is optional, and if omitted, blanks are used for padding.  If the pad string is longer than one character, only the left-most is used.  If the pad string is specified as two consecutive quotes, padding is done with a single blank, just as if you omitted the pad character altogether.


Field size:


This is similar to a column-reference specification, with a few differences.


L9

L'x'9

The current result string is Left-justified, with a fixed length of 9.  If the result-string was longer than 9, excess characters are truncated on the right.  If the result-string was shorter than 9, extra padding characters are added on the right to force the length to be 9 characters.  If pad-character 'x' was specified, that is the character used for padding; otherwise padding is done with blanks.  If the command is specified as L or L0,the result string is justified within the bounds of its current size.


L3-9

L'x'3-9

The current result string is Left-justified, with a minimum length of 3 and a maximum length of 9.  If the result-string was longer than 9, excess characters are truncated on the right.  If the result-string was shorter than 3, extra padding characters are added on the right to force the length to be at least 3 characters.  If pad-character 'x' was specified, that is the character used for padding; otherwise padding is done with blanks.  It is legal to specify a minimum length of 0.  It is illegal to specify a minimum length greater than the maximum length.  It is illegal to specify Ln-0 (where n is any number) since that would discard the entire result string.



L-9

L'x'-9

The current result string is Left-justified, with a maximum length of 9. but no minimum length.  If the result-string was longer than 9, excess characters are truncated on the right.  If the result-string was shorter than 9, no padding takes place, and the value is allowed to be remain shorter than 9 characters.  It is illegal to specify L-0 since that would discard the entire result string.  


Note 1.  Because padding does not take place with alignment items in this form, any padding string that you may specify is allowed but will be ignored.  Thus, L'x'-9 is processed exactly the same as L-9, which is why this is shown above as grayed-out.


Note 2.  An alignment item of L-9 operates the same way as L0-9.  


L9+

L'x'9+

The current result string is Left-justified, with a minimum length of 9. but no maximum length.  If the result-string was longer than 9, no padding takes place, and the value is allowed to be remain unchanged in its current length.  If the result-string was shorter than 9, extra padding characters are added on the right to force the length to be at least 9 characters.  If pad-character 'x' was specified, that is the character used for padding; otherwise padding is done with blanks.  It serves no purpose to specify a minimum length here of 0, using L0+, since every string is at least zero characters long; the string would not be changed.


When the alignment code is L, data is aligned left, and padding and truncation take place on the right.


When the alignment code is R, data is aligned right, and padding and truncation take place on the left.


When the alignment code is C, data is centered within the specified field.  This is handled somewhat differently than left- or right-aligned data.  If centering of data within a field results in an odd number of ‘extra’ positions, centering is done in such a way that the number of remaining extra positions is divided by two, and the ‘short half’ goes on the left side, while the ‘long half’ goes on the right side.  So, if you have a 4-character field and you are centering it in a 9-position field, there are 5 extra positions to deal with.  Since 5 is odd, we divide it into 2 and 3.  The result string will have 2 positions of padding on the left, then 4 positions of data, then 3 positions of padding on the right.



Created with the Personal Edition of HelpNDoc: Free EPub producer