Fetch and write the table space data


Lines 84 through 102 of the following figure prepare the data, write it, close the cursor, and execute the cleanup procedure.

Preparing and writing the data

84 do forever                        /* loop for all tablepart rows     */
85   rc = asurxsql('FETCH TP ');     /* fetch next row                  */
86
87   if (rc ¬= 0) then               /* if fetch failed                 */
88     signal sqlerror;              /* go output sql error message     */
89   if (sqlcode = 100) then         /* if end of data                  */
90     leave;                        /* leave forever loop              */
91
92   dbn = strip(tp.dbname, 'T');    /* remove trailing blanks          */
93   tsn = strip(tp.tsname, 'T');
94   tsobj = dbn'.'tsn;              /* dbname.tsname                   */
95   rc = asurxrpt('WRITE tpfd');    /* output tablepart data           */
96   if (rc ¬= 0) then               /* if an error                     */
97     signal rpterror;              /* go output report error message  */
98   end                             /* end do forever                  */
99
100 rcx = asurxsql('CLOSE TP');       /* close cursor                    */
101
102 signal cleanup;                   /* cleanup                         */
103

Line Number

Description

84-98

These lines are a do-forever loop to fetch the table partition rows.

85

This line fetches the first row or next row by using the ASURXSQL function. The line places the data in the TP variable; assigns the return code to the variable rc.

87-88

If the FETCH fails (if the return code is not 0), these lines trap the SQL error condition ( sqlerror ) and execute the SQL error procedure (lines 135 through 144).

89-90

These lines exit the loop if all rows have been fetched (if the return SQLCODE = 100).

92-93

These lines remove trailing blanks from the database name and table space name by using the strip function with the T (Trailing) argument. The lines assign the resulting names to the dbn and tsn variables, respectively.

94

This line creates the qualified table space name by placing a period (.) between the trimmed database name (line 92) and the trimmed table space name (line 93). This line assigns the resulting table space name to the variable tsobj.

95

This line executes the ASURXRPT WRITE function, identifies the stem variable that identifies the report formats, and assigns the resulting return code to the variable rc.

96-97

If the return code is not 0, this line trap the report error condition and output the report error message (lines 111 through 115).

98

This line ends the do-forever loop begun in line 84.

100

This line closes the cursor opened in lines 62 and 63.

102

This line executes the cleanup procedure.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*