Referencing host variables in embedded SQL applications

After you have declared a host variable in your embedded SQL application code, you can reference it later in the application.

About this task

When you use a host variable in an SQL statement, prefix its name with a colon (:). If you use a host variable in host language programming syntax, omit the colon.

Reference the host variables using the syntax for the host language that you are using. The following table provides examples.
Table 1. Host Variable References by Host Language
Language Example Source Code
C or C++
EXEC SQL FETCH C1 INTO :cm; 
printf( "Commission = %f\n", cm );
COBOL
EXEC SQL FETCH C1 INTO :cm END-EXEC 
DISPLAY 'Commission = ' cm
FORTRAN
EXEC SQL FETCH C1 INTO :cm 
WRITE(*,*) 'Commission = ', cm
REXX
CALL SQLEXEC 'FETCH C1 INTO :cm' 
SAY 'Commission = ' cm