2010 Jan 11 6:35 AM
I have 15-20 character message in my program, I want to declare it as constants. Which type to assign it String or char(20)?
from performance point, which is better?
2010 Jan 11 6:43 AM
I have 15-20 character message in my program, I want to declare it as constants. Which type to assign it String or char(20)?
from performance point, which is better?
2010 Jan 11 6:43 AM
2010 Jan 11 6:51 AM
Kumar is right CHAR is better.
if u know the length and its <=255 then CHAR is good.
and if you want to store more characters and length is not known the use STRING.
Regards,
Chintan
2010 Jan 11 8:18 AM
If your values are >255 chars, better to declare as Character.
If more than 255 characters, then declare as String.
2010 Jan 11 8:39 AM
2010 Jan 11 8:50 AM
Hi,
there is only a very small difference in performance which can not be seen nor measured, so use that one, which You want to use for some other reasons (if any).
Regards,
Adrian
2010 Jan 11 9:13 AM
Hi,
ABAP Data declaration has no major impact on performance. When you define a variable it is allocated a memory location. So, from the performance point of view there will be no major impact. But later in the code how you want to access it will impact your data declaration. So, you can create a TOP include in your report program and then define all the global variables there. So, you can use the STRING if you have a long character type or you can use CHAR or you can even use a constant. And keep in mind to stick to ABAP Naming configuration.
Hope this helps.
Thanks,
Samantak.
Edited by: Samantak Chatterjee on Jan 11, 2010 2:43 PM
2010 Jan 11 9:20 AM
Hi Bhushankotwal,
There will be no major performance diff.
Strings - can be of any Data type(C,N,I...etc) and it can take upto any length.
In your scenario, it is not required, you can go for Character type or with the data type the constant is(I,N, D...etc).
Regards,
Kittu
2010 Jan 25 6:26 AM
hi,
its better to use CHAR if you know the exact length of your message and when the message lenght could be less than 255 otherwise you use string.
thanks
shivraj
2010 Jan 26 11:28 AM
So, there you are. Char is better. Or it makes no difference.
Why not develop a few test programs and check it yourself?
matt
2010 Jan 26 11:41 AM
I created a program that did string to string, char to string, string to char and char to char ten million times. The results are:
string to string 4,1
char to string 5,9
string to char 2,4
char to char 1,5
And that's in seconds comparing a string and a char variable, both length 20.
When the length is 200, we get:
string to string 4,1
char to string 9,7
string to char 3,5
char to char 2,6
I can't say it's something that is likely to be critical to performance. I'll continue to use a string where that's appropriate and a char variable where that's appropriate. There's more to programming than getting your code to execute 0.0001% faster.
2010 Jan 26 12:14 PM
Strings or fixed length characters is an issue of memory consumption.
You should use strings if your content is of different length and if the maximal length is often not reached.
However, with very small sizes less than 30 or 40B the string is not advisable because of some basic costs.
=> 20B use characters!
2010 Mar 06 6:30 PM
Hello Bhushankotwal, Hello Siegfried,
To be more precise a string has a fixed administration overhead of ~ 8 bytes. One big advantage is that the value is shared (thus the adminstration overhead). So in case a 20 character value is used 100 times string could be a benefit even in this case. For text values < 10 characters in nearly all cases CHAR types are the better choice.
The reuse of the text value can also be a performance advantage. In case one string value gets assigned to another string variable only the administration data is updated. For char fields the value needs to be copied.
If the text value is frequently changed, say multiple times some fragments are added, a CHAR buffer might yield the better performance. Increasing the length of a string value requires to increase the size of the internally referred memory. For the fixed CHAR buffer there is no need to allocated memory if the length of the value changes.
Best Regards
Klaus
2010 Mar 06 6:49 PM
If it is a constant so you know its size already, therefore no reason to use dynamic length type - string .
2010 Mar 07 6:41 AM
Unless you're using it with a FM, or Method that takes a string parameter
2010 Mar 07 9:19 AM
Check in SE30 Tips and Tricks .....under section Character/String Manupluation.......you will get the answer.......
Not much differnce but it says strings may give you slight benefit.....
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |