Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 14:- Database Interface


Host variables

  • Host Variables are used to store data that is accessed by both COBOL and DB2.
  • Thus, with used of Host variables we can :-
    • Collect data from DB2 table using FETCH, INTO, VALUES INTO etc. clause
    • Place data into Host variable and perform INSERT, UDPATE etc. operations
    • Use the data in the host variable when evaluating a WHERE or HAVING clause.
    • Use the host variable to indicate a null value
  • Host Variables should be declared in WOKRING-SOTRAGE SECTION.
  • When we use Host variable in Embedded SQL statement, it must be prefixed by (:) colon sign without any space in between. This also helps compiler to distinguish between Host variables and column/table names.
  • You define a host variable as a data structure that represents the column names and data types of the tables that are accessed by the COBOL program. Such host variables are usually defined in copybooks as it is possibility that multiple program uses the same table.
  • Host variable must be an elementary data item.
  • Example:-
    In WORKING-STORAGE SECTION:

    01 EMP-REC. 05 EMP-ID PIC X(05). 05 EMP-NAME PIC X(10) VALUE ‘AMIT’.

    In PROCEDURE DIVISION:

    EXEC SQL SELECT EMP-ID INTO :WS-ID FROM EMP WHERE EMP-NAME = :WS-NAME END-EXEC.

  • In above example, “:WS-ID” and ”:WS-NAME” are host variables. Now WS-NAME contains ‘AMIT’ and thus when SELECT statement will be executed, EMP-ID of ‘AMIT’ will be pulled into WS-ID.






© copyright mainframebug.com
Privacy Policy