abap 中字符串类型与 char 类型
abap中String类型有什么缺点?什么时候使用它,什么时候不使用它?
一个例子:我有一个文本字段,应该保存 0 到 12 个字符的值,最好使用字符串或 Char(12)?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
字符串存储为动态字符数组,而字符则静态分配。
字符串的一些缺点包括:
因此,为了回答您的问题,字符串只能用于长度范围很广的相当长的值,其中相对于静态 char(x) 变量的潜在浪费空间,额外的开销可以忽略不计。
A string is stored as a dynamic array of characters while a char is statically allocated.
Some of the downsides of strings include:
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.我认为 CHAR 是最好的,因为您可以 100% 确定该字段只能包含 0-12 个字符。
I think CHAR is the best because you are 100% sure that the field has to only hold 0-12 characters.
string是可变长度的数据类型,而在char中你必须定义长度..
对于类型 C(文本字段(字母数字字符))和字符串 X 或十六进制字符串具有初始值 (X'0 … 0') 。
为了避免初始值,并使用实际长度,使用 C 类型
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
字符串适合以下情况:
CHAR 字段很好:
需要记住的事情:
'test'
,对 STRING 使用`test`
。这通常会稍微快一些。Strings are good when:
CHAR fields are good:
Things to remember:
'test'
for CHAR and`test`
for STRING. This is usually slightly faster.字符串变量:
字符串是一种可变长度数据类型,用于存储任意长度的数据。使用可变长度字段是因为它们节省空间。
字符串,可以存储任意数量的字符。 String会在运行时分配内存,也称为动态内存分配,会根据字符串的大小分配内存。字符串不能使用参数声明,因为分配的内存是动态的。
但在您的情况下,您已经知道字段的最大长度(0 - 12 个字符),因此
CHAR 类型
最适合您的情况。STRING
类型通常用于可变长度数据或长值。了解更多
String Variable :
A String is a variable length data type which is used to store any length of data. Variable length fields are used because they save space.
String, can store any number of characters. String will allocate the memory at runtime which is also called as dynamic memory allocation, will allocate the memory as per the size of the string. Strings cannot be declared using parameters as the memory of allocation is dynamic.
But in your case, you already know max-length of field(0 - 12 characters), So
CHAR type
is best for use in your case. ASTRING
type generally used to variable length data or a long values.Read more