The best way to do this is to create your SELECT statement in a program variable where you can substring in the field names you want for ORDER BY. Then use the PREPARE statement to tell the program in which variable your SELECT statement resides. After that you do your normal DECLARE cursor, OPEN cursor and FETCH statements.
The ISeries SQL reference manual will show you more detail on this.
REGISTER or login: