cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SQL Script in HANA: Access row of table

Shky
Product and Topic Expert
Product and Topic Expert
0 Kudos
885

Hi experts,

I have created the following table in my AMDP as below. I want to loop at the table and fetch the contents to fill the variables:

tab1 = SELECT mandt AS client,

                        col1 as Column1,

           col2 as Column2

           FROM DB_Table WHERE col1 = :input_parameter;

Now I want to implement the following logic:

If Column2 IS ' '      "Column2 returned from the query is BLANK

Then query again.

However I am not sure how to get the work area from the internal table tab1. Please help. Also I want to know how to set up a WHILE loop for the above scenario.

Regards,

Shalini

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

SQLScript is not ABAP. You should use a different approach and use CASE WHEN within your SQL statement. For some circumstances you can use the CURSOR.

Greetz

Silvio

Shky
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Haehner,

Yes, I used the cursor to loop over my table entries. However I want to append these into a new table.

How can I repeatedly insert into a same table?

say, result:

(tab is populated from cursor row)

result = select * from :result

               union Select * from :tab;

Here I would get an error on the first line - I want to do this inside a for loop and keep adding entries to result table.


Regards,

Shalini

SergioG_TX
SAP Champion
SAP Champion
0 Kudos

what if you added another condition to your where statement.

select *

from table

where col1 = :inputParam

AND col2 <> '';

Former Member
0 Kudos

Hi,

Just to be clear: With inserting you mean populating in result and not inserting in a physical table?

Assuming the first:

The syntax of code seems correct, except I would use a union all. But if its resulting in an error in the first line... Hm

Can you use temporary tables in your project?

These you can use like any other tables. In your scenario:

insert into <temp_table> (select * from :tab);

Silvio

Answers (0)