<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Efficient string concatenation in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-string-concatenation/m-p/1596879#M268062</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pradeep&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
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.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Oct 2006 06:51:50 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-10-02T06:51:50Z</dc:date>
    <item>
      <title>Efficient string concatenation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-string-concatenation/m-p/1596879#M268062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pradeep&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
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.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Oct 2006 06:51:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-string-concatenation/m-p/1596879#M268062</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-02T06:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient string concatenation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-string-concatenation/m-p/1596880#M268063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Take a look at the "TRANSLATE" Statement, as I can see, you never use it and it can be the more useful !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Syntax :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;translate mysinglevalue using',/'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another things, I guess that to use the option 3, you'll need to use field-symbol.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Erwan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Oct 2006 06:59:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-string-concatenation/m-p/1596880#M268063</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-10-02T06:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient string concatenation</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-string-concatenation/m-p/1596881#M268064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why wouldn't you try reg. expr.&lt;/P&gt;&lt;P&gt;See also &lt;A href="http://help.sap.com/saphelp_nw2004s/helpdata/en/42/9d6ceabb211d73e10000000a1553f6/frameset.htm" target="test_blank"&gt;http://help.sap.com/saphelp_nw2004s/helpdata/en/42/9d6ceabb211d73e10000000a1553f6/frameset.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Eddy&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PS. &lt;/P&gt;&lt;P&gt;Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points. &lt;/P&gt;&lt;P&gt;Spread the wor(l)d!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Oct 2006 07:06:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-string-concatenation/m-p/1596881#M268064</guid>
      <dc:creator>eddy_declercq</dc:creator>
      <dc:date>2006-10-02T07:06:29Z</dc:date>
    </item>
  </channel>
</rss>

