ABAPCOMPUTE_STRING_FORMAT_OPTIONS - COMPUTE STRING FORMAT OPTIONS
PERFORM Short Reference General Material DataThis documentation is copyright by SAP AG.
Embedded expressions - format_options
Syntax
... [WIDTH = len]
[ALIGN = LEFT|RIGHT|CENTER|(val)]
[PAD = c]
[CASE = RAW|UPPER|LOWER|(val)]
[SIGN = LEFT|LEFTPLUS|LEFTSPACE|RIGHT|RIGHTPLUS|RIGHTSPACE|(val)]
[EXPONENT = exp]
[DECIMALS = dec]
[ZERO = YES|NO|(val)]
[STYLE = SIMPLE|SIGN_AS_POSTFIX|SCALE_PRESERVING
|SCIENTIFIC|SCIENTIFIC_WITH_LEADING_ZERO
|SCALE_PRESERVING_SCIENTIFIC|ENGINEERING
|MONETARY|EXTENDED_MONETARY
|(val)]
[CURRENCY = cur]
[NUMBER = RAW|USER|ENVIRONMENT|(val)]
[DATE = RAW|ISO|USER|ENVIRONMENT|(val)]
[TIME = RAW|ISO|USER|ENVIRONMENT|(val)]
[TIMESTAMP = SPACE|ISO|USER|ENVIRONMENT|(val)]
[TIMEZONE = tz]
[COUNTRY = cty] ... .
Additions
1. ... WIDTH = len ...
2. ... ALIGN = LEFT|RIGHT|CENTER|(val) ...
3. ... PAD = c ...
4. ... CASE = RAW|UPPER|LOWER|(val) ...
5. ... SIGN = LEFT|LEFTPLUS|LEFTSPACE|RIGHT|RIGHTPLUS|RIGHTSPACE|(val) ...
6. ... EXPONENT = exp ...
7. ... DECIMALS = dec ...
8. ... ZERO = YES|NO|(val) ...
9. ... STYLE = ...|(val) ...
10. ... CURRENCY = cur ...
11. ... NUMBER = RAW|USER|ENVIRONMENT|(val) ...
12. ... DATE = RAW|ISO|USER|ENVIRONMENT|(val) ...
13. ... TIME = RAW|ISO|USER|ENVIRONMENT|(val) ...
14. ... TIMESTAMP = SPACE|ISO|USER|ENVIRONMENT|(val) ...
15. ... TIMEZONE = tz ...
16. ... COUNTRY = cty ...
Effect
These formatting options override the predefined formats ofembedded expressions instring templates. The formatting options are declared as optional keyword parameters to which an actual parameter is assigned.
The formatting options you can specify depend on the data type of the embedded expression. The formattingoptions NUMBER, DATE, TIME, TIMESTAMP, and COUNTRY are mutually exclusive.
Addition 1
... WIDTH = len ...
Effect
This formatting option defines the length of the string displayed by the embedded expression as the value of len, where len is anumerical expression position.
You can declare the option WIDTH for all data types of the embedded expression. If the valueof len is less than the minimum required length, it is ignored. This means that you can onlyincrease the predefined length, not reduce it. By default, a string is extended on the right and padded with blanks. You can override this default setting with the formatting options ALIGN and PAD.
Example
See Character String Templates, Length
Addition 2
... ALIGN = LEFT|RIGHT|CENTER|(val) ...
Effect
This formatting option defines the alignment of the string represented by the embedded expression. It only takes effect if WIDTH is used to define a length that is greater than the minimum required length.
The alignment can either be declared statically with one of the predefined parameters or dynamicallyas the content of a data object val, declared in parentheses. The possible values of val are defined as constants in the class CL_ABAP_FORMAT.
| Parameter | Value of val | Effect |
| LEFT | CL_ABAP_FORMAT=>A_LEFT | Left-aligned |
| RIGHT | CL_ABAP_FORMAT=>A_RIGHT | Right-aligned |
| CENTER | CL_ABAP_FORMAT=>A_CENTER | Centered |
The default setting is LEFT. Depending on the alignment, excess characters in the result arepadded with blanks (default) on the right, left, or alternately left and right. You can override this default setting with the formatting option PAD.
Example
See Character String Templates, Alignments, and Padding
Addition 3
... PAD = c ...
Effect
This formatting option defines the character used to pad excess spaces in the result. It only takes effect if WIDTH is used to define a length that is greater than the minimum required length.
A data object of data type c or string can be defined for c, the first characterof which is used as padding. If the PAD option is not declared or if c is specified as an empty string, blanks are used as padding.
Example
See Character String Templates, Alignments, and Padding
Addition 4
... CASE = RAW|UPPER|LOWER|(val) ...
Effect
This formatting option defines the case of the string represented by the embedded expression. You can declare it for all data types of the embedded expression.
The case (upper/lower) can either be declared statically with one of the predefined parameters or dynamicallyas the content of a data object val, declared in parentheses. The possible values of val are defined as constants in the class CL_ABAP_FORMAT.
| Parameter | Value of val | Effect |
| RAW | CL_ABAP_FORMAT=>C_RAW | Unchanged |
| UPPER | CL_ABAP_FORMAT=>C_UPPER | Uppercase |
| LOWER | CL_ABAP_FORMAT=>C_LOWER | Lowercase |
The default setting is RAW.
Note
The formatting option CASE affects the letters in a string. It has no effect on padding charactersdeclared using PAD. In numeric data types, the "e" or "E" of an exponent is affected; in byte-like data types, the letters in a hexadecimal representation are affected.
Example
See String Templates, Upper/Lower Case
Addition 5
... SIGN = LEFT|LEFTPLUS|LEFTSPACE|RIGHT|RIGHTPLUS|RIGHTSPACE|(val) ...
Effect
This formatting option defines the format of the +/- sign when the string represented by the embedded expression contains a numeric value. You can declare it only if the embedded expression has anumeric data type.
The format of the +/- sign can either be declared statically with one of the predefined parameters ordynamically as the content of a data object val, declared in parentheses. The possible values of val are defined as constants in the classCL_ABAP_FORMAT.
| Parameter | Value of val | Effect |
| LEFT | CL_ABAP_FORMAT=>S_LEFT | "-" left without space, no "+" |
| LEFTPLUS | CL_ABAP_FORMAT=>S_LEFTPLUS | "-" and "+" left without space |
| LEFTSPACE | CL_ABAP_FORMAT=>S_LEFTSPACE | "-" left without space, blank left for "+" |
| RIGHT | CL_ABAP_FORMAT=>S_RIGHT | "-" right without space, no "+" |
| RIGHTPLUS | CL_ABAP_FORMAT=>S_RIGHTPLUS | "-" and "+" right without space |
| RIGHTSPACE | CL_ABAP_FORMAT=>S_RIGHTSPACE | "-" left without space, blank right for "+" |
The default setting is LEFT.
Example
Addition 6
... EXPONENT = exp ...
Effect
This formatting option defines the exponent as the value of exp when formattingfloating point numbers, where exp is anumerical expression position. You can declare the option EXPONENT only if the embedded expression has anumeric data type. You cannot declare it in combination with the option TIMEZONE.
The option EXPONENT only affects the data type f or if the option STYLE is declaredwith the value scientific. The string is then formatted in exactly the same way as with the formattingoption EXPONENTof the statement WRITE TO, with the following exception:
If exp is declared as the value of the constant CL_ABAP_FORMAT=>EXP_PRESERVE, the exponent is used that matches the internal representation of the floating point value.
Addition 7
... DECIMALS = dec ...
Effect
This formatting option defines the number of decimal places as the value of dec, where dec is anumerical expression position. You can declare the option DECIMALS only if the embedded expression has anumeric data type. You cannot declare it in combination with the option TIMEZONE.
The string is then formatted in exactly the same way as with the formatting option DECIMALSof the statement WRITE TO.
Note
The DECIMALS formatting option does not override thepredefined format specifying that thousands separators are not inserted.
Addition 8
... ZERO = YES|NO|(val) ...
Effect
This formatting option defines the format of the numerical value zero. You can declare the option ZERO only if the embedded expression has anumeric data type. You cannot declare it in combination with the option TIMEZONE.
The format of the value zero can either be declared statically with one of the predefined parametersor dynamically as the content of a data object val, declared in parentheses. The possible values of val are defined as constants in the classCL_ABAP_FORMAT.
| Parameter | Value of val | Effect |
| YES | CL_ABAP_FORMAT=>Z_YES | The value zero is represented as a numeric value in accordance with the current formatting. |
| NO | CL_ABAP_FORMAT=>Z_NO | The value zero is represented as an empty string. |
The default setting is YES.
Addition 9
... STYLE = ...|(val) ...
Effect
This formatting option defines the style of decimal floating point numbers. You can declare the option STYLE only if the embedded expression has anumericdata type. You cannot declare it in combination with the optionsSIGN or TIMEZONE.
The style of a decimal floating point number can either be declared statically with a predefined parameteror dynamically as the content of a data object val, specified in parentheses. The possible values of val are defined as constants in the classCL_ABAP_FORMAT. The following table shows the predefined parameters and the constants of the class CL_ABAP_FORMAT:
| Parameter | Value of val |
| SIMPLE | CL_ABAP_FORMAT=>O_SIMPLE |
| SIGN_AS_POSTFIX | CL_ABAP_FORMAT=>O_SIGN_AS_POSTFIX |
| SCALE_PRESERVING | CL_ABAP_FORMAT=>O_SCALE_PRESERVING |
| SCIENTIFIC | CL_ABAP_FORMAT=>O_SCIENTIFIC |
| SCIENTIFIC_WITH_LEADING_ZERO | CL_ABAP_FORMAT=>O_SCIENTIFIC_WITH_LEADING_ZERO |
| SCALE_PRESERVING_SCIENTIFIC | CL_ABAP_FORMAT=>O_SCALE_PRESERVING_SCIENTIFIC |
| ENGINEERING | CL_ABAP_FORMAT=>O_ENGINEERING |
| MONETARY | CL_ABAP_FORMAT=>O_MONETARY |
| EXTENDED_MONETARY | CL_ABAP_FORMAT=>O_EXTENDED_MONETARY |
The default setting is SIMPLE.
The string is then formatted in exactly the same way as with the formatting option STYLEof the statement WRITETO. This means that the numerical value is converted to the data type decfloat34 and is handled as described here. Unlike WRITE TO, the following applies:
- SIMPLE uses the predefined format of embedded expressions.
- The generalrules for embedded expressions apply to thousands separators and decimal separators for embedded expressions.
As in WRITE TO, the following rules apply when combining these options with other formatting options:
- The option EXPONENT must only be declared with the output style SCIENTIFIC.
- The option CURRENCY must be specified for the output styles MONETARY and EXTENDED_MONETARY.
- The option DECIMALS cannot be declared for output styles that include scaling.
Example
See Decimal Floating Point Number, Formatting with STYLE
Addition 10
... CURRENCY = cur ...
Effect
This formatting option defines the number of decimal spaces when formatting numerical values, dependent on a currency when specified incur using acurrency code. You can declare the option CURRENCY only if the embedded expression has anumericdata type. You cannot declare it in combination with the option TIMEZONE. When the optionSTYLE is used, only the parameters MONETARY and EXTENDED_MONETARY may be specified there. If the option STYLE is not specified, the value MONETARY is used implicitly fordecimal floating point numbers. The option SIGN can be used to control the formatting of the sign.
The string is formatted in exactly the same way as with the formatting option CURRENCYof the statement WRITETO with the exception of data type p. In the case of data type p, the formatting depends on how the value is specified:
- When the value is specified as a data object or a functional method, CURRENCY works as in WRITETO, meaning that the actual decimal places are ignored and the decimal separator is inserted according to the currency associated with the specified currency ID.
- When specifying a value of an arithmetic expression or ageneral numerical function, CURRENCY works as in DECIMALS.
For all numerical data types other than decimal floating point numbers, a currency ID from the WAERS column of the database tableTCURC is expected in cur, while a value from the column CURRENCYCODE of the database table/ISCER/C_CUR must be specified for decimal floatingpoint numbers. An invalid currency for decimal floating point numbers raises the exception CX_SY_UNKNOWN_CURRENCY.Two decimal places are used for every currency ID specified, unless it is contained in the CURRKEY column of the database tableTCURX. In this case, the number of decimal places is determined from the CURRDEC column of the corresponding row in tableTCURX.
Note
The CURRENCY formatting option does not override thepredefined format specifying that thousands separators are not inserted.
Example
See Decimal Floating Point Number, Formatting with STYLE
Addition 11
... NUMBER = RAW|USER|ENVIRONMENT|(val) ...
Effect
This formatting option defines the format of the decimal representation (decimal and thousand separators). The option NUMBER can only be specified if the embedded expression has anumericdata type. As well as the exclusions mentioned above, it cannot be used in combination with the option TIMEZONE .
The format of the decimal representation can either be declared statically with one of the predefinedparameters or dynamically as the content of a data object val, declared in parentheses. The possible values of val are defined as constants in the classCL_ABAP_FORMAT.
| Parameter | Value of val | Effect |
| RAW | CL_ABAP_FORMAT=>N_RAW | The decimal separator is the period (.) and no thousand separators are inserted. |
| USER | CL_ABAP_FORMAT=>N_USER | The decimal and thousand separators are taken from theuser master record. |
| ENVIRONMENT | CL_ABAP_FORMAT=>N_ENVIRONMENT | The decimal and thousand separators are determined |
according to the current formatting setting of thelanguageenvironment that can be set using SET COUNTRY.
The default setting is RAW.
Note
If the formatting setting of thelanguage environment has not been set to acountry-specificformat by means of SET COUNTRY, the use of environment has the same effect as the use of user.
Example
See character string templates, formatting settings
Addition 12
... DATE = RAW|ISO|USER|ENVIRONMENT|(val) ...
Effect
This formatting option defines the format of a date. You can declare the option DATE only if the embedded expression has the data type d.
The format of the date can either be declared statically with one of the predefined parameters or dynamicallyas the content of a data object val, declared in parentheses. The possible values of val are defined as constants in the class CL_ABAP_FORMAT.
| Parameter | Value of val | Effect |
| RAW | CL_ABAP_FORMAT=>D_RAW | The content of the date field is used without being formatted. |
| ISO | CL_ABAP_FORMAT=>D_ISO | The date if formatted in accordance with ISO 8601, using hyphens (-) as separators: "yyyy-mm-dd". |
| USER | CL_ABAP_FORMAT=>D_USER | The date is formatted in accordance with the information in theuser master data. |
| ENVIRONMENT | CL_ABAP_FORMAT=>D_ENVIRONMENT | The formatting of the date is determined |
according to the current formatting setting of thelanguageenvironment that can be set using SET COUNTRY.
The default setting is RAW.
Note
If the formatting setting of thelanguage environment has not been set to acountry-specificformat by means of SET COUNTRY, the use of environment has the same effect as the use of user.
Example
See character string templates, formatting settings
Addition 13
... TIME = RAW|ISO|USER|ENVIRONMENT|(val) ...
Effect
This formatting option defines the format of a time. You can declare the option TIME only if the embedded expression has the data type t.
The format of the time can either be declared statically with one of the predefined parameters or dynamicallyas the content of a data object val, declared in parentheses. The possible values of val are defined as constants in the class CL_ABAP_FORMAT.
| Parameter | Value of val | Effect |
| RAW | CL_ABAP_FORMAT=>T_RAW | The content of the time field is used without being formatted. |
| ISO | CL_ABAP_FORMAT=>T_ISO | The time is formatted in accordance with ISO 8601, in 24-hour format using colons (:) as separators: "hh:mm:ss". |
| USER | CL_ABAP_FORMAT=>T_USER | The time is formatted in accordance with the information in theuser master data. |
| ENVIRONMENT | CL_ABAP_FORMAT=>T_ENVIRONMENT | The formatting of the time is determined |
according to the current formatting setting of thelanguageenvironment that can be set using SET COUNTRY.
The default setting is RAW.
Note
You can configure a 24-hour format and four 12-month formats in the user master data or using the SETCOUNTRY statement. To use 12-hour format, you must declare USER or ENVIRONMENT or work with the open formatting option COUNTRY.
Note
If the formatting setting of thelanguage environment has not been set to acountry-specificformat by means of SET COUNTRY, the use of environment has the same effect as the use of user.
Example
See character string templates, formatting settings
Addition 14
... TIMESTAMP = SPACE|ISO|USER|ENVIRONMENT|(val) ...
Effect
This formatting option defines the format of a time stamp. The option TIMESTAMP can be declared only if the embedded expression has thedata type p with the length 8 and no decimal places (TIMESTAMP from ABAP Dictionary) or datatype p with length 11 and seven decimal places (TIMESTAMPL from ABAP Dictionary). The value of the embedded expression is interpreted as a time stamp.
The format of the time stamp can either be declared statically with one of the predefined parametersor dynamically as the content of a data object val, declared in parentheses. The possible values of val are defined as constants in the classCL_ABAP_FORMAT.
| Parameter | Value of val | Effect |
| SPACE | CL_ABAP_FORMAT=>TS_SPACE | The content of the time stamp is converted by default to a date and time inUTCreference time and they are both represented in accordance with ISO 8601: "yyyy-mm-dd hh:mm:ss.zzzzzzz". You can use the option TIMEZONE to declare a different time zone. |
| ISO | CL_ABAP_FORMAT=>TS_ISO | As SPACE, but in accordance with ISO 8601 the character "T" is placed between the date and the time and the decimal separator is always a comma(,): "yyyy-mm-ddThh:mm:ss,zzzzzzz". |
| USER | CL_ABAP_FORMAT=>TS_USER | As SPACE, but the date format and the time format are taken from theuser master record. |
| ENVIRONMENT | CL_ABAP_FORMAT=>TS_ENVIRONMENT | As SPACE. However, the date format and time format are defined in accordance with |
according to the current formatting setting of thelanguageenvironment that can be set using SET COUNTRY.
| - | CL_ABAP_FORMAT=>TS_RAW | The content of the time stamp is not converted and the output is a packed number. |
The default setting is SPACE.
Note
If the formatting setting of thelanguage environment has not been set to acountry-specificformat by means of SET COUNTRY, the use of environment has the same effect as the use of user.
Example
See character string templates, formatting settings
Addition 15
... TIMEZONE = tz ...
Effect
This formatting option defines the time zone into which atimestamp is converted. The option TIMEZONE can only be declared if the embedded expressionhas the data type p with the length 8 and no decimal places (TIMESTAMP from ABAP Dictionary)or the data type p the length 11 with seven decimal places (TIMESTAMPL from ABAP Dictionary).The value of the embedded expression is interpreted as a time stamp. If the option TIMEZONE isdeclared without the option TIMESTAMP, the time stamp is formatted implicitly as if the optionTIMESTAMP is declared with the parameter SPACE. If val in TIMESTAMP is declared as the value of CL_ABAP_FORMAT=>TS_RAW, TIMEZONE cannot be declared.
tz must be declared as a data object of the type TIMEZONE from ABAP Dictionary. This data object must contain a time zone from the TZONE column of the database tableTTZZ in uppercase letters. If tz is initial, theUTC reference time is used.
Example
See String Templates, Time Zones
Addition 16
... COUNTRY = cty ...
Effect
The formatting option COUNTRY defines a temporaryformattingsetting for the currently embedded expression. You can declare it as an alternative to all formattingoptions for which the parameter ENVIRONMENT can be declared (that is, instead of NUMBER,DATE, TIME, and TIMESTAMP). The embedded expression is formatted as a number, date, or time, or time stamp, depending on its data type.
For cty you have to specify a data object of the typeLAND1 from ABAP Dictionary and it must either contain a value from the LAND column of the database tableT005X or it must be initial. If not, an exception of the class CX_SY_STRG_FORMAT is raised.
If cty contains a value from the table T005X, thecountry-specific format defined there is used. If cty is initial, the formatting specified in theuser master record is used.
Notes
- Unlike using the statement SETCOUNTRY and the parameter ENVIRONMENT, there are no side-effects when using the formattingoption COUNTRY. The country specified only has an effect on the currently embedded expression and not on any subsequent statements from the current internal mode.
- In numbers, the COUNTRY formatting option overrides thepredefined setting with regard to thousand separators.
Examples
See
- Character String Templates, Number Formats
- Character String Templates, Date Formats
- Character String Templates, Time Formats
Addresses (Business Address Services) Addresses (Business Address Services)
This documentation is copyright by SAP AG.
Length: 44577 Date: 20120522 Time: 040053 triton ( 988 ms )






