IBM AS/400 Managing Dynamically-Allocated Storage, The logic of the subprocedures is as follows

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 150
Image 150
The logic of the subprocedures is as follows:

Managing Dynamically-Allocated Storage

The logic of the subprocedures is as follows:

1.DYNA_INIT creates the heap using the ILE bindable API CEECRHP (Crea Heap), storing the heap Id in a global variable HeapId. It alloc

based on

initial value of the array (in this case 100) by calling

API CEEGTST

(Get Heap Storage).

2.DYNA_TERM destroys the heap using the ILE bindable API CEEDSHP (Discard Heap).

3.DYNA_SET sets the value of an element in the array.

Before adding an element to the array, the procedure checks to s sufficient heap storage. If not, it uses operation code REALLOC to additional storage.

4. DYNA_GET returns the value of a specified element. The procedure the caller either the element requested, or zeros. The latter occ requested element has not actually been stored in the array.

To create the module DYNARRAY, type:

CRTRPGMOD MODULE(MYLIB/DYNARRAY) SRCFILE(MYLIB/QRPGLESRC￿)

The procedure can then be bound with other modules using CRTPGM or

CRTSRVPGM.

Figure 57 shows another module that tests the procedures in DYNARRAY.

*=================================================================

*DYNTEST: Test program for DYNARRAY module. *=================================================================

/COPY EXAMPLES,DYNARRI

D X

S

LIKE(DYNA_TYPE)

 

* Initialize the array

 

C

 

CALLP

DYNA_INIT

 

* Set a few elements

 

C

 

CALLP

DYNA_SET (25 : 3)

C

 

CALLP

DYNA_SET (467252232 : 1)

C

 

CALLP

DYNA_SET (-2311 : 750)

 

* Retrieve a few elements

 

C

 

EVAL

X = DYNA_GET (750)

C

'750'

DSPLY

X

C

 

EVAL

X = DYNA_GET (8001)

C

'8001'

DSPLY

X

C

 

EVAL

X = DYNA_GET (2)

C

'2'

DSPLY

X

 

* Clean up

 

 

C

 

CALLP

DYNA_TERM

C

 

SETON

LR

Figure 57. Sample module using procedures in DYNARRAY

126 ILE RPG for AS/400 Programmer's Guide

Page 150
Image 150
IBM AS/400 manual Managing Dynamically-Allocated Storage, The logic of the subprocedures is as follows