My guess is you need this, you can't just group by listno, you have to group by list no and dealer.
Code:
lcprefix = "D:\nvatomate\jobs\retarget\"
IF NOT Directory(lcprefix)
MD (lcprefix)
ENDIF
Select Count(*) as qty, list_no, dlrcode, dealer FROM t3temp ;
Where EMPTY(Status);
Group By list_no, dlrcode, dealer;
Into Cursor curGroups
Select curGroups
SCAN
lcNewfile = ALLTRIM(lcprefix)+ALLTRIM(curCounts.dlrcode)+"-"+ALLTRIM(curCounts.dealer)+"-"+substr(curcounts.list_no,7,10)+"-"+ALLTRIM(STR(curCounts.qty,10,0))+" recs.csv"
SELECT t3temp
COPY TO (lcNewfile) CSV FOR list_no = curCounts.list_no and dlrcode=curCounts.dlrcode and dealer = curCounts.dealer
ENDSCAN
CLOSE ALL
CLEAR
If your main goal is to have one CSV file per dealer the grouping would also not be done by list_no. Instead, you could output ordered by list_no, for example. But all in all your cursor curCounts should be curGroups, as I renamed it, as it has to contain all fields that actually make one group. Your file name can only contain all information of a group. If you really only want to output by list_no, then this is the only field and information you have for the file name. Not the dealer or matchdate. If you want to group by machdate, too, you'll likely have multiple files per list_no, one for each unique matchdate, but as you said matchdate isn't unique per list_no, that means multiple files per list_no.
In very short: The grouping you want in your files determines what gropuing to use in creating the curGroups cursor and the FOR condition to filter records of that group also has to contain all group fields. And vice versa, if you use less fields for grouping, you can't be sure about the uniqueness of other fields within the group and can't make them part of the filename, at least if the file name should point out that all rows within it are with the value that's put into the filename. If you make a filename like "starting from"+matchdate, then the expectation is that matchdate is the first date in that file, not the only date. You can always also do such things, but then need to determine Min(Matchadate) per group, of course.
So file naming isn't strictly bound to the constant values in a group only, but usually it is. The naming of your files was your main problem, and overwriting them, therefore.
It's important to have the FOR condition of the COPY TO match all fields that make up the group. Otherwise, the row count in the CSV will not be the Count(*) counted while determining the group sizes. You didn't error on that as you only grouped by list_no. But your file names weren't unique as list_no wasn't in the name. You have list_no in your name now, besides other information, so you never get a same file name and row counts will add up, but check whether the names are actually correct in terms of the information aside from the list_no. Because this always comes from the first record in t3temp, it is likely false for all but one file.
Chriss