Declaring an array

The precompiler supports complex definitions, which are structures and arrays. You may nest structures, but you cannot have an array of structures.

The precompiler recognizes single-dimensional arrays of all datatypes.

The precompiler also recognizes double-dimensional arrays of characters, as the following example demonstrates:

#define maxrows 25
 int numsales [maxrows];
exec sql begin declare section; 
 #define DATELEN 30 
 #define DAYS_PER_WEEK 7
 CS_CHAR days_of_the_week[DAYS_PER_WEEK][DATELEN+1]; 
 exec sql end declare section; 

You can declare arrays of any datatype. However, to select into an array element, its datatype must be scalar—integer, character, floating point, or pointer. You can select into elements of any scalar array, even an array of structures, as shown:

exec sql begin declare section;
     int sales_totals[100];
     struct sales_record{ 		 
         int total_sales;
         char store_name[40];
         }[100];
 exec sql end declare section;
 
 /*
 ** If there are fewer than 100 stores, 
 ** this will get the sales totals for all
 ** of them.  If there are more than
 ** 100, it will cause an error at runtime.
 */
 exec sql select total_sales into :sales_totals
     from sales_table;
 /*
 ** This gets the sales for just one store.
 */
 exec sql select total_sales into :sales_totals[0]
     from sales_table where store_ID = 'xyz';
 /*
 ** This gets two pieces of information on a single **
store.
 */
 exec sql select total_sales, store_name 
     into :sales_records[i]
     from sales_table where store_ID = 'abc';