Q

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.

This was first published in December 2008

Dig deeper on DB2 UDB (universal databases)

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchEnterpriseLinux

SearchDataCenter

Close