cancel
Showing results for 
Search instead for 
Did you mean: 

FOR Loop

Former Member
0 Kudos

hi Friends,

Whats the FOR loop, what is situations where we use this.

regards

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Sushil,

Normally, you can use for loop in procedure or sql script base of calculation view , it is only loop syntax, such as below script.

CREATE PROCEDURE nested_block_for(IN inval INT, OUT val INT) LANGUAGE SQLSCRIPT

READS SQL DATA AS

BEGIN

DECLARE a1 int default 0;

DECLARE a2 int default 0;

DECLARE v1 int default 1;

DECLARE v2 int default 1;

DECLARE v3 int default 1;

DECLARE CURSOR C FOR SELECT * FROM mytab1;

FOR R as C DO

          DECLARE CURSOR C FOR SELECT * FROM mytab2;

                    a1 := a1 + R.a;

                              FOR R as C DO DECLARE CURSOR C FOR SELECT * FROM mytab3;

                                        a2 := a2 + R.a;

                                                  FOR R as C DO

                                                            a3 := a3 + R.a;

                                                  END FOR;

                              END FOR;

END FOR;

END;

You can reference SQL guide document.

http://help.sap.com/hana/SAP_HANA_SQL_Reference_en.pdf

Hope this can help you.

Regards,

Jerry

Former Member
0 Kudos

thanks Jerry.

I also got some more info that it executes a statement or group of statement for each row of a table in defined result set.

regards

Sushil

Former Member
0 Kudos

Hi Sushil,

Yes, you can do it, note, if possible, please avoid to use cursor in procedure for loop, you can use other loop function, such as while.

Regards,

Jerry