Table Processing Interview Questions


What are the different table manipulation verbs available?

Below list of verbs used in table handling -

  • OCCURS
  • INDEX
  • SET Statement
  • SEARCH
  • SEARCH ALL

What is the difference between an array and a table in COBOL?

Both are same

Array | Table -

How do you define a table in COBOL?

COBOL arrays are also known as tables. Array is a collection of individual data items of same type and length.

What does the COBOL OCCURS clause mean?

OCCURS clause is used to declare the table in program. It specifies the number that represents how many times the data item is repeated in the table.

How arrays can be defined in COBOL?

Example - Let us declare a table to store two student details. WS-CLASS is the group variable and WS-STUDENT is a variable with all student information OCCURS 2 times to capture the two students information.

       ...
       WORKING-STORAGE SECTION. 
      * Single Dimensional table
       01 WS-CLASS.
          03 WS-STUDENT  OCCURS 2 TIMES.
             05 WS-ROLL-NO      PIC X(03) VALUE "001".
             05 WS-NAME         PIC X(10) VALUE "STUDENT1".

Why should we cannot define OCCURS clause at 01 level?

The table name is a group variable and should be declared with 01 level. It should not have an OCCURS clause associated with it. So OCCURS cannot come up with 01 level.

SET statement -

What are the different usages of SET statement?

The SET statement is used to perform the below operations -

  • Initializing the table indexes.
  • Increasing or decreasing table indexes.
  • Setting the condition name to true or false.

Subscript -

Explain subscript in programming?

Subscript represents the number of table occurrences. Table data can be accessed by using subscript.

How the subscript is declared in COBOL program?

	  * Declaring a subscript
       01 WS-SUB       PIC S9(04) COMP. 

How to initialize the subscript?

      * Initializing the subscript to 1 
           MOVE 1       TO WS-SUB. 

How to increment or decrement the subscript?

      * Incrementing subscript by 1
           COMPUTE WS-SUB = WS-SUB + 1.

Index -

Explain index in programming?

Index refers the table element as the number of displacement positions from the table starting position. Table data can be accessed by using index.

How the index is declared in COBOL program?

	  * Declaring table with index
       01 WS-CLASS.
          03 WS-STUDENT  OCCURS 2 TIMES INDEXED BY WS-IDX.
             05 WS-ROLL-NO      PIC X(03).
             05 WS-NAME         PIC X(10).

How to initialize the index?

      * Initializing index to 1 
		   SET WS-IDX          TO 1.

How to increment or decrement the index?

      * Incrementing index by 1
		   SET WS-IDX          UP BY 1.

SEARCH -

Explain the search process?

SEARCH scans the table elements one by one until a match is found or until the end of the table is reached.

List some of the rules for searching?

  • INDEX should be declared on the table.
  • INDEX should be initialized before the SEARCH starts.
  • SEARCH can apply on both sorted or unsorted tables.
  • If SEARCH is used on multi-dimensional arrays, then the index value should set for all dimensions.

Can a Search be done on a table with or without Index?

No. Index is needed.

SEARCH ALL -

What is the use of Search All statement?

SEARCH ALL statement performs binary search on tables (or arrays).

What are the different rules to perform a Search All?

  • INDEX should be declared on the table.
  • INDEX Initialization not required before the SEARCH starts.
  • SEARCH ALL can apply only on sorted tables.

Common Questions -

What is the difference between subscript and index?

SubscriptIndex
Subscript is no of occurrences of an array. An index is the number of displacement positions of an array.
Subscript should declare separately with S9(04) COMP in WORKING-STORAGE SECTION. The index doesn't require a separate declaration. INDEX BY phrase used to declare it along with table declaration.
Subscript is slow in accessing table data. The index is faster in accessing table data.
Subscript can initialize by using MOVE statement. An index should be initialized by using the SET statement.
Subscript can increase by an ADD statement and decrease by using the SUBTRACT statement. An index can increased and decreased by using the SET statement.

Frequently Asked Questions -

How do you handle table processing in COBOL?

In COBOL, how can arrays be defined?

Define the arrays available in COBOL?

Why occurs cannot be used in 01 level?
Why we cannot define an Occurs clause at 01 level?
Why should the OCCURS clause not be defined at the 01 levels?
Why not define the OCCURS clause at the 01 levels?

Where can we specify OCCURS clause?
What is the purpose of the OCCURS clause in COBOL, and how is it used?

Describe an index from a subscript?
Advantages of Index over subscript?
How are index and subscript different?
Differentiate between subscript and index in COBOL?
What distinguishes an index from a subscript?
What is the difference between subscript and index?
Describe the difference between subscripting and indexing?
What is the difference between subscript and index in COBOL?

What is the usage of subscript in array?

What is the usage of index in array?

What is the use of Search statement?

What is binary search?