String type versus char in abap
Solution 1
A string is stored as a dynamic array of characters while a char is statically allocated.
Some of the downsides of strings include:
- Overhead - because they are dynamic the length must be stored in addition to the actual string.
- The substring and offset operators don't work with strings.
- Strings cannot be turned into translatable text elements.
So to answer your question, strings should only be used for fairly long values with a wide range of lengths where the additional overhead is negligible relative to the potential wasted space of a static char(x)
variable.
Solution 2
I think CHAR is the best because you are 100% sure that the field has to only hold 0-12 characters.
Solution 3
string is the variable length Data type , while in char you have to define the length .. for type C(Text field (alphanumeric characters)) and String X or hexadecimal string have initial value (X'0 … 0') . to avoid initial value , and to use actual length C type is used
Related videos on Youtube
Peter
SOreadytohelp Make everything as simple as possible.. (but not simpler!) Albert Einstein The irrationality of a thing is no argument against its existence, rather a condition of it. Friedrich Nietzsche
Updated on June 04, 2022Comments
-
Peter almost 2 years
What are the drawbacks of the String type in abap? When to use it, when not?
An example : I have a text field that should save values ranging from 0 to 12 chars, better to use a string or a Char(12)?
Thanks!
-
tomdemuyt almost 11 years1. ABAP stores metadata for every variable, not just strings 2. Substring and offset operators do work on up to date NetWeaver installations. -1 for me.
-
tomdemuyt almost 11 yearsThis seems the correct answer to me, not sure why you got -1'd.