Can I pass a variable to an RPG program and have it open the referenced file?Can I use another file to hold a list of fields I want to read?
Both of these questions are asking if RPG can use indirection to get files fields instead of declaring them directly in the program.The answer is a qualified yes. Using SQL, you can construct a dynamic SELECT statement to fetch data into your program. What you actually do with the buffer is up to you.The following sample code has no error handling and assumes that the values you are looking for are character, not decimal. If you try it with a decimal, you’ll get a -303 SQLCOD, telling you that the host variable is not compatible. It’s also missing the WHERE clause on the prepared SELECT statement – that’s where you’d select “that particular customer.” Also, you should probably use SQLSTT instead of SQLCOD.
Related Questions
- Can I pass a variable to an RPG program and have it open the referenced file?Can I use another file to hold a list of fields I want to read?
- I am currently in the waiting list. What is the likelihood of getting a confirmed position in the PASS program?
- Which list cleanup (.fuz) file do I use for which fields?