× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Embedded SQL is the basis of the report. The SQL is sorted by department
then item number. At the end of each department they want a top 10 summary
of costs and quantity, and a top 10 for the whole plant. The criteria is
sufficiently complex that I am hesitant to write more SQL. Also, if the data
changes betweeen running the detail for a department and the summary (for
instance, running the report for today), the top 10 do not match the detail.
The data is already in memory so was hoping to manipulate the arrays.

Thanks,
Loyd

On Thu, Apr 23, 2009 at 2:56 PM, Carel Teijgeler <coteijgeler@xxxxxxxxx>wrote:

Why not use embedded SQL? Something in the line of:

SELECT dept, item, desc, SUM(qty) as quantity, SUM(cost) AS costs INTO
:toplist
FROM file
WHERE criteria
GROUP BY dept, item, desc
ORDER BY quantity DESC
FOR 10 ROWS

Of course you need two SQLstatements, unless you can refer to the ordinal
column number of the result set to do the order by using a host variable
(meaning: ORDER BY :myorder, where myorder has either the value 4 (for
quantity) or 5 (for costs)) .

Beware, not tested and I am not a guru in SQL, either.

With regards,
Carel Teijgeler


*********** REPLY SEPARATOR ***********

On 23-4-2009 at 11:16 Loyd Goodbar wrote:

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.

/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
arrays called topsort, and copy topqty or topcost to topsort, then sort on
that column.

Any suggestions appreciated.


--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.