Here are some tips from the Nutrition Action Health Letter on how to avoid those souvenirs of the beans you had for lunch. First, cook thoroughly. If you cook beans from scratch, don't eat them al dente. Canned beans are probably safer, because they are thoroughly cooked. Second, rinse thoroughly.
Beans contain indigestible sugars indigestible by people, that is.
The bacteria that live in our intestines gobble them up like candy. In exchange, the bacteria give off gases that may make you do likewise. Some of the sugar migrates from the beans to the liquid in which they've been soaked, cooked or canned. So tossing the liquid and rinsing your canned beans helps, and cuts the salt to boot. Finally, take it slowly.