\`...\`) and have the data type `string`.
- Text field literals are enclosed in single quotes (`'...'`) and have the data type `c`.
- The literals can be (but should not according to the [programming guidelines on literals (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenliterals_guidl.htm)) used like constants of these types in [operand positions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenoperand_position_glosry.htm). They should be only used for start values when declaring [named data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abennamed_data_object_glosry.htm).
```abap
CLASS zcl_some_test_class DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
ENDCLASS.
CLASS zcl_some_test_class IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
out->write( `I am a text string literal` ). "text string literal of type string
out->write( 'I am a text field literal' ). "text field literal of type c
ENDMETHOD.
ENDCLASS.
```
- [Named](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abennamed_data_object_glosry.htm) character-like data types and objects can be declared like other types and objects using [`TYPES`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaptypes.htm), [`DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdata.htm) [`CONSTANTS`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapconstants.htm) and by referring to a character-like data type.
- In addition, character-like data objects can be declared inline with the operators `DATA` and [`FINAL`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfinal_inline.htm).
Syntax examples:
``` abap
"Type declarations using built-in types
TYPES: c_type TYPE c LENGTH 3, "Explicit length specification
str_type TYPE string.
"Data object declarations using built-in, local and DDIC types
DATA: flag TYPE c LENGTH 1, "Built-in type
str1 TYPE string, "Built-in type
char1 TYPE c_type, "Local type
str2 LIKE str1, "Deriving type from a local data object
str3 TYPE str_type, "Local type
tstmp TYPE timestampl, "DDIC type
char3 TYPE zdemo_abap_flsch-carrid. "Using the type of a DDIC table component
"You may also encounter declarations with type c and the length
"specified in parentheses. This is not recommended, to avoid confusion
"with the use of parentheses in dynamic programming.
DATA char(4) TYPE c.
"Just a TYPE c specification without length means LENGTH 1.
DATA char_len_one TYPE c.
"No type and length specification: TYPE c LENGTH 1 by default
DATA char_no_type_len.
```
## Assigning Values
- When you declare character-like data objects, you can specify start values directly with the `VALUE` addition, e.g. `DATA chars TYPE c LENGTH 3 VALUE 'abc'.`.
- Various ABAP statements assign values. You can do value assignments to data objects using the [assignment operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenassignment_operator_glosry.htm "Glossary Entry") `=`.
- As mentioned above, you can declare character-like data objects inline using the operators `DATA` or `FINAL`.
- You can use the operators at many [write positions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenwrite_position_glosry.htm "Glossary Entry").
- Unlike the `VALUE` addition of the declaration statements, inline declarations allow you to declare variables for the results of expressions or at other positions where character strings are returned.
- In the case below, a variable specified in parentheses preceded by `DATA` (or `FINAL`) on the left side of the assignment operator automatically derives a data type from the operand on the right. This helps to make your
programs leaner.
Syntax examples:
``` abap
"Data object declarations including default values with VALUE
"Note the chained statement: DATA followed by a colon, listing the data object declarations,
"separated by a comma.
DATA: flag TYPE c LENGTH 1 VALUE 'X',
str1 TYPE string VALUE `Hallo!`.
"Examples for type n
DATA zip_code TYPE n LENGTH 5 VALUE '12345'.
DATA isbn_number TYPE n LENGTH 13 VALUE '1234567890123'.
"Constant; content cannot be changed at runtime
CONSTANTS pi TYPE p LENGTH 8 DECIMALS 14 VALUE '3.14159265358979'.
"More data object declarations
DATA: char1 TYPE c LENGTH 5,
html TYPE string,
str2 LIKE html.
"Value assignments
char1 = 'ab123'.
html = `hallo
`. "Escaping backquotes in text string literals with another one str1 = `This is a backquote: ``.`. "If possible, avoid unnecessary type conversion; in principle, every "convertible type can be specified str2 = 'abc'. "Fixed length string assigned to data object of type string DATA str3 TYPE string VALUE 'X'. "type c length 1 DATA str4 TYPE string VALUE -1. "type i "Inline declarations DATA(char2) = 'abcd'. "Type c length 4 DATA(str5) = `efgh`. "You can use FINAL to create immutable variables. FINAL(final_string) = `zyx`. "Since char2 is of type c length 4 (the length is also derived), "characters are truncated in the following example assignment "Note: In newer ABAP releases, the following statement shows a syntax "warning that the value of the literal (intentionally specified "here like this) is not an admissable value for the target type. char2 = 'ijklmnopq'. "ijkl "Trailing blanks after assigning fixed length to variable length string DATA(char3) = 'ab '. DATA(str6) = `cdefgh`. str6 = char3. "'ab' (trailing blanks are not respected due to conversion rule) ``` - When assigning strings, not only data objects can be placed on the right side. Various expressions and strings can be concatenated using the [concatenation operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconcatenation_operator_glosry.htm "Glossary Entry") `&&`. - Alternatively, you can concatenate strings using [string templates](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstring_template_glosry.htm "Glossary Entry"), as described in the *Concatenating Strings* section. ``` abap str5 = str3 && ` ` && str4 && `!`. "X 1-! "Note the output for str4 that includes the conversion of type i to "string above demonstrating a possibly inadvertent specification "of an integer value for str4 that is of type string. ``` ## String Templates - Using string templates, you can construct strings very elegantly from literal text and - which is the primary use case - by including embedded ABAP [expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenexpression_glosry.htm "Glossary Entry") within a pair of delimiters (`|...|`) if these expressions can be converted to `string`. - To embed expressions, you enclose them in curly brackets: `{ ... }`. - Among the expressions that can be specified in the curly brackets are data objects and [functional method calls](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfunctional_method_call_glosry.htm) that have a [return value](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreturn_value_glosry.htm). The expression result must be convertible to type `string`. > **💡 Note**Hallo\n
Ciao!
Salut.
|. DATA(html_b) = html_a. REPLACE ALL OCCURRENCES OF PCRE `()(.*?)(<\/p>)` IN html_a WITH `$1Hi$3`. *
Hallo *
Hi
Hi
"Regular expression: any character or a new line with zero or more repretitions REPLACE ALL OCCURRENCES OF PCRE `()(.|\n)*?(<\/p>)` IN html_b WITH `$1Hi$3`. *
Hi
Hi
Hi
``` ## More String Functions As also covered in the [Built-In Functions](24_Builtin_Functions.md) cheat sheet, the following sections show more string functions available. ### Checking the Similarity of Strings - [`distance`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendistance_functions.htm) returns the Levenshtein distance between two strings, which reflects their similarity. - Unlike other string functions, the return value has the type `i`. - Optional addition `max`: Positive integer. The calculation of the Levenshtein distance will stop if the calculated value is greater than this integer. ```abap DATA(str_to_check) = `abap`. DATA(dist1) = distance( val1 = str_to_check val2 = `abap` ). "0 DATA(dist2) = distance( val1 = str_to_check val2 = `axbap` ). "1 DATA(dist3) = distance( val1 = str_to_check val2 = `yabyyapy` ). "4 DATA(dist4) = distance( val1 = str_to_check val2 = `zabapzzzzzzzzzzzz` max = 5 ). "5 "If the value of max is 0 or less, an exception is raised. TRY. DATA(dist5) = distance( val1 = str_to_check val2 = `#ab#ap#` max = 0 ). CATCH cx_sy_strg_par_val. ... ENDTRY. ``` ### Repeating Strings - [`repeat`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrepeat_functions.htm) returns a string that contains the content of a specified string for parameter `val` as many times as specified in the parameter `occ`. - An empty string is returned when `occ` has the value 0 or `val` is empty. ```abap DATA(repeat1) = repeat( val = `abap` occ = 5 ). "abapabapabapabapabap DATA(repeat2) = |#{ repeat( val = ` ` occ = 10 ) }#|. "# # DATA(repeat3) = COND #( WHEN repeat( val = `a` occ = 0 ) = `` THEN `Y` ELSE `Z` ). "Y (initial value returned) "If occ has a negative value, an exception is raised. TRY. DATA(repeat4) = repeat( val = `X` occ = -3 ). CATCH cx_sy_strg_par_val. ... ENDTRY. ``` ### Returning the Smallest/Biggest of a Set of Character-Like Arguments - [`cmin/cmax`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencmax_cmin_functions.htm) returns a string that contains the content of the smallest or biggest of a set of character-like arguments - 'Set' means at least two arguments and a maximum of nine argeuments are passed (`valn` operators) for comparison. - The comparison is made from left to right, and the first different character found determines the smaller or bigger argument. ```abap DATA(min) = cmin( val1 = `zzzzzzz` val2 = `zzazzzzzzzz` "smallest argument val3 = `zzzzabc` ). DATA(max) = cmax( val1 = `abcdef` "biggest argument val2 = `aaghij` val3 = `aaaaklmn` val4 = `aaaaaaopqrs` val5 = `aaaaaaaaaatuvwxy` val6 = `aaaaaaaaaaaaaz` ). ``` ### Escaping Special Characters - [`escape`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenescape_functions.htm) returns a string that is provided for the `val` parameter by escaping special characters according to the specification in the `format` parameter. - Suitable values for the `format` parameter (which expects a data object of type `i`) are available in the `CL_ABAP_FORMAT` class (the constants starting with `E_`). - Special rules apply to different contexts, such as URLS and JSON. Also note the prevention of Cross Site Scripting (XSS) attacks on web applications. For more information, refer to the [documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenescape_functions.htm). ```abap "Context: URLs DATA(esc1) = escape( val = '...test: 5@8...' format = cl_abap_format=>e_url_full ). "...test%3A%205%408... "Context: JSON DATA(esc2) = escape( val = 'some "test" json \ with backslash and double quotes' format = cl_abap_format=>e_json_string ). "some \"test\" json \\ with backslash and double quotes "Context: String templates DATA(esc3) = escape( val = 'Special characters in string templates: |, \, {, }' format = cl_abap_format=>e_string_tpl ). "Special characters in string templates: \|, \\, \{, \} "Invalid value for the format parameter TRY. DATA(esc4) = escape( val = 'This will raise an exception due to an invalid format value.' format = 123 ). CATCH cx_sy_strg_par_val. ENDTRY. ``` ## Excursions ### Comparison Operators for Character-Like Data Types in a Nutshell The comparison operators have already been covered in different sections above. This is a summary of the operators.| Comparison Operator | Details | Example |
|---|---|---|
CA |
Contains any To determine whether any character of a given character set is contained in a string. Note: The search is case-sensitive. sy-fdpos contains the offset of the first character found, while 0 stands for the very first position. If nothing is found, sy-fdpos contains the length of the string. |
```abap DATA(s1) = `cheers`. IF s1 CA `aeiou`. ... "true; sy-fdpos: 2 IF s1 CA `xy`. ... "false; sy-fdpos: 6 ``` |
NA |
Contains not any To determine whether any character of a given character set is not contained in a string. See the note above. |
```abap DATA(s2) = `Hallo`. IF s2 NA `bcdeh`. ... "true; sy-fdpos: 5 IF s2 NA `bcdeH`. ... "false; sy-fdpos: 0 ``` |
CO |
Contains only To determine whether a string contains only a certain set of characters. See the note above. |
```abap DATA(s3) = `abcd`. IF s3 CO `abcd`. ... "true; sy-fdpos: 4 IF s3 CO `abCd`. ... "false; sy-fdpos: 2 ``` |
CN |
Contains not only To determine whether a string does not only contain a certain set of characters, i.e. whether a string contains characters other than those in the character set. See the note above. |
```abap DATA(s4) = `abap`. IF s4 CN `ab`. ... "true; sy-fdpos: 3 IF s4 CN `abp`. ... "false; sy-fdpos: 4 ``` |
CS |
Contains string For simple substring searches and determining whether a string contains a substring. Note: The search is not case-sensitive. sy-fdpos contains the offset of the first substring found. If it is not found, sy-fdpos contains the length of the string searched. |
```abap DATA(s5) = `Lorem ipsum dolor sit amet.`. IF s5 CS `or`. ... "true; sy-fdpos: 1 IF s5 CS `zz`. ... "false; sy-fdpos: 27 ``` |
NS |
Contains no string To determine whether a substring is not contained in a string. See the note for CS. |
```abap DATA(s6) = `some test string`. IF s6 NS `tests`. ... "true; sy-fdpos: 16 IF s6 NS `TEST`. ... "false; sy-fdpos: 5 ``` |
CP |
Conforms to pattern For simple pattern searches and determining whether a set of characters is contained in a string that matches a particular pattern. You can use the following special characters as patterns:
#. If a pattern is found, sy-fdpos returns the offset of the first occurrence. Otherwise, it contains the length of the string searched.
|
```abap DATA(s7) = `abc_def_ghi`. "Pattern: f is preceded by any character sequence, must be followed "by '_' and then followed by any character sequence IF s7 CP `*f#_*`. ... "true; sy-fdpos: 6 "Pattern: i is preceded by any character sequence, must be followed "by any character or a blank IF s7 CP `*i+`. ... "false; sy-fdpos: 11 ``` |
NP |
Does not conform to pattern Negation of CP. See the previous notes. |
```abap DATA(s8) = `abcDEFghi`. "Pattern: c is preceded by any character sequence, must be followed "by a small letter d, and then followed by any character sequence IF s8 NP `*c#d*`. ... "true; sy-fdpos: 9 "Pattern: c is preceded by any character sequence, must be followed "by a capital letter D, and then followed by any character sequence IF s8 NP `*c#D*`. ... "false; sy-fdpos: 2 ``` |
string).
``` abap
DATA(string) = `ABAP `.
"Removing trailing blanks
cl_abap_string_utilities=>del_trailing_blanks( CHANGING str = string ).
"`ABAP`
"Preserving trailing blanks when assigning text fields to data objects of
"type string
DATA(chars) = 'ABAP '.
cl_abap_string_utilities=>c2str_preserving_blanks( EXPORTING source = chars
IMPORTING dest = DATA(str_w_blanks) ).
"`ABAP `
DATA(str_no_blanks) = CONV string( chars ).
"`ABAP`
```
- `XCO_CP`: The Extension Components Library (XCO) library provides [released APIs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreleased_api_glosry.htm) and offers various development utilities. Find more information [here](https://help.sap.com/docs/btp/sap-business-technology-platform/overview-of-xco-modules). The following code snippet demonstrates several methods of the class that deal with string processing.
```abap
"--------- Extracting a substring from a string ---------
DATA(some_string) = `abcdefghijklmnopqrstuvwxyz`.
"Creating an encapsulation of a string using XCO
DATA(str) = xco_cp=>string( some_string ).
"Using the FROM and TO methods, you can determine
"the character position. Note that the value includes the
"character at the position specified.
"The character index pattern for the example string above
"is (the string has 26 characters in total):
"a = 1, b = 2, c = 3 ... z = 26
"a = -26, b = -25, c = -24 ... z = -1
"Providing a value that is out of bounds means that
"the first (or the last) character of the string is used
"by default.
"Note: When combining FROM and TO, e.g. with method
"chaining ...->from( ...)->to( ... ), note that another
"instance is created with the first 'from', and another
"character index pattern is created based on the new
"and adjusted string value.
"bcdefghijklmnopqrstuvwxyz
DATA(sub1) = str->from( 2 )->value.
"defghijklmnopqrstuvwxyz
DATA(sub2) = str->from( -23 )->value.
"vwxyz
DATA(sub3) = str->from( -5 )->value.
"abcde
DATA(sub4) = str->to( 5 )->value.
"ab
DATA(sub5) = str->to( -25 )->value.
"Result of 1st 'from' method call: bcdefghijklmnopqrstuvwxyz
"Based on this result, the 'to' method call is
"applied.
"bcdefg
DATA(sub6) = str->from( 2 )->to( 6 )->value.
"Result of 1st 'to' method call: abcdefghijklmnopq
"Based on this result, the 'from' method call is
"applied.
"defghijklmnopq
DATA(sub7) = str->to( -10 )->from( 4 )->value.
"Values that are out of bounds.
"In the example, the first and last character of the
"string are used.
"abcdefghijklmnopqrstuvwxyz
DATA(sub8) = str->from( 0 )->to( 100 )->value.
"--------- Splitting and joining ---------
"Splitting a string into a string table
DATA(str_table) = xco_cp=>string( `Hello.World.ABAP` )->split( `.` )->value.
"Hello
"World
"ABAP
"Concatenating a string table into a string; specifying a delimiter
str_table = VALUE #( ( `a` ) ( `b` ) ( `c` ) ).
"a, b, c
DATA(conc_str1) = xco_cp=>strings( str_table )->join( `, ` )->value.
"Concatenating a string table into a string; specifying a delimiter and
"reversing the table order
"c / b / a
DATA(conc_str2) = xco_cp=>strings( str_table )->reverse( )->join( ` / ` )->value.
"--------- Prepending and appending strings ---------
DATA(name) = xco_cp=>string( `Max Mustermann` ).
"Max Mustermann, Some Street 1, 12345 Someplace
DATA(address) = name->append( `, Some Street 1, 12345 Someplace` )->value.
"Mr. Max Mustermann
DATA(title) = name->prepend( `Mr. ` )->value.
"--------- Transforming to lowercase and uppercase ---------
"ABAP
DATA(to_upper) = xco_cp=>string( `abap` )->to_upper_case( )->value.
"hallo world
DATA(to_lower) = xco_cp=>string( `HALLO WORLD` )->to_lower_case( )->value.
"--------- Checking if a string starts/ends with a specific string ---------
DATA check TYPE string.
DATA(str_check) = xco_cp=>string( `Max Mustermann` ).
"yes
IF str_check->ends_with( `mann` ).
check = `yes`.
ELSE.
check = `no`.
ENDIF.
"no
IF str_check->starts_with( `John` ).
check = `yes`.
ELSE.
check = `no`.
ENDIF.
"--------- Converting strings to xstrings using a codepage ---------
"536F6D6520737472696E67
DATA(xstr) = xco_cp=>string( `Some string` )->as_xstring( xco_cp_character=>code_page->utf_8 )->value.
"--------- Camel case compositions and decompositions with split and join operations ---------
"Pascal case is also possible
"someValue
DATA(comp) = xco_cp=>string( `some_value` )->split( `_` )->compose( xco_cp_string=>composition->camel_case )->value.
"Camel case decomposition
"some_value
DATA(decomp) = xco_cp=>string( `someValue` )->decompose( xco_cp_string=>decomposition->camel_case )->join( `_` )->value.
"--------- Matching string against regular expression ---------
DATA match TYPE string.
"yes
IF xco_cp=>string( ` 1` )->matches( `\s\d` ).
match = 'yes'.
ELSE.
match = 'no'.
ENDIF.
"no
IF xco_cp=>string( ` X` )->matches( `\s\d` ).
match = 'yes'.
ELSE.
match = 'no'.
ENDIF.
```
### Byte String Processing
#### Determining the Length of xstrings
The built-in function [`xstrlen`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendescriptive_functions_binary.htm) returns the number of bytes of a byte-like argument.
``` abap
DATA(hi) = `Hello world`.
"48656C6C6F20776F726C64
DATA(conv_xstring) = cl_abap_conv_codepage=>create_out( codepage = `UTF-8` )->convert( hi ).
"22
DATA(len_str) = strlen( CONV string( conv_xstring ) ).
"11
DATA(len_xstr) = xstrlen( conv_xstring ).
```
#### Character String and Byte String Processing with ABAP Statements
- Several ABAP statements include the `IN CHARACTER MODE` and `IN BYTE MODE` additions.
- These additions determine whether operations process character strings or byte strings.
- If neither option is specified, the default is character string processing (i.e. `IN CHARACTER MODE`).
- Byte string processing with the `IN BYTE MODE` addition is supported by the following ABAP statements: `CONCATENATE`, `FIND`, `REPLACE`, `SHIFT`, `SPLIT`.
- In byte string processing, the data objects used must be byte-like. For character string processing, only character-like data objects are allowed.
The following code snippet explores various statements with the `IN CHARACTER MODE` and `IN BYTE MODE` additions.
```abap
DATA off TYPE i.
DATA(abc_str) = `abc def ghi jkl mno pqr stu vwx yz`.
DATA(copy_str) = abc_str.
"-----------------------------------------------------------------------------
"------------------------ FIND and REPLACE statements ------------------------
"-----------------------------------------------------------------------------
"------------------------ IN CHARACTER MODE addition ------------------------
"Searching for the first blank in the string
"3
FIND ` ` IN abc_str IN CHARACTER MODE MATCH OFFSET off.
"The following example is the same as the previous as the IN CHARACTER MODE
"addition is optional. The FIRST OCCURRENCE OF addition is also optional.
"Just using FIND without FIRST OCCURRENCE OF means searching for the first
"occurrence by default.
"3
FIND FIRST OCCURRENCE OF ` ` IN abc_str MATCH OFFSET off.
"Searching for all blanks in the string
FIND ALL OCCURRENCES OF ` ` IN abc_str IN CHARACTER MODE RESULTS DATA(res).
DATA(offsets_of_findings) = concat_lines_of(
table = VALUE string_table( FOR wa IN res ( condense( val = CONV string( wa-offset ) to = `` ) ) ) sep = `, ` ).
"3, 7, 11, 15, 19, 23, 27, 31
"Replacing the first blank in the string
"abc#def ghi jkl mno pqr stu vwx yz
REPLACE ` ` IN abc_str WITH `#` IN CHARACTER MODE.
abc_str = copy_str.
"Replacing all blanks in the string
"abc#def#ghi#jkl#mno#pqr#stu#vwx#yz
REPLACE ALL OCCURRENCES OF ` ` IN abc_str WITH `#` IN CHARACTER MODE.
abc_str = copy_str.
"------------------------ IN BYTE MODE addition ------------------------
"Converting to xstring
"6162632064656620676869206A6B6C206D6E6F20707172207374752076777820797A
DATA(abc_xstr) = cl_abap_conv_codepage=>create_out( )->convert( abc_str ).
"20
DATA(blank_xstr) = cl_abap_conv_codepage=>create_out( )->convert( ` ` ).
"23
DATA(repl_xstr) = cl_abap_conv_codepage=>create_out( )->convert( `#` ).
DATA(copy_xstr) = abc_xstr.
"Searching for the first byte that represents a blank in the UTF-8 code page
"3
FIND blank_xstr IN abc_xstr IN BYTE MODE MATCH OFFSET off.
FIND ALL OCCURRENCES OF blank_xstr IN abc_xstr IN BYTE MODE RESULTS res.
"3, 7, 11, 15, 19, 23, 27, 31
DATA(offsets_of_findings_xstr) = concat_lines_of(
table = VALUE string_table( FOR wa IN res ( condense( val = CONV string( wa-offset ) to = `` ) ) ) sep = `, ` ).
"Replacing the first byte that represents a blank in the UTF-8 code page
"6162632364656620676869206A6B6C206D6E6F20707172207374752076777820797A
REPLACE blank_xstr IN abc_xstr WITH repl_xstr IN BYTE MODE.
abc_xstr = copy_xstr.
"Replacing all bytes that represent a blank in the UTF-8 code page
"6162632364656623676869236A6B6C236D6E6F23707172237374752376777823797A
REPLACE ALL OCCURRENCES OF blank_xstr IN abc_xstr WITH repl_xstr IN BYTE MODE.
"-----------------------------------------------------------------------------
"--------------------------- CONCATENATE statements --------------------------
"-----------------------------------------------------------------------------
DATA(part_str1) = `abc`.
DATA(part_str2) = `def`.
"abcdef
CONCATENATE part_str1 part_str2 INTO DATA(concat_str) IN CHARACTER MODE.
"abc/def
CONCATENATE part_str1 part_str2 INTO concat_str SEPARATED BY `/` IN CHARACTER MODE.
"Same as above
CONCATENATE part_str1 part_str2 INTO concat_str.
CONCATENATE part_str1 part_str2 INTO concat_str SEPARATED BY `/`.
DATA(part_xstr1) = cl_abap_conv_codepage=>create_out( )->convert( part_str1 ).
DATA(part_xstr2) = cl_abap_conv_codepage=>create_out( )->convert( part_str2 ).
DATA(sep_xstr) = cl_abap_conv_codepage=>create_out( )->convert( `/` ).
"616263646566
CONCATENATE part_xstr1 part_xstr2 INTO DATA(concat_xstr) IN BYTE MODE.
"abcdef
DATA(concat_xstr_converted) = cl_abap_conv_codepage=>create_in( )->convert( concat_xstr ).
"6162632F646566
CONCATENATE part_xstr1 part_xstr2 INTO concat_xstr SEPARATED BY sep_xstr IN BYTE MODE.
"abc/def
concat_xstr_converted = cl_abap_conv_codepage=>create_in( )->convert( concat_xstr ).
"Creating a table of type xstring
DATA(xstr_table) = VALUE xstring_table( ( part_xstr1 ) ( part_xstr2 ) ).
"616263646566
CONCATENATE LINES OF xstr_table INTO DATA(concat_xstr_tab) IN BYTE MODE.
"abcdef
DATA(concat_xstr_tab_converted) = cl_abap_conv_codepage=>create_in( )->convert( concat_xstr_tab ).
"-----------------------------------------------------------------------------
"------------------------------- SHIFT statements ----------------------------
"-----------------------------------------------------------------------------
DATA(str) = `abcdef`.
DATA(copy) = str.
"bcdef
SHIFT str IN CHARACTER MODE.
str = copy.
"Same as
SHIFT str.
str = copy.
"616263646566
DATA(xstr) = cl_abap_conv_codepage=>create_out( )->convert( str ).
"6263646566
SHIFT xstr IN BYTE MODE.
"-----------------------------------------------------------------------------
"------------------------------- SPLIT statements ----------------------------
"-----------------------------------------------------------------------------
str = `abc def`.
"`abc` / `def`
SPLIT str AT space INTO DATA(str1) DATA(str2) IN CHARACTER MODE.
SPLIT str AT space INTO TABLE DATA(tab_str) IN CHARACTER MODE.
"Same as above
SPLIT str AT space INTO str1 str2.
SPLIT str AT space INTO TABLE tab_str.
"61626320646566
xstr = cl_abap_conv_codepage=>create_out( )->convert( str ).
"20
blank_xstr = cl_abap_conv_codepage=>create_out( )->convert( ` ` ).
"`616263` / `646566`
SPLIT xstr AT blank_xstr INTO DATA(xstr1) DATA(xstr2) IN BYTE MODE.
SPLIT xstr AT blank_xstr INTO TABLE DATA(xstr_tab) IN BYTE MODE.
```
#### SET BIT and GET BIT Statements
- Unlike the ABAP statements in the previous section, the following statements are are only for byte string processing:
- [`SET BIT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABAPSET_BIT.html)
- Syntax pattern: `SET BIT pos OF byte_string [TO value].`
- In a byte-like data object, the bit is set to 1 by default at a specified position, or to 0 or 1 as specified after `TO`.
- Alternatively, you can use the built-in function [`bit-set`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENBIT_FUNCTIONS.html).
- [`GET BIT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABAPGET_BIT.html)
- Syntax pattern: `GET BIT pos OF byte_string INTO value.`
- Reads a bit at a specified position in a byte string into a target data object.
Expand the following collapsible section for example code, which experiments with byte string processing (converting a hexadecimal value to the character-like representation of the binary values by reading bits, getting hexadecimal values from the character-like representation of the binary values, setting bits). To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.