Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String type versus char in abap

Tags:

abap

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!

like image 206
Peter Avatar asked Sep 05 '25 06:09

Peter


1 Answers

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.

like image 153
BenV Avatar answered Sep 07 '25 23:09

BenV