The difference between Type C and String
1. Variable Length
The variable declared using type C will has the fixed length which is part of definition. Below ABAP statement declared a variable with type C length 10.
DATA: lv_text(10) TYPE c.
The variable declared using type string will have a variable length until runtime.
2. Initial Value
The initial value of the variable with type c is space (Hexadecimal value: 20). The initial value of the variable declared with type string is null (Hexadecimal value: NULL).
REPORT ztest. DATA str1 TYPE string. DATA str2 TYPE string. DATA char(10) TYPE c.
Set a break point in above program. In the debug mode, we can find the initial value for each variable.
3. Text Field Literals and String Literals
Character literals are sequences of alphanumeric characters in the source code of an ABAP program enclosed in single quotation marks or backquotes. Character literals enclosed in quotation marks have the predefined ABAP type C and are described as text field literals. Literals enclosed in backquotes have the ABAP type STRING and are described as string literals. The field length is defined by the number of characters. With text field literals trailing blanks are ignored while in string literals they are taken into account.
4. How to assign ‘ ’ to a variable with type string?
Because the trailing blank will be ignored in a text field literals, we could assign BLANK or ‘ ’ to a string variable. Below are the two options to assign blank to a string variable.
REPORT ztest. DATA str1 TYPE string. DATA str2 TYPE string. SHIFT str1 RIGHT BY 1 PLACES. str2 = ` `.
5. ABAP Standard Class to process variable with type c and string.
CL_ABAP_CHAR_UTILITIES
CL_ABAP_STRING_UTILITIES