I have already written about these two SQL procedures:
GENERATE_SQLGENERATE_SQL_OBJECTS
Both can retrieve the SQL statement(s) from a SQL object. With the release of IBM i 7.5 and 7.4 TR6 new parameters and values have been added to them both. I have to admit I do use GENERATE_SQL far more often than the other, therefore, the examples I give will be using this SQL Procedure.
Most of time I use GENERATE_SQL I am retrieving the DDL source from Tables, Indexes, Views, and Physical files. In this example I am going to use a different type of SQL object, a variable.