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

All sort of Mainframes Interview Questions.
Post Reply
Jyoti Chibber
Registered Member
Posts: 16
Joined: Wed Aug 20, 2014 5:40 pm

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

Post 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."
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: What is the use of level number 88, in COBOL?

Post 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' ...
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

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

Post 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).
Jyoti Chibber
Registered Member
Posts: 16
Joined: Wed Aug 20, 2014 5:40 pm

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

Post 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?
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

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

Post 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 :-)
Jyoti Chibber
Registered Member
Posts: 16
Joined: Wed Aug 20, 2014 5:40 pm

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

Post 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?
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

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

Post 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.
Jyoti Chibber
Registered Member
Posts: 16
Joined: Wed Aug 20, 2014 5:40 pm

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

Post by Jyoti Chibber »

Thanks William.

Appreciate your help.
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 “Interview Questions.”