From: Dirk Biernat <Dirk on
Hi everybody!

Did anybody know, is there a reference document for the FORMAT command
available?!? I did not know the meaning of the Overflow or Comma Attribute!

If have the following requirement:

Working with AutoFormatType and AutoFormatExpr property on a field in a
table to change the text displayed, when the table is run.

Thanks for any information!
Example: Value in field is BE, the text to be displayed should be something
else! (Bestellung for example)

Is it possible!??!

Did someone has a reference for the command!??!

Any help is
From: H Ruiz (Savatage) on
Are you talking about the OnFormat (Trigger)??

OnFormat
Use this trigger to determine how the entries the user makes appear on the
screen, including the horizontal and vertical alignment of the entry.

OnFormat(TextString)

Applies to
Text boxes

Comments
The formatting instructions you enter in this trigger, via C/AL code, affect
only what the user sees on screen. The code you place in this trigger does
not affect how the system stores the data.

This is the first trigger the system executes when a user highlights the
control to enter data. The system then executes the OnBeforeInput trigger.

The system calls this trigger after it performs the default formatting of
the control. The TextString parameter contains the default formatting.

If there is an error in the C/AL code you enter into this trigger, the
system closes the form.

You cannot use this trigger to write to the database.

From: Dirk Biernat on
No, I'm not talking about the OnFormat Trigger! I'm talking about the FORMAT
command! (Variable := FORMAT(Variable,Length,FormatString))

The Format string can have attributes, to modify the value of a variable and
return them into another variable.

One of this attributes is Overflow!

"H Ruiz (Savatage)" wrote:

> Are you talking about the OnFormat (Trigger)??
>
> OnFormat
> Use this trigger to determine how the entries the user makes appear on the
> screen, including the horizontal and vertical alignment of the entry.
>
> OnFormat(TextString)
>
> Applies to
> Text boxes
>
> Comments
> The formatting instructions you enter in this trigger, via C/AL code, affect
> only what the user sees on screen. The code you place in this trigger does
> not affect how the system stores the data.
>
> This is the first trigger the system executes when a user highlights the
> control to enter data. The system then executes the OnBeforeInput trigger.
>
> The system calls this trigger after it performs the default formatting of
> the control. The TextString parameter contains the default formatting.
>
> If there is an error in the C/AL code you enter into this trigger, the
> system closes the form.
>
> You cannot use this trigger to write to the database.
>
From: H Ruiz (Savatage) on
FORMAT
Use this function to format a value into a string.

String := FORMAT(Value [, Length] [, FormatNumber | FormatString])

String : Data type: text or code
This string contains the formatted output.

Value : Data type: any

This is a C/AL variable (expression) of any simple data type, such as
option, integer, decimal, char, text, code, date, time, boolean, binary or
GUID.

If, when the system formats Value, the result is a value larger than the
maximum length MAXSTRLEN of String, a run-time error occurs.

Length: Data type: integer

Use this optional argument to determine the length of String. These rules
apply:

If Length...
It means...

Equals zero (0)
The system will return the entire value (default)
Is greater than zero (0)
String will be exactly Length characters.
If Value is less than Length characters, the system inserts either leading
or trailing spaces, depending on the format you select.

If Value is an integer which exceeds Length digits, the system places Length
asterisks in String.

If Value is not an integer and it exceeds Length characters, the system
truncates String accordingly.

Is less than zero (0)
String will have the maximum length of Length characters.

If Value is less than Length characters, the length of String will equal the
length of Value.

If Value is an integer which exceeds Length digits, the system places Length
asterisks in String.

If Value is not an integer and it exceeds Length characters, the system
truncates String accordingly.

FormatNumber : Data type: decimal

Use this optional argument to determine the format you want the system to
use. Here is a list of the basic options. The example below explains all
available formats:

The following table shows the predefined formats for the decimal data type.

Decimal : Format
<Sign><Integer Thousand><Decimals>
0

<Sign><Integer><Decimals>
1

<Sign><Integer><Decimals><1000Character,.>
2

<Integer Thousand><Decimals><Sign,1>
3

<Integer><Decimals><Sign,1>
4

FormatString : Date type: string

A literal string that defines a format as in the Format property.

Note:You can only use one of FormatNumber and FormatString at a time.

Comments
The description of the Format property describes the various predefined
formats in detail, and also how to create customized formats.

For more information about formats used by the various data type, see the
Format property.

Example
This example shows how to use the FORMAT function.

MESSAGE(Text000, FORMAT(-123456.78, 15, 3));

Create the following text constant in the C/AL Globals window:

Text Constant : ENU Value

Text000
'The formatted value: >%1<'

The message window shows:

The formatted value: > 123,456.78

To use a string to build a format, use the function like this:

MESSAGE(Text001, FORMAT(TODAY,0,'<Month Text> <Day>.');

Create the following text constant in the C/AL Globals window:

Text Constant : ENU Value

Text001
'Today is %1'

which could give this message:
Today is April 15.

From: H Ruiz (Savatage) on
Also, Format

Use this property to define how the system formats the source expression for
various data types.

Applies to
Text boxes, dataport fields

Comments
The Format property can be set to a predefined format, or you can build a
format of your own. See also the FORMAT function.

Basic Settings
To choose a predefined format, use the syntax: <Standard Format,X>, where X
is one of the entries in the Select... column of the following table:

To use this format... Select...
Standard Display Format (the default for all data types)
0

Standard Display Format 2 (edit)
1

C/AL Code Constant Format
2

Note you must enter the brackets < and >, as in <Standard Format,2>.
For a list of the predefined formats that are available, read the rest of
this Help topic.

Building Formats
The Format property also lets you create your own formats. To create a
format, use the syntax described below and keep the following rules in mind:

A format property consists of zero or more Chars, Fields or Attributes.

Fields and Attributes are expressed with an identifier inside brackets (<>).

Attributes must contain a comma (,) and a parameter after the identifier.

Fields can optionally take a comma (,) and a FieldLen.

The precise syntax is:

FormatProperty :=
[<Char> | <Field> | <Attribute>]

<Char> :=
character with ASCII value [32..255]

<Field> :=
'<' <FieldName> [',' <FieldLen>] '>'

[, <Attribute>]

<FieldName> :=
literal name of field (format component)

<FieldLen> :=
length of field (0 or no entry means that the length is dynamic)

<Attribute> :=
['<' <AttributeName> ',' <Char> '>']

<AttributeName> :=
[Standard Format | Filler | 1000Character | Comma | Overflow | Filler
Character | Precision]

Note
Comma is used to define the decimal symbol that is used, Filler and Filler
Character both mean the character that is used to fill empty spaces.

The FieldName is a "component" that you can use to build a format
expression. Depending on the data type of the text box or dataport field,
FieldName can be chosen from this list:

Data Type FieldNames
Decimal
Sign,Integer,Decimals,Integer Thousand

Date
Day,Month,Month Text,Quarter,Year,Year4,Week,

Week Year,Week Year4,Weekday,Weekday Text,Closing

Time
Hours24,Hours12,Minutes,Seconds,Thousands,AM/PM,Second dec.

Integer
Sign,Integer,Integer Thousand

Boolean
Text,Number

Option
Text,Number

Code
Text

Char
Char/Number,Char,Number

Text
Text

Example
Here are some examples of how to use the Format property:

Choosing a standard format:

Use the Standard Format attribute to select one of the standard formats
(these are listed at the end of this Help topic).

For example, <Standard Format,5> will select Standard Format 5.

Using a standard format with an attribute:

<Precision,2:3><Standard Format,0> will use Standard Format 0 and will
format the data with a minimum of 2 and a maximum of 3 decimal places. See
also the DecimalPlaces property. If you do not specify any precision the form
will use the precision specified in the Decimal Places property of the
corresponding field in the table.

Building a Format

You can create your own formats by using Chars (which will be displayed
literally), Fields (to choose specific components of a value, for example the
year-part of a date) and Attributes (for example to select which character to
use as a filler).

For example, a text box based on a source expression of the Date data type,
that uses the following format string:

<Weekday Text>, <Month Text> <Day>

will display the date as: Monday, April 15

In the following list of predefined formats, you can see many examples of
how to build formats.

You must remember that the settings that are specified under the Regional
and Language Options in Windows determine how a number of the separators are
displayed. This applies to the time and decimal separators among others.

The Standard Formats
The following tables list the predefined formats for each data type:

Decimal Format Example
<Sign><Integer Thousand><Decimals>
0
-76,543.21

<Sign><Integer><Decimals>
1
-76543.21

<Sign><Integer><Decimals><1000Character,.>
2
-76543.21

<Integer Thousand><Decimals><Sign,1>
3
76,543.21-

<Integer><Decimals><Sign,1>
4
761543.21-


For Dates, the Regional and Language Options in Windows is used to select
the actual format that is used. The table below shows the Fields that will be
used to build the various formats. This table, incidentally, corresponds to
the Regional setting for a European country.

Date Format Example
<Closing><Day,2>-<Month,2>-<Year>
0
05-04-03

<Closing><Day,2>-<Month,2>-<Year>
1
05-04-03

<Day,2><Month,2><Year><Closing>D
2
050403D

<Closing><Year>-<Month,2>-<Day,2>
3
03-04-05

<Closing><Day>. <Month Text> <Year4>
4
5. April 2003

<Closing><Day,2><Month,2><Year>
5
050403

<Closing><Year><Month,2><Day,2>
6
6030405

<Day,2><Filler Character, >. <Month Text,3> <Year4>
7
5. Apr 2003


The table below shows how these formats will change if the Regional and
Language Options is "United States."

US Date Format Example
<Closing><Month,2>/<Day,2>/<Year>
0
04/05/03

<Closing><Month,2>/<Day,2>/<Year>
1
04/05/03

<Month,2><Day,2><Year><Closing>D
2
040503D

<Closing><Year>/<Month,2>/<Day,2>
3
03/04/05

<Month Text> <Closing><Day>, <Year4>
4
April 5, 2003

<Closing><Month,2><Day,2><Year>
5
040503

<Closing><Year><Month,2><Day,2>
6
030504


For Times, the Regional and Language Options in Windows are used to select
the actual format used. The table below shows the Fields that will be used to
build the various formats. This table, incidentally, corresponds to the
Regional setting for a European country.

Time Format Example
<Hours24,2>.<Minutes,2>.<Seconds,2>
0
4.35.55

<Hours24>.<Minutes,2>.<Seconds,2><Second dec.>
1
4.35.55.553

<Hours24,2><Filler Character,0><Minutes,2><Seconds,2> <Second dec.><Comma,.>T
2
043555.553T


The next table shows how these time formats will appear if the Regional
setting is changed to "United States."

US Time Format Example
<Hours12,2>:<Minutes,2>:<Seconds,2><Second dec.> <AM/PM>
0
4:35:55 AM

<Hours12>:<Minutes,2>:<Seconds,2><Second dec.> <AM/PM>
1
4:35:55.553 AM

<Hours24,2><Filler Character,0><Minutes,2><Seconds,2> <Second dec.><Comma,.>T
2
043555 .553T





Integer Format Example
<Sign><Integer>
0
-567

<Sign><Integer>
1
-567

<Sign><Integer>
2
-567





Boolean Format Example
<Text>
0
Yes/No

<Text>
1
Yes/No

<Number>
2
1/0





Option Format Example
<Text>
0
Blue

<Text>
1
Blue

<Number>
2
1


For Chars, all formats are: <Char/Number>

For Text and Code, all formats are: <Text>