# System Functions

TBL( ) | Convert String Via Table

## Formats

1. | Translation Table in Program: | TBL(string$,TBL=tbl_stmtref[,ERR=stmtref])
2. | Translation Table in Variable: | TBL(string$,tbl_var$[,ERR=stmtref])
3. | Translate Using Position: | TBL(position,expr_0[$],expr_1[$] ... ,expr_n[$][,ERR=stmtref])
4. | Character to Character Conversion: | TBL(var$,compare$,table$)

Where:

compare$ | String table to compare character by character with the value in var$. String expression.
expr_0[$]…n | List of expressions to be returned. Numeric or string expressions. Restriction: The expressions must all be the same type (i.e. all characters or all numeric).
position | Determines which expression to use. Positional or numeric expression, range 0 (zero) to n.
stmtref | Program line number or statement label to which to transfer control.
string$ | String to be translated/replaced (must be all characters or all numeric).
table$ | Table to use for conversion when a character in the compared value matches the value in var$. String expression.
tbl_stmtref | Optional, if your table is embedded in the same statement as the TBL( ) function. If you refer to a program tbl_stmtref, it must contain a conversion table.
tbl_var$ | String variable. Contains conversion table to replace elements in the string$. String expression.
var$ | String variable. Contains a string to be translated or replaced.

## Returns

Converts string to values in table.

## Description

The TBL( ) function converts a string (all characters or all numeric) to the corresponding values set in a given translation table.

## Format 1

Translation Table in Program
TBL(string$,TBL=tbl_stmtref[,ERR=stmtref])

Use this format if the translation table to convert the string$ is an embedded table in your program.

If you include a tbl_stmtref, it must refer to a program statement containing a conversion table defined by a TABLE directive. This statement reference is optional if the conversion table is embedded in the same statement as the TBL( ) function.

## Format 2

Translation Table in Variable
TBL(string$,tbl_var$[,ERR=stmtref])

Use this format if the translation table to convert the string$ is in a variable.

## Format 3

Translate Using Position

TBL(position,expr_0[$],expr_1[$] ... ,expr_n[$][,ERR=stmtref])

Use this format to obtain a value based on the numeric value of an expression. The value that the TBL( ) function returns depends on the value of position. If it is 0 (zero), then the value of expr_0 will be returned. If it is 1, then expr_1 will be returned, and so on.

#### Note:
The values for expr_0[$], expr_1[$], …n[$] can be either string or numeric. The only requirement is that they must be all the same (i.e. all string or all numeric).

## Format 4

Character to Character Conversion

TBL(var$,compare$,table$)

Use this format to do a character-to-character conversion of a string. PxPlus replaces each character in the string variable that matches a character in the first comparison string expression with the corresponding character from the table; that is, when a character in the string variable matches a character in compare$, then:

> compare$ character 1 is replaced by table$ character 1 in var$,

> compare$ character 2 is replaced by table$ character 2 in var$,

> compare$ character 3 is replaced by table$ character 3 in var$,

> ... and so on

Example:

> X$=tbl(X$,"abc","ABC")

The above would replace all lower a, b or c's with A, B or C respectively.

## Example

Example 1:

> T$="W"
> P$=tbl(pos(T$="DWM"),"???","Daily","Weekly","Monthly")
> print P$
> Weekly

In the above example, the value in T$ is passed to a POS function to determine where in the string "DWM" it occurs. The POS function will return 1, 2 or 3 based on which character it matches, or 0 if none. This value is then processed by the TBL function to return "???" for zero or the appropriate text.

Example 2:

> print "Expires:",tbl(EXP_DT$="",EXP_DT$,"Never")

If EXP_DT$ is null, the logical expression EXP_DT$=" " yields 1. A null date will print "Never"; otherwise, it yields 0 (zero) and the value of EXP_DT$ is printed. In effect, this form of TBL( ) becomes TBL(logical_expr,else_value,true_value).

Example 3:

> string$="ABCDEFG 123"
> newstring$=tbl(string$,"ACF ","123_") ! newstring$ is "1B2DE3G_123"

This format of the TBL function replaces each character found in "ACF " with its corresponding character in "123_".