I am working on my first Perl script and I have a sub that calls a sub. The 1st sub returns a list of location/item/abccodes. If the abccode = 'A' then I want to call the 2nd sub to get and return the quantity. When I comment out the call to the 2nd sub, the 1st sub spins through and prints out all the correct data. When I uncomment and make the call to the second, as soon as it hits the first "A" qty, the sub return and goes onto the next location even thought there may be other A items at that location. I believe my problem is in the looping and/or the return but I'm not certain. Can someone help me?
Code:
sub get_items_for_loc_abc_stkclass
{
my $loc = shift;
my $abc = shift;
my $stkclass = shift;
$sth = $dbh->prepare( "SELECT a.loc
, a.item
, a.p_abc
FROM stsc.sku a
, stsc.loc b
, stsc.item c
WHERE a.loc = '$loc'
AND a.loc = b.loc
AND a.p_abc IN ($abc)
AND c.p_stkclass IN ($stkclass)
AND a.item = c.item
ORDER BY a.loc, a.item" );
$sth->execute();
### Retrieve the returned rows of data
my @row;
while ( @row = $sth->fetchrow_array( ) )
{
if ( $row[2] eq 'A')
{
LogMsg("\t Item = " . $row[1] . " ABC Code = " . $row[2] . " A Qty = ");
[COLOR=red]#my $A_qty = get_qty_for_A_items_cat3( $row[0], $row[1] );
#LogMsg("\t Item = " . $row[1] . " ABC Code = " . $row[2] . " A Qty = " . $A_qty);[/color red]
}
else
{
LogMsg("\t Item = " . $row[1] . " ABC Code = " . $row[2] . " BCE Qty = ");
}
}
warn "Data fetching terminated early by error: $DBI::errstr\n"
if $DBI::err;
#LogMsg("Done Fetching Rows");
}
sub get_qty_for_A_items_cat3
{
my $loc = shift;
my $item = shift;
$sth = $dbh->prepare( "SELECT ROUND((CEIL((SUM (ROUND (a.totfcst)) - (b.oh + NVL(c.qty,0))) / d.p_pdc_spq) * d.p_pdc_spq) * b.p_dlrnet)
FROM stsc.dfutoskufcst a
, stsc.sku b
, stsc.schedrcpts c
, stsc.item d
WHERE a.skuloc = '$loc'
AND a.item = '$item'
AND a.startdate = ADD_MONTHS (TRUNC (SYSDATE, 'MM'), 1 )
AND a.item = b.item
AND a.skuloc = b.loc
AND b.item = c.item(+)
AND b.loc = c.loc(+)
AND a.item = d.item
GROUP BY b.oh
, c.qty
, d.p_pdc_spq
, b.p_dlrnet" );
$sth->execute();
### Retrieve the returned row of data
my $row;
while ($row = $sth->fetchrow_array( ) )
{
return ($row);
}
warn "Data fetching terminated early by error: $DBI::errstr\n"
if $DBI::err;
}