Preheat oven to 350 degree F. For sauce, in a large saucepan melt butter over medium heat. Stir in the flour, salt, and pepper. Cook and stir for 2 to 3 minutes until lightly browned. Add milk all at once. Cook and stir over medium heat until thickened and bubbly.
Stir the sliced onions, beans, and ham into sauce. Transfer to a 1-1/2-quart oval or 2-quart rectangular baking dish. Place dish on a baking sheet.
Bake, covered, for 1 hour. Uncover and sprinkle with cheese. Bake, uncovered, for 15 minutes more or until onions are tender and top is golden. Let stand 10 minutes before serving. Makes 6 to 8 side-dish servings.