Page 1 of 1

What is the use of level number 88, in COBOL?

Posted: Mon Oct 20, 2014 3:31 pm
by Jyoti Chibber
HI,

I've been asked this that what is the use of level number 88? How to use in program and how can we use it differently in different programs, give examples.

I answered that, level 88 variables are "condition names". They are used mostly to test conditions. Can someone help me to get an answer for the later part of the question, "How to use in program and how can we use it differently in different programs, give examples."

Re: What is the use of level number 88, in COBOL?

Posted: Mon Oct 20, 2014 4:26 pm
by Robert Sample
The condition name can be used to provide meaningful names in your code. One example would be

Code: Select all

15  STATE-CODE     PIC X(02).
    88  NORTHEAST        VALUE 'ME' 'NY' 'VT' 'NH' 'MA' 'RI' 'CT'.
    88  SOUTH            VALUE 'VA' 'NC' 'SC' 'GA' 'FL 'TN' 'AL' 'MS' 'LA'.
.
.
.
IF  NORTHEAST
   ...
ENDIF.
IF  SOUTH 
   ...
ENDIF.
is easier to understand than

Code: Select all

IF  STATE-CODE = 'ME' OR 'NY' OR 'VT' OR 'NH' ...

Re: What is the use of level number 88, in COBOL?

Posted: Mon Oct 20, 2014 5:14 pm
by William Collins
You can also use condition-names with the SET statement.

Taking Robert's example:

Code: Select all

SET NORTHEAST TO TRUE
Will give STATE-CODE the value of "ME", the first literal on the VALUE clause on the 88. Not so useful here, but for "flags":

Code: Select all

01  FILLER.
    05  FILLER                                 PIC X.
        88  NORTHEAST                          VALUE "Y".
        88  NORTHEAST-FALSE                    VALUE "N".
    05  FILLER                                 PIC X.
        88  COLOUR-GREEN                       VALUE "Y".
        88  COLOUR-GREEN-FALSE                 VALUE "N".

Code: Select all

SET NORTHEAST-FALSE 
    COLOUR-GREEN-FALSE                      TO TRUE
PERFORM                                     CHECK-NORTHEAST
IF NORTHEAST
    PEFORM                                  CHECK-COLOUR
END-IF
The use of the FILLER for flags ensures that only the 88-levels can be referenced, no-one can mess up the flags by using MOVE (even with reference-modification).

Re: What is the use of level number 88, in COBOL?

Posted: Tue Oct 21, 2014 9:47 am
by Jyoti Chibber
Thanks Robert and William.

William - with this
William Collins wrote:The use of the FILLER for flags ensures that only the 88-levels can be referenced, no-one can mess up the flags by using MOVE (even with reference-modification).
will not it be confusing as FILLER is not a specific variable-name?

Re: What is the use of level number 88, in COBOL?

Posted: Tue Oct 21, 2014 11:53 am
by William Collins
In this case the only specific names you need are the condition names. If there was a name, it would be confusing (as the name was not referenced) and would it would be just waiting for someone to use it.

Code: Select all

01  FILLER PIC X(50).
    05  FLAG-ON VALUE "ROSES ARE RED, VIOLETS ARE BLUE".
    05  FLAG-OFF VALUE "SOME POEMS RHYME, OTHERS DON'T".

Code: Select all

SET FLAG-OFF TO TRUE
IF W-NUMBER-OF-ACCOUNTS > 20
    SET FLAG-ON TO TRUE
END-IF
It is not the length or the relevance of the content of the field which is important for a flag, it is just the condition names.

The first SET will "move" "SOME POEMS RHYME, OTHERS DON'T" to the FILLER, and if tested at that point FLAG-ON would be false. The second SET "moves" "ROSES ARE RED, VIOLETS ARE BLUE" to the FILLER, and the same test would now be true.

You don't need to spell out FILLER anyway the following is equivalent:

Code: Select all

01  PIC X(50).
    05  FLAG-ON VALUE "ROSES ARE RED, VIOLETS ARE BLUE".
    05  FLAG-OFF VALUE "SOME POEMS RHYME, OTHERS DON;T".
The point of the exercise is that all you have to know in the program is the references to the condition names. The content of the condition names does not matter, the compiler looks after that, and you can even typo them and your program will still work 100% accurately. If you allow someone to mess that up by giving the field a name, then they will :-)

Re: What is the use of level number 88, in COBOL?

Posted: Mon Oct 27, 2014 9:23 am
by Jyoti Chibber
Thank you William. Really thankful to your great explanation!
William Collins wrote:

Code: Select all

01  PIC X(50).
    05  FLAG-ON VALUE "ROSES ARE RED, VIOLETS ARE BLUE".
    05  FLAG-OFF VALUE "SOME POEMS RHYME, OTHERS DON;T".
The point of the exercise is that all you have to know in the program is the references to the condition names. The content of the condition names does not matter, the compiler looks after that, and you can even typo them and your program will still work 100% accurately. If you allow someone to mess that up by giving the field a name, then they will :-)
So "FLAG-OFF VALUE "SOME POEMS RHYME, OTHERS DON;T" was a deliberate typo?

Re: What is the use of level number 88, in COBOL?

Posted: Mon Oct 27, 2014 12:38 pm
by William Collins
Errr... no. When constructing the example, some time after the paste I spotted the typo, but only fixed one of them :-)

The point was, the value on the VALUE doesn't actually matter (as long as different from the other 88). Nobody needs to even know the value on the VALUE becasuse the program never directly references that, and in the second constuct, can't reference that. This is better than a one or more MOVE "Y" or MOVE "N" somewhere in the program. The flag becomes a flag. On/off. Certainly, the typo does not matter, as it would not affect the running of the program, nor would it affect the program if someone corrected it (or further typoed it).

On/Off. Content irrelevant.

Re: What is the use of level number 88, in COBOL?

Posted: Thu Dec 11, 2014 2:44 pm
by Jyoti Chibber
Thanks William.

Appreciate your help.