For a report I'm developing, I need to track the top ten quantity and cost
for a department, as well as for the entire report. I have two
identical-in-kind arrays, but I have to process each of them twice (once for
cost, again for quantity). Since the arrays are defined identically, I want
to halve the code: process cost or process quantity, regardless of which
array it is. I feel like there is a solution involving basing the arrays on
a pointer but haven't wrapped my head around it.
d toplistcount s 5i 0 inz(0)
d ds
d toplist 90 dim(1000) descend
d topdept inz like(sqlrow.department)
d overlay(toplist:1)
d topitem inz like(sqlrow.item)
d overlay(toplist:*next)
d topdesc inz like(sqlrow.item_desc)
d overlay(toplist:*next)
d topqty inz
d like(sqlrow.dr_qty)
d overlay(toplist:*next)
d topcost inz
d like(sqlrow.ext_cost)
d overlay(toplist:*next)
d deptlistcount s 5i 0 inz(0)
d ds
d deptlist 90 dim(1000) descend
d deptdept inz like(sqlrow.department)
d overlay(toplist:1)
d deptitem inz like(sqlrow.item)
d overlay(deptlist:1)
d deptdesc inz like(sqlrow.item_desc)
d overlay(deptlist:*next)
d deptqty inz
d like(sqlrow.dr_qty)
d overlay(deptlist:*next)
d deptcost inz
d like(sqlrow.ext_cost)
d overlay(deptlist:*next)
And here is the code I have so far. It works but is inefficient respective
to repeating itself.
// Top N for each department, inside a level break routine.
wrtsection('wrappertabletop');
// Top "rank" quantity and cost info.
sorta %subarr(deptqty:1:deptlistcount);
wrtsection('topqtyheader');
for i = 1 to workrank;
if i <= deptlistcount;
updhtmlvar('topqtyitem':deptitem(i));
updhtmlvar('topqtydesc':deptdesc(i));
updhtmlvar('topqtyqty':%editc(deptqty(i):'J'));
wrtsection('topqtydetail');
endif;
endfor;
wrtsection('detailbottom');
exsr GraphDeptQty;
wrtsection('wrappertablemid');
sorta %subarr(deptcost:1:deptlistcount);
wrtsection('topcostheader');
for i = 1 to workrank;
if i <= deptlistcount;
updhtmlvar('topcostitem':deptitem(i));
updhtmlvar('topcostdesc':deptdesc(i));
updhtmlvar('topcostcost':%editc(deptcost(i):'J'));
wrtsection('topcostdetail');
endif;
endfor;
wrtsection('detailbottom');
exsr GraphDeptCost;
wrtsection('wrappertablebottom');
reset deptlist;
deptlistcount = 0;
// Top N for whole plant.
updhtmlvar('dept':'plant');
wrtsection('wrappertabletop');
// Top "rank" quantity and cost info.
sorta %subarr(topqty:1:toplistcount);
wrtsection('topqtyheader');
for i = 1 to workrank;
if i <= toplistcount;
updhtmlvar('topqtyitem':topitem(i));
updhtmlvar('topqtydesc':topdesc(i));
updhtmlvar('topqtyqty':%editc(topqty(i):'J'));
wrtsection('topqtydetail');
endif;
endfor;
wrtsection('detailbottom');
exsr GraphTopQty;
wrtsection('wrappertablemid');
sorta %subarr(topcost:1:toplistcount);
wrtsection('topcostheader');
for i = 1 to workrank;
if i <= toplistcount;
updhtmlvar('topcostitem':topitem(i));
updhtmlvar('topcostdesc':topdesc(i));
updhtmlvar('topcostcost':%editc(topcost(i):'J'));
wrtsection('topcostdetail');
endif;
endfor;
wrtsection('detailbottom');
exsr GraphTopCost;
wrtsection('wrappertablebottom');
/end-free
If I wanted to really reduce the code, I would have another column in the
arrays called topsort, and copy topqty or topcost to topsort, then sort on
that column.
This mailing list archive is Copyright 1997-2026 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.