SAP® Documentation

Single view

ABAPCOMPUTE_STRING_FORMAT_OPTIONS - COMPUTE STRING FORMAT OPTIONS

BAL Application Log Documentation   Vendor Master (General Section)  
This documentation is copyright by SAP AG.
SAP E-Book

Embedded Expressions - format_options

Syntax

... $[WIDTH     = len$]
    $[ALIGN     = LEFT$|RIGHT$|CENTER$|(dobj)$|expr$]
    $[PAD       = c$]
    $[CASE      = RAW$|UPPER$|LOWER$|(dobj)$|expr$]
    $[SIGN      = LEFT$|LEFTPLUS$|LEFTSPACE$|RIGHT$|RIGHTPLUS$|RIGHTSPACE$|(dobj)$|expr$]
    $[EXPONENT  = exp$]
    $[DECIMALS  = dec$]
    $[ZERO      = YES$|NO$|(dobj)$|expr$]
    $[XSD       = YES$|NO$|(dobj)$|expr$]
    $[STYLE     =  SIMPLE$|SIGN_AS_POSTFIX$|SCALE_PRESERVING
                 $|SCIENTIFIC$|SCIENTIFIC_WITH_LEADING_ZERO
                 $|SCALE_PRESERVING_SCIENTIFIC$|ENGINEERING
                 $|(dobj)$|expr$]
    $[CURRENCY  = cur$]
    $[NUMBER    = RAW$|USER$|ENVIRONMENT$|(dobj)$|expr$]
    $[ALPHA     = IN$|OUT$|RAW$|(dobj)$|expr$]
    $[DATE      = RAW$|ISO$|USER$|ENVIRONMENT$|(dobj)$|expr$]
    $[TIME      = RAW$|ISO$|USER$|ENVIRONMENT$|(dobj)$|expr$]
    $[TIMESTAMP = SPACE$|ISO$|USER$|ENVIRONMENT$|(dobj)$|expr$]
    $[TIMEZONE  = tz$]
    $[COUNTRY   = cty$] ...


Additions

1. ... WIDTH = len ...

2. ... ALIGN = LEFT$|RIGHT$|CENTER$|(dobj)$|expr ...

3. ... PAD = c  ...

4. ... CASE = RAW$|UPPER$|LOWER$|(dobj)$|expr ...

5. ... SIGN = LEFT$|LEFTPLUS$|LEFTSPACE$|RIGHT$|RIGHTPLUS$|RIGHTSPACE$|(dobj)$|expr ...

6. ... EXPONENT = exp ...

7. ... DECIMALS = dec ...

8. ... ZERO = YES$|NO$|(dobj)$|expr ...

9. ... XSD = YES$|NO$|(dobj)$|expr ...

10. ... STYLE = ...$|(dobj)$|expr ...

11. ... CURRENCY  = cur ...

12. ... NUMBER = RAW$|USER$|ENVIRONMENT$|(dobj)$|expr ...

13. ... ALPHA = IN$|OUT$|RAW$|(dobj)$|expr ...

14. ... DATE = RAW$|ISO$|USER$|ENVIRONMENT$|(dobj)$|expr ...

15. ... TIME = RAW$|ISO$|USER$|ENVIRONMENT$|(dobj)$|expr ...

16. ... TIMESTAMP = SPACE$|ISO$|USER$|ENVIRONMENT$|(dobj)$|expr ...

17. ... TIMEZONE = tz ...

18. ... COUNTRY = cty ...

Effect

These formatting options override the predefined formats of embedded expressions in string templates. The formatting options are specified as optional key word parameters to which an actual parameter is assigned.

Actual parameters with fixed values can be specified as follows:

  • Statically as a key word
  • Dynamically as
  • the content of a data object (dobj) specified in parentheses

The possible values of dobj or expr are defined as constants in the class CL_ABAP_FORMAT.

The possible formatting options depend on the data type of the embedded expression. The formatting options NUMBER, DATE, TIME, TIMESTAMP, and COUNTRY are mutually exclusive.

If a formal parameter or a field symbol with a generic data type is specified as an embedded expression, only those formatting options can be specified that are permitted for all possible fixed data types.

Note

If specified, (dobj) and expr represent a summary functional operand position. Unlike the regular functional operand positions, however, the data object dobj must be placed in parentheses to distinguish it clearly from a parameter specified as a key word.

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 a numeric expression position.

The option WIDTH can be specified for all data types of the embedded expression. If the value of len is less than the minimum required length, it is ignored. This means that the predefined length cannot be reduced, only increased. By default, a string is extended on the right and padded with blanks. This default setting can be overridden using the formatting options ALIGN and PAD.

Example

The length of the result of the following string template is 20. It consists of 4 digits, a decimal separator, and 15 trailing blanks.

DATA(text) = |{ CONV decfloat34( 1234 / 10 ) WIDTH = 20 }|.

String Templates, Length

Addition 2

... ALIGN = LEFT$|RIGHT$|CENTER$|(dobj)$|expr ...

Effect

This formatting option defines the alignment of the string represented by the embedded expression. It is applied only if WIDTH is used to define a length that is greater than the minimum required length.

The values for the alignment are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or exprEffect
LEFTCL_ABAP_FORMAT=>A_LEFTLeft-justified
RIGHTCL_ABAP_FORMAT=>A_RIGHTRight-justified
CENTERCL_ABAP_FORMAT=>A_CENTERCentered

The default setting is LEFT. Depending on the alignment, surplus places in the result are padded with blanks (default) on the right, left, or alternately left and right. This default setting can be overridden using the formatting option PAD.

Example

The following string template creates the character string shown below it.

DATA(text) =
  |{ 1 WIDTH = 5 ALIGN = RIGHT
  }{ 2 WIDTH = 5 ALIGN = RIGHT
  }{ 3 WIDTH = 5 ALIGN = RIGHT }<-|.

    1    2    3<-

String Templates, Alignments and Padding

Addition 3

... PAD = c  ...

Effect

This formatting option defines the character used to pad any surplus places in the result. It is applied only 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 character of which is used as padding. If the PAD option is not specified or if c is specified as an empty string, blanks are used as padding.

Example

The following string template creates the character string shown below it.

DATA(text) = |{ 'X' ALIGN = RIGHT WIDTH = 10 PAD = '_' }|.

_________X

Example

See Character String Templates, Alignments and Padding

Addition 4

... CASE = RAW$|UPPER$|LOWER$|(dobj)$|expr ...

Effect

This formatting option defines the case of the string represented by the embedded expression. It can be specified for all data types of the embedded expression.

The values for the case are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or exprEffect
RAWCL_ABAP_FORMAT=>C_RAWUnchanged
UPPERCL_ABAP_FORMAT=>C_UPPERUppercase
LOWERCL_ABAP_FORMAT=>C_LOWERLowercase

The default setting is RAW.

Note

The formatting option CASE affects the letters in a string. It is ignored by characters specified 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

The following string template creates the character string shown below it.

DATA(text) =
  |{ cl_abap_conv_codepage=>create_out( )->convert(
       'Hello World!' ) CASE = LOWER }| .

48656c6c6f20576f726c6421

String Templates, Case

Addition 5

... SIGN = LEFT$|LEFTPLUS$|LEFTSPACE$|RIGHT$|RIGHTPLUS$|RIGHTSPACE$|(dobj)$|expr ...

Effect

This formatting option defines the format of the +/- sign when the string represented by the embedded expression contains a numeric value. It can be specified only if the embedded expression has a numeric data type.

The values for the format of the sign are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or exprEffect
LEFTCL_ABAP_FORMAT=>S_LEFT"-" left without space, no "+"
LEFTPLUSCL_ABAP_FORMAT=>S_LEFTPLUS"-" and "+" left without space
LEFTSPACECL_ABAP_FORMAT=>S_LEFTSPACE"-" left without space, blank left for "+"
RIGHTCL_ABAP_FORMAT=>S_RIGHT"-" right without space, no "+"
RIGHTPLUSCL_ABAP_FORMAT=>S_RIGHTPLUS"-" and "+" right without space
RIGHTSPACECL_ABAP_FORMAT=>S_RIGHTSPACE"-" left without space, blank right for "+"

The default setting is LEFT.

Example

The following string template creates the character string shown below it.

DATA(text) = |{ 1 SIGN = LEFTPLUS }| .

+1

String Templates, Sign

Addition 6

... EXPONENT = exp ...

Effect

This formatting option defines the exponent as the value of exp when formatting floating point numbers, where exp is a numeric expression position. The option EXPONENT can be specified only if the embedded expression has a numeric data type. It cannot be specified in combination with the options TIMESTAMP or TIMEZONE.

The option EXPONENT only affects the data type f or if the option STYLE is specified with the value scientific.

If exp is specified 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.

Example

The following string template creates the character string shown below it.

DATA(text) = |{ CONV f( 2 / 3 ) }, { CONV f( 2 / 3 ) EXPONENT = -1 }|.

0.66666666666666663, 6.6666666666666663E-01

Addition 7

... DECIMALS = dec ...

Effect

This formatting option defines the number of decimal places as the value of dec, where dec is a numeric expression position. The option DECIMALS can be specified only if the embedded expression has a numeric data type. It cannot be specified in combination with the options TIMESTAMP or TIMEZONE.

Note

The formatting option DECIMALS does not override the predefined format specifying that thousands separators are not inserted.

Example

The following string template creates the character string shown below it. If the conversion operator is not specified, the calculation type of the embedded expression is i.

DATA(text) = |{                  - 2 / 3   DECIMALS = 3 }, {
                CONV decfloat34( - 2 / 3 ) DECIMALS = 3 }, {
                CONV          f( - 2 / 3 ) DECIMALS = 3 }|.

-1.000, -0.667, -0.667

Addition 8

... ZERO = YES$|NO$|(dobj)$|expr ...

Effect

This formatting option defines the format of the numeric value zero. The option ZERO can be specified only if the embedded expression has a numeric data type. It cannot be specified in combination with the options TIMESTAMP or TIMEZONE.

The values for the format of the zero value are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or exprEffect
YESCL_ABAP_FORMAT=>Z_YESThe value zero is represented as a number value in accordance with the current formatting.
NOCL_ABAP_FORMAT=>Z_NOThe value zero is represented as an empty string.

The default setting is YES.

Example

The following string template creates the character string shown below it.

DATA(text) = |{ 0 ZERO = NO }, { 0 ZERO = YES }|.

, 0

Addition 9

... XSD = YES$|NO$|(dobj)$|expr ...

Effect

This formatting option formats the value of the embedded expression in the asXML format that is associated with its data type. The option XSD can be specified for all elementary data types. It cannot be specified together with other formatting options; with the exception of WIDTH, ALIGN, PAD, CASE, and ZERO.

The option XSD affects all data types listed under Mapping of Elementary ABAP Types, as specified there.

The values for the asXML format are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or exprEffect
YESCL_ABAP_FORMAT=>X_YESThe data type of the embedded expression determines how it is formatted in accordance with the asXML format specified under Mapping of Elementary ABAP Types. If the data type references one of the domains specified under Mapping of Further XML Schema Data Types (with the exception of XSDQNAME), the format specified there is used. XML fragments cannot be mapped using the domain XSDANY.
NOCL_ABAP_FORMAT=>X_NOUnchanged

If the data type of the embedded expression has the type x or xstring, a formatting option CASE specified at the same time is ignored (unless it refers to the domain XSDUUID_RAW).

Note

The formatting of an embedded expression with XSD generally produces the same result as applying the predefined identity transformation ID. Unlike a CALL TRANSFORMATION call, exceptions that can be raised by mappings, but not wrapped, should be handled directly.

Example

The following string template creates the character string shown below it. XSDBOOLEAN is a data element that references the special domain XSDBOOLEAN for the mapping of truth values.

DATA:
  flag1 TYPE xsdboolean VALUE abap_true,
  flag2 TYPE xsdboolean VALUE abap_false.

DATA(text) = |{ flag1 XSD = YES }, { flag2 XSD = YES }|.

true, false

String Templates, asXML Format

Addition 10

... STYLE = ...$|(dobj)$|expr ...

Effect

This formatting option defines the style of decimal floating point numbers. The option STYLE can be specified only if the embedded expression has a numeric data type. It cannot be specified in combination with the options CURRENCY, SIGN, TIMESTAMP, or TIMEZONE.

The values for the format of a decimal floating point number are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or expr
SIMPLECL_ABAP_FORMAT=>O_SIMPLE
SIGN_AS_POSTFIXCL_ABAP_FORMAT=>O_SIGN_AS_POSTFIX
SCALE_PRESERVINGCL_ABAP_FORMAT=>O_SCALE_PRESERVING
SCIENTIFICCL_ABAP_FORMAT=>O_SCIENTIFIC
SCIENTIFIC_WITH_LEADING_ZEROCL_ABAP_FORMAT=>O_SCIENTIFIC_WITH_LEADING_ZERO
SCALE_PRESERVING_SCIENTIFICCL_ABAP_FORMAT=>O_SCALE_PRESERVING_SCIENTIFIC
ENGINEERINGCL_ABAP_FORMAT=>O_ENGINEERING

This means that the numeric value of the string is converted to the data type decfloat34 and is handled as follows:

  • The default settings SIMPLE creates the predefined format of embedded expressions.
  • SIGN_AS_POSTFIX creates a commercial notation. The sign is appended on the right (a minus sign for negative values, a blank for positive values). Trailing zeroes in decimal places are cut off.
  • SCALE_PRESERVING preserves the scale. Here, trailing zeroes in the decimal places are not cut off. The same format is created as in conversions of a source field of type decfloat34 to the type string.
  • SCIENTIFIC creates a scientific notation. No sign is added for positive numbers. The result always has at least a two digit exponent with a sign. If the addition EXPONENT is not specified, only one integer digit (whose value is not zero) is represented in the mantissa, unless the source field has the value 0. Any trailing zeroes in the decimal places of the mantissa are cut off. The formatting option DECIMALS can be used to specify the number of decimal places and EXPONENT can be used to specify the exponent.
  • SCIENTIFIC_WITH_LEADING_ZERO creates a scientific notation with leading zero. Like SCIENTIFIC with the following differences:
  • Only one integer digit with the value 0 is represented.

  • The formatting option EXPONENT cannot be specified.

  • SCALE_PRESERVING_SCIENTIFIC creates a scientific notation while preserving the scale. Like SCIENTIFIC with the following differences:
  • The exponent always has three digits for decfloat16 and four digits for decfloat34.

  • Trailing zeroes after the decimal point of the mantissa are not cut off.

  • The formatting option EXPONENT cannot be specified.

  • ENGINEERING creates a technical format. Like SCIENTIFIC with the following differences:
  • The value of the exponent is always an integer multiple of 3.

  • The value range of the integer digits is between 1 and 999 (except if the source field has the value 0).

  • The formatting option EXPONENT cannot be specified.

The general rules for embedded expressions apply to thousands separators and decimal separators. When combining other formatting options, the following applies:

  • The formatting option EXPONENT can only be specified in combination with the output style SCIENTIFIC.
  • The formatting option DECIMALS cannot be specified for output styles that preserve scaling. For the output formats SIMPLE and SIGN_AS_POSTFIX, DECIMALS defines the number of decimal places. In some cases, commercial rounding may take place or trailing zeroes may be appended. For the scientific output formats, DECIMALS determines the number of decimal places in the mantissa. In some cases commercial rounding may take place.


Example

The following string template creates the character string shown below it.

DATA(text) = |{ CONV decfloat34( '123456' ) STYLE = ENGINEERING }|.

123.456E+03

Decimal Floating Point Number, Formatting with STYLE

Addition 11

... CURRENCY  = cur ...

Effect

This formatting option defines the number of decimal places when formatting numeric values, dependent on a currency when specified incur using a currency ID. The option CURRENCY can be specified only if the embedded expression has one of the numeric data typesi, p, or f. It cannot be specified for the numeric data types decfloat16 and decfloat34 and not in combination with the options STYLE, TIMESTAMP, or TIMEZONE. The option SIGN can be used to control the formatting of the sign.

With respect to its decimal places. the string is formatted as follows for the individual numeric data types:

  • For data objects of the types (b, s), i and int8, a decimal separator is inserted into the result at the place determined by cur.
  • In the case of data type p, the formatting depends on how the value is specified:
  • If specified as a data object or as a functional method, the decimal places specified in the definition of the data type are ignored in full. Regardless of the actual value and without rounding, a decimal separator is inserted between the digits in the places determined by cur.

  • For data objects of type f, the formatting option CURRENCY has the same effect as DECIMALS, where the number of decimal places is determined by cur.

cur in the numeric data types i, p, and f expects a currency ID from the column WAERS of the database table TCURC. Two decimal places are used for every currency ID specified, unless it is contained in the CURRKEY column of the database table TCURX. In this case, the number of decimal places is determined from the CURRDEC column of the corresponding row in table TCURX.

Notes

  • The CURRENCY formatting option does not override the predefined format specifying that thousands separators are not inserted.
  • The formatting option CURRENCY is useful with currencies from the tables TCURX or TCURX for formatting data objects of types (b, s), i, int8, or p without decimal places, whose contents are currency amounts in the smallest unit of the currency.
  • For decimal floating point numbers, the methods CONVERT_CURR_TO_DECFLOAT and CONVERT_DECFLOAT_TO_CURR of the system class CL_ABAP_DECFLOAT are provided. These methods convert currency amounts to decimal floating point numbers, as specified by a currency key, and back again.


Example

The following string template creates the character string shown below it.

DATA(text) = |{ 12345678 CURRENCY = 'EUR' }|.

123456.78

Addition 12

... NUMBER = RAW$|USER$|ENVIRONMENT$|(dobj)$|expr ...

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 a numeric data type. As well as the exclusions mentioned above, it cannot be used in combination with the options TIMESTAMP or TIMEZONE .

The values for the format of the decimal representation are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or exprEffect
RAWCL_ABAP_FORMAT=>N_RAWThe decimal separator is the period (.) and no thousand separators are inserted.
USERCL_ABAP_FORMAT=>N_USERThe decimal and thousand separators are taken from the user master record.
ENVIRONMENTCL_ABAP_FORMAT=>N_ENVIRONMENTThe decimal and thousand separators are determined

according to the current formatting setting of the language environment that can be set using SET COUNTRY.

The default setting is RAW.

Note

If the formatting setting of the language environment has not been set to a country-specific format 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

Example

The following string template generates the character string shown below it.

SET COUNTRY 'US'.
DATA(text) = |{ 1000000 NUMBER = ENVIRONMENT }|.

1,000,000

Addition 13

... ALPHA = IN$|OUT$|RAW$|(dobj)$|expr ...

Effect

This formatting option adds leading zeroes to strings of digits or removes them. The option ALPHA can be specified only if the embedded expression has the data type string, c, or n. It cannot be specified together with other formatting options; apart from WIDTH and CASE.

The values for the format of the string of digits are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or exprEffect
INCL_ABAP_FORMAT=>L_INIf the character string of the embedded expression only contains an uninterrupted string of digits (apart from leading and trailing blanks), the string of digits is right-justified in a character string of specified length (see below), which is padded on the left with the digit "0", if necessary. Otherwise, the characters of the character string of the embedded expression are left-justified in the character string and padded with blanks on the right, if necessary. If the length is not sufficient, the string is cut off on the right in both cases.
OUTCL_ABAP_FORMAT=>L_OUTIf the character string of the embedded expression only contains an uninterrupted string of digits (apart from leading and trailing blanks), leading zeroes are removed from the string of digits and the remaining digits are left-justified in a character string of a specified length (see below), which is padded on the right with blanks, if necessary Otherwise, all characters of the character string of the embedded expression are left-justified in the character string and padded with blanks on the right, if necessary. If the length is not sufficient, the string is cut off on the right in both cases.
RAWCL_ABAP_FORMAT=>L_RAWNo formatting

The length of the resulting character string is determined as follows:

  • If the formatting option WIDTH is not specified and the embedded expression, as the only content of a character string template, is assigned to a fixed-length target field of type c, n, d, or t, the length of this field determines the available length. Otherwise, the length of the original field, including trailing blanks, is used.
  • If the formatting option WIDTH is specified, the specified length is only used if it is greater than the length of the uninterrupted string of digits without leading zeroes, or the character string without trailing blanks. Otherwise, the length of the uninterrupted string of digits without leading zeroes or the character string without trailing blanks is used.

Notes

Example

The following string template creates the character string shown below it.

DATA(text) = |{ '1234' ALPHA = IN WIDTH = 10 }|.

0000001234

String Templates, Strings of Digits

Addition 14

... DATE = RAW$|ISO$|USER$|ENVIRONMENT$|(dobj)$|expr ..

Effect

This formatting option defines the format of a date. The option DATE can be specified only if the embedded expression has the data type d.

The values for the format of the date are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or exprEffect
RAWCL_ABAP_FORMAT=>D_RAWThe content of the date field is used without being formatted.
ISOCL_ABAP_FORMAT=>D_ISOThe date if formatted in accordance with ISO 8601, using dashes (-) as separators: "yyyy-mm-dd".
USERCL_ABAP_FORMAT=>D_USERThe date is formatted in accordance with the information in the user master data.
ENVIRONMENTCL_ABAP_FORMAT=>D_ENVIRONMENTThe formatting of the date is determined

according to the current formatting setting of the language environment that can be set using SET COUNTRY.

The default setting is RAW.

Note

If the formatting setting of the language environment has not been set to a country-specific format 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

Example

The following string template generates the character string shown below it (depending on the current date).

DATA(text) = |{ sy-datlo DATE = ISO }|.

2016-09-09

Addition 15

... TIME = RAW$|ISO$|USER$|ENVIRONMENT$|(dobj)$|expr ..

Effect

This formatting option defines the format of a time. The
option TIME can be specified only if the embedded expression has the data type t.

The values for the format of the time are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or exprEffect
RAWCL_ABAP_FORMAT=>T_RAWThe content of the time field is used without being formatted.
ISOCL_ABAP_FORMAT=>T_ISOThe time is formatted in accordance with ISO 8601, in 24-hour format using colons (:) as separators: "hh:mm:ss".
USERCL_ABAP_FORMAT=>T_USERThe time is formatted in accordance with the information in the user master data.
ENVIRONMENTCL_ABAP_FORMAT=>T_ENVIRONMENTThe formatting of the time is determined

according to the current formatting setting of the language environment that can be set using SET COUNTRY.

The default setting is RAW.

Note

A 24-hour format and four 12-month formats can be configured in the user master data or using the statement SET COUNTRY. To use 12-hour format, USER or ENVIRONMENT must be specified or the formatting option COUNTRY used.

Note

If the formatting setting of the language environment has not been set to a country-specific format 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

Example

The following string template creates the character string shown below it (depending on the current time) if a country with a 12-hour format is found in the database table T005X.

SELECT SINGLE land
       FROM t005x
       WHERE timefm = 1
       INTO @DATA(land).
IF sy-subrc <> 0.
  RETURN.
ENDIF.

SET COUNTRY land.
DATA(text) = |{ sy-timlo TIME = ENVIRONMENT }|.

10:55:58 AM

Addition 16

... TIMESTAMP = SPACE$|ISO$|USER$|ENVIRONMENT$|(dobj)$|expr ...

Effect

This formatting option defines the format of a time stamp. The option TIMESTAMP can be specified only if the embedded expression has the data type p with the length 8 and no decimal places (TIMESTAMP from ABAP Dictionary) or data type 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 values for the format of the time stamp are fixed. The following table shows the key words and the associated values from the class CL_ABAP_FORMAT that can be specified as dobj or expr:

KeywordValue of dobj or exprEffect
SPACECL_ABAP_FORMAT=>TS_SPACEThe content of the time stamp is converted by default to a date and time in UTC reference time and they are both represented in accordance with ISO 8601: "yyyy-mm-dd hh:mm:ss.zzzzzzz". The option TIMEZONE can be used to specify a different time zone.
ISOCL_ABAP_FORMAT=>TS_ISOLike 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".
USERCL_ABAP_FORMAT=>TS_USERAs SPACE, but the date format and the time format are taken from the user master record.
ENVIRONMENTCL_ABAP_FORMAT=>TS_ENVIRONMENTAs SPACE. However here the date format and time format are defined in accordance with

according to the current formatting setting of the language environment that can be set using SET COUNTRY.

-CL_ABAP_FORMAT=>TS_RAWThe 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 the language environment has not been set to a country-specific format 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

Example

The following string template generates the character string shown below it (depending on the current time stamp).

GET TIME STAMP FIELD DATA(tmstmp).
DATA(text) = |{ tmstmp TIMESTAMP = ISO }|.

2016-09-09T09:12:04

Addition 17

... TIMEZONE = tz ...

Effect

This formatting option converts the date and time information of a time stamp to the local date and the local time of the specified time zone. The information is formatted in accordance with how the option TIMESTAMP is specified.

The option TIME ZONE can be specified only if the embedded expression has one of the data types TIMESTAMPL or TIMESTAMP from ABAP Dictionary (as with type p with length 11 and 7 decimal places or p with length 8 and no decimal places) as a time stamp. Other data types produce a syntax error or runtime error.

tz expects a character-like data object containing a time zone from the database table TTZZ. If the rule set for the specified time zone is incomplete, a non-handleable exception is raised. If tz is initial, the time zone is set implicitly to "UTC".

If the addition TIMEZONE is specified for source fields with the types TIMESTAMPL or TIMESTAMP from ABAP Dictionary, the content of the source field is handled like a time stamp. If the option TIMEZONE is specified without the option TIMESTAMP, the parameter SPACE is added to the option TIMESTAMP implicitly. The option TIMEZONE cannot be specified if the value of CL_ABAP_FORMAT=>TS_RAW is specified for TIMESTAMP in dobj or expr. The conversion is performed in the same way as with the statement CONVERT TIME STAMP.

If the value of tz is not in the database table TTZZ, if the source field does not contain a valid time stamp, or if the conversion produces a local time outside the value range for local dates and times, the content is formatted as a UTC time stamp, regardless of the value.

Example

The following string template creates the character string shown below it (depending on the current time stamp).

GET TIME STAMP FIELD DATA(tmstmp).
DATA(text) =
  |{ tmstmp TIMESTAMP = ISO } {
     tmstmp TIMESTAMP = ISO TIMEZONE = 'CET'  }|.

2016-09-09T09:18:27 2016-09-09T11:18:27

String Templates, Time Zones

Addition 18

... COUNTRY = cty ...

Effect

The formatting option COUNTRY defines a temporary formatting setting for the currently embedded expression. It can be specified as an alternative to all formatting options for which the parameter ENVIRONMENT can be specified (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.

cty expects a data object of the type LAND1 from ABAP Dictionary. It must either contain a value from the LAND column of the database table T005X 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 data base table T005X, the country-specific format defined there is used. If cty is initial, the formatting specified in the user master record is used.

Notes

  • Unlike using the statement SET COUNTRY and the parameter ENVIRONMENT, there are no side-effects when using the formatting option COUNTRY. The country specified applies only to the currently embedded expression and not on any subsequent statements from the current internal session.
  • In numbers, the formatting option COUNTRY overrides the predefined setting with respect to thousand separators.


Example

The following string template creates the character string shown below it (depending on the content of the database table T005X).

DATA(text) = |{ 1000000 COUNTRY = 'DE ' }|.

1,000,000






General Material Data   PERFORM Short Reference  
This documentation is copyright by SAP AG.

Length: 68106 Date: 20191216 Time: 135920     sap01-206 ( 294 ms )

Our Service

Looking for Support? Questions?

The

Consolut

Callback-Service

Leave us your contact details and we will call you back. Panels marked with * are mandatory.