Update
This commit is contained in:
@@ -269,8 +269,8 @@ started.
|
||||
options](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcompute_string_format_options.htm).
|
||||
- Refer to the ABAP Keyword Documentation for all options.
|
||||
|
||||
Syntax examples:
|
||||
``` abap
|
||||
The following syntax examples demonstrate a selection:
|
||||
```abap
|
||||
"Control characters
|
||||
s4 = |{ s1 }\n{ s2 }\nSee you.|. "\n is interpreted as a line feed
|
||||
|
||||
@@ -283,22 +283,39 @@ ASSERT cl_abap_char_utilities=>horizontal_tab = |\t|.
|
||||
ASSERT cl_abap_char_utilities=>cr_lf = |\r\n|.
|
||||
|
||||
"Various formatting options
|
||||
"Time and date
|
||||
"Formatting according to the user master data
|
||||
DATA(d) = |The date is { cl_abap_context_info=>get_system_date( ) DATE = USER }.|.
|
||||
"DATE: Defining the format of a date
|
||||
"The output is just an example and depends on your settings.
|
||||
DATA(d) = |The date is { cl_abap_context_info=>get_system_date( ) DATE = USER }.|. "The date is 01/01/2024.
|
||||
d = |{ cl_abap_context_info=>get_system_date( ) DATE = RAW }|. "20240101
|
||||
d = |{ cl_abap_context_info=>get_system_date( ) DATE = ISO }|. "2024-01-01
|
||||
d = |{ cl_abap_context_info=>get_system_date( ) DATE = ENVIRONMENT }|. "01/01/2024
|
||||
|
||||
"Formatting in accordance with ISO 8601
|
||||
DATA(tm) = |The time is { cl_abap_context_info=>get_system_time( ) TIME = ISO }.|.
|
||||
"TIME: Defining the format of a time
|
||||
"The output is just an example and depends on your settings.
|
||||
DATA(tm) = |The time is { cl_abap_context_info=>get_system_time( ) TIME = ISO }.|. "The time is 14:37:24.
|
||||
tm = |{ cl_abap_context_info=>get_system_time( ) TIME = RAW }|. "143724
|
||||
tm = |{ cl_abap_context_info=>get_system_time( ) TIME = USER }|. "14:37:24
|
||||
tm = |{ cl_abap_context_info=>get_system_time( ) TIME = ENVIRONMENT }|. "14:37:24
|
||||
|
||||
"Formatting to UTC; date and time are represented in ISO 8601
|
||||
DATA(ts) = |Timestamp: { utclong_current( ) TIMESTAMP = SPACE }.|.
|
||||
"TIMESTAMP: Defining the format of a time stamp
|
||||
"The output is just an example and depends on your settings.
|
||||
DATA(ts) = |{ utclong_current( ) TIMESTAMP = SPACE }|. "2024-01-01 14:39:50.4069170
|
||||
ts = |{ utclong_current( ) TIMESTAMP = ISO }|. "2024-01-01T14:39:50,4071110
|
||||
ts = |{ utclong_current( ) TIMESTAMP = USER }|. "01/01/2024 14:39:50.4072010
|
||||
ts = |{ utclong_current( ) TIMESTAMP = ENVIRONMENT }|. "01/01/2024 14:39:50.4073230
|
||||
ts = |{ utclong_current( ) }|. "2024-01-01 14:39:50.4074060
|
||||
|
||||
"Lowercase and uppercase
|
||||
"TIMEZONE: Defining the format of a time stamp using the rules for time zones
|
||||
DATA(tz) = |{ utclong_current( ) TIMEZONE = 'UTC' }|. "2024-12-30 14:43:20.6534640
|
||||
tz = |{ utclong_current( ) TIMEZONE = 'CET' COUNTRY = 'DE ' }|. "30.12.2024 15:43:20,6536320
|
||||
tz = |{ utclong_current( ) TIMEZONE = 'EST' COUNTRY = 'US ' }|. "12/30/2024 09:43:20.6889180 AM
|
||||
|
||||
"CASE: Lowercase and uppercase
|
||||
s1 = |AbCdEfG|.
|
||||
s2 = |{ s1 CASE = LOWER }|. "abcdefg
|
||||
s2 = |{ s1 CASE = UPPER }|. "ABCDEFG
|
||||
|
||||
"Width and alignment
|
||||
"WIDTH/ALIGN
|
||||
s1 = `##`.
|
||||
s2 = |{ s1 WIDTH = 10 ALIGN = LEFT }<---|. "'## <---'
|
||||
s2 = |{ s1 WIDTH = 10 ALIGN = CENTER }<---|. "' ## <---'
|
||||
@@ -306,8 +323,74 @@ s2 = |{ s1 WIDTH = 10 ALIGN = CENTER }<---|. "' ## <---'
|
||||
"PAD: Used to pad any surplus places in the result with the specified character.
|
||||
s2 = |{ s1 WIDTH = 10 ALIGN = RIGHT PAD = `.` }<---|. "'........##<---'
|
||||
|
||||
"Numbers
|
||||
"DECIMALS
|
||||
s1 = |{ CONV decfloat34( - 1 / 3 ) DECIMALS = 3 }|. "'-0.333'
|
||||
|
||||
"SIGN: Defining the format of the +/- sign when the string represented
|
||||
"by the embedded expression represents a numeric value
|
||||
"- left without space, no +
|
||||
s1 = |{ +1 SIGN = LEFT }|. "1
|
||||
"- and + left without space
|
||||
s1 = |{ 1 SIGN = LEFTPLUS }|. "+1
|
||||
"- left without space, blank left for +
|
||||
s1 = |{ 1 SIGN = LEFTSPACE }|. " 1
|
||||
"- right without space, no +
|
||||
s1 = |{ -1 SIGN = RIGHT }|. "1-
|
||||
"- and + right without space
|
||||
s1 = |{ 1 SIGN = RIGHTPLUS }|. "1+
|
||||
"- left without space, blank right for +
|
||||
s1 = |{ +1 SIGN = RIGHTSPACE }|. "1
|
||||
|
||||
"ZERO: Defining the format of the numeric value zero.
|
||||
"Only to be specified if the embedded expression has a numeric data type.
|
||||
s1 = |'{ 0 ZERO = NO }' and '{ 0 ZERO = YES }'|. "'' and '0'
|
||||
|
||||
"XSD: Formatting is applied to an embedded expression (elementary data types) in asXML format that is
|
||||
"assigned to its data type. Check the information in the ABAP Keyword Documentation about the asXML
|
||||
"mapping of elementary ABAP types.
|
||||
DATA xstr TYPE xstring VALUE `41424150`.
|
||||
DATA dat type d value '20240101'.
|
||||
DATA tim type t value '123456'.
|
||||
DATA(utc) = utclong_current( ). "e.g. 2024-01-01 13:51:38.5708800
|
||||
|
||||
s1 = |{ xstr XSD = YES }|. "QUJBUA==
|
||||
s1 = |{ dat XSD = YES }|. "2024-01-01
|
||||
s1 = |{ tim XSD = YES }|. "12:34:56
|
||||
s1 = |{ utc XSD = YES }|. "2024-01-01T13:51:38.57088Z
|
||||
|
||||
"STYLE: Defining the style of decimal floating point numbers;
|
||||
"see the details in the ABAP Keyword Documentation.
|
||||
DATA(dcfl34) = CONV decfloat34( '-123.45600' ).
|
||||
s1 = |{ dcfl34 }|. "-123.456out->write( s1 ).
|
||||
"Creates the predefined format
|
||||
s1 = |{ dcfl34 STYLE = SIMPLE }|. "-123.456
|
||||
"+/- added to the right, removes trailing zeros
|
||||
s1 = |{ dcfl34 STYLE = SIGN_AS_POSTFIX }|. "123.456-
|
||||
"Retains trailing zeros
|
||||
s1 = |{ dcfl34 STYLE = SCALE_PRESERVING }|. "-123.45600
|
||||
"Scientific notation; at least a two digit exponent with a plus/minus sign
|
||||
s1 = |{ dcfl34 STYLE = SCIENTIFIC }|. "-1.23456E+02
|
||||
"Scientific notation; only one integer digit with the value 0
|
||||
s1 = |{ dcfl34 STYLE = SCIENTIFIC_WITH_LEADING_ZERO }|. "-0.123456E+03
|
||||
"Scientific notation; exponent has 3 digits for decfloat16 and 4 digits for decfloat34
|
||||
s1 = |{ dcfl34 STYLE = SCALE_PRESERVING_SCIENTIFIC }|. "-1.2345600E+0002
|
||||
"Technical format
|
||||
s1 = |{ dcfl34 STYLE = ENGINEERING }|. "-123.456E+00
|
||||
|
||||
"ALPHA: Adds or removes leading zeros from strings of digits; the data type
|
||||
"must be string, c, or n
|
||||
"Adding leading zeros
|
||||
"Additionally specifying WIDTH
|
||||
"Note: The specified length is only used if it is greater than
|
||||
"the length of provided string (without leading zeros)
|
||||
s1 = |{ '1234' ALPHA = IN WIDTH = 10 }|. "0000001234
|
||||
s1 = |{ '00000000000000000000000012' ALPHA = IN WIDTH = 10 }|. "0000000012
|
||||
"Fixed-length string provided, WIDTH not specified
|
||||
s1 = |{ ' 12' ALPHA = IN }|. "00012
|
||||
"Removing leading zeros
|
||||
s1 = |{ '00001234' ALPHA = OUT }|. "1234
|
||||
"Do not apply formatting
|
||||
s1 = |{ '00001234' ALPHA = RAW }|. "00001234
|
||||
```
|
||||
|
||||
> **💡 Note**<br>
|
||||
|
||||
Reference in New Issue
Block a user