Naming Program Variables in PUT

When the INSERT statement is prepared (see PREPARE statement), you cannot use program variables in its VALUES clause, but you can represent values by a question-mark ( ? ) placeholder. List the program variables in the FROM clause of the PUT statement to supply the missing values.

The following example lists host variables in a PUT statement:
char answer [1] = 'y';
EXEC SQL BEGIN DECLARE SECTION;
   char ins_comp[80];
   char u_company[20];
EXEC SQL END DECLARE SECTION;

main()
{
   EXEC SQL connect to 'stores_demo';
   EXEC SQL prepare ins_comp from
      'insert into customer (customer_num, company) values (0, ?)';
   EXEC SQL declare ins_curs cursor for ins_comp;
   EXEC SQL open ins_curs;

   while (1)
      {
      printf("\nEnter a customer: ");
       gets(u_company);
      EXEC SQL put ins_curs from :u_company;
      printf("Enter another customer (y/n) ? ");
      if (answer = getch() != 'y')
         break;
      }
   EXEC SQL close ins_curs;
   EXEC SQL disconnect all;
}

Indicator variables are optional, but you should use an indicator variable if the possibility exists that output_var might contain a NULL value. If you specify the indicator variable without the INDICATOR keyword, you cannot put a blank space between output_var and indicator_var.