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 are various search techniques in COBOL? Explain.

There are two search techniques in COBOL and those are -

  • SEARCH
  • SEARCH ALL

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

Both are same

My Program Has An Array Defined To Have 10 Items. Due To A Bug, I Find That Even If The Program Access The 11th Item. In This Array, the Program Does Not Abend. What Is Wrong With It?

Program is not compiled with SSRANGE option.

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.

Explain the intention of using arrays in programming?

It is a linear data structure that uses to store the identical data repeated multiple times. For example - student marks for all subjects.

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".

How to define fixed-length array?

The number of OCCURS has a static value. If any changes needed to the number of OCCURS that requires a program modification. For example - OCCURS 10 TIMES.

How to define variable-length array?

The number of OCCURS value will be decided by using variable at the runtime of the program. For example - OCCURS 10 TIMES DEPENDING ON WS-CNT.

Can you define a variable length table? When does space allocation happens for such tables?

Yes. Space allocation will be happend during the runtime.

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.

What is the purpose of the SET verb in COBOL, and how does it differ from the MOVE verb?

SET statement performs - initializing, incrementing and decrementing the index, setting the condition names variables.
MOVE statement only used to move the data from one field and another.

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.

A table has two indexes defined. Which one will be used by the SEARCH?

Both indexes can be used

Which Search verb is equivalent to PERFORM...VARYING?

SEARCH or Linear Search

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.

Do you require an index for a SEARCH ALL?

Yes

What sorting order is required for SEARCH ALL?

Ascending or Descending

You need to do a SEARCH ALL in a array of 1000 elements sorted in the ascending order, if the first 800 are full, what should you populate in the remaining 200?

High values

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.

What is the difference between SEARCH and SEARCH ALL?

SEARCHSEARCH ALL
SEARCH is a linear or sequential search.SEARCH ALL is a binary search.
Should handle index initialization and increment.Only initialization is required for an index. Incrementing is taken care of automatically by the system.
Coding multiple WHEN conditions are allowed and validated.Only one WHEN condition is allowed to code.
Can use arithmetic operators like =, >, <, <=, >=, NOT=.Only = operator is allowed.
Search process is slow.Search process is fast.
SEARCH can be used on single-dimensional and multidimensional tables.SEARCH ALL can be used for only single-dimensional arrays.
Data inside an array need not be in sorted order. Data inside an array should be in a sorted order.

Frequently Asked Questions -

How do you handle table processing in COBOL?

What is the Process of Binary Search and Simple Search?
What is binary search and sequential search? How they can be accomplished in COBOL? Are there any pre-requisites to do these searches?
What is the difference between a binary search and a sequential search?
What is the difference between SEARCH and SEARCH ALL? What is more efficient?
How do you use the SEARCH and SEARCH ALL statements in COBOL, and what are the different search options available?
What is the difference between a SEARCH and a SEARCH ALL statement in COBOL? When would you use each?

In COBOL, how to get tables dynamically loaded?

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 does the COBOL SET verb mean, and how is it different from the MOVE word?
What is the use of the SET statement in COBOL, and how can it be used to manipulate flags and status variables?

What is the usage of subscript in array?

What is the usage of index in array?

What is the use of Search statement?

What are the different rules to perform a Search?
What is the pre-requisite for these SEARCHES?

What is binary search?

What is the pre-requisite for these SEARCH ALL?