TechTalk: Dynamic Sorting with OPNQRYF

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Am I the only one who missed this Open Query File (OPNQRYF) trick?

I needed to sort nine fields in any order requested by the user. The file being sorted has the potential to be large, and I wanted to use OPNQRYF with a real sort. I always use a variable with QRYSLT, but I never thought of trying the same thing with the KEYFLD parameter. I came up with a statement like this:

 OPNQRYF FILE((TSTQRYF)) + QRYSLT(&QRYSLT) + KEYFLD((&KEY1) (&KEY2) + (&KEY3) (&KEY4) (&KEY5) + (&KEY6) (&KEY7) (&KEY8) + (&KEY9)) ALWCPYDTA(*OPTIMIZE) 

My program inserts the proper field names in the &KEYx variables. The result is one OPNQRYF statement that handles all of my users' sort selections.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$