To meet your needs, we constantly work to improve Querix products.
This means that Lycia documentation is developing as well.
In case you have found a certain dissonance between the provided information and the actual behavior of Lycia 3 and/or your applications, please, let us know about this via documentation@querix.com so that we can introduce the necessary changes to our documentation.
Thank you for your attention and cooperation.
USING operator specifies a character-string format for a number, MONEY, or DATE operand and returns the formatted value.
With a number or MONEY operand, you can use the USING operator to align decimal points or currency symbols, to right- or left-align numbers, to put negative numbers in parentheses, and to perform other formatting tasks. USING can also convert a DATE operand to a variety of formats.
USING is typically used in DISPLAY and PRINT statements, but you can also use it with LET to assign the formatted value to a character variable. If a value is too large for the field, 4GL fills it with asterisks ( * ) to indicate an overflow.
Symbols that the USING operator recognizes in format-string are described in "The USING Formatting Symbols for Number Values" section and the "Formatting DATE Values" section of this volume for number values and DATE values respectively.
Formatting Number Expressions
The USING operator takes precedence over the DBMONEY or DBFORMAT environment variables and is required to display the thousands separator of DBFORMAT. When 4GL displays a number value, it follows these rules:
GL displays the leading currency symbol (as set by DBFORMAT or DBMONEY) for MONEY values. (But if the FORMAT attribute also specifies a leading currency symbol, 4GL displays that symbol for other data types.)
4GL omits the thousands separators, unless they are specified by a FORMAT attribute or by the USING operator.
4GL displays the decimal separator, except for INT or SMALLINT values.
4GL displays the trailing currency symbol (as set by DBFORMAT or DBMONEY) for MONEY values unless you specify a FORMAT attribute or the USING operator. In this case, the user cannot enter a trailing currency symbol, and 4GL does not display it.
USING Formatting Symbols for Number Values
The format-string value can include the following characters.
Character |
Description |
* |
The asterisk character will cause any spaces in the display field that would normally be blank, to be filled with asterisks |
& |
The ampersand character will cause any spaces that would normally be blank to be filled with zeros. |
# |
The hash character does not have any effect on blank spaces; it can be used to specify the maximum width of a field. |
< |
The greater than symbol causes numbers in a field to be aligned to the left-hand edge. |
, |
The comma is a literal character. USING displays it as a comma when there is a number to the left of it. |
. |
The period is a literal character. USING displays it as a period. Only one period can appear in a number format string, where it is used as the decimal point. |
- |
The hyphen is a literal character. USING displays it as a minus sign, but it only appears when the expression it relates to is a number with a negative value. When several hyphens are placed in a row, only one is displayed. This floats one character space to the left of the number being printed. |
+ |
The plus sign is a literal character. USING displays it as a plus sign when the expression it relates to is a number that is zero or greater. When the number is less than zero it automatically displays as a minus sign. When several plus signs are placed in a row, only one is displayed. This floats one character space to the left of the number being printed. |
$ |
The dollar symbol is displayed as a literal character. When several dollar signs are placed in a row, only one is displayed. This floats one character space to the left of the number being printed. |
( |
The left parenthesis symbol is displayed before a negative number. It is known as the accounting parenthesis because in accounting negative numbers are displayed within parentheses, rather than being preceded by a minus sign. |
) |
The right parenthesis symbol is used to close a negative number when the left parenthesis is used at the beginning to indicate a negative number. |
The minus sign ( - ), plus sign ( + ), parentheses, and dollar sign ( $ ) float, meaning that when you specify multiple leading occurrences of one of these characters, 4GL displays only a single character immediately to the left of the number that is being displayed. Any other character in format-string is interpreted as a literal.
These characters are not identical to the formatting characters that you can specify in the format-strings of the FORMAT or PICTURE field attributes.
For examples of using format strings for number expressions, see "Examples of the USING Operator" further on in this section. Because format strings interact with data to produce visual effects, you might find that the examples are easier to follow than the descriptions on the previous page of USING format string characters.
The following example prints a MONEY value using a format string that allows values up to $9,999,999.99 to be formatted correctly.
MAIN
DEFINE mon_val1, mon_val2 MONEY(8,2)
LET mon_val1 = 43243.18
LET mon_val2 = -18589.57
DISPLAY "*** USING Example 1 ***" AT 1,5
DISPLAY "43243.18 - $#,###,##&.&& - The current balance is :", mon_val1 USING "$#,###,##&.&&" at 3,5
DISPLAY "43243.18 - +$#,###,##&.&& - The current balance is :", mon_val1 USING "+$#,###,##&.&&" at 4,5
DISPLAY "-18589.57 - -$#,###,##&.&& - The current balance is :", mon_val2 USING "-$#,###,##&.&&" at 5,5
DISPLAY "-18589.57 - $#,###,##&.&& - The current balance is :", mon_val2 USING "$#,###,##&.&&" at 6,5
DISPLAY "-18589.57 - $(#,###,##&.&&) - The current balance is :", mon_val2 USING "$(#,###,##&.&&)" at 7,5
DISPLAY "-18589.57 - €(#'###'##&,&&) - The current balance is :", mon_val2 USING "€(#'###'##&,&&)" at 8,5
DISPLAY "43243.18 - $<<,<<<,<<&.&& - The current balance is :", mon_val1 USING "€<<,<<<,<<&.&&" at 9,5
CALL fgl_winmessage("Exit","Press any key to close this demo application","info")
END MAIN
The above examples also use the # and & fill characters. The # character provides blank fill for unused character positions, while the & character provides zero filling. This format ensures that even if the number is zero, any positions marked with & appear as zero, not blank.
Dollar signs can be used instead of # characters, as in the following statement:
DISPLAY "Total amount due: ",inv_total
USING "$$,$$$,$$&.&&"
In this example, the currency symbol floats with the size of the number so that it appears immediately to the left of the most significant digit in the display. This example would produce the following formatted output, if the value of the inv_total variable were 14187.00:
Total amount due: $14,187.00
By default, 4GL displays numbers right aligned. You can use the < symbol in a USING format string to override this default. For example, specifying
DISPLAY "
Total amount due: ", inv_total
USING "$<<,<<<,<<&.&&"
produces the following output when the value of inv_total is 14187.00:
The current balance is $14,187.00
Formatting DATE Values
When you use it to format a DATE value, USING takes precedence over any DBDATE or GL_DATE environment variable settings. The format-string value for a date can be a combination of the characters m, d, and y.
Symbols |
Resulting Time Unit in Formatted DATE Display |
dd |
Day of the month, from 01 up to 31, as appropriate. |
ddd |
Day of the week, as a three letter abbreviation. |
mm |
Month of the year, from 01 to 12, as appropriate. |
mmm |
Month of the year, as a three letter abbreviation. |
yy |
The year of the century, from 00 to 99, as appropriate. |
yyyy |
The full numerical year description, from 0001 to 9999. |
In these instances lowercase letters must be used; uppercase will not be recognized.
Any other characters within a USING formatting mask for DATE values are interpreted as literals.
The following examples show valid format-string masks for December 25, 1999, and the resulting display for the default U.S. English locale.
Format String |
Formatted Result |
"mmddyy" |
122599 |
"ddmmyy" |
251299 |
"yymmdd" |
991225 |
"yy/mm/dd" |
99/12/25 |
"yy mm dd" |
99 12 25 |
"yy-mm-dd" |
99-12-25 |
"mmm. dd, yyyy" |
Dec. 25, 1999 |
"mmm dd yy" |
Dec 25 1999 |
"yyyy dd mm" |
1999 25 12 |
"mmm dd yyyy" |
Dec 25 1999 |
"ddd, mmm. dd, yyyy" |
Sat, Dec. 25, 1999 |
"(ddd) mmm. dd, yyyy" |
(Sat) Dec. 25, 1999 |
This example programs demonstrates all different date formats:
MAIN
DEFINE my_date DATE, inp_char char(1)
LET my_date = today
DISPLAY "*** USING Example 2 ***" AT 3,5
DISPLAY "using mmddyy: ", my_date USING "mmddyy" at 5,5
DISPLAY "using ddmmyy: ", my_date USING "ddmmyy" at 6,5
DISPLAY "using mmddyy: ", my_date USING "yymmdd" at 7,5
DISPLAY "using yy/mm/dd: ", my_date USING "yy/mm/dd" at 8,5
DISPLAY "using yy mm dd: ", my_date USING "yy mm dd" at 9,5
DISPLAY "using yy-mm-dd: ", my_date USING "yy-mm-dd" at 10,5
DISPLAY "using mmm. dd, yyyy: ", my_date USING "mmm. dd, yyyy" at 11,5
DISPLAY "using mmm dd yyy: ", my_date USING "mmm dd yyy" at 12,5
DISPLAY "using yyyy dd mm: ", my_date USING "yyyy dd mm" at 13,5
DISPLAY "using mmm dd yyyy: ", my_date USING "mmm dd yyyy" at 14,5
DISPLAY "using ddd, mmm. dd, yyyy: ", my_date USING "ddd, mmm. dd, yyyy" at 15,5
DISPLAY "using mmm dd yyyy: ", my_date USING "mmm dd yyyy" at 16,5
Prompt "Press any key to close this demo application" FOR inp_char
END MAIN
Using non-default locales, the NUMERIC and MONETARY categories in the locale files affect how the format string of the USING operator is interpreted for formatting number and currency data values.
In format string, the period ( . ) is not a literal character but a placeholder for the decimal separator specified by environment variables. Likewise, the comma is a placeholder for the thousands separator specified by environment variables. The dollar sign ( $ ) is a placeholder for the leading currency symbol. The @ symbol is a placeholder for the trailing currency symbol. Thus, the format string $#,###.## formats the value 1234.56 as £1,234.56 in a U.K. English locale, but as €1.234,56 in a French locale. Setting either DBFORMAT or DBMONEY overrides these locale settings.
The mmm and ddd specifiers in a format string can display language-specific month-name and day-name abbreviations. This needs the LANG environment variable to be set, and the appropriate locale to be installed on your local operating system.
Examples of the USING Operator
Tables that follow illustrate some of the capabilities of the USING operator with number or currency operands (for the default U.S. English locale). Each table has the following format:
The first column shows a format string (the left-hand operand).
The second column shows a data value (the right-hand operand).
The third column shows the resulting formatted display.
The fourth column provides a comment (for some rows).
In the following table, the character b in the Formatted Result column represents a blank space.
Format String |
Data Value |
Formatted Result |
Comment on Result |
"#####" |
0 |
bbbbb |
No zero symbol |
"&&&&&" |
0 |
00000 |
|
"$$$$$" |
0 |
bbbb$ |
No zero symbol |
"*****" |
0 |
***** |
No zero symbol |
"<<<<<" |
0 |
|
(NULL string) |
"<<<,<<<" |
12345 |
12,345 |
|
"<<<,<<<" |
1234 |
1,234 |
|
"<<<,<<<" |
123 |
123 |
|
"<<<,<<<" |
12 |
12 |
|
"##,###" |
12345 |
12,345 |
|
"##,###" |
1234 |
b1,234 |
|
"##,###" |
123 |
bbb123 |
|
"##,###" |
12 |
bbbb12 |
|
"##,###" |
1 |
bbbbb1 |
|
"##,###" |
-1 |
bbbbb1 |
No negative sign |
"##,###" |
0 |
bbbbbb |
No zero symbol |
"&&,&&&" |
12345 |
12,345 |
|
"&&,&&&" |
1234 |
01,234 |
|
"&&,&&&" |
123 |
000123 |
|
"&&,&&&" |
12 |
000012 |
|
"&&,&&&" |
1 |
000001 |
|
"&&,&&&" |
-1 |
000001 |
No negative sign |
"&&,&&&" |
0 |
000000 |
|
"&&,&&&.&&" |
12345.67 |
12,345.67 |
|
"&&,&&&.&&" |
1234.56 |
01,234.56 |
|
"&&,&&&.&&" |
123.45 |
000123.45 |
|
"&&,&&&.&&" |
0.01 |
000000.01 |
|
"$$,$$$" |
12345 |
****** |
(Overflow) |
"$$,$$$" |
1234 |
$1,234 |
|
"$$,$$$" |
123 |
bb$123 |
|
"$$,$$$" |
12 |
bbb$12 |
|
"$$,$$$" |
1 |
bbbb$1 |
|
"$$,$$$" |
0 |
bbbbb$ |
No zero symbol |
"**,***" |
12345 |
12,345 |
|
"**,***" |
1234 |
*1,234 |
|
"**,***" |
123 |
***123 |
|
"**,***" |
12 |
****12 |
|
"**,***" |
1 |
*****1 |
|
"**,***" |
0 |
****** |
No zero symbol |
In the following table the character b in the Formatted Result column represents a blank space.
Format String |
Data Value |
Formatted Result |
Comment on Result |
"##,###.##" |
12345.67 |
12,345.67 |
|
"##,###.##" |
1234.56 |
b1234.56 |
|
"##,###.##" |
123.45 |
bbb123,45 |
|
"##,###.##" |
12.34 |
bbbb12.34 |
|
"##,###.##" |
1.23 |
bbbbb1.23 |
|
"##,###.##" |
0.12 |
bbbbb0.12 |
|
"##,###.##" |
0.01 |
bbbbbb.01 |
No leading zero |
"##,###.##" |
-0.01 |
bbbbbb0.01 |
No negative sign |
"##,###.##" |
-1 |
bbbbb1.00 |
No negative sign |
"$$,$$$.$$" |
12345.67 |
********* |
(overflow) |
"$$,$$$.$$" |
1234.56 |
$1,234.56 |
|
"$$,$$$.##" |
0.00 |
$.00 |
No leading zero |
"$$,$$$.##" |
1234.00 |
$1,234.00 |
|
"$$,$$$.&&" |
0.00 |
$.00 |
No leading zero |
"$$,$$$.&&" |
1234.00 |
$1,234.00 |
|
"-$$$,$$$.&&" |
-12345.67 |
-$12,345.67 |
|
"-$$$,$$$.&&" |
-1234.56 |
-b$1,234.56 |
|
"-$$$,$$$.&&" |
-123.45 |
-bbb$123.45 |
|
"--$$,$$$.&&" |
-12345.67 |
-$12,345.67 |
|
"--$$,$$$.&&" |
-1234.56 |
-$1,234.56 |
|
"--$$,$$$.&&" |
-123.45 |
-bb$123.45 |
|
"--$$,$$$.&&" |
-12.34 |
-bbb$12.34 |
|
"--$$,$$$.&&" |
-1.23 |
-bbbb$1.23 |
|
"-##,###.##" |
-12345.67 |
-12,345.67 |
|
"-##,###.##" |
-123.45 |
-bbb123.45 |
|
"-##,###.##" |
-12.34 |
-bbbb12.34 |
|
"--#,###.##" |
-12.34 |
-bbb12.34 |
|
"---,###.##" |
-12.34 |
-bb12.34 |
|
"---,-##.##" |
-12.34 |
-12.34 |
|
"---,--#.##" |
-1.00 |
-1.00 |
|
"-##,###.##" |
12345.67 |
12,345.67 |
|
"-##,###.##" |
1234.56 |
1,234.56 |
|
"-##,###.##" |
123.45 |
123.45 |
|
"-##,###.##" |
12.34 |
12.34 |
|
"--#,###.##" |
12.34 |
12.34 |
|
"---,###.##" |
12.34 |
12.34 |
|
"---,-##.##" |
12.34 |
12.34 |
|
"---,---.##" |
1.00 |
1.0 |
|
"---,---.--" |
-.01 |
-0.01 |
|
"---,---.&&" |
-.01 |
-0.01 |
|
Here the character b in the Formatted Result column represents a blank space.
Format String |
Data Value |
Formatted Result |
Comment on Result |
"----,--$.&&" |
-12345.67 |
-$12,345.67 |
|
"----,--$.&&" |
-1234.56 |
-$1234.56 |
|
"----,--$.&&" |
-123.45 |
-$123,45 |
|
"----,--$.&&" |
-12.34 |
-$12.34 |
|
"----,--$.&&" |
-1.23 |
-$1.23 |
|
"----,--$.&&" |
-.12 |
-$.12 |
|
"$***,***.&&" |
12345.67 |
$*12,345.67 |
|
"$***,***.&&" |
1234.56 |
$**1,234.56 |
|
"$***,***.&&" |
123.45 |
$***123.45 |
|
"$***,***.&&" |
12.34 |
$*****12.34 |
|
"$***,***.&&" |
1.23 |
$******1.23 |
|
"$***,***.&&" |
.12 |
$*******.12 |
|
"($$$,$$$.&&)" |
-12345.67 |
($12,345.67) |
Accounting parentheses |
"($$$,$$$.&&)" |
-1234.56 |
(b$1,234.56) |
|
"($$$,$$$.&&)" |
-123.45 |
(bb$123.45) |
|
"(($$,$$$.&&)" |
-12345.67 |
($12,345.67) |
|
"(($$,$$$.&&)" |
-1234.56 |
(b$1,234.56) |
|
"(($$,$$$.&&)" |
-123.45 |
(bb$123.45) |
|
"(($$,$$$.&&)" |
-12.34 |
(bbb$12.34) |
|
"(($$,$$$.&&)" |
-1.23 |
(bbbb$1.23) |
|
"((((,(($.&&)" |
-12345.67 |
($12345.67) |
|
"((((,(($.&&)" |
-1234.56 |
($1234.56) |
|
"((((,(($.&&)" |
-123.45 |
($123.45) |
|
"((((,($$.&&)" |
-12.34 |
($12.34) |
|
"((((,($$.&&)" |
-1.23 |
($1.23) |
|
"((((,($$.&&)" |
-.12 |
($.12) |
|
"($$$,$$$.&&)" |
12345.67 |
$12,345.67 |
|
"($$$,$$$.&&)" |
1234.56 |
$1,234.56 |
|
"($$$,$$$.&&)" |
123.45 |
$123.45 |
|
"(($$,$$$.&&)" |
12345.67 |
$12,345.67 |
|
"(($$,$$$.&&)" |
1234.56 |
$1,234.56 |
|
"(($$,$$$.&&)" |
123.45 |
$123.45 |
|
"(($$,$$$.&&)" |
12.34 |
$12.34 |
|
"(($$,$$$.&&)" |
1.23 |
$1.23 |
|
"((((,(($.&&)" |
12345.67 |
$12,345.67 |
|
"((((,(($.&&)" |
1234.56 |
$1,234.56 |
|
"((((,(($.&&)" |
123.45 |
$123.45 |
|
"((((,(($.&&)" |
12.34 |
$12.34 |
|
"((((,(($.&&)" |
1.23 |
$1.23 |
|
"((((,(($.&&)" |
.12 |
$.12 |
|
A third sample code example has been prepared to show how various values would be displayed using the USING operator to define different output formats. This can be found within the ‘functions’ demonstration application packaged with your Lycia installation. It is the program called "using3_operator.exe". If you want to see the program working, or the code in the .4gl file please look at the demonstration application using Lycia.