First, you need to understand the environment your program will be running in. If it is REXX, you will use DSNREXX. If it is Java, your choice would be JDBC or even DDF. If it is C or C++ you may want to use ODBC. For other modern ways you may want to refer to the prior blog from Marcus.
However, what if you are writing a traditional z/OS application in COBOL, PL/I, or C, or even in High Level Assembler? That is where we come to Db2 attachment facilities.
Db2 attachment facilities are interfaces between your application and Db2 and they provide a communication channel. Applications must invoke an attachment facility implicitly or explicitly. In order to use any attachment facility, your code must use a specific attachment facility module (language interface) or a universal interface module (DSNULI).
There are couple of attachment facilities available. Some are specific to certain environments, some are not.
If your application runs in CICS, there is a CICS Attachment Facility. If you application runs in IMS, there is an IMS Attachment Facility.
However, what if you application is none of CICS nor IMS? Then you have three options - TSO Attachment Facility, Call Attachment Facility (CAF), RRS Attachment Facility (RRSAF). Which one to use? Let's explore the differences of these three a bit.