gnucobol-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [open-cobol-list] Sorting method, word by word or letter by letter.


From: Ron Norman
Subject: Re: [open-cobol-list] Sorting method, word by word or letter by letter.
Date: Tue, 8 Apr 2014 16:41:16 -0400

I believe that what Joe has described is correct and most COBOL compilers do work as described.

However also keep in mind that for ISAM files if the key contains signed numeric fields you may not get the ordering you would expect.
For example if signed trailing the order would be
0001-
0001+
0002-
0002+

But without thinking about it you might expect:
0002-
0001-
0001+
0002+



On Mon, Apr 7, 2014 at 6:04 AM, Joe Robbins <address@hidden> wrote:
Hello John

Not sure I fully understand your question but here's some info that may be helpful:

1.    Using the COBOL SORT verb to order data:  SORT sort-file ON KEY k0, k1 ... kn
       ... when determining whether one record is less than, equal to or greater than another record, SORT compares each value of k from the two records in the order given.
       1.1 if k is a COBOL NUMERIC then function cob_numeric_cmp() is used to compare the two values. This is the generic comparator for GNU COBOL numeric fields. So the result is the same as comparing two numeric fields in code.
       1.2 otherwise: the two values are compared byte-by-byte (from left to right as they would appear in a string) using the COLLATING-SET declared for the COBOL module.

2.    Using ORGANIZATION INDEXED
        Strictly speaking, the key ordering  depends on the underlying implementation you configure for ISAM: BDB, VBISAM, SQL, etc. In practice, I would be surprised if key-values were not compared byte-by-byte (from left to right as they would appear in a string).
         For example: VBISAM uses the LINUX function memcmp() to compare two key values. This is documented as: "The memcmp() function compares the first n bytes (each interpreted as unsigned char) of the memory areas s1 and s2."


Would you like to elaborate and/or give an example of "sorted letter-by-letter and not word-by-word"?


Joe Robbins
address@hidden


________________________________________
From: john Culleton <address@hidden>
Sent: 05 April 2014 01:43
To: address@hidden
Subject: [open-cobol-list] Sorting method, word by word or letter by letter.

This is a technical distinction. My latest client
requires that an index be sorted letter-by-letter
and not word-by-word. Which method does GNUCOBOL
use?

--
John Culleton
Wexford Press
Free list of books for self-publishers:
http://wexfordpress.net/shortlist.html
PDF e-book: "Create Book Covers with Scribus"
available at
http://www.booklocker.com/books/4055.html

------------------------------------------------------------------------------
_______________________________________________
open-cobol-list mailing list
address@hidden
https://lists.sourceforge.net/lists/listinfo/open-cobol-list

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees_APR
_______________________________________________
open-cobol-list mailing list
address@hidden
https://lists.sourceforge.net/lists/listinfo/open-cobol-list



--
Cheers
Ron Norman

reply via email to

[Prev in Thread] Current Thread [Next in Thread]