Skip to Content
avatar image
Former Member

VAR_OUT inside cursor

Hello,

I need to calculate cumulative stocks. I want to do it using SAP HANA analysis process. I created test procedure with cursor and VAR_OUT  inside cursor. When i call this procedure i always get only one value. How i can get more then one value from this procedure?

DECLARE CURSOR c_cursor1 FOR

Select "SUPNUM" FROM "_SYS_BIC"."Stocks/STOCKS"

                              WHERE "SUPNUM" IN ('00000028345', '00000039053')

GROUP BY "SUPNUM";

FOR cur_row as c_cursor1 DO

     VAR_OUT = Select "SUPNUM" FROM "_SYS_BIC"."Stocks/STOCKS"

                           WHERE "SUPNUM" = cur_row.SUPNUM GROUP BY "SUPNUM";

END FOR

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jul 22, 2014 at 06:22 AM

    Hi Sergey,

    If you want to retain the cursor(though you could try the same with JOINS), you can consider using arrays.

    DECLARE CURSOR c_cursor1 FOR

                               SELECT "SUPNUM" FROM "_SYS_BIC"."Stocks/STOCKS"

    WHERE "SUPNUM" IN ('00000028345', '00000039053')

                               GROUP BY "SUPNUM";

    DECLARE AR_SUPNUM   VARCHAR(10) ARRAY;


    FOR cur_row as c_cursor1 DO

        

             V_COUNT := V_COUNT + 1;

         Select "SUPNUM" FROM "_SYS_BIC"."Stocks/STOCKS" INTO V_SUPNUM

             WHERE "SUPNUM" = cur_row.SUPNUM GROUP BY "SUPNUM";

            AR_SUPNUM[:V_COUNT] =  :V_SUPNUM;

    END FOR


    VAR_OUT = UNNEST(:AR_SUPNUM)




    Nehal.


    Add comment
    10|10000 characters needed characters exceeded