Fmt

From BR Wiki
Jump to navigation Jump to search

The FMT format specification is supported for use with FIELDS processing for validating and formatting of entered string or numeric data. It is similar to PIC as used for screen I/O, but more powerful, and more suited to use with strings.

One of the advantages of FMT is that it handles simple error checking of entered data (beeping when any character entered is in the wrong format) and it can fully format a field for input by forcing uppercase/lowercase, flush right and zero fill formatting. Another advantage is that it can display a single field (from the programmer's perspective) as two or more fields for the user.

Similarly, as of 4.3, #FMT can be used to work with numeric values from a string. Similar to #PIC and #G, #FMT indicates that string data should be processed numerically. This works for INPUT FIELDS as well as GRIDs and LISTs.

For example: #FMT(###.##), when used in conjunction with the strings "231.45", "430", etc.

Input And Cursor Characteristics

The first field specification in the following example displays to the user what looks and acts like two fields which are separated by a dash. Insert, delete, erase and field plus will modify only one part of the field. Pressing the down arrow will move the cursor from any position in the first part to the first position in the second part.

However, when the cursor is positioned at the first field after the field specified by a FMT spec (at row 12, column 10 in the following example), pressing the up arrow will cause the cursor to move to the first position in the first part of the FMT field.

Only numeric data will be allowed, even though the entered value is to be assigned to a string Variable. A beep will sound if an invalid character is typed for any position. Once entered, the data will be right justified.

00100 INPUT FIELDS "10,10,FMT(R999-R9);12,10,C 12,AE":X$,Y$

Examples

The following INPUT FIELDS statement will display two field parts separated by a dash.

1.) The first field part will accept any character, leaving case as entered. It will also be right justified upon field part exit.
2.) The second field part will accept any character but force it to uppercase if alphabetic. No right flush formatting will be done on field exit.
00200 INPUT FIELDS "10,10,FMT(RXXX-XXX),AE":X$

The next INPUT FIELDS statement displays two field parts separated by a dash. The first four characters must be alphabetic, and they will be forced to uppercase. The second four characters must be numeric.

If fewer than four characters are entered, the entered data will be right justified and, within the second group of four characters. Positions to the left of the first entered character will be filled with zeros.

00200 INPUT FIELDS "10,10,FMT(RAAA-#999),AE":X$

Examples of values that could be entered for the above code fragment are as follows:

ABCD-1234
ACB-0001
B-1000

FMT Vs PIC

With some exceptions, FMT is best suited to handling strings, whereas PIC is generally used with numeric data only. See the chart below comparing the two:

FMT Syntax


The FMT spec can be used in the same places that PIC is allowed in INPUT FIELDS, RINPUT FIELDS and PRINT FIELDS statements. The FMT keyword must be followed by up to 40 character identifiers and/or insertion characters.

Character identifiers tell the system which characters are allowed in the current position, and they identify the way in which the data part should be formatted for input. (Business Rules considers any section of a FMT spec, which is separated from other sections by one or more insertion characters to be a data part.) The following character identifiers are currently available:

9 Allow any number from 0 to 9.
a Allow any character from A to Z or a to z, and leave case as entered.
G Allow any character from A to Z, a to z, or 0 to 9, and force it to upppercase if its alphabetic.
g Allow any character from A to Z, a to z, or 0 to 9, and force it to lowercase if its alphabetic.
P or p Protected. Business Rules will not allow the cursor to rest on or change any data that is displayed in this position
R Mimic the next character specification. Right flush this part from current position to the end of this part (preceding next R or #), process according to the next character identifier within this part (if R is the only character type used, error 0805 will result).
X Allow any character and force to uppercase if its alphabetic.
x Allow any character and force to lowercase if its alphabetic.
Y Allow only Y, y, N, or n, and force it to uppercase.
y Allow only Y, y, N, or n, and force it to lowercase.
# Mimic the next character specification. Right flush and zero fill from current position to end of this part (preceding next R or #), process according to the next character identifier within this part (if # is the only one used, error 0805 will result).


Insertion characters are displayed exactly as they appear in the FMT specification. Business Rules treats any keyboard character that is not a character identifier (listed above) as an insertion character.

Insertion characters are inserted for the operator's benefit. They will not be in the data. Note that "P" can be used to protect characters that you want to appear in the data.