<?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: HANA SQL loop over columns in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707553#M193166</link>
    <description>&lt;P&gt;I meant, that you could write a program that creates the code for the "simple explicit comparison" for you based on the table structure. &lt;/P&gt;
  &lt;P&gt;If the tables change at some point in time you would just need to run this generator program to update the comparison.&lt;/P&gt;
  &lt;P&gt;Given the additional information, I'm under the impression that you've already found the optimal solution in terms of value for money. Sure, a generic record compare and report utility for arbitrary tables does sound useful, but the effort required to build this generic solution probably outweighs the benefit quite a bit.&lt;/P&gt;</description>
    <pubDate>Sun, 02 Sep 2018 00:08:30 GMT</pubDate>
    <dc:creator>lbreddemann</dc:creator>
    <dc:date>2018-09-02T00:08:30Z</dc:date>
    <item>
      <title>HANA SQL loop over columns</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaq-p/707548</link>
      <description>&lt;P&gt;I'm working in SAP BW powered by HANA. You can transform data using SQL in AMDPs (ABAP Managed Database Procedure).&lt;/P&gt;
  &lt;P&gt;I have tried and failed to write a script that can do the following - &lt;/P&gt;
  &lt;P&gt;1) Compare each column of 2 tables with an identical structure&lt;/P&gt;
  &lt;P&gt;2) Determine for each record and for each column if the column value differs between the 2 tables&lt;/P&gt;
  &lt;P&gt;3) List the difference for each record and column&lt;/P&gt;
  &lt;P&gt;4) The program should be generic, i.e. if the table structure changes, I will not have to change the code. The code should be able to determine the table structure.&lt;/P&gt;
  &lt;P&gt;I did think about using "cursor". Didn't work. Not sure whether this is because cursors don't work in an AMDP or because they can't use internal tables.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Example&lt;/P&gt;
  &lt;P&gt;Table 1&lt;/P&gt;
  &lt;P&gt;Col1 Col2 Col3&lt;/P&gt;
  &lt;P&gt;A01 1 2&lt;/P&gt;
  &lt;P&gt;A02 3 4&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Table 2&lt;/P&gt;
  &lt;P&gt;Col1 Col2 Col3&lt;/P&gt;
  &lt;P&gt;A01 1 2&lt;/P&gt;
  &lt;P&gt;A02 3 5&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;U&gt;&lt;/U&gt;&lt;SUB&gt;&lt;/SUB&gt;&lt;SUP&gt;&lt;/SUP&gt;&lt;/P&gt;
  &lt;P&gt;Result&lt;/P&gt;
  &lt;P&gt;Col1 Col2 Col3 Col4&lt;BR /&gt;(ID) (Col Name) (Value 1) (Value 2)&lt;/P&gt;
  &lt;P&gt;A02 Col3 4 5&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;U&gt;&lt;/U&gt;&lt;SUB&gt;&lt;/SUB&gt;&lt;SUP&gt;&lt;/SUP&gt;&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;U&gt;&lt;/U&gt;&lt;SUB&gt;&lt;/SUB&gt;&lt;SUP&gt;&lt;/SUP&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;U&gt;&lt;/U&gt;&lt;SUB&gt;&lt;/SUB&gt;&lt;SUP&gt;&lt;/SUP&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Aug 2018 15:08:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaq-p/707548</guid>
      <dc:creator>martin_chambers</dc:creator>
      <dc:date>2018-08-25T15:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: HANA SQL loop over columns</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707549#M193162</link>
      <description>&lt;P&gt;Wow, very challenging requirement (especially "generic")...&lt;/P&gt;
  &lt;P&gt;In general I would try the next (it isn't a solution, but direction) in AMDP:&lt;/P&gt;
  &lt;P&gt;1. in each table concatenate all non key values (something like this)&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/207271-1.png" /&gt;&lt;/P&gt;
  &lt;P&gt;In order to be generic we need to know what columns are in the table so we can try using "SYS"."COLUMNS"&lt;/P&gt;
  &lt;P&gt;2. join the tables and compare concatenated columns to identify rows that differ (using case/when)&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/207272-2.png" /&gt;&lt;/P&gt;
  &lt;P&gt;3. finally, if you need to know in which column there is a difference then try to parse values by "|" and compare&lt;/P&gt;
  &lt;P&gt;It seems to be extremely complex solution (if it is possible at all).&lt;/P&gt;
  &lt;P&gt;Please share if you succeed (in any way)...&lt;/P&gt;
  &lt;P&gt;BR,&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 09:21:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707549#M193162</guid>
      <dc:creator>former_member302041</dc:creator>
      <dc:date>2018-08-26T09:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: HANA SQL loop over columns</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707550#M193163</link>
      <description>&lt;P&gt;This is a question from the corner of "&lt;EM&gt;making SQL a dynamically typed language&lt;/EM&gt;"... &lt;/P&gt;
  &lt;P&gt;I see different approaches to this problem and ways to solve some smaller problems easily, but before that, it would be good if you could explain the use case here. &lt;/P&gt;
  &lt;UL&gt;
   &lt;LI&gt;Why do you want a column-based comparison over a pair of (necessarily) ordered list of rows? &lt;/LI&gt;
   &lt;LI&gt;And why does it need to be generic in itself? &lt;/LI&gt;
   &lt;LI&gt;What's speaking against generating the actual compare routines for each pair of tables?&lt;/LI&gt;
   &lt;LI&gt;What volume of data do you expect to be compared? &lt;/LI&gt;
   &lt;LI&gt;How many records do you think will be mismatches? &lt;/LI&gt;
   &lt;LI&gt;How often does the comparison be done and how much time can it take at max?&lt;/LI&gt;
   &lt;LI&gt;How often does the actual structure of the tables to be compared change? Or is it always just the table names that change? &lt;/LI&gt;
  &lt;/UL&gt;
  &lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 00:02:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707550#M193163</guid>
      <dc:creator>lbreddemann</dc:creator>
      <dc:date>2018-08-27T00:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: HANA SQL loop over columns</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707551#M193164</link>
      <description>&lt;P&gt;Hi Andrey,&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Thank you very much for your solution. In my particular situation, I already know which records are different. I need to identify the fields with different contents. Parsing does seem like a complicated way. Our current solution, is simple, but not generic. I simply write a comparison for each field. Unfortunately, this means that I have to adjust the coding if the underlying table structure changes.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;By the way, a generic solution is possible in ABAP. In retrospect, I probably should have chosen that path, as the number of records is very small (1000 records). No performance issues.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Aug 2018 16:12:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707551#M193164</guid>
      <dc:creator>martin_chambers</dc:creator>
      <dc:date>2018-08-31T16:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: HANA SQL loop over columns</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707552#M193165</link>
      <description>&lt;P&gt;Hi Lars,&lt;/P&gt;
  &lt;P&gt;The use case:&lt;/P&gt;
  &lt;P&gt;Data records are uploaded into a SAP Business Warehouse System.&lt;/P&gt;
  &lt;P&gt;The business department, can check and, if necessary, correct records before further processing. These manually changed records are saved in a shadow table. Later on they will overwrite the values in the original records. &lt;BR /&gt;Unfortunately, the ABAP program that is used to make these manual changes, does not tag the modified field.The comparison is made, so that a report can be sent to the data originators. They have to make the identical corrections in their data source. Otherwise, we will receive the same errors next month.&lt;/P&gt;
  &lt;P&gt;The volume of changed records is actually quite small, order of magnitude 1000 compared to the several 10 million records sent per month. The comparison is made for 8 paired tables (16 in total) and 10 data deliveries (countries) per month.&lt;/P&gt;
  &lt;P&gt;I'm not quite sure what you mean by "generating the actual compare routines for each pair of tables". We have now implemented a simple solution where we have coded a comparison explicitly for each field. This is done separately for each of the paired tables. This is not really what we wanted, e.g. if the table structure changes, the code will have to be adapted. Some things are easier in ABAP.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Aug 2018 16:26:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707552#M193165</guid>
      <dc:creator>martin_chambers</dc:creator>
      <dc:date>2018-08-31T16:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: HANA SQL loop over columns</title>
      <link>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707553#M193166</link>
      <description>&lt;P&gt;I meant, that you could write a program that creates the code for the "simple explicit comparison" for you based on the table structure. &lt;/P&gt;
  &lt;P&gt;If the tables change at some point in time you would just need to run this generator program to update the comparison.&lt;/P&gt;
  &lt;P&gt;Given the additional information, I'm under the impression that you've already found the optimal solution in terms of value for money. Sure, a generic record compare and report utility for arbitrary tables does sound useful, but the effort required to build this generic solution probably outweighs the benefit quite a bit.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Sep 2018 00:08:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/hana-sql-loop-over-columns/qaa-p/707553#M193166</guid>
      <dc:creator>lbreddemann</dc:creator>
      <dc:date>2018-09-02T00:08:30Z</dc:date>
    </item>
  </channel>
</rss>

