A never answered behavior : how to mix monovalued and multivaluled data into a SREFORMAT result.
Here is the a sample uniQuery, SORT + WITH + WHEN + BY.EXP on HS.SALES (demo account into uv)
I filter data on STATE (monovalue field) and BUY_DATE (multivalued field) and I display data from monovalued and multivalued field.
As expected, with SORT BY.EXP, the monovalued field are replicated on each occurence of multivalued line.
SORT CUSTOMER WITH STATE = "MA" AND WHEN BUY_DATE >= "20/01/91" AND <= "29/01/91" BY.EXP BUY_DATE BY CUSTID CUSTID STATE CITY BUY_DATE PRODID ID.SUP
Customer ID State City........ Date Purchased Product
8 MA Lowell 21/01/91 M3000
8 MA Lowell 21/01/91 S3000
2 MA Waltham 22/01/91 S3000
3 records listed.
​
so, now I'll send these result to a temporary file with SREFORMAT, which build a record by line of result ; the first column is the key on the temp file.
I use the same phrase, replace the SORT verb by SREFORMAT.
CREATE.FILE FTEMP 18 53 4
SREFORMAT CUSTOMER WITH STATE = "MA" AND WHEN BUY_DATE >= "20/01/91" AND <= "29/01/91" BY.EXP BUY_DATE BY CUSTID CUSTID STATE CITY BUY_DATE PRODID ID.SUP
File Name = FTEMP​
so, when I look inside the temp file, I read there is no value for monovalued field.
>CT FTEMP *
8
0001
0002
0003 21/01/91
0004 S3000
2
0001
0002
0003 22/01/91
0004 S3000​
I try to define DICT CUSTID and STATE with a lot of tricks (REUSE, SUBR, build it as part of the ORDER assoc, ... ) I can't get any data in my temp file.
Bonus, why only one multivalue on record id 8 then SORT show two lines !!
Enjoy the challenge :-)