Endoscopy is a simple outpatient procedure It is generally done to diagnose the cause of abdominal pain It can detect ulcers  inflammation and cancer of the food pipe  stomach and the first part of the intestine