Post

String Templates in ABAP

Learn how to use ABAP string templates with formatting options such as ALPHA, WIDTH, CURRENCY, DATE, DECIMAL, and CASE.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"String Templates
"ALPHA(IN/OUT)
DATA(lv_vbeln) = CONV vbeln( '1' ).
lv_vbeln = |{ lv_vbeln ALPHA = IN }|. "-> 0000000001
lv_vbeln = |{ lv_vbeln ALPHA = OUT }|. "-> 1

"WIDTH
DATA(lv_vbeln_with_extra_zeros) = |{ lv_vbeln ALPHA = IN WIDTH = 15 }|. "->000000000000001

"CURRENCY
DATA(lv_amount) = 123456.
DATA(lv_inr) = |{ lv_amount CURRENCY = 'INR' }|. "1234.56
DATA(lv_omr) = |{ lv_amount CURRENCY = 'OMR' }|. "123.456

"NUMBER
DATA(lv_number) = 12345678.
DATA(lv_user_specific) = |{ lv_number NUMBER = USER }|. "12.345.678
SET COUNTRY 'US'.
DATA(lv_env) = |{ lv_number NUMBER = ENVIRONMENT }|. "12,345,678

"DATE -> Same we have for TIME,TIMESTAMP
DATA(lv_date) = sy-datum.
DATA(lv_user_date) = |{ lv_date DATE = USER }|. "20.01.2025
DATA(lv_iso_date) = |{ lv_date DATE = ISO }|. "2025-01-20

"DECIMAL
DATA(lv_decimal) = CONV f( `1234.456877` ).
DATA(lv_3_decimal) = |{ lv_decimal DECIMALS = 3 }|. "1234.457

"CASE
DATA(lv_name) = `Bharathi S`.
DATA(lv_uppercase) = |{ lv_name CASE = UPPER }|. "BHARATHI S"
DATA(lv_lowercase) = |{ lv_name CASE = LOWER }|. "bharathi s"

"SIGN
DATA(lv_sign) = 123.
DATA(lv_plus_sign) = |{ lv_sign SIGN = LEFTPLUS }|. "+123
DATA(lv_right_plus_sign) = |{ lv_sign SIGN = RIGHTPLUS }|. "123+

"ALIGN
DATA(lv_text) = '1'.
DATA(lv_align_right) = |{ lv_text ALIGN = RIGHT WIDTH = 5 }|."    1

"PAD
DATA(lv_pad) = |{ lv_text ALIGN = RIGHT WIDTH = 5 PAD = '_' }|."____1

"https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcompute_string_format_options.htm
This post is licensed under CC BY 4.0 by the author.