Skip to main content

SORT A TABLE

  • June 10, 2020
  • 8 replies
  • 0 views

I want to get rid of all the old "SORTT" (Wang Conversion to AcuCobol) and use AcuCobol SORT.

Here is the table I want to Sort.

Do I have to have a SD File ETC.?

or can I use something like this.

 

 

8 replies

Stephen Hjerpe
  • Participating Frequently
  • June 10, 2020

I want to get rid of all the old "SORTT" (Wang Conversion to AcuCobol) and use AcuCobol SORT.

Here is the table I want to Sort.

Do I have to have a SD File ETC.?

or can I use something like this.

 

 

Try SORT SUMMARY-WS-ENTRY 


  • June 11, 2020

Try SORT SUMMARY-WS-ENTRY 

It Works!

Do you know if a item count can be added.

The table occurs 360 but only has 40 items in it.

When I sort it puts those items last.

On the old Wang sort I could put a item count in to only sort 40 of 360.

If not no big deal .

 

Thanks

 

 


Stephen Hjerpe
  • Participating Frequently
  • June 11, 2020

It Works!

Do you know if a item count can be added.

The table occurs 360 but only has 40 items in it.

When I sort it puts those items last.

On the old Wang sort I could put a item count in to only sort 40 of 360.

If not no big deal .

 

Thanks

 

 

If the table is defined with "occurs 1 to 360 times depending on z" then the number of records sorted can be changed by setting z to 40.

 

identification division.
program-id. sort1.

environment division.
configuration section.
special-names.
    alphabet ignore-case is 1 thru 65,
	'A' ALSO 'a', 'B' ALSO 'b', 'C' ALSO 'c',
	'D' ALSO 'd', 'E' ALSO 'e', 'F' ALSO 'f',
	'G' ALSO 'g', 'H' ALSO 'h', 'I' ALSO 'i',
	'J' ALSO 'j', 'K' ALSO 'k', 'L' ALSO 'l',
	'M' ALSO 'm', 'N' ALSO 'n', 'O' ALSO 'o',
	'P' ALSO 'p', 'Q' ALSO 'q', 'R' ALSO 'r',
	'S' ALSO 's', 'T' ALSO 't', 'U' ALSO 'u',
	'V' ALSO 'v', 'W' ALSO 'w', 'X' ALSO 'x',
	'Y' ALSO 'y', 'Z' ALSO 'z'.

data division.
working-storage section.
01 i pic 99.
01 record-count pic 99.
01 table-records occurs 1 to 10 times depending on record-count
	ascending key is table-record.
    03 table-record pic x(10).

procedure division.
main-logic.
    move 5 to record-count

    move "GGGGGGGGGG" to table-record(1)
    move "bbbbbbbbbb" to table-record(2)
    move "EEEEEEEEEE" to table-record(3)
    move "AAAAAAAAAA" to table-record(4)
    move "ffffffffff" to table-record(5)
    move "hhhhhhhhhh" to table-record(6)
    move "IIIIIIIIII" to table-record(7)
    move "dddddddddd" to table-record(8)
    move "jjjjjjjjjj" to table-record(9)
    move "CCCCCCCCCC" to table-record(10)

    display "before:"
    perform varying i from 1 by 1 until i > record-count
        display table-record(i)
    end-perform

    display "normal sort:"
    sort table-records on ascending key table-record
    perform varying i from 1 by 1 until i > record-count
        display table-record(i)
    end-perform

    display "collated sort:"
    sort table-records on ascending key table-record
	    sequence ignore-case
    perform varying i from 1 by 1 until i > record-count
        display table-record(i)
    end-perform

    accept omitted
    .

Claude Greiner
  • Participating Frequently
  • June 11, 2020

If the table is defined with "occurs 1 to 360 times depending on z" then the number of records sorted can be changed by setting z to 40.

 

identification division.
program-id. sort1.

environment division.
configuration section.
special-names.
    alphabet ignore-case is 1 thru 65,
	'A' ALSO 'a', 'B' ALSO 'b', 'C' ALSO 'c',
	'D' ALSO 'd', 'E' ALSO 'e', 'F' ALSO 'f',
	'G' ALSO 'g', 'H' ALSO 'h', 'I' ALSO 'i',
	'J' ALSO 'j', 'K' ALSO 'k', 'L' ALSO 'l',
	'M' ALSO 'm', 'N' ALSO 'n', 'O' ALSO 'o',
	'P' ALSO 'p', 'Q' ALSO 'q', 'R' ALSO 'r',
	'S' ALSO 's', 'T' ALSO 't', 'U' ALSO 'u',
	'V' ALSO 'v', 'W' ALSO 'w', 'X' ALSO 'x',
	'Y' ALSO 'y', 'Z' ALSO 'z'.

data division.
working-storage section.
01 i pic 99.
01 record-count pic 99.
01 table-records occurs 1 to 10 times depending on record-count
	ascending key is table-record.
    03 table-record pic x(10).

procedure division.
main-logic.
    move 5 to record-count

    move "GGGGGGGGGG" to table-record(1)
    move "bbbbbbbbbb" to table-record(2)
    move "EEEEEEEEEE" to table-record(3)
    move "AAAAAAAAAA" to table-record(4)
    move "ffffffffff" to table-record(5)
    move "hhhhhhhhhh" to table-record(6)
    move "IIIIIIIIII" to table-record(7)
    move "dddddddddd" to table-record(8)
    move "jjjjjjjjjj" to table-record(9)
    move "CCCCCCCCCC" to table-record(10)

    display "before:"
    perform varying i from 1 by 1 until i > record-count
        display table-record(i)
    end-perform

    display "normal sort:"
    sort table-records on ascending key table-record
    perform varying i from 1 by 1 until i > record-count
        display table-record(i)
    end-perform

    display "collated sort:"
    sort table-records on ascending key table-record
	    sequence ignore-case
    perform varying i from 1 by 1 until i > record-count
        display table-record(i)
    end-perform

    accept omitted
    .
Good example in Cobol!
i had most use a isam temporaly isam file with the necessary keys, today i use a SQL temporaly table.
Sorting in the working storage is depending on the data,this was by Little ram Memory not possible!

  • July 30, 2020

Try SORT SUMMARY-WS-ENTRY 

Ran into another problem. If I have 4 items in a table and they are numbered 1 thru 4 and I am sorting on a field where all the values are 0, the new sequence will be 2, 3, 4 than 1 instead of 1 thru 4 . Can you think of a solution? I have tried using the "WITH DUPLICATES IN ORDER" which didn't change anything. Thanks

   


Stephen Hjerpe
  • Participating Frequently
  • July 30, 2020

Ran into another problem. If I have 4 items in a table and they are numbered 1 thru 4 and I am sorting on a field where all the values are 0, the new sequence will be 2, 3, 4 than 1 instead of 1 thru 4 . Can you think of a solution? I have tried using the "WITH DUPLICATES IN ORDER" which didn't change anything. Thanks

   

DUPLICATES IN ORDER should work, but it appears to be broken for sorting a table.  I'll post an update to this thread when we can provide a fix for that.


  • July 30, 2020

DUPLICATES IN ORDER should work, but it appears to be broken for sorting a table.  I'll post an update to this thread when we can provide a fix for that.

Thanks!


Stephen Hjerpe
  • Participating Frequently
  • August 7, 2020

Thanks!

A fix for the  SORT Table with DUPLICATES in ORDER has been made. Please contact Customer Care and let them know the version you are using and that you'd like ECN-4680.