The 1st step is a composite Sort of 2 fields
This sorts say FLD1,FLD2
This is followed by SORT2, which sorts the last field i.e FLD2 and then the output of that is used as input to SORT3 which sorts by the 1st field ie.FLD1
Now i notice that BBBB.XYFILE.OUT1 is same as BBBB.XYFILE.OUT3
So is it always true that if i want to sort by FLD1,FLD2,FLD3
Then it will produce same result when i sort in reverse way successively i.e
sort by FLD3. Use the o/p of this to sort by FLD2
Use the o/p of this to sort by FLD1
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Wed Jan 17, 2024 5:09 pm Post subject:
deepa12,
Do you ever pay attention to what is being told? I warned several times you the about the chat language titles both privately and publicly and yet you seem to do the same thing over and over.
From the above control cards SORT1 and SORT2 will have the exact same results. As you used OPTION EQUALS, it will retain the duplicates as is
deepa12 wrote:
So is it always true that if i want to sort by FLD1,FLD2,FLD3
Then it will produce same result when i sort in reverse way successively i.e
sort by FLD3. Use the o/p of this to sort by FLD2
Use the o/p of this to sort by FLD1
First off not sure how you added FLD3 into the mix, but where did you get the information that you would get the same results if you sort in reverse way even if you are talking about 2 fields?
Take a simple example.
Zoned decimal fields will have the sign overpunched on the last byte.
Hex C0 thru C9 are positive numbers and D0 thru D9 are negative numbers. So -5 would look as 0000000N
Since BI fields cannot be seen visually, I coded the readable values and converted to binary at position 30. You can turn on HEX and see the contents.
Code:
//***************************************************************
//* Sort on 2 fields *
//* Field-1: Position 01 for a length of 8 in ZD format *
//* Field-2: Position 30 for a length of 4 in BI format *
//***************************************************************
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
0000000G = +7 BI=10
0000000N = -5 BI=50
0000000A = +1 BI=02
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC OVERLAY=(30:20,02,ZD,BI,LENGTH=4)
SORT FIELDS=(01,08,ZD,A,
30,04,BI,A),EQUALS
/*
//***************************************************************
//* Sort on 1 field *
//* Field-1: Position 01 for a length of 8 in ZD format *
//***************************************************************
//STEP0200 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
0000000G = +7 BI=10
0000000N = -5 BI=50
0000000A = +1 BI=02
//SORTOUT DD DSN=&&T,DISP=(,PASS),SPACE=(TRK,(1,1),RLSE)
//SYSIN DD *
INREC OVERLAY=(30:20,02,ZD,BI,LENGTH=4)
SORT FIELDS=(01,08,ZD,A),EQUALS
/*
//***************************************************************
//* Sort on 1 field *
//* Field-2: Position 30 for a length of 4 in BI format *
//***************************************************************
//STEP0300 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=(OLD,DELETE),DSN=&&T
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(30,04,BI,A),EQUALS
/*
Go look at the output from the ddname SORTOUT from STEP0100 and STEP0300 steps and see the results. _________________ Kolusu
www.linkedin.com/in/kolusu
Joined: 05 Apr 2005 Posts: 131 Topics: 64 Location: chennai
Posted: Fri Jan 19, 2024 12:07 am Post subject:
Thank you for the explanation
Yes the SORT CARD IN SORT1 STEP should have been
Code:
SORT FIELDS=(361,4,BI,A,114,8,ZD,A)
It is my mistake
In the STEP0100 since the composite sort is as below
Code:
SORT FIELDS=(01,08,ZD,A,
30,04,BI,A),EQUALS
i slightly modified the run STEP0300 followed by STEP0200 , since STEP0300 has 30,04,BI,A which is minor sort . I followed this with major Sort
In this case the output of STEP0100 i.e. SORTOUT & STEP0200 i.e. the final output i.e. SORTOUT were same
So i want to know if i have 3 fields to be sorted fld1,fld2,fld3 all in ascending for e.g.
And the sorted output is say A.B
will this be equivalent to
sort the file by fld3 .
then sort the output of that by fld2
then sort the output of that by fld1. Say o/p is C.D
Will A.B = C.D _________________ deepa
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Fri Jan 19, 2024 10:53 am Post subject:
deepa12,
What exactly is this requirement about ? What do you intend to achieve with this? why do you want to run 3 passes over data when you can do it in 1 pass. Imagine the overhead of reading the same file 3 times and adding EQUALS parm to retain the order of the duplicate records. _________________ Kolusu
www.linkedin.com/in/kolusu
Joined: 05 Apr 2005 Posts: 131 Topics: 64 Location: chennai
Posted: Sat Jan 20, 2024 4:10 am Post subject:
need to develop a generic sort algorithm in Cobol to sort records based on any field for say maximum of 100 records
so am using SORT verb of Cobol in the sort module So i wanted to check if individual field resultant table sort from minor to major sort will yield same result as a composite sort , so that algorithm can be developed using the later _________________ deepa
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Sat Jan 20, 2024 8:26 pm Post subject:
deepa12 wrote:
need to develop a generic sort algorithm in Cobol to sort records based on any field for say maximum of 100 records
so am using SORT verb of Cobol in the sort module So i wanted to check if individual field resultant table sort from minor to major sort will yield same result as a composite sort , so that algorithm can be developed using the later
Deepa12,
How are you going to accomplish this. The SORT Verb in COBOL needs to have a key defined. Once compiled you can never change the key in the cobol program. Are you dynamically going to generate the Source of the COBOL program and recompile every time?
You are complicating a simple request. If your intention is to sort a MAX of 100 records, then load them into an internal table and do the sorting yourself. _________________ Kolusu
www.linkedin.com/in/kolusu
Joined: 05 Apr 2005 Posts: 131 Topics: 64 Location: chennai
Posted: Sun Jan 21, 2024 12:14 am Post subject:
Here i have provided the partial code snippet. i have not provided the data structures for binary and packed decimal since they are not yet tested but it is similar to zoned decimal i initially copy the unsorted data & record positions in WS-TEMP-SORT-GRP2
after sorting in this array it will be repopulated into
05 BIOUT-NO-RECORDS PIC 9(03) VALUE ZEROS.
01 WS-SORT-GRP2.
* CATER FOR INSYNC FIELD TYPES G,X
10 WS-ALPHANUM-TBL OCCURS 100 TIMES
DEPENDING ON
WS-TBL-SIZE.
15 WS-ALPHANUM-POSN PIC S9(4) COMP.
15 WS-ALPHANUM-KEY PIC X(500).
* CATER FOR INSYNC FIELD TYPE BINARY OR COMP ARITH(COMPAT)
01 WS-SORT-GRP3.
10 WS-BINARY-TBL OCCURS 100 TIMES
DEPENDING ON
WS-TBL-SIZE.
15 WS-BINARY-POSN PIC S9(4) COMP.
15 WS-BINARY-KEY PIC S9(18) COMP.
* CATER FOR INSYNC FIELD TYPE P -PACKED DECIMAL ARITH(COMPAT)
01 WS-SORT-GRP4.
10 WS-PACKED-DEC-TBL OCCURS 100 TIMES
DEPENDING ON
WS-NBR-OF-RECS.
15 WS-PACKED-DEC-POSN PIC S9(4) COMP.
15 WS-PACKED-DEC-KEY PIC S9(18) COMP-3.
01 WS-SORT-GRP5.
10 WS-ZONE-DEC-TBL OCCURS 100 TIMES
DEPENDING ON
WS-TBL-SIZE.
15 WS-ZONE-DEC-POSN PIC S9(4) COMP.
15 WS-ZONE-DEC-KEY PIC S9(18).
*CLEARED & REFORMED FOR EVERY SORT
01 WS-TEMP-SORT-GRP2.
10 WS-TEMP-SRTD-TBL OCCURS 100 TIMES
DEPENDING ON
WS-TBL-SIZE.
15 WS-TEMP-SRTD-DATA PIC X(20000).
15 WS-TEMP-SRTD-CURR-POSN
PIC S9(4) COMP.
...
PROCEDURE DIVISION.
PERFORM D2000-SORT
VARYING WS-SUB
FROM WS-NO-OF-ORD-FLDS
BY -1
UNTIL WS-SUB <= 0
.....
*
D2000-SORT SECTION.
******************************************************************
*START FROM MINOR SORT FIELD TO MAJOR SORT FIELD IN REVERSE DIRN *
*CONSIDER EACH SORT FIELD *
*1. INITIALIZE FIELD TYPEWISE ARRAY *
*2. POPULATE FIELD TYPEWISE ARRAY DEPENDING ON THE TYPE AND LENGTH
* FIELD BEING SORTED, FROM TEMP-SRTD ARRAY
*3. SORT ASC/DESC OF RESPECTIVE FIELD TYPE ARRAY
*4. INITIALIZE TEMP-SRTD ARRAY TO
*5. FORM THE RESULT SRTD TABLE FROM FIELD TYPE,LEN FOR WS-SUB FIELD
* THAT HAS BEEN SORTED
*6. THIS WILL BE INPUT TO NEXT STEP
******************************************************************
MOVE "D2000-SORT" TO
DERR-PARM-SECTION-CHAIN
MOVE 0 TO WS-FLD-LEN
WS-FLD-POS
WS-CURR-FLD-LEN
MOVE WS-NBR-OF-RECS TO WS-TBL-SIZE
* MOVE WS-NBR-OF-RECS TO WS-SORT-END-POS
DISPLAY "TEMP-SRTD BEF D2000"
PERFORM
VARYING WS-SUB1
FROM 1 BY 1
UNTIL WS-SUB1 > WS-NBR-OF-RECS
MOVE WS-TEMP-SRTD-CURR-POSN(WS-SUB1)
TO WS-REC-POSN
DISPLAY "POSN DATA "
BIOUT-DATA(WS-REC-POSN)(1:WS-RECLEN) ":"
WS-TEMP-SRTD-DATA(WS-SUB1) (1:WS-RECLEN) ":"
WS-TEMP-SRTD-CURR-POSN(WS-SUB1)
END-PERFORM .
PERFORM D2400-INIT-SORT-SUB-TBLS
VARYING WS-SUB1
FROM 1 BY 1
UNTIL WS-SUB1 > WS-NBR-OF-RECS
PERFORM D2100-POPLAT-FLD-TYPE-SORT-TBL
PERFORM D2500-SORT-BY-FLD-TYPE
*INITIALIZE TEMP SRTD ARRAY *
PERFORM D2600-INIT-TEMP-SRT-TBL
VARYING WS-SUB1
FROM 1
BY 1
UNTIL WS-SUB1 > WS-NBR-OF-RECS
PERFORM D2900-REFORM-SRTABL4NEXT-ITER
VARYING WS-SUB1
FROM 1 BY 1
UNTIL WS-SUB1 > WS-NBR-OF-RECS
DISPLAY "AFTER D2900- SORT " WS-SUB ":"
BIIN-ORD-FIELD-NAME(WS-SUB)
PERFORM
VARYING WS-SUB1
FROM 1 BY 1
UNTIL WS-SUB1 > WS-NBR-OF-RECS
MOVE WS-TEMP-SRTD-CURR-POSN(WS-SUB1)
TO WS-REC-POSN
DISPLAY "POSN DATA "
BIOUT-DATA(WS-REC-POSN)(1:WS-RECLEN) ":"
WS-TEMP-SRTD-DATA(WS-SUB1) (1:WS-RECLEN) ":"
WS-TEMP-SRTD-CURR-POSN(WS-SUB1)
END-PERFORM .
D2000-EXIT.
EXIT.
D2100-POPLAT-FLD-TYPE-SORT-TBL SECTION.
*----------------------------------------------------------------*
*BASED ON FIELD TYPE POPULATE INDVIDUAL FIELD ARRAY WHICH WILL *
*BE SORTED *
*----------------------------------------------------------------*
MOVE "D2100-POPLAT-FLD-TYPE-SORT-TBL" TO
DERR-PARM-SECTION-CHAIN
DISPLAY "IN D2100 FLD TYPE " BIIN-FIELD-TYPE(WS-SUB)
MOVE 0 TO WS-FLD-LEN
WS-FLD-POS
MOVE BIIN-FIELD-LEN(WS-SUB) TO WS-FLD-LEN
WS-CURR-FLD-LEN
MOVE BIIN-FIELD-SEL-DATA-POS(WS-SUB) TO WS-FLD-POS
EVALUATE TRUE
WHEN BIIN-FIELD-TYPE-ALPHA(WS-SUB)
PERFORM D2320-POPLAT-FOR-ALPHANUM-SORT
VARYING WS-SUB1 FROM 1 BY 1
UNTIL WS-SUB1 > WS-NBR-OF-RECS
OR WS-TEMP-SRTD-DATA(WS-SUB1) <= SPACES
WHEN BIIN-FIELD-TYPE-BINARY(WS-SUB)
PERFORM D2200-POPLAT-FOR-BINARY-SORT
VARYING WS-SUB1 FROM 1 BY 1
UNTIL WS-SUB1 > WS-NBR-OF-RECS
OR WS-TEMP-SRTD-DATA(WS-SUB1) <= SPACES
WHEN BIIN-FIELD-TYPE-PACKED(WS-SUB)
PERFORM D2300-POPLAT-FOR-PKD-DEC-SORT
VARYING WS-SUB1 FROM 1 BY 1
UNTIL WS-SUB1 > WS-NBR-OF-RECS
OR WS-TEMP-SRTD-DATA(WS-SUB1) <= SPACES
WHEN BIIN-FIELD-TYPE-ZONE(WS-SUB)
PERFORM D2310-POPLAT-FOR-ZON-DEC-SORT
VARYING WS-SUB1 FROM 1 BY 1
UNTIL WS-SUB1 > WS-NBR-OF-RECS
OR WS-TEMP-SRTD-DATA(WS-SUB1) <= SPACES
END-EVALUATE .
*
D2100-EXIT.
EXIT.
D2200-POPLAT-FOR-BINARY-SORT SECTION.
*-----------------------------------------------------------------------
* BASED ON FIELD POSITION AND LENGTH, POPULATE KEY AND ITS POSITION IN
* TEMP-SRTD ARRAY I.E FOR BINARY FIELDS COMP OR COMP-4
* SAY CASE-COUNT-WP IN WPRECORD
* THIS IS S9(4) COMP 2 BYTES SO IT IS A HEX MOVE
* FOLLOWED BY ACCESSING THE CORRECT HALF WORD & STORING INA MAX SIZE
* FIELD OF THAT TYPE ARRAY FIELD IS MAX SIZE
*-----------------------------------------------------------------------
MOVE "D2200-POPLAT-FOR-BINARY-SORT" TO
DERR-PARM-SECTION-CHAIN
*
* MOVE 0 TO WS-FLD-LEN
* WS-FLD-POS
* MOVE BIIN-FIELD-LEN(WS-SUB) TO WS-FLD-LEN
* WS-CURR-FLD-LEN
* MOVE BIIN-FIELD-SEL-DATA-POS(WS-SUB) TO WS-FLD-POS
MOVE WS-TEMP-SRTD-CURR-POSN(WS-SUB1) TO WS-BINARY-POSN
(WS-SUB1)
EVALUATE TRUE
WHEN BIIN-FIELD-LEN(WS-SUB) = 2
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-HALF-WRD-X
MOVE WS-HALF-WRD-9 TO WS-BINARY-KEY
(WS-SUB1)
WHEN BIIN-FIELD-LEN(WS-SUB) = 4
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-FULL-WRD-X
MOVE WS-FULL-WRD-9 TO WS-BINARY-KEY
(WS-SUB1)
WHEN BIIN-FIELD-LEN(WS-SUB) = 8
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-DBL-WRD-X
MOVE WS-DBL-WRD-9 TO WS-BINARY-KEY
(WS-SUB1)
END-EVALUATE.
D2200-EXIT.
EXIT.
D2300-POPLAT-FOR-PKD-DEC-SORT SECTION.
*-----------------------------------------------------------------------
* BASED ON FIELD POSITION AND LENGTH, POPULATE KEY AND ITS POSITION IN
* TEMP-SRTD ARRAY I.E FOR COMP-3 OR PACKED DECIMAL
* E..G LAST-MEASUREMENT-DATE-UPR IN PRUSER S9(08) COMP-3
* THIS IS 5 BYTES SO IT WILL BE HEX MOVE TO 5 BYTE FIELD & THEN MOVED
* INTO SORT ARRAY WHICH IS ALWAYS DECLARED AS S9(18) MAX SIZE
* S9(6)V99 ASSUMED DECIMALSAY 000456.78 IS STORED IN HEX AS
* X'000000000045678C'
*-456.78 IS STORED AS X'000000000045678D'
*-----------------------------------------------------------------------
MOVE "D2300-POPLAT-FOR-PKD-DEC-SORT" TO
DERR-PARM-SECTION-CHAIN
*
* MOVE 0 TO WS-FLD-LEN
* WS-FLD-POS
* MOVE BIIN-FIELD-LEN(WS-SUB) TO WS-FLD-LEN
* WS-CURR-FLD-LEN
* MOVE BIIN-FIELD-SEL-DATA-POS(WS-SUB) TO WS-FLD-POS
MOVE WS-TEMP-SRTD-CURR-POSN(WS-SUB1) TO WS-PACKED-DEC-POSN
(WS-SUB1)
EVALUATE WS-FLD-LEN
WHEN 1
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-PKD-DEC-X1
MOVE WS-PKD-DEC-9-1 TO WS-PACKED-DEC-KEY
(WS-SUB1)
WHEN 2
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-PKD-DEC-X2
MOVE WS-PKD-DEC-9-2 TO WS-PACKED-DEC-KEY
(WS-SUB1)
WHEN 3
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-PKD-DEC-X3
MOVE WS-PKD-DEC-9-3 TO WS-PACKED-DEC-KEY
(WS-SUB1)
WHEN 4
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-PKD-DEC-X4
MOVE WS-PKD-DEC-9-4 TO WS-PACKED-DEC-KEY
(WS-SUB1)
WHEN 5
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-PKD-DEC-X5
MOVE WS-PKD-DEC-9-5 TO WS-PACKED-DEC-KEY
(WS-SUB1)
WHEN 6
MOVE WS-TEMP-SRTD-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-PKD-DEC-X14
MOVE WS-PKD-DEC-9-14 TO WS-PACKED-DEC-KEY
(WS-SUB1)
WHEN 15
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-PKD-DEC-X15
MOVE WS-PKD-DEC-9-15 TO WS-PACKED-DEC-KEY
(WS-SUB1)
WHEN 16
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-PKD-DEC-X16
MOVE WS-PKD-DEC-9-16 TO WS-PACKED-DEC-KEY
(WS-SUB1)
WHEN 17
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-PKD-DEC-X17
MOVE WS-PKD-DEC-9-17 TO WS-PACKED-DEC-KEY
(WS-SUB1)
WHEN 18
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-PKD-DEC-X18
MOVE WS-PKD-DEC-9-18 TO WS-PACKED-DEC-KEY
(WS-SUB1)
END-EVALUATE .
D2300-EXIT.
EXIT.
*
D2310-POPLAT-FOR-ZON-DEC-SORT SECTION.
*-----------------------------------------------------------------------
* BASED ON FIELD POSITION AND LENGTH, POPULATE KEY AND ITS POSITION IN
* TEMP-SRTD ARRAY I.E FOR COMP-3 OR PACKED DECIMAL
* E..G LAST-MEASUREMENT-DATE-UPR IN PRUSER S9(08) COMP-3
* THIS IS 5 BYTES SO IT WILL BE HEX MOVE TO 5 BYTE FIELD & THEN MOVED
* INTO SORT ARRAY WHICH IS ALWAYS DECLARED AS S9(18) MAX SIZE
* S9(6)V99 ASSUMED DECIMALSAY 000456.78 IS STORED IN HEX AS
* X'000000000045678C'
*-456.78 IS STORED AS X'000000000045678D'
*-----------------------------------------------------------------------
MOVE "D2310-POPLAT-FOR-ZON-DEC-SORT" TO
DERR-PARM-SECTION-CHAIN
* MOVE 0 TO WS-FLD-LEN
* WS-FLD-POS
* MOV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
WHEN 16
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-ZONE-DEC-X16
MOVE WS-ZONE-DEC-9-16 TO WS-ZONE-DEC-KEY
(WS-SUB1)
WHEN 17
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-ZONE-DEC-X17
MOVE WS-ZONE-DEC-9-17 TO WS-ZONE-DEC-KEY
(WS-SUB1)
WHEN 18
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO WS-ZONE-DEC-X18
MOVE WS-ZONE-DEC-9-18 TO WS-ZONE-DEC-KEY
(WS-SUB1)
END-EVALUATE .
D2310-EXIT.
EXIT.
*
D2320-POPLAT-FOR-ALPHANUM-SORT SECTION.
*-----------------------------------------------------------------------
* BASED ON FIELD POSITION AND LENGTH, POPULATE KEY AND ITS POSITION IN
* TEMP-SRTD ARRAY I.E FOR ALPHANUMERIC PIC A-X,GROUP FLDS
* SAY NNDX1-KEY-LA OR LONG-DESCRIPTION-PR SORT
*-----------------------------------------------------------------------
MOVE "D2320-POPLAT-FOR-ALPHANUM-SORT" TO
DERR-PARM-SECTION-CHAIN
*
* MOVE 0 TO WS-FLD-LEN
* WS-FLD-POS
* MOVE BIIN-FIELD-LEN(WS-SUB) TO WS-FLD-LEN
* WS-CURR-FLD-LEN
* MOVE BIIN-FIELD-SEL-DATA-POS(WS-SUB) TO WS-FLD-POS
MOVE WS-TEMP-SRTD-CURR-POSN(WS-SUB1) TO
WS-ALPHANUM-POSN(WS-SUB1)
MOVE WS-TEMP-SRTD-DATA(WS-SUB1)
(WS-FLD-POS:WS-FLD-LEN)
TO
WS-ALPHANUM-KEY(WS-SUB1).
D2320-EXIT.
EXIT.
D2400-INIT-SORT-SUB-TBLS SECTION.
******************************************************************
*INITIALIZE SORT TABLE WHICH WILL BE REALLY SORTED *
******************************************************************
MOVE "D2400-INIT-SORT-SUB-TBLS" TO
DERR-PARM-SECTION-CHAIN
MOVE SPACES TO WS-ALPHANUM-KEY
(WS-SUB1)
D2500-SORT-BY-FLD-TYPE SECTION.
******************************************************************
*DEPENDING ON FIELD TYPE - COMP/COMP-3/ALPHANUM *
* AND ORDER OF SORT I.E ASC/DESC *
* PERFORM COBOL TABLE SORT FOR THIS FIELD SAY FLD1 *
* INSTEAD OF DATA DATA POSITION IS SORTED *
* IN CASE OF ASCENDING SORT SAY WE HAVE 50 RECODS ONLY 1ST *
* 150 RECORDS WILL BE BLANK SINCE IT IS STATIC ARRAY *
******************************************************************
MOVE "D2500-SORT-BY-FLD-TYPE" TO
DERR-PARM-SECTION-CHAIN
DISPLAY " IN D2500- " BIIN-FIELD-TYPE(WS-SUB) ":" WS-SUB
EVALUATE TRUE
WHEN BIIN-FIELD-TYPE-ALPHA(WS-SUB)
IF BIIN-ORD-TYPE-ASC(WS-SUB)
SORT WS-ALPHANUM-TBL
ASCENDING KEY WS-ALPHANUM-KEY
WITH DUPLICATES IN ORDER
ELSE
SORT WS-ALPHANUM-TBL
DESCENDING KEY WS-ALPHANUM-KEY
WITH DUPLICATES IN ORDER
END-IF
WHEN BIIN-FIELD-TYPE-BINARY(WS-SUB)
IF BIIN-ORD-TYPE-ASC(WS-SUB)
SORT WS-BINARY-TBL
ASCENDING KEY WS-BINARY-KEY
WITH DUPLICATES IN ORDER
ELSE
SORT WS-BINARY-TBL
DESCENDING KEY WS-BINARY-KEY
WITH DUPLICATES IN ORDER
END-IF
WHEN BIIN-FIELD-TYPE-PACKED(WS-SUB)
IF BIIN-ORD-TYPE-ASC(WS-SUB)
SORT WS-PACKED-DEC-TBL
ASCENDING KEY WS-PACKED-DEC-KEY
WITH DUPLICATES IN ORDER
ELSE
SORT WS-PACKED-DEC-TBL
DESCENDING KEY WS-PACKED-DEC-KEY
WITH DUPLICATES IN ORDER
END-IF
WHEN BIIN-FIELD-TYPE-ZONE(WS-SUB)
IF BIIN-ORD-TYPE-ASC(WS-SUB)
SORT WS-ZONE-DEC-TBL
ASCENDING KEY WS-ZONE-DEC-KEY
WITH DUPLICATES IN ORDER
ELSE
SORT WS-ZONE-DEC-TBL
DESCENDING KEY WS-ZONE-DEC-KEY
WITH DUPLICATES IN ORDER
END-IF
END-EVALUATE.
*
D2500-EXIT.
EXIT.
*
D2600-INIT-TEMP-SRT-TBL SECTION.
*----------------------------------------------------------------*
*BASED ON FIELD TYPE POPULATE INDVIDUAL FIELD ARRAY WHICH WILL *
*----------------------------------------------------------------*
MOVE "D2600-INIT-TEMP-SRT-TBL " TO DERR-PARM-SECTION-CHAIN
MOVE SPACES TO WS-TEMP-SRTD-DATA
(WS-SUB1).
MOVE 0 TO WS-TEMP-SRTD-CURR-POSN
(WS-SUB1).
*
D2600-EXIT.
EXIT.
*
D2900-REFORM-SRTABL4NEXT-ITER SECTION.
*----------------------------------------------------------------*
*FROM FIELD TYPEWISE SORTED TABLE FORM THE SRTD TABLE *
*----------------------------------------------------------------*
MOVE "D2900-REFORM-SRTABL4NEXT-ITER " TO
DERR-PARM-SECTION-CHAIN
EVALUATE TRUE
WHEN BIIN-FIELD-TYPE-ALPHA(WS-SUB)
MOVE WS-ALPHANUM-POSN(WS-SUB1)
TO WS-REC-POSN
WHEN BIIN-FIELD-TYPE-BINARY(WS-SUB)
MOVE WS-BINARY-POSN(WS-SUB1)
TO WS-REC-POSN
WHEN BIIN-FIELD-TYPE-PACKED(WS-SUB)
MOVE WS-PACKED-DEC-POSN(WS-SUB1)
TO WS-REC-POSN
WHEN BIIN-FIELD-TYPE-ZONE(WS-SUB)
MOVE WS-ZONE-DEC-POSN(WS-SUB1)
TO WS-REC-POSN
END-EVALUATE.
MOVE BIOUT-DATA(WS-REC-POSN)(1:WS-RECLEN)
TO
WS-TEMP-SRTD-DATA(WS-SUB1) (1:WS-RECLEN).
MOVE WS-REC-POSN TO
WS-TEMP-SRTD-CURR-POSN(WS-SUB1).
*
D2900-EXIT.
EXIT.
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Sun Jan 21, 2024 1:08 am Post subject:
deepa12,
No offense but that program is ...
You hard coded sorting for character (CH) binary (BI) and Packed (PD) and Zoned( ZD) for both ascending and descending sequence. So this is NOT exactly a generic sort
There are tons of other formats that you can sort . Look at the different formats that DFSORT can sort.
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Mon Jan 22, 2024 7:45 pm Post subject:
deepa12,
You still are not understanding the issues of sorting hex characters. for example negative Packed decimal number will have "D" in the lower half of the last byte and positive numbers would have "C" to denote sign
ie
Quote:
+456.78 in hex is X'000000000045678C'
-456.78 in hex is X'000000000045678D'
Now you sorting the array in ascending sequence and obviously "D" will come after "C" which means the negative numbers are sorted after the positive number which is totally incorrect. _________________ Kolusu
www.linkedin.com/in/kolusu
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum