Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

RPG fetch statement coding to dynamically call unknown fields and data types

On the AS/400 in DB2 it may be necessary to make a RPG program that calls select statements with unknown data and fields. SQL Descriptor Area processing or SQL CLI can provide a solution to programmers in need.

I am writing an RPGLE program that will read a control file that contains the select statement criteria. The program then builds the select statement so that any field(s) within any file on the iSeries could retrieve. How would I code the fetch statement to handle this without knowing the number of fields or data types until execution time?
You would need to use the SQL Descriptor Area to dynamically determine the number and attributes of the columns being returned. SQL Descriptor programming is discussed in the IBM SQL Programming book.

If you find the SQL Descriptor Area processing to be complex, you may want to investigate using the SQL CLI (Call Level Interface) functions in your RPG program.

Dig Deeper on DB2 UDB (universal databases)

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.