2010 Dec 14 11:29 AM
Hello Xperts,
during the loading of data into BW it occasionally happens that certain fields contain non allowed characters.
We have set up a set of rules for dealing with these characters, but now the question is how to code it from an ABAP point of view.
The logic is that the coding will be called from a user exit and compare the load string with a string of allowed characeters (filled over SAP FM 'RSKC_ALLOWED_CHAR_GET'). Not allowed characters in the load string will either:
a. be replaced with _ or
b. deleted or
c. dealt with in some more complex way.
The implemented solution must include all three alternatves.
Due to the coding being called for each record (many 000, even million times) performance is of utmost importance.
The identified alternatives are:
A. calling a method in a class passing the load string as a parameter (where the string with allowed characters is a static attribute filled once). This is our preferred alternative since it agrees with our general ABAP architecture.
B. calling a function module passing the load string as a parameter (where the string with allowed characters is a top-include variable filled once).
C. add the logic in an include
Is there any other reasonable alternative?
From a performance point of view what is the best and what are the perormance pros and cons of each?
Thanx in advance.
2010 Dec 15 9:35 AM
Hi,
well, this might violate rules of structured programming, but since your going to
call it millions of times it might be worth to check, what the cost for passing the string as
a parameter is against using a global variable (do not hit me for that .
I know one should avoid these, unless you have a good reason, but this may be one...I'd do measurement.
What type of comparison are you doing? unicode or non-unicode ?
Are the "invalid" chars beside our "out of the middle" from a typical char-range that might be valid.
I mean, it might be worth to first check for a VALID range if this is true frequently and therefore
do the special checks only if it is an unusual case, allthough it might be a more expensive check in this case then.
Example:
20 chars to check with A...Z beinig valid for 70% of the typical chars and "äöüÄÖÜ" the ones to eliminate.
So 14 from 20 chars average will be A...Z the rest might be numbers or specialchars or the ones to process.
a) You could go 20 times check against 6 chars = 120 equal comparisons.
b) You could do 14 times a ">= A and <=Z" = 28 comparisons (true) and stop for those
plus you need additional 6 ">= A and <=Z" (false) plus 6 times 6 equal comparisons (36) -> Total 64
You would save ~50% of your comparisons in this case (depending on real data distribution).
Volker
Hi,
well, this might violate rules of structured programming, but since your going to
call it millions of times it might be worth to check, what the cost for passing the string as
a parameter is against using a global variable (do not hit me for that .
I know one should avoid these, unless you have a good reason, but this may be one...I'd do measurement.
What type of comparison are you doing? unicode or non-unicode ?
Are the "invalid" chars beside our "out of the middle" from a typical char-range that might be valid.
I mean, it might be worth to first check for a VALID range if this is true frequently and therefore
do the special checks only if it is an unusual case, allthough it might be a more expensive check in this case then.
Example:
20 chars to check with A...Z beinig valid for 70% of the typical chars and "äöüÄÖÜ" the ones to eliminate.
So 14 from 20 chars average will be A...Z the rest might be numbers or specialchars or the ones to process.
a) You could go 20 times check against 6 chars = 120 equal comparisons.
b) You could do 14 times a ">= A and <=Z" = 28 comparisons (true) and stop for those
plus you need additional 6 ">= A and <=Z" (false) plus 6 times 6 equal comparisons (36) -> Total 64
You would save ~50% of your comparisons in this case (depending on real data distribution).
Volker
2010 Dec 15 9:35 AM
Hi,
well, this might violate rules of structured programming, but since your going to
call it millions of times it might be worth to check, what the cost for passing the string as
a parameter is against using a global variable (do not hit me for that .
I know one should avoid these, unless you have a good reason, but this may be one...I'd do measurement.
What type of comparison are you doing? unicode or non-unicode ?
Are the "invalid" chars beside our "out of the middle" from a typical char-range that might be valid.
I mean, it might be worth to first check for a VALID range if this is true frequently and therefore
do the special checks only if it is an unusual case, allthough it might be a more expensive check in this case then.
Example:
20 chars to check with A...Z beinig valid for 70% of the typical chars and "äöüÄÖÜ" the ones to eliminate.
So 14 from 20 chars average will be A...Z the rest might be numbers or specialchars or the ones to process.
a) You could go 20 times check against 6 chars = 120 equal comparisons.
b) You could do 14 times a ">= A and <=Z" = 28 comparisons (true) and stop for those
plus you need additional 6 ">= A and <=Z" (false) plus 6 times 6 equal comparisons (36) -> Total 64
You would save ~50% of your comparisons in this case (depending on real data distribution).
Volker
2010 Dec 16 11:30 AM
Thanks for ur answer Volker. Not really what i asked for but nevertheless useful since I had not thought about it.
2010 Dec 16 1:16 PM
Hi Martin,
quite hard to give you an answer here ... since you experience peformance "problems" on that level or want to optimize on that level it can be difficult to see significant improvements. On the other side we can congratulate you if you don't have any
other problems on other levels (sql, internal tables, ...)
1.) Generally speaking you should make sure to pass your data per reference (avoid copy costs).
2.) Generally speaking you should keep the number of calls as small as possible (modularize don't atomize)
3.) Generally speaking local calls (performs, call methods in local classes or instances, function calls to one function group) should be faster than global calls (external performs, call methos in global classes or instances, function calls in other funciton groups) (not sure if this is true any more.
4.) Some years ago i learned the performs are faster than methods or function modules but i'm not sure whether this is true with current releases.
5.) I suppose you have to meassure it yourself if you want to find it out.
So i would double check 1 and 2... reg. 3 - 5 I'm afraid you you have to do your own test. If you do so, please
share your results with us.
Kind regards,
Hermann
2010 Dec 17 7:08 AM
Not allowed characters in the load string will either:
a. be replaced with _ or
b. deleted or
c. dealt with in some more complex way.
\[..\]
From a performance point of view what is the best and what are the performance pros and cons of each?
I like Volker's answer, because based on the details you've given it's not obvious that the three proposed different call approaches actually make a significant difference.
Maybe I'm off here and you measured already and noticed that your find&fix logic is lightning fast (compared to the call overhead). If so, ignore my comment, otherwise I'd strongly suggest to code the logic and measure. It should be trivial to try the different approaches and see if varying your call approach actually has a significant impact. I'm suspecting you might end up spending some time on figuring out the best way for the find&fix rather than how to invoke that logic...
On top of the general comments Hermann made, I'm also wondering if there might be some differences in the ABAP VM optimizations based on platform that might impact the results.
Cheers, harald
2010 Dec 20 7:36 AM
Thanks for the answers.
It seems like the best idea is to implment alternatives and measure the difference. This begs the question: how to measure the performance?
I have no experience in measuring ABAP performance. Hence I would appreicate any suggestions - pls not too scientific/complex - on how to approach this issue.
Thank you.
2010 Dec 20 7:28 PM
Hi,
you can use SE30 for that.
Volker
P.S. I missed 12 comparisons in my example...
The 28 comparisons (true) are OK, but the remaining lack the 12 from the (false) section thus bringing the total number to 76
and the ratio to 33% savings, but anyway it was a theoretical examle.
For real it will depend on you average data distribution, and of course you can sort the elimination of the desired
target chars by cardinality in addition, in case those are unevenly distributed as well (exit upon first hit).
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |