Endoscopic retrograde cholangiopancreatography is a procedure that combines upper gastrointestinal (GI) endoscopy and x rays to treat problems of the bile and pancreatic ducts. ERCP is also used to diagnose problems, but the availability of non-invasive tests such as magnetic resonance cholangiography has allowed ERCP to be used primarily for cases in which it is expected that treatment will be delivered during the procedure; see “How is ERCP performed?”