|
For a report I'm developing, I need to track the top ten quantity and costfor 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 (oncefor cost, again for quantity). Since the arrays are defined identically, I
to halve the code: process cost or process quantity, regardless of whicharray it is. I feel like there is a solution involving basing the arrays on
a pointer but haven't wrapped my head around it.to repeating itself.
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
arrays called topsort, and copy topqty or topcost to topsort, then sort on
/free
// This code populates the arrays.
deptlistcount += 1;
if deptlistcount <= %elem(deptlist);
deptdept(deptlistcount) = saverow.department;
deptitem(deptlistcount) = saverow.item;
deptdesc(deptlistcount) = saverow.item_desc;
deptqty(deptlistcount) = itemqtytotal;
deptcost(deptlistcount) = itemcosttotal;
endif;
toplistcount += 1;
if toplistcount <= %elem(toplist);
topdept(toplistcount) = saverow.department;
topitem(toplistcount) = saverow.item;
topdesc(toplistcount) = saverow.item_desc;
topqty(toplistcount) = itemqtytotal;
topcost(toplistcount) = itemcosttotal;
endif;
// 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
that column.
Any suggestions appreciated.
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.