LOW-VALUES and HIGH-VALUES and collating sequence..

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Anup Apte
Registered Member
Posts: 22
Joined: Mon Aug 12, 2013 11:39 am
India

LOW-VALUES and HIGH-VALUES and collating sequence..

Post by Anup Apte »

Hi,

What are LOW-VALUES & HIGH-VALUES in COBOL? I read about them and got more confused. Most the definitions I read keep on mentioning about "collating sequence" while defining them, for example - LOW-VALUES are the lowest possible value in collating sequence? What does that mean?

Is collating-sequence dependent on machine hardware? Do LOW-VALUES & HIGH-VALUES exist outside COBOL too, if yes - what other languages can use them.

Please help me with some direction.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: LOW-VALUES & HIGH-VALUES & collating sequence..

Post by Robert Sample »

Collating sequence is very important to know. Unix and Windows machines, for example, use ASCII whereas mainframes use EBCDIC. Among other differences, ASCII collating sequence places numbers before letters whereas EBCDIC places numbers after letters. Hence if you sort A, 1, B, 2, C, 3 you may get results of 1,2,3,A,B,C or A,B,C,1,2,3 depending upon which machine you are using. Which is right? Both are -- for their respective collating sequence. The collating sequence merely defines, for each possible bit pattern, what the character (or control character) represents. Hence in ASCII the number zero is represented by B'0110000' or X'30' while EBCDIC uses B'11110000' or X'F0' to represent the number zero. Note that there are multiple collating sequences for ASCII, and EBCDIC -- these are called code pages and allow special characters not used in English to be defined in the collating sequence. Pure ASCII is a 7-bit collating sequence although Windows uses an 8-bit version of ASCII; EBCDIC is 8 bits. Hence pure ASCII assigns 128 values in the collating sequence; EBCDIC and Windows ASCII assign 256 values in the collating sequence.

LOW-VALUES and HIGH-VALUES are terms specific to COBOL but they are fairly common terms to hear outside of COBOL. LOW-VALUES is X'00' or B'0000000' in ASCII and B'00000000' in EBCDIC. HIGH-VALUES will be X'7F' or B'1111111' in ASCII and X'FF' or B'11111111' in EBCDIC. For Windows machines, HIGH-VALUES will be the same as for EBCDIC.

Collating sequence is NOT dependent upon the machine hardware, but rather the operating system in use. ASCII and EBCDIC are both acronyms -- Google can help you find out what they mean. Unicode (UTF-8 or UTF-16) would be good to learn about, as well.
User avatar
Anuj Dhawan
Founder
Posts: 2802
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: LOW-VALUES & HIGH-VALUES & collating sequence..

Post by Anuj Dhawan »

Robert has given you an excellent excellent explanation. Continuing with that from COBOL per se, as the post is in COBOL part of the Forum - there are occasions when you may wish to set a variable to an infinitely high or infinitely low number. For example, suppose you were merging two files on surnames as the primary key:

In data division FILE SECTION

Code: Select all

 FD FILE-1. 
 01 RECORD-1. 
     03 IN-NAME-1 PIC X(20). 
     03 FILLER    PIC X(50). 

 FD MERGE-FILE. 
 01 RECORD-OUT    PIC X(70). 

   : 
   : 

   PERFORM WITH TEST AFTER EOF-FLAG-1 AND EOF-FLAG-2
  • loop until each file has been read to completion
    read each file

Code: Select all

      READ FILE-1 
          AT END SET EOF-FLAG-1 TO TRUE 
          MOVE HIGH-VALUES TO IN-NAME-1 
      END-READ 
      READ FILE-2 
          AT END SET EOF-FLAG-2 TO TRUE 
          MOVE HIGH-VALUES TO IN-NAME-2 
      END-READ
  • sort the records (assuming no 2 names are the same)
    on ascending surname

Code: Select all

      IF IN-NAME-1 IS < IN-NAME-2 THEN 
          WRITE RECORD-OUT FROM RECORD-1 
      ELSE 
          WRITE RECORD-OUT FROM RECORD-2 
      END-IF 

   END-PERFORM
In this example, when IN-NAME-1 is less than IN-NAME-2 (based on their ASCII values e.g. A < B etc..) then the FILE-1 record (RECORD-1) is written to the merge file (RECORD-OUT). One of FILE-1 and FILE-2 will come to an end before the other so the completed file has its IN-NAME- value set to constant that will ALWAYS be greater than the IN-NAME- value still being read, ensuring all remain files are written to the merge file. This is done with the lines: MOVE HIGH-VALUES TO IN-NAME-1 and MOVE HIGH-VALUES TO IN-NAME-2.

Hope this helps..
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: LOW-VALUES & HIGH-VALUES & collating sequence..

Post by Robert Sample »

One slight correction to Anuj's comments:
IN-NAME-1 is less than IN-NAME-2 (based on their ASCII values e.g. A < B etc..)
substitute "collating sequence" for "ASCII" here since the code could be running on an EBCDIC or ASCII platform.
User avatar
Anuj Dhawan
Founder
Posts: 2802
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: LOW-VALUES & HIGH-VALUES & collating sequence..

Post by Anuj Dhawan »

That's correct, Thanks Robert.
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: LOW-VALUES & HIGH-VALUES & collating sequence..

Post by William Collins »

"Collating Sequence" is the order in which bit-patterns are treateed when they are being treated "in order".

Code: Select all

IF A LESS THAN B


The collating sequence tells you, for specific values of A and B, whether the IF is true or not.

LOW-VALUES is the lowest and HIGH-VALUES the highest in the collating sequence.

Typically (and I've never seen otherwise in practice in a COBOL program) you use the "default" collating sequnce. which is simply the bit-patterns in order from B'00000000' to B'00000001' to B'00000010' etc through to B'11111111'.

In a COBOL program you can change the collating sequence for the program to use (have a look at SPECIAL-NAMES).

If you do change the collating sequence, LOW-VALUES represents the first value in that sequence, and HIGH-VALUES represents the last.

For an old 7-bit ASCII file being processed on the Mainframe, you could have defined the highest value as B'01111111', and that would be the value of all uses of HIGH-VALUE(S) in that program.

With the SPECIAL-NAMES you can define the alphabet in reverse order, or letters missing, or intermingle numbers. Whatever you do, LOW-VALUES is the lowest (first) and HIGH-VALUES the highest (last). They are not necessarily X'00' and X'FF'.

This is one of the problems in referring to low-values and high-values "elsewhere", as they are/can be a "moveable feast".

Anuj,

Not good to set anything in the record area after end of file. It might work with compiler option AWO (if variable-length) or with a non-Mainframe compiler, but that only counts as "works sometimes".
User avatar
Anuj Dhawan
Founder
Posts: 2802
Joined: Sun Apr 21, 2013 7:40 pm
Location: Mumbai, India
Contact:
India

Re: LOW-VALUES & HIGH-VALUES & collating sequence..

Post by Anuj Dhawan »

Make sense, William. I should have been careful in citing the example.
Thanks,
Anuj

Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Anup Apte
Registered Member
Posts: 22
Joined: Mon Aug 12, 2013 11:39 am
India

Re: LOW-VALUES and HIGH-VALUES and collating sequence..

Post by Anup Apte »

Thanks for this great discussion. I had been away from work for some time and could not really come back.

I'll read the explanations again to come up with some new question, if any.

Thanks
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”