The DDS keyword RTNCSRLOC has the option to return to your program the field (including subfile fields) that the cursor is in when a function key is pressed. You can test this field to determine what column your user wants to sort on.
One item to watch out for — the subfile column headings in a subfile control record are often constants rather than fields. If the user asks for sorting when the cursor is in a constant then the field name returned is blank (which makes sense as the cursor isn’t in field). You can then either prompt them to put the cursor in a “valid” place or test the actual location of the cursor yourself. Alternatively, you can make the column headings a field to simplify processing.