How to append elements from one array to another array using PeopleCode

This example is simple form of combining/appending two arrays for programetic purposes.
This is fairly straightforward example where I used PeopleCode array Push method to add item to the end of array &MYARRAY1.
If you want to add items in the beginning of the array use Unshift method instead.

/*Suppose you have two arrays as follows*/
Local Array of Number &MYARRAY1;
Local Array of Number &MYARRAY2;

/*Populate two arrays*/
&MYARRAY1 = CreateArray(100, 200, 300);
&MYARRAY2 = CreateArray(400, 500, 600);

/*append items from &MYARRAY2 to &MYARRAY1 at the end of &MYARRAY1*/
For &i = 1 To &MYARRAY2.Len
&MYARRAY1.Push(&MYARRAY2 [&i]);
End-For;

/*Printout the values for the array &MYARRAY1*/
For &j = 1 To &MYARRAY1.Len
WinMessage(&MYARRAY1 [&j]);
End-For;

/*Suppose you have array of any (any data type) like this*/
/*You can do the same thing as above*/
Local array of any &ArrayAny = CreateArrayAny(1, 2, "hi", "there");

For &k = 1 To &MYARRAY2.Len
&ArrayAny.Push(&MYARRAY2 [&k]);
End-For;

For &l = 1 To &ArrayAny.Len
WinMessage(&ArrayAny [&l]);
End-For;

SHARE

Ayesha Wee

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment