I solved my problem :)
the problem is in the query that calls my function:
select * from calcolo_inventario('26','2008-02-22','05')
where giacenza > 0
because the resulset has a negative row that doesn't appear on screen
Thank you very much to all of you
Enrico