I'm looking for some hint towards the solution of the following problem (which is a homework question, so I don't expect a complete solution) with which I'm having unexpected difficulties.
Problem statement: Let $\phi :X\rightarrow Y$ be a morphism between the affine varieties $X=Sp(A)$ and $Y=Sp(B)$. Let also $g_1, \dots ,g_s\in B$ be such that the corresponding principal open subsets $V_i=Y_{g_i}$ cover $Y$. Show that the restriction of $\phi$ to $U_i=\phi^{-1}(V_i)$ being a finite morphism to $V_i$ for all $1\le i\le s$ implies that $\phi$ is finite too.
Attempt at a solution: My ideas are rather vague, but I post them anyway, in case they are of any use. I don't know much machinery yet, so I try to prove the statement almost from the definitions. Let $\phi^\star$ denote the pullback of $\phi$. We want to show that $A$ is finitely generated over $\phi^\star(B)$. If we assume that the restriction of $\phi$ to $U_i$ indeed is finite, I conjecture that we can find a set of generators $\{ a_j \}\subset A$ of $A$ (thereby solving the problem) so that restrictions of the $a_j$ to appropriate $U_i$ generate the corresponding sets of regular functions.
I also suspect that this may be of use: The $U_i$ are principal open sets which cover $X$. Therefore the $\phi^\star (g_i)$ don't all have a common zero, so by a basic result, an arbitrary $a\in A$ can be written $a=\sum_{i=1}^s{f_i(a\phi^\star (g_i))}$, where $f_i\in A$.
All kinds of help is much appreciated!
Edit: By the definition I'm working with, $\phi$ is finite means precisely that $A$ is a finitely generated $B$-module (or equivalently that A is integral over $\phi^\star (B)$ ). So what I'm trying to show is that each $U_i$ being finitely generated over $V_i$ (with $\phi$ restricted accordingly) implies that $A$ is finitely generated over $B$.