How to sort Alternate Array?

185 pts.
Tags:
Arrays
AS/400 testing
Load testing
RPGLE
Arr1       s        10 A Dim(4)   Perrcd(2)  Fromfile(abc)

Arr2       s         2  0  Dim(4) Alt(arr1)
Now, I have load records From file to that array then I want to show these record in reverse Order. How I can do this?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Arr1 can be sorted ascending or descending with the SORTA op-code, but the alternate array Arr2 shouldn’t change. From the ILE RPG Language Reference, SORTA (Sort an Array) page:

  • If the array is defined as a compile-time or prerun-time array with data in alternating form, the alternate array is not sorted

I wouldn’t use a run-time array like this if I need to sort it in an order different from how it loaded. Either define the arrays as data structure subfields where the data structure itself is dimensioned and load it yourself from the file, or let your run-time arrays load as they are now and copy them into a data structure array.

After you have them in a data structure array, then you can sort the array using SORTA or any other method you choose.

I suppose you could change from Fromfile(abc) to a different file. Perhaps create a LF that presents the records in descending order.

Almost forgot… If the array is loaded in ascending order and you need to display it descending, just start from the bottom (the highest index) and work through to the top (lowest index).

Tom

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: