Use dynamic CALL statement where no CREATE PROCEDURE exists

The following rules pertain to the processing of a dynamic CALL statement when there is no CREATE PROCEDURE definition.

Example: Dynamic CALL statement where no CREATE PROCEDURE exists

The following is a C example of a dynamic CALL statement:

  char hv3[10],string[100];
      :
  strcpy(string,"CALL MYLIB.P3 ('P3 TEST')");
  EXEC SQL EXECUTE IMMEDIATE :string;
      :
 

This example shows a dynamic CALL statement executed through an EXECUTE IMMEDIATE statement. The call is made to program MYLIB.P3 with one parameter passed as a character variable containing 'P3 TEST'.

When executing a CALL statement and passing a constant, as in the previous example, the length of the expected argument in the program must be kept in mind. If program MYLIB.P3 expected an argument of only 5 characters, the last 2 characters of the constant specified in the example is lost to the program.

Note: For this reason, it is always safer to use host variables on the CALL statement so that the attributes of the procedure can be matched exactly and so that characters are not lost. For dynamic SQL, host variables can be specified for CALL statement arguments if the PREPARE and EXECUTE statements are used to process it.