Skip to Content
Aug 25, 2018 at 03:08 PM

HANA SQL loop over columns


I'm working in SAP BW powered by HANA. You can transform data using SQL in AMDPs (ABAP Managed Database Procedure).

I have tried and failed to write a script that can do the following -

1) Compare each column of 2 tables with an identical structure

2) Determine for each record and for each column if the column value differs between the 2 tables

3) List the difference for each record and column

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.

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.


Table 1

Col1 Col2 Col3

A01 1 2

A02 3 4

Table 2

Col1 Col2 Col3

A01 1 2

A02 3 5


Col1 Col2 Col3 Col4
(ID) (Col Name) (Value 1) (Value 2)

A02 Col3 4 5