Mapping strings allow for data reordering, data reformatting, and data transformation.
Data reordering is a type of CHANGE operation in which the relative character positions of string are altered. For example, changing a string "ABCD" into "DCDA" is a simple data reordering operation. Data reordering my also include data extraction, because it is not necessary for all of the original data to be included in the resulting string value.
Data reformatting is a type of CHANGE operation in which additional characters are added to the original data, or where the original data is modified by having certain common text operations applied to it. For example, modifying a string "ABCD" into "** AB-CD **" is a data reformatting operation. Refer to the Quick Reference Guide to see examples in the how these and other operations can be performed with mapping strings.
Data transformation is a type of CHANGE operation in which the representation of characters in the original data is fundamentally changed. Commands are available in a mapping string to change data from character-mode to hex-mode using either ASCII or EBCDIC character sets, and to alter data by the use of a translation table. That is, it’s possible to replace all instances of A with 1, B with 2 and C with 3 – regardless of where the A, B and C appeared in your data – in a single operation. It is also possible to mutually exchange a pair of strings in your data, such as changing each occurrence of the word “one” into “two” and vice-versa. Without the data transformation capabilities in mapping strings, these actions could require up to 3 passes over your data, and the effort could incorrectly change some data, making that effort less reliable. In contrast, a mapping-string data transformation alters all of the effected data at the same time. You can also transform certain numeric data by converting it between hex and decimal and/or adjusting its length and formatting.
A mapping string is a string value appearing on a CHANGE command. It takes the place of a conventional change string in a CHANGE command. (Some documentation may describe the change string of a CHANGE command as string-2, whereas the find string part of the CHANGE command may be called string-1.) SPFLite uses mapping strings on CHANGE commands to define how a given reordering, reformatting or transformation operation takes place. Reordering, reformatting and transformation operations can be applied at the same time. (When you use these strings just for reformatting or transformation, rather than for reordering, you might think of these strings as modification strings rather than mapping strings. However, we use the term mapping string to cover all uses, since you are free to do several desired actions at the same time.)
Mapping strings are introduced by a quoted string value with a string type code of M. As with other SPFLite string types, M strings may be enclosed in any of the three types of quotes: ( ' ) single, ( " ) double, or ( ` ) accent), the M type code is case-insensitive, and the letter M may appear either at the beginning or at the end of the string, as M'xxx' or 'xxx'M. Because an M string may contain mapping items with their own quoted string operands, you may find it convenient to enclose the M string itself in " double quotes, and use ' single quotes or ` accent quotes inside the M string, for clarity and ease of typing.
An M string is only allowed on CHANGE commands, and only as the second string operand. (You cannot attempt to find strings of type M.)
Why would you use mapping strings? The main reason is to convert or reformat existing structured data from one pattern to another. Example data might include part numbers, serial numbers, telephone numbers, record keys, etc. Mapping strings can be used on any sort of file, though the types of reformatting you would perform on data files vs. program source code files is likely to be different.
When you use a mapping string on a CHANGE command, the first string operand for that command can be any valid SPFLite find-string type. However, if you had a find string like 'ABCD', there would be no real need to reformat it as a literal 'DCBA' using mapping, since you could already do that with a simple command of CHANGE 'ABCD' 'DCBA'. The place where mapping is the most useful is when the find-string locates a variety of different data values. In practice, that means a CHANGE command that has a mapping string will normally have a find-string which is of type Picture (P) or a Regular Expression (R), rather than a literal string of type C, T or X or unquoted text.
Note: It is possible to apply a mapping string operation to an entire line of data, by finding whole lines at a time with the find string of your CHANGE command, using a Regular Expression of R'^.*$'. Be aware that if you do this, the source string value of various lines will likely be of differing sizes. You would need to consider how you would refer to particular columns of varying-length data in such circumstances; the use of end-relative column notation could prove helpful.
Note: Starting with release 8.3 of SPFLite, a Regular Expression of R'^.*$' can find lines of length zero, because the Regular Expression engine has changed for 8.3; that did not occur in prior releases. This should not affect most users, but if you should encounter any issues because of this, be sure to let us know on the SPFLite forum, so we can make sure everything is working properly.
Created with the Personal Edition of HelpNDoc: Write EPub books for the iPad