|
I posted this the other day but I never say it come through on summary. I have a utility (service program) called XVSRTQ. Here is discussion from last e-mail. For those that have an interest, I have a utility (Service Program) called XVSRTQ which I will happy to provide. I can send to Leif at Think400 for download or can send directly. XVSRTQ was designed for just these situations. You can select any field or set of fields to sort on, and have then sorted using QSORT. I wrote it originally to be able to sort subfiles. The unique thing about XVSRTQ is that it deals with data types correctly. For example, it sorts negative number correctly and dates. A example of how it is used. In this example, a data structure mapped to a user space has four fields and I am going to sort on two of the fields. First sort ascending and then sort descending. I am mapping to a user space in this example. No requirement that be done. Can sort on a data structure or a an array of records. Makes no difference. Just needs the 256 sort key on the end. Basically logic is to load record, build sort key and when loaded call sort. d SortDs... d ds Qualified d Occurs(32767) d Based(ptrSortDs) d Field1... d 15a d Field2... d 7p 2 d Field3... d 5p 3 d Field4... d Like(StdDat) d SortKey... d 256 Varying d x... d s Like(StdInt) /Free ptrSortDs = MakeAUserSpace(%Size(SortDs)); %Occur(SortDs) = 1; SortDs.Field1 = 'Rcd01'; SortDs.Field2 = 25.24; SortDs.Field3 = -15.905; SortDs.Field4 = %Date('1998-12-01'); Exsr srBuildSortKey; %Occur(SortDs) = 2; SortDs.Field1 = 'Rcd02'; SortDs.Field2 = -14.19; SortDs.Field3 = 16.70; SortDs.Field4 = %Date('1949-03-07'); Exsr srBuildSortKey; %Occur(SortDs) = 3; SortDs.Field1 = 'Rcd03'; SortDs.Field2 = -14.19; SortDs.Field3 = -55.25; SortDs.Field4 = %Date('1953-06-24'); Exsr srBuildSortKey; %Occur(SortDs) = 4; SortDs.Field1 = 'Rcd04'; SortDs.Field2 = -7.34; SortDs.Field3 = 12.25; SortDs.Field4 = %Date('2005-07-01'); Exsr srBuildSortKey; SRTQ_Sort(ptrSortDs : // Pointer to User Space. cSRTQ_Ascending : // Sort Ascending. 4 : // Number of records loaded. %Size(SortDs) : // Size of each record. %Size(SortDs.SortKey)); // Size of sort key. // Must be 256 or error. // Rebuild sort keys. Internal sort key is cleared by call to // SRTQ_Sort. Practically this means nothing. In a real system, // you would not sort one and then sort another. For x = 1 to 4; %Occur(SortDs) = x; Exsr srBuildSortKey; EndFor; SRTQ_Sort(ptrSortDs : // Pointer to User Space. cSRTQ_Descending : // Sort Descending. 4 : // Number of records loaded. %Size(SortDs) : // Size of each record. %Size(SortDs.SortKey)); // Size of sort key. For x = 1 to 4; %Occur(SortDs) = x; EndFor; *InLR = *On; Return; // Build Sort Key. BegSr srBuildSortKey; SRTQ_BuildSortKeyNumeric(cSRTQ_First : SortDs.Field2 : %Len(SortDs.Field2) : %DecPos(SortDs.Field2)); SRTQ_BuildSortKeyDate(cSRTQ_Next : SortDs.Field4); SortDs.SortKey = SRTQ_GetSortKey();
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.