skip to main content

Embedded SQL : Host Variables

Host Variables
Host variables allow the host program and the database to communicate. A host variable is any COBOL variable or constant, declared in file, working-storage or linkage section.
A host variable reference must be prefixed with a colon ":" in SQL statements.
Code example
The content of column1 is sotred in the host variable named item1.
exec sql include SQLCA end-exec.
77 item1 pic 9(3).
procedure division.
exec sql select column1 into :item1 from table1 where column1 = 1 end-exec.
Note: alphanumeric data items with picture X(n) are internally translated to their unicode representation according to the current locale when they’re used as host variables. This rule may cause unexpected data translation if the content of the data item is a non representable character.
How to specify the parent data item
The parent data item of a host variable can be referenced using a separator dot or the OF keyword. The IN keyword cannot be used as the compiler may confuse it with a stored procedure parameter type.
Given the following group items:
01 group-1.
   03 item-1 pic x(30).
01 group-2.   
   03 item-1 pic 9(9).
In order to avoid ambiguos identifiers, you can reference item-1 of group-1 in these ways
 

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left