Fetch
In mainframe computing, "Fetch" primarily refers to two distinct but related concepts: the dynamic loading of an executable program or module into virtual storage for execution, and the retrieval of data records, typically one at a time, from a database or file system. Both involve bringing required resources into an active processing state for an application.
Key Characteristics
-
- Program Loading: Involves locating a load module (or program object) in a program library (e.g.,
STEPLIB,JOBLIB,LINKLIB, LPA) and loading it into the program's private virtual storage for execution. - Dynamic Nature: Programs can be fetched and released from memory as needed during execution, rather than being loaded solely at job initiation, optimizing memory usage and allowing for modular application design.
- Database Retrieval: For relational databases like DB2,
FETCHis an SQL statement used in conjunction with a cursor to retrieve the next row from a result set into designated host variables within the application program. - Sequential Access: Database
FETCHoperations typically retrieve data sequentially, row by row, after the cursor has beenOPENed and before it isCLOSEd. - Error Handling: Both program
FETCH(e.g., viaLOADmacro or implicitCALL) and dataFETCH(SQLFETCH) operations can return status codes or indicators (e.g., SQLCODE) signaling success, end-of-data, or various errors, which must be handled by the application.
- Program Loading: Involves locating a load module (or program object) in a program library (e.g.,
Use Cases
-
- Dynamic Program Invocation: A COBOL program using a
CALLstatement to invoke another program that is not statically linked, causing the called program's load module to be fetched into memory for execution. - Database Record Processing: An application program iterating through a result set from a DB2 query, using
EXEC SQL FETCH CURSOR_NAME INTO :HOST_VAR1, :HOST_VAR2 END-EXECto process each matching record sequentially. - CICS Program Control: A CICS transaction using
EXEC CICS LINK PROGRAM('PROGNAME')orEXEC CICS XCTL PROGRAM('PROGNAME')to transfer control to another program, which implicitly involves fetching the target program's load module if it's not already in storage. - Assembler Program Loading: An assembler program explicitly using the
LOADmacro to fetch a specific program or routine into memory for subsequent execution viaCALLorBALR. - Sequential File Processing: While not explicitly called "fetch," reading the next record from a sequential file (e.g., using
READin COBOL) is conceptually a data retrieval operation.
- Dynamic Program Invocation: A COBOL program using a
Related Concepts
Program fetching is intrinsically linked to Program Management (PDS/PDSE, load modules, program objects), the Link-Editor/Binder, and virtual storage management. It works in conjunction with statements like COBOL CALL or JCL EXEC PGM. Data fetching, particularly in DB2, relies on SQL Cursors, OPEN and CLOSE cursor statements, and the concept of host variables to transfer data between the database and the application program's working storage. It also relates to **