Entering content frame

Recursive DECLARE CURSOR statement Locate the document in its SAP Library structure

The recursive DECLARE CURSOR statement can be used to receive bills of material by means of a command.

Syntax

<recursive_declare_cursor_statement> ::= DECLARE <result_table_name> CURSOR FOR
WITH RECURSIVE <reference_name> (<alias_name>,...) AS
(<initial_select> UNION ALL <recursive_select>) <final_select>

<initial_select> ::= <query_spec>
<recursive_select> ::= <query_spec>
<final_select> ::= <select_statement>

result_table_name, reference_name, alias_name, query_spec, select_statement

Example

DECLARE C CURSOR FOR
WITH RECURSIVE PX (MAJOR, MINOR, NUMBER, MAINMAJOR) AS
  (SELECT W,X,Y,W FROM T WHERE W = 'aaa' UNION ALL
   SELECT W,X,Y,MAINMAJOR FROM T, PX WHERE MINOR = T.W)
 SELECT MAINMAJOR,MINOR,NUMBER FROM PX ORDER BY NUMBER

Explanation

If a result table name with the specified reference name existed before the recursive DECLARE CURSOR statement was executed, the corresponding cursor is closed implicitly.

Leaving content frame