You need dynamic SQL for that. I.e. build the statement as a string, then declare a cursor for it and open that cursor.
The reason for dynamic is simply that DB2 (or any other serious DBMS) cannot generate a single access plan with different sort requirements in the picture. For example, if you have a simple query that selects from a table, and you order by a column on which an index exists, then DB2 can fetch based on the index and doesn't have to apply a SORT operator itself. If no such index is available, you have a high chance that the SORT operator is necessary. Depending on the size of the table, the SORT operator may be expensive if, for example, it has to spill to disk. So different plans for different sort criteria are usually a good idea.