|
On Mon, 8 Dec 2003 keblake@xxxxxxxxxxxxxxxxxxx wrote: > I have an array defined as follows: [SNIP] > and I recieve the following compilation error: > RNF5159: Factor 2 operand must be an array name for specified operation. Hi, I don't think you can use SORTA with a qualified data structure. This is a perfect use for QSORT, though. Another advantage of QSORT is that you won't have to initialize everything to 9999, since QSORT will only sort the elements you ask it to sort... What's really nice about qualified structures is that you can define one as a prototype, and use LIKEDS to make many more copies that are the same format. This allows you to pass them as parameters nicely, as well. Here's some sample code that demonstrates sorting your array with QSORT: H DFTACTGRP(*NO) BNDDIR('QC2LE') D qsort PR ExtProc('qsort') D base * value D num 10U 0 value D width 10U 0 value D compare * procptr value D SortByItem PR 10I 0 D parm1 likeds(Order) D parm2 likeds(Order) D SortByQty PR 10I 0 D parm1 likeds(Order) D parm2 likeds(Order) D Order DS based(prototype_only) D Qualified D DtlItem 12A D DtlOrdQty 5S 0 D Order1 DS likeds(Order) dim(99) D numitems s 10I 0 ** Throw some sample data into array to test it. c eval order1(1).DtlItem = 'ZZ123' c eval order1(1).DtlOrdQty = 5 c eval order1(2).DtlItem = 'BB321' c eval order1(2).DtlOrdQty = 17 c eval order1(3).DtlItem = 'RR826' c eval order1(3).DtlOrdQty = 14 c eval order1(4).DtlItem = 'AA000' c eval order1(4).DtlOrdQty = 3 c eval numitems = 4 ** Sort the array by DtlItem c callp qsort(%addr(Order1): numitems: c %size(Order): %paddr('SORTBYITEM')) ** Sort the array by DtlOrdQty c callp qsort(%addr(Order1): numitems: c %size(Order): %paddr('SORTBYQTY')) c eval *inlr = *on *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P SortByItem B D SortByItem PI 10I 0 D parm1 likeds(Order) D parm2 likeds(Order) c select c when parm1.DtlItem < parm2.DtlItem c return -1 c when parm1.DtlItem > parm2.DtlItem c return 1 c other c return 0 c endsl P E *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P SortByQty B D SortByQty PI 10I 0 D parm1 likeds(Order) D parm2 likeds(Order) c select c when parm1.DtlOrdQty < parm2.DtlOrdQty c return -1 c when parm1.DtlOrdQty > parm2.DtlOrdQty c return 1 c other c return 0 c endsl P E
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.