String manipulation and Conversions
We use mainly ‘&&’(chaining) and ‘|’(pipe) operator to do concatenation but ‘&’ can also be used .
3.9.1.Concatenation
DATA : lv_str1 TYPE char5 VALUE 'uses'.
CONSTANTS : lc_sap TYPE char5 VALUE 'SAP',
lc_abap TYPE char5 VALUE 'ABAP'.
DATA(lv2) = |SAP| && | | && |ABAP|.
DATA(lv5) = |{ lc_sap } { lc_abap } { lv_str1 } advanced open SQL|.
" my personal favorite known as embedded concatenation
Output :
3.9.2. Define width, pad characters , set alignment
DATA : lv_str2 TYPE char5 VALUE 'SAP'.
DATA(lv6) = |{ lv_str2 WIDTH = '10' pad = 'A' ALIGN = LEFT }| .
Output :
DATA : lv_str3 TYPE int4 VALUE '-407'.
DATA(lv7) = |{ lv_str3 SIGN = LEFT }|. " Sign to left , by default its right
Output :
3.9.4. Replace keyword
DATA : lv_str4 TYPE string VALUE 'SAP ABAP used 7.4 version'.
REPLACE '7.4' WITH '7.51' INTO lv_str4.
Output :
DATA : lv_str5 TYPE char10 VALUE '0407'.
DATA(lv8) = |{ lv_str5 ALPHA = in }|.
DATA(lv9) = |{ lv_str5 ALPHA = OUT }|.
Output :
3.9.6. Changing case
DATA(lv_upper) = |{ lv_str4 CASE = UPPER }| .
" Case values : Upper , lower or raw
Output :
3.9.7. Changing currency
DATA(lv_curr) = |{ lv_str3 CURRENCY = 'USD' NUMBER = USER }|.
Output :
DATA(lv_date) = |{ sy-datum DATE = USER }|. " SY-UZEIT is used for time conversion
Output :
Next - Conditional operators
No comments:
Post a Comment