SQL Programming Manual for TAL
Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL—527887-001
7-17
Dynamically Allocating Memory
Allocating Memory for the SQLDA Structures and Names 
Buffers
In preparation for allocating memory to store the SQLDA structure, you must get the 
number of input parameters or output variables from the SQLSA structure. Similarly, to 
allocate memory for the names buffer, you must get the length of the input or output 
names buffer from the SQLSA structure. For example:
-- Save the SQLSA values immediately after PREPARE:
inum := sqlsa.PREPARE.INPUT^NUM;
inameslen := sqlsa.PREPARE.INPUT^NAMES^LEN;
IF ( inum > 0) THEN
 CALL allocate^sqlda(inum);
...
IF ( inameslen > 0) THEN
 CALL allocate^namesbuf(inameslen);
To allocate memory for the SQLDAs and names buffers for the input and output 
variables, use the GETPOOL system procedure. GETPOOL allocates a block of 
memory, and returns the address of that block.
Before calling GETPOOL, initialize the pool using the system procedure 
DEFINEPOOL. For example:
-- In global declarations:
 LITERAL pool^size^in^bytes = 8192d;
 INT .EXT pool^head[0:18];
 INT .EXT pool[0 : pool^size^in^bytes/2d - 1d];
-- In setup or main procedure code:
 error := DEFINEPOOL(pool^head, pool, pool^size^in^bytes);
After calling GETPOOL, your program should put the values returned by GETPOOL 
into pointers to the SQLDA and names buffer variables that were defined earlier.
The is code shows declaring an SQLDA template and using the template to calculate 
the memory required for the SQLDA structure:
-- Global variable declarations:
 EXEC SQL INCLUDE SQLDA (sqlda^type, 1);
-- Code in allocate^sqlda procedure:
 mem^needed := $LEN(sqlda^type) +
 (num^entries -1) * $LEN(sqlda^type.sqlvar);
-- Call to GETPOOL:
 @sqlda^ptr := GETPOOL(pool^head, mem^needed);
Caution. If your program uses more than one extended segment, you must ensure that the 
memory in which you place the SQLDA structure is visible when the SQL statement that uses 
the SQLDA executes.










