‎2006 Oct 02 7:51 AM
Hi,
In my function module, I have to return many values as just one value - a comma seperated string. Performance is important as there could potentially be more than one hundred thousand values being concatenated.
As the values themselves may have commas in them, I need to escape such commas by a "\" character. I then would also need to escape a "\" character by another "\" character. Standard escape mechanism. Nothing special.
I have listed here are some possible options. Although my pseudo code does not show it, I am looping over the data values. mySingleValue holds the current value.
I am inclined towards option 3 being the best in terms of performance. However, I would appreciate your feedback or any newer suggestions that you may have.
Thank you in advance for your help.
Pradeep
Option 1:
data: myReturnValue type string.
...
REPLACE ALL OCCURENCES OF '' IN mySingleValue BY '\'.
REPLACE ALL OCCURENCES OF ',' IN mySingleValue BY ','.
CONCATENATE myReturnValue mySingleValue INTO myReturnValue SEPARATED BY ','
...
Option 2:
data: myReturnValue type string.
data: myReturnValueLen type i.
...
REPLACE ALL OCCURENCES OF '' IN mySingleValue BY '\'.
REPLACE ALL OCCURENCES OF ',' IN mySingleValue BY ','.
WRITE ',' TO myReturnValue+myReturnValueLen.
myReturnValueLen = myReturnValueLen + 1.
WRITE mySingleValue TO myReturnValue.
myReturnValueLen = myReturnValueLen + STRLEN( mySingleValue ).
...
OPTION 3:
data: myReturnValue type string.
data: myReturnValueLen type i.
data: ch TYPE char1.
WRITE ',' TO myReturnValue+myReturnValueLen.
myReturnValueLen = myReturnValueLen + 1.
len = STRLEN( mySingleValue ).
DO len TIMES
ch = mySingleValue(sy-index).
if ch EQ '' OR ch EQ ','.
WRITE ',' TO myReturnValue+myReturnValueLen.
myReturnValueLen = myReturnValueLen + 1.
ENDIF.
WRITE ch TO myReturnValue+myReturnValueLen.
myReturnValueLen = myReturnValueLen + 1.
ENDDO.
‎2006 Oct 02 7:59 AM
Take a look at the "TRANSLATE" Statement, as I can see, you never use it and it can be the more useful !
Syntax :
translate mysinglevalue using',/'.Another things, I guess that to use the option 3, you'll need to use field-symbol.
Regards,
Erwan
‎2006 Oct 02 8:06 AM
Hi,
Why wouldn't you try reg. expr.
See also http://help.sap.com/saphelp_nw2004s/helpdata/en/42/9d6ceabb211d73e10000000a1553f6/frameset.htm
Eddy
PS.
Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.
Spread the wor(l)d!