I'm sorry about the code below being wrapped on single lines... I can't get it to show differently... MC Press???
This thread discusses the Content article:
Sorting Data Structures
I have a web application were I need to sort an array based on a data structure. The array should be sorted using the qsort function. My definitions looks like the following:
| Code: |
h bnddir('QC2LE')
d IFS_EntryDS ds
d Name 64a varying
d Attr 6a varying
d IFS ds qualified
d List likeds(IFS_EntryDS) dim(100)
d IFS_ListCount s 10i 0 inz(0)
d SortArrayQ pr extproc('qsort')
d base * value
d num 10u 0 value
d width 10u 0 value
d compare * procptr value
d SortCompare pr 10i 0
d parm1 * value
d parm2 * value
d i s 10i 0 inz(0)
|
and my SortCompare (I have removed the logic to keep the example short and this always returns 0 meaning no sort):
| Code: |
/end-free
p SortCompare b
d SortCompare pi 10i 0
d parm1 * value
d parm2 * value
/free
return 0;
/end-free
p e
/free
|
My main looks like the following:
| Code: |
IFS_ListCount = 5;
IFS.List(1).Name = 'Q1';
IFS.List(2).Name = 'c2';
IFS.List(3).Name = 'A3';
IFS.List(4).Name = 'a4';
IFS.List(5).Name = 'f5';
SortArrayQ(
%addr(IFS.List) :
IFS_ListCount :
%size(IFS_EntryDS) :
%paddr('SortCompare')
);
for i = 1 to IFS_ListCount;
// From here I should be able to work with:
// %trim(IFS.List(i).Name)
endfor;
|
The program compiles perfectly but never generates any output. If I comment out the SortArrayQ(...) statement then it generates the logic in the for-loop and returns content. I can't figure out why.... any ideas?