[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

RE: [sqr-users] SQRW Question (SORT ARRAYS)





  MAYBE YOU CAN USE THIS SORT.
Begin-Procedure SORT-FDVSQ
  ! SORT FDVSQ
  LET #ix1 = 0

  WHILE #ix1 < 400
     GET $F1 #F0 #F1 #F2 #F3 #F4 #F5 #F6 #F7 #F8 #F9 #F10 #F11 FROM
FDVSQ(#ix1)
     FDQ FDD(0) FDD(1) FDD(2) FDD(3) FDD(4) FDD(5) FDD(6) FDD(7) FDD(8)
FDD(9) FDD(10) FDD(11)
     IF $TS1 = ''
        BREAK
     END-IF
     LET $sortkey1 = $TS1
     LET #ix2 = #ix1 + 1
     WHILE #ix2 < 400
        GET $F12 #F02 #F12 #F22 #F32 #F42 #F52 #F62 #F72 #F82 #F92 #F102
#F112 FROM FDVSQ(#ix1)
        FDQ FDD(0) FDD(1) FDD(2) FDD(3) FDD(4) FDD(5) FDD(6) FDD(7) FDD(8)
FDD(9) FDD(10) FDD(11)
        IF $TS2 = ''
           BREAK
        END-IF
        LET $sortkey2 = $TS2
        IF ($sortkey1 >= $sortkey2)
           PUT $TS2 #S12 INTO FDVSQ(#ix1) FDQ FDD(0)
           PUT $TS1 #S11 INTO FDVSQ(#ix2) FDQ FDD(0)
           LET $TS1  = $TS2
           LET #F1   = #F12
           LET #F2   = #F22
           LET #F3   = #F32
           LET #F4   = #F42
           LET #F5   = #F52
           LET #F6   = #F62
           LET #F7   = #F72
           LET #F8   = #F82
           LET #F9   = #F92
           LET #F10  = #F102
           LET #F11  = #F112
           LET $sortkey1 = $TS1
        END-IF
        ADD 1 to #ix2
     END-WHILE
     ADD 1 to #ix1
  END-WHILE
End-Procedure ! SORT FDVSQ

-----Original Message-----
From: sqr-users-bounces+dduwe=nookind.com@sqrug.org
[mailto:sqr-users-bounces+dduwe=nookind.com@sqrug.org]On Behalf Of
Bartlett, Dwain
Sent: Wednesday, April 06, 2005 1:17 PM
To: This list is for discussion about the SQR database reporting
languagefrom Hyperion Solutions.
Subject: RE: [sqr-users] SQRW Question


The attachment did get sent, so here is the code.

!**********************************************************************
!*                                                                    *
!*       MODULE:  TDSORTR.SQR                                         *
!*       AUTHOR:  TONY DELIA.                                         *
!*         DATE:  03/01/1999.                                         *
!*       SYSTEM:  TD SQR UTILITY SERIES.                              *
!*         DESC:  SQR RECURSIVE SORT EXPLANATION (QUICKSORT).         *
!*                                                                    *
!**********************************************************************
!*                                                                    *
!*         NOTE:  THIS SAMPLE EXPANDS ON THE SQR TUTORIAL PROGRAM     *
!*                EX24A.SQR (QUICKSORT SAMPLE CODE). THE QUICKSORT    *
!*                ALGORITHM IS COMMONLY UTILIZED IN C, BASIC, JAVA,   *
!*                ETC. BUT NOT COMMONLY UNDERSTOOD. SOME STRUCTURAL   *
!*                CHANGES HAVE BEEN MADE TO THE QUICKSORT ROUTINE     *
!*                AS FOLLOWS:                                         *
!*                                                                    *
!*                A) ALLOW MULTIPLE SORT KEYS TO BE USED.             *
!*                                                                    *
!*                   EXAMPLE USES STATE AND AREA CODE AS KEYS.        *
!*                                                                    *
!*                B) SENSIBLE POINTER NAMES REPLACING #m, #n, #i, #j. *
!*                                                                    *
!*                   #qlo  - LO ARRAY BOUNDARY.                       *
!*                   #qhi  - HI ARRAY BOUNDARY.                       *
!*                   #qbwd - BACKWARD TRAVERSAL POINTER.              *
!*                   #qfwd - FORWARD  TRAVERSAL POINTER.              *
!*                                                                    *
!*                C) CHANGED MISLEADING POINTER LIMIT ON BACKWARD     *
!*                   TRAVERSAL. EX24A.SQR USES STATEMENT...           *
!*                                                                    *
!*                   while #j >= 0  TO CONTROL BACKWARD TRAVERSAL.    *
!*                                                                    *
!*                   THIS IMPLIES BACKWARD TRAVERSAL GOES THROUGH THE *
!*                   START OF ARRAY. ACTUALLY THE BACKWARD TRAVERSAL  *
!*                   ENDS WHEN IT INTERSECTS WITH FORWARD POINTER.    *
!*                   BESIDES WHEN 2ND RECURSIVE SORT IS CALLED WITHIN *
!*                   THE 'PARENT' SORT THE LO BOUNDARY IS NEVER ZERO. *
!*                                                                    *
!*                D) FURTHER CLARIFIED CODE ON FINAL SWAP. CURRENTLY  *
!*                   LO/BWD SWAP IS UNCONDITIONAL. IF ELEMENTS ARE IN *
!*                   THEIR PROPER PLACE THERE'S NO NEED TO SWAP. ALSO *
!*                   STREAMLINED RECURSIVE ARRAY POPULATION A BIT.    *
!*                                                                    *
!*                E) COMMENTS INSERTED TO EXPLAIN FUNCTIONALITY OF    *
!*                   PROGRAM.                                         *
!*                                                                    *
!**********************************************************************
!*                                                                    *
!*     OVERVIEW:  THE RECURSIVE 'QUICKSORT' PERFORMS SEVERAL TASKS.   *
!*                NOTE THE FIRST ELEMENT IS USED AS THE 'OBJECT' KEY. *
!*                LO AND HI ARRAY BOUNDARIES ARE PASSED TO THE SORT.  *
!*                                                                    *
!*                THE FIRST STEP USES A FORWARD POINTER TO FIND THE   *
!*                'NEXT' ELEMENT > OBJECT KEY. THEN STARTING FROM THE *
!*                HI BOUNDARY A BACKWARD POINTER IS USED TO FIND THE  *
!*                'NEXT' ELEMENT < OBJECT KEY. THE FWD AND BWD ARRAY  *
!*                ELEMENTS MAY THEN BE SWAPPED. THIS IS BASED ON THE  *
!*                SIMPLE ALGEBRAIC RULE:                              *
!*                                                                    *
!*                IF (KEY < FWD) AND (KEY > BWD) THEN (FWD > BWD).    *
!*                                                                    *
!*                ABOVE PROCESS REPEATED UNTIL FWD/BWD POINTERS       *
!*                INTERSECT. ONCE COMPLETE A FINAL SWAP 'MAY' BE      *
!*                REQUIRED BETWEEN THE OBJECT KEY (LO) AND BACKWARD   *
!*                POINTER. AT THIS POINT THE BACKWARD POINTER IS USED *
!*                AS A TABLE DIVIDER. FOR BOTH SECTIONS THE RECURSIVE *
!*                SORT IS PERFORMED AGAIN USING THE SECTION LO/HI     *
!*                BOUNDARIES. SINCE SQR DOES NOT SUPPORT RECURSIVE    *
!*                VARIABLES AN ARRAY IS USED TO STORE LO/HI BOUNDARY  *
!*                PARAMETERS FOR THE SECOND HALF OF THE TABLE (THE    *
!*                FIRST SECTION IS CALLED IMMEDIATELY).               *
!*                                                                    *
!*      GRAPHIC:                                                      *
!*                     ---------------------------------------------- *
!*              LEVEL  LO     FWD->                     <-BWD      HI *
!*               #1    0   1   2   3   4   5   6   .   .   .   .   n  *
!*                                            /|                      *
!*                     ---------------------   ---------------------- *
!*              LEVEL  LO  FWD->    <-BWD HI   LO  FWD->    <-BWD  HI *
!*               #2    0   1   2   3   4   5   6   .   .   .   .   n  *
!*                                /|                      /|          *
!*                     etc.        etc.        etc.        etc.       *
!*                     ---------   ---------   ---------   ---------- *
!*               #3    0   1   2   3   4   5   6   .   .   .   .   n  *
!*                                                                    *
!**********************************************************************
!*                                                                    *
!*                SEE TDSORTR.ALC FOR IBM/370 ASSEMBLER VERSION OF    *
!*                RECURSIVE SORTING. COMMENTS GIVEN FOR EACH LINE.    *
!*                SAME STATE/AREACODE/DESCRIPTION ARRAY USED IN BOTH  *
!*                ASSEMBLER AND SQR VERSIONS.                         *
!*                                                                    *
!**********************************************************************
#include 'setenv.sqc'        ! Set environment
!**********************************************************************
!*       Setup Procedure                                              *
!**********************************************************************
begin-setup
#Include 'setup02a.sqc'      ! Printer and page-size init landscape
#define max_rows 5000
end-setup

!**********************************************************************
!*       Mainline Processing                                          *
!**********************************************************************
begin-report
        do Init-DateTime
        do Get-Current-DateTime
        move $AsOfToday to $AsOfDate
        do Process-Main
end-report

!**********************************************************************
!*       Set Defaults                                                 *
!**********************************************************************
begin-procedure Set-Defaults
        let $ReportId = 'TDSORTR'
        let $ReportTitle = 'SQR Recursive Sort (QuickSort)'
        display $ReportId    noline
        display ' '          noline
        display $ReportTitle
        display ' '
end-procedure

!**********************************************************************
!*       Process Main                                                 *
!**********************************************************************
begin-procedure Process-Main
        create-array name=Qsort size={max_rows}
                field=Qlo:number
        field=Qhi:number

        create-array name=Qarray size={max_rows}
                field=Qkey:char
        field=Qarea:char
        field=Qdesc:char

        do Load-Array
        do QuickSort(0, 0, #Qmax)
        do Display-Results
end-procedure

!**********************************************************************
!*       Recursive Sort                                               *
!**********************************************************************
begin-procedure QuickSort(#level, #Qlo, #Qhi)
        if #Qlo < #Qhi
                        let #Qfwd = #Qlo                ! Init forward  pointer
                        let #Qbwd = #Qhi + 1            ! Init backward pointer
                        !   Lo Boundary is Key Object(s)
                        let $Qkey = Qarray.Qkey (#Qlo)
                        let $Qarea = Qarray.Qarea (#Qlo)
                        while 1 = 1
                                !     Traverse Forward  - find 'next' array.key 
> Qkey
                                !     Bypass all keys less than Object Key 
(Qkey)
                                let #Qfwd = #Qfwd + 1
                                while #Qfwd <= #Qbwd
                                        if $Qkey < Qarray.Qkey (#Qfwd) or
                                           $Qkey = Qarray.Qkey (#Qfwd) and
                                           $Qarea < Qarray.Qarea (#Qfwd)
                                                        break
                                        end-if
                                        let #Qfwd = #Qfwd + 1
                                end-while
                                !     Traverse Backward - find 'next' array.key 
< Qkey
                                !     Bypass all keys more than Object Key 
(Qkey)
                                let #Qbwd = #Qbwd - 1
                                while #Qbwd >= #Qfwd              ! Logically 
#Qfwd is limit
                                        if $Qkey > Qarray.Qkey (#Qbwd) or
                                           $Qkey = Qarray.Qkey (#Qbwd) and
                                           $Qarea > Qarray.Qarea (#Qbwd)
                                                        break
                                        end-if
                                        let #Qbwd = #Qbwd - 1
                                end-while
                                !  Once traversed Boundaries meet exit main loop
                                if #Qfwd >= #Qbwd
                                                break
                                end-if
                                !  Swap Forward/Backward Elements
                                do QSortSwap(#Qfwd, #Qbwd)
                        end-while
                        !   Swap Lo Boundary / Backward Elements
                        if $Qkey > Qarray.Qkey (#Qbwd) or
                           $Qkey = Qarray.Qkey (#Qbwd) and
                           $Qarea > Qarray.Qarea (#Qbwd)
                                        do QSortSwap(#Qlo, #Qbwd)
                        end-if
                        !   At this point the table is split in two sections.
                        !   Save boundaries of 2nd half (due to non-recursive 
variables)
                        let #level = #level + 1
                        let Qsort.Qlo (#level - 1) = #Qbwd + 1
                        let Qsort.Qhi (#level - 1) = #Qhi
                        !   Now sort from Lo to New Hi
                        let #Qhi = #Qbwd - 1
                        do QuickSort(#level, #Qlo, #Qhi)
                        !   Now sort from New Lo to Hi (Restoring first)
                        let #Qlo = Qsort.Qlo (#level - 1)
                        let #Qhi = Qsort.Qhi (#level - 1)
                        do QuickSort(#level, #Qlo, #Qhi)
                        let #level = #level - 1
        end-if
end-procedure

!**********************************************************************
!*       Sort Lo/Hi Array Elements                                    *
!**********************************************************************
begin-procedure QSortSwap(#lo, #hi)
        get $Qkey $Qarea $Qdesc from Qarray (#lo) Qkey Qarea Qdesc
        let Qarray.Qkey (#lo) = Qarray.Qkey (#hi)
        let Qarray.Qarea (#lo) = Qarray.Qarea (#hi)
        let Qarray.Qdesc (#lo) = Qarray.Qdesc (#hi)
        put $Qkey $Qarea $Qdesc into Qarray (#hi) Qkey Qarea Qdesc
end-procedure

!**********************************************************************
!*       Load Array                                                   *
!**********************************************************************
begin-procedure Load-Array
        let #idx = 0
        let $Qdata = 'AK907ALASKA'
        do Load-Element
        let $Qdata = 'DE302DELAWARE'
        do Load-Element
        let $Qdata = 'GA404GEORGIA'
        do Load-Element
        let $Qdata = 'GA706GEORGIA'
        do Load-Element
        let $Qdata = 'MD301MARYLAND'
        do Load-Element
        let $Qdata = 'NJ201NEW JERSEY'
        do Load-Element
        let $Qdata = 'WA206WASHINGTON'
        do Load-Element
        let $Qdata = 'NY607NEW YORK'
        do Load-Element
        let $Qdata = 'NJ908NEW JERSEY'
        do Load-Element
        let $Qdata = 'NJ609NEW JERSEY'
        do Load-Element
        let $Qdata = 'WA509WASHINGTON'
        do Load-Element
        let $Qdata = 'MD410MARYLAND'
        do Load-Element
        let $Qdata = 'PA610PENNSYLVANIA'
        do Load-Element
        let $Qdata = 'GA912GEORGIA'
        do Load-Element
        let $Qdata = 'NY212NEW YORK'
        do Load-Element
        let $Qdata = 'PA412PENNSYLVANIA'
        do Load-Element
        let $Qdata = 'NY914NEW YORK'
        do Load-Element
        let $Qdata = 'PA814PENNSYLVANIA'
        do Load-Element
        let $Qdata = 'NY315NEW YORK'
        do Load-Element
        let $Qdata = 'NY516NEW YORK'
        do Load-Element
        let $Qdata = 'NY716NEW YORK'
        do Load-Element
        let $Qdata = 'NY917NEW YORK'
        do Load-Element
        let $Qdata = 'NY917MANHATTEN'
        do Load-Element
        let $Qdata = 'PA215PENNSYLVANIA'
        do Load-Element
        let $Qdata = 'PA717PENNSYLVANIA'
        do Load-Element
        let $Qdata = 'NY518NEW YORK'
        do Load-Element
        let $Qdata = 'NY718NEW YORK'
        do Load-Element
        let $Qdata = 'PA724PENNSYLVANIA'
        do Load-Element
        let $Qdata = 'NJ732NEW JERSEY'
        do Load-Element
        let $Qdata = 'MD240MARYLAND'
        do Load-Element
        let $Qdata = 'MD443MARYLAND'
        do Load-Element
        let $Qdata = 'WA360WASHINGTON'
        do Load-Element
        let $Qdata = 'GA770GEORGIA'
        do Load-Element
        let $Qdata = 'NJ973NEW JERSEY'
        do Load-Element
        let $Qdata = 'GA678GEORGIA'
        do Load-Element
        let #Qmax = #idx - 1
end-procedure

!**********************************************************************
!*       Load Element                                                 *
!**********************************************************************
begin-procedure Load-Element
        let Qarray.Qkey (#idx) = substr($Qdata,1,2)
        let Qarray.Qarea (#idx) = substr($Qdata,3,3)
        let Qarray.Qdesc (#idx) = rtrim(substr($Qdata,6,20),' ')
        let #idx = #idx + 1
end-procedure

!**********************************************************************
!*       Display Results                                              *
!**********************************************************************
begin-procedure Display-Results
        display ' '
        display 'Sorted Results'
        display ' '
        display 'State  Area  Description'
        display '-----  ----  --------------------'
        display ' '
        let #idx = 0
        while #idx <= #Qmax
                let $Qkey = Qarray.Qkey  (#idx)
                let $Qarea = Qarray.Qarea (#idx)
                let $Qdesc = Qarray.Qdesc (#idx)
                let $Qdata = rpad($Qkey,7,' ') || rpad($Qarea,6,' ') || $Qdesc
                display $Qdata
                let #idx = #idx + 1
end-while

        display ' '
end-procedure

!**********************************************************************
!*       Include Members:                                             *
!**********************************************************************
#Include 'curdttim.sqc'  !Get-Current-DateTime procedure
#Include 'datetime.sqc'  !Routines for date and time formatting
                         !Init-DateTime procedure

Dwain Bartlett
SABHRS Services Bureau, ITSD
HR Systems Analyst
(406) 444-0418
dbartlett@mt.gov


-----Original Message-----
From: sqr-users-bounces+dbartlett=mt.gov@sqrug.org
[mailto:sqr-users-bounces+dbartlett=mt.gov@sqrug.org]On Behalf Of
fpickava@earthlink.net
Sent: Wednesday, April 06, 2005 10:07 AM
To: This list is for discussion about the SQR database reporting
language from Hyperion Solutions.; This list is for discussion about the
SQR database reporting language from Hyperion Solutions.
Subject: Re: [sqr-users] SQRW Question


Is there some way an Array can be sorted?

Thanks

-----Original Message-----
From: Robert Goshko <robert.goshko@gmail.com>
Sent: Feb 25, 2005 6:52 AM
To: "This list is for discussion about the SQR database reporting language
        from Hyperion Solutions." <sqr-users@sqrug.org>
Subject: Re: [sqr-users] SQRW Question

On Fri, 25 Feb 2005 07:47:01 -0500 (GMT-05:00), fpickava@earthlink.net
<fpickava@earthlink.net> wrote:
> To All,
>
> I am going to a client site that does not have SQRW installed.  They
develop SQR's in text and submit for execution via native Unix (ugly).  How
do I go abount obtaining the SQRW software and documentation?

SQR programs are always text files, unless compiled to an SQT.  If
they do not own an SQRW license, then you would have to get one.

I usually run SQR from the command line in UNIX, if you think that is
ugly, try running SQR on MVS.

--
...Rob

-- No trees were killed in the sending of this message.  However a
large number of electrons were terribly inconvenienced.

====================================================================
Robert Goshko
Registered Linux User #260513

Want a Gmail account, 1 GB web mail,  just ask me.

_______________________________________________
sqr-users mailing list
sqr-users@sqrug.org
http://www.sqrug.org/mailman/listinfo/sqr-users


_______________________________________________
sqr-users mailing list
sqr-users@sqrug.org
http://www.sqrug.org/mailman/listinfo/sqr-users

_______________________________________________
sqr-users mailing list
sqr-users@sqrug.org
http://www.sqrug.org/mailman/listinfo/sqr-users




*********************************************************************
 Note: The information contained in this message may be privileged
 and confidential and protected from disclosure. If the reader of 
 this message is not the intended recipient, or an employee or agent 
 responsible for delivering this message to the intended recipient, 
 you are hereby notified that any dissemination, distribution or 
 copying of this communication is strictly prohibited. If you have 
 received this communication in error, please notify us immediately 
 by replying to the message and deleting it from your computer.

*********************************************************************




_______________________________________________
sqr-users mailing list
sqr-users@sqrug.org
http://www.sqrug.org/mailman/listinfo/sqr-users