IBM AS/400 manual Managing Dynamically-Allocated Storage, Part 3 of, DYNARRAY Subprocedures

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 148
Image 148
(Part 3 of 5).

Managing Dynamically-Allocated Storage

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

*DYNA_SET: Set an array element.

*Function: Ensure the array is big enough for this element￿,

*and set the element to the provided value.

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

P DYNA_SET

B

 

EXPORT

 

*-----------------------------------------------------------------

 

 

 

* Input parameters for this procedure.

 

*-----------------------------------------------------------------

 

 

D DYNA_SET

PI

 

 

D

Element

 

 

VALUE LIKE(DYNA_TYPE)

D

Index

 

5I 0

VALUE

 

*-----------------------------------------------------------------

 

 

 

* Local variables.

 

 

 

*-----------------------------------------------------------------

 

 

D Size

S

10I 0

 

 

*-----------------------------------------------------------------

 

 

*If the user selects to add to the array, then first check

*if the array is large enough, if not then increase its

*size. Add the element.

 

*-----------------------------------------------------------------

 

C

Index

IFGT

NumElems

C

 

EXSR

REALLOC

C

 

ENDIF

 

C

 

EVAL

DynArr(Index) = Element

*================================================================= * REALLOC: Reallocate storage subroutine

*

 

 

*

Function: Increase the size of the dynamic

array

*

and initialize the new elements.

 

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

C REALLOC BEGSR

*

*Remember the old number of elements

C

Z-ADD

NumElems

OldElems

5 0

 

 

 

 

Figure 56

(Part 3 of 5).

DYNARRAY Subprocedures

 

124 ILE RPG for AS/400 Programmer's Guide

Page 148
Image 148
IBM Managing Dynamically-Allocated Storage, Part 3 of, DYNARRAY Subprocedures, ILE RPG for AS/400 Programmers Guide