Example 1: Function fetching customer number

FUNCTION findCustomerNumber(name)
  DEFINE name VARCHAR(50)
  DEFINE num INTEGER
  CONSTANT sqltxt = "SELECT cust_num FROM customer WHERE cust_name = ?"
  PREPARE stmt FROM sqltxt 
  EXECUTE stmt INTO num USING name 
  IF SQLCA.SQLCODE = 100 THEN
     LET num = -1
  END IF
  RETURN num 
END FUNCTION