\`...\`) 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
char2 TYPE s_toairp, "DDIC type (used e. g. for a field in a demo table)
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'.`.
- You can do value assignments to data objects using the 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 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. ``` Note that there is also the [literal operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenliteral_operator_glosry.htm "Glossary Entry") `&` that joins [text string literals](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentext_string_literal_glosry.htm "Glossary Entry"), however, with [significant differences](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenliteral_operator.htm) to `&&`. ## 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: `{ ... }`. > **💡 Note**| 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 ``` |