Proper Use of Cursors (TB#10) (Functions/Subroutines/Programs)

Proper Use of Cursors

 

With the release of version 1.1, Advanced Revelation supports the use of nine active select lists. The different select lists are available through cursors. As explained in the Version 1.1 Addendum (p. 140), the cursor keyword is an expression that resolves to a number (0-8). However, the extended SELECT syntax also allows the developer to put the cursor number directly in the statement. For example, the following is a valid statement:

 

SELECT 'CUST' BY 'ST' USING 1 ELSE FLAG = 1

 

There are potential problems in the direct use of cursor numbers. The most serious is an occasional 'Invalid Version of RTP20' error message. The error is frustrating because it effectively stops program execution and appears to happen randomly. However, two coding techniques illustrated here will avoid the problem.

 

There are two methods for using multiple cursors. The first is to allow the system to allocate the cursor number. The following code fragment illustrates this:

 

CURSOR = '' SELECT 'CUST' BY 'ST' SETTING CURSOR ELSE FLAG = 1

 

The SETTING keyword indicates that the program needs the next available cursor, whichever one it happens to be.

 

If a particular cursor must be used, for example cursor 2, and that cursor has not been used before in the program, it must first be cleared.

 

CLEARSELECT 2 SELECT 'CUST' BY 'ST' USING 2 ELSE FLAG = 1

 

CLEARSELECT will remove any information that may remain in the cursor from a previous SELECT, even if the select was performed in another program.

 

By using one of these two methods the developer can be assured of consistent, proper behavior when using extended SELECT syntax.

  • kb/kb_articles/kb0025.txt
  • Last modified: 2024/01/30 13:36
  • by 127.0.0.1