<?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>Question Re: Case...when for CURRENCY_CONVERSION function in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465522#M4669526</link>
    <description>&lt;P&gt;Hi Brandeis,&lt;/P&gt;&lt;P&gt;     Thanks a lot for your analysis, I really appreciate it. I tried your idea and compared the performance. It did be more faster, the performance was improved about 25%~30%. Currently, I guess this might be the way to improve the performance for this case. The behavior of SAP HANA SQL execution is very confusing.  Anyway, thanks for you great idea. &lt;/P&gt;</description>
    <pubDate>Fri, 07 May 2021 02:39:40 GMT</pubDate>
    <dc:creator>eugene_517</dc:creator>
    <dc:date>2021-05-07T02:39:40Z</dc:date>
    <item>
      <title>Case...when for CURRENCY_CONVERSION function</title>
      <link>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaq-p/12465519</link>
      <description>&lt;P&gt;Hi guys, recently, I encountered a strange issue. I have an analytic CDS query to derive records from VBAP, the currency conversion function bring heavy performance issue. I added 'Case ... when' in CDS view and compared the input currency and item currency, if they were same, returned the amount directly without conversion. And in test system, we had 800,000+ VBAP records. ( EUR had 700,000+ records, USD had 100,000 records) . I tested the performance in HANA studio (SQL) and GW client (server request) by passing EUR and USD, there was no different. Logically, if passing 'EUR', it should be faster as it has less records to do the conversion. eh...., not sure how the HANA works with it. I really appreciate if anyone has any experience or idea about this case. Thanks in advance!&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1929452-currency-conversion.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 11:10:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaq-p/12465519</guid>
      <dc:creator>eugene_517</dc:creator>
      <dc:date>2021-05-06T11:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Case...when for CURRENCY_CONVERSION function</title>
      <link>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465520#M4669524</link>
      <description>&lt;P&gt;Hi Eugene, &lt;/P&gt;&lt;P&gt;to find out the truth, you have to analyze the execution plan. But I have some suspicions. &lt;/P&gt;&lt;P&gt;I think it is due to the fact that the SQL function &lt;A href="https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/d22d746ed2951014bb7fb0114ffdaf96.html"&gt;CONVERT_CURRENCIES&lt;/A&gt; in SQLScript still internally calls the obsolete CE function &lt;A href="https://help.sap.com/viewer/de2486ee947e43e684d39702027f8a94/1.0.12/en-US/d5193d2beef74c5da7bcb982fb9f1ea9.html"&gt;CE_CONVERSION&lt;/A&gt;. This function works on table level and not on row level. See &lt;A href="https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/d22d746ed2951014bb7fb0114ffdaf96.html"&gt;SAP documentation&lt;/A&gt;. &lt;/P&gt;&lt;P&gt;If this suspicion is correct, you could separate the table into two halves: &lt;/P&gt;&lt;UL&gt;
&lt;LI&gt;One where both currencies are the same and &lt;/LI&gt;&lt;LI&gt;The other with the rest of the records, where you can apply the CONVERT_CURRENCIES&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;
And I would merge them again at the end with a UNION_ALL. &lt;/P&gt;&lt;P&gt;If you try this, please post the result! It would be interesting to see if this was successful.&lt;/P&gt;&lt;P&gt;Regards, &lt;BR /&gt;Jörg&lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 12:14:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465520#M4669524</guid>
      <dc:creator>Joerg_Brandeis</dc:creator>
      <dc:date>2021-05-06T12:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Case...when for CURRENCY_CONVERSION function</title>
      <link>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465521#M4669525</link>
      <description>&lt;P&gt;I'm not sure that a different internal implementation of the conversion function would change all that much here. &lt;/P&gt;&lt;P&gt;One part of the answer to this "mystery" is that the CASE WHEN clause is a declaration for how data should be handled and not the exact instruction for how the DB has to perform this. &lt;/P&gt;&lt;P&gt;Practically speaking, this means, that the whole set of tuples that remains after applying the WHERE clause is fed into the conversion function. Unwanted results (the data that matches the other WHEN branches) is later discarded. &lt;/P&gt;&lt;P&gt;On the plus side, the conversion itself works on a whole set of records at once and not just row-by-row. So, the execution speed difference between e.g. 100 and 10000 records should barely be noticeable. But 100k to 700k difference means many more "chunks" to work through.&lt;/P&gt;&lt;P&gt;I would not recommend working around this by putting in two different code paths with UNION. This likely will introduce another bottleneck (materialisation) and complicate the CDS view a lot. &lt;/P&gt;&lt;P&gt;Instead, try and filter the data as much as possible before the conversion (WHERE clause). No frontend facing view should return 100k+ records. &lt;/P&gt;</description>
      <pubDate>Thu, 06 May 2021 22:46:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465521#M4669525</guid>
      <dc:creator>lbreddemann</dc:creator>
      <dc:date>2021-05-06T22:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: Case...when for CURRENCY_CONVERSION function</title>
      <link>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465522#M4669526</link>
      <description>&lt;P&gt;Hi Brandeis,&lt;/P&gt;&lt;P&gt;     Thanks a lot for your analysis, I really appreciate it. I tried your idea and compared the performance. It did be more faster, the performance was improved about 25%~30%. Currently, I guess this might be the way to improve the performance for this case. The behavior of SAP HANA SQL execution is very confusing.  Anyway, thanks for you great idea. &lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 02:39:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465522#M4669526</guid>
      <dc:creator>eugene_517</dc:creator>
      <dc:date>2021-05-07T02:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Case...when for CURRENCY_CONVERSION function</title>
      <link>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465523#M4669527</link>
      <description>&lt;P&gt;Hi Lars,&lt;/P&gt;&lt;P&gt;      Thanks a lot for you explanation. It's really helpful. I tried Brandies way to separate the table into two halves based on currency, and union them together. Due to my comparation, the performance gets improved about 25%~30%. I looked deep into the execution plan, the time cost of the 'Calculation Model' did be reduced due to the less number of the records to be converted I guess. &lt;/P&gt;</description>
      <pubDate>Fri, 07 May 2021 02:46:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465523#M4669527</guid>
      <dc:creator>eugene_517</dc:creator>
      <dc:date>2021-05-07T02:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: Case...when for CURRENCY_CONVERSION function</title>
      <link>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465524#M4669528</link>
      <description>&lt;P&gt;Hey &lt;SPAN class="mention-scrubbed"&gt;eugene_517&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;thanks for taking the time to come back with your results. Much appreciated.&lt;/P&gt;&lt;P&gt;It's good to hear that you were able to improve the performance of the query by splitting it up into two disjunct branches: one where conversion is not required (as the data is already in display currency ) and a second one for where conversion is required (data is not in display currency).&lt;/P&gt;&lt;P&gt;Now, this specific pattern is rather common for queries in SAP systems; SAP HANA should understand this pattern and automatically optimize accordingly.&lt;/P&gt;&lt;P&gt;Leaving this to the SQL/CDS developer is not a good solution as it is trivial to make errors in the separation of the two branches, leading to tuples that may be present in both of the branches. This would mean wrong results.&lt;/P&gt;&lt;P&gt;Also, it pushes an optimisation decision (when is it better/faster to split the two data sets and when is it better to just do a single set of data) to the design level; that is precisely what SQL optimisers should prevent. &lt;/P&gt;&lt;P&gt;I would suggest to SAP HANA development to consider automating this optimisation. There are plenty of options to do this. One simple way could be to extend the currency_conversion function with a list of conditions - similar to the ones in the case clause - to split the data into two.&lt;/P&gt;&lt;P&gt;The optimiser could use these "split-conditions" at execution time to estimate how large each group is likely going to be and decide the actual execution based on that.&lt;/P&gt;&lt;P&gt;This would also make for a much cleaner SQL/CDS statements as the cumbersome CASE construct could be removed.&lt;/P&gt;&lt;P&gt;Cheers.&lt;/P&gt;&lt;P&gt;Lars&lt;/P&gt;</description>
      <pubDate>Sun, 09 May 2021 05:17:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/case-when-for-currency-conversion-function/qaa-p/12465524#M4669528</guid>
      <dc:creator>lbreddemann</dc:creator>
      <dc:date>2021-05-09T05:17:49Z</dc:date>
    </item>
  </channel>
</rss>

