COBOL Frequently Asked Questions and Answers

1/03/2010 No Comment

COBOL Frequently Asked Questions Answers.

Mainframe Interview Questions with their respective answers.

Explain why it becomes necessary that the file be opened in I-O mode for REWRITE? 
Answer : Before REWRITE is to be performed, the record must be read from a file. As such, REWRITE includes an input operation and an output operation. Hence, the file must be opened in I-O mode.

Explain how will you open a file in the EXTEND mode?
Answer : When an existing file is be appended by adding new records at its end. EXTEND mode opens the file for output only, but the file is positioned following the last record on the existing file.

What are the access mode requirements of START statement? 

Answer : Access mode must be DYNAMIC or SEQUENTIAL.

Explain why is the LINKAGE SECTION used for? 

Answer : The linkage section is used to pass data from one program to another program or to pass data from a PROC to a program. It is part of a called program that 'links' or maps to data items in the calling program's working storage. It is the part of the called program where these share items are defined.

When you were passing a table via linkage, which is preferable - a subscript or an index? 

Answer : It is not at all possible to pass an index via linkage. The index is not part of the calling programs working storage. Indexing uses binary displacement. Subscripts use the value of the occurrence.

Explain in detail what is the difference between a subscript and an index in a table definition?

Answer : In COBOL, a subscript is a working storage data definition item, typically a PIC (999) where a value must be moved to the subscript and then increment or decremented it by ADD TO and SUBTRACT FROM statements. An index is a register item that exists outside the program's working storage. You SET an index to a value and SET it UP BY value and DOWN BY value.

Subscript refers to the array occurrence while index is the displacement (in no of bytes) from the beginning of the array. An index can only be modified using PERFORM, SEARCH & SET. Need to have index for a table in order to use SEARCH, SEARCH ALL Cobol statements.

What does a CLOSE WITH LOCK statement do?
Answer : The statement CLOSE WITH LOCK closes an opened file and it prevents the file from further being opened by the same program.

Which mode of opening is required when REWRITE is used?

Answer : When REWRITE is used, I-O mode is required.

Explain the difference between COMP and COMP-3 usage? Please also explain other COBOL usages. 

Answer : COMP is a binary usage, while comp-3 is a packed decimal. The other common usages
are binary and display. Display is the default. Comp is defined as the fastest/preferred numeric data type for the machine it runs on. IBM Mainframes are typically binary and AS400's are packed.'

What is COMP-1 and COMP-2 in COBOL? 

Answer : COMP-1 : Single precision floating point. It uses 4 bytes.
COMP-2 : Double precision floating point. It uses 8 bytes.

How many bytes does a S9(7) COMP-3 field occupy ? 

Answer : Will take 4 bytes. Sign is stored as hex value in the last nibble.
General formula is INT((n/2) + 1)), where n=7 in this example.

Explain how will you define a variable of COMP-1? COMP-2?
Answer : No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.

In COBOL, what is the maximum value that can be stored in S9(8) COMP? 

Answer : 99999999

Explain in detail what is COMP SYNC in COBOL?

Answer : COMP SYNC causes the item to be aligned on natural boundaries. It can be SYNCHRONIZED LEFT or RIGHT. As for binary data items, the address resolution will be faster, if they are located at word boundaries in the memory. For instance, on main frame the memory word size is 4 bytes. Which means that each word will start from an address divisible by 4. 

If my first variable is x(3) and next one is s9(4) comp, then if you do not specify the SYNC clause, S9(4) COMP will start from byte 3 ( assuming that it starts from 0 ). If you specify SYNC, then the binary data item will start from address 4. Hence you will  see some wastage of memory, but the access to this computational field will be much faster.

Can you tell me the difference between PIC 9.99 and 9v99 
Answer : PIC 9.99 is a FOUR-POSITION field that actually contains a decimal point where as PIC 9v99 is THREE-POSITION numeric field with implied or assumed decimal position.

Explain what does PIC 9v99 Indicate in COBOL?
Answer : PICTURE 9v99 is a three position Numeric field with an implied or assumed decimal point after the first position; the v means an implied decimal point.

Explain how is PIC 9.99 is different from PIC 9v99 
Answer : PIC 9.99 is a four position field that actually contains a decimal point where as 9v99 is a three position numeric field with an implied or assumed decimal point.

Which clause can be used instead of checking for FILE STATUS = 10?
Answer : FILE STATUS 10 is the end of file condition. Hence AT END clause can be used.

How will you position an indexed file at a specific point so that the subsequent sequential operations on the file can start from this point?

Answer : Use START
START filename KEY IS EQ/GT/LT.. dataname

Explain what will happen if we move a comp-3 field to an edited ( say z(9).zz-) 

Answer : The editing characters are to be used with data items with usage clause as display, which is the default. When you try to display a data item with usage as computational,  it will not give the expected display format because the data item is stored as packed decimal. As such, if you want this particular data item to be edited you have to move it into a data item whose usage is display and then have that particular data item edited in the format desired.

Explain what is the difference between a Global and an External Variable in Cobol?
Answer : Global variables are accessible only to the batch program. On the other hand, external variables can be referenced from any batch program residing in the same system library.

What are the causes for S0C1, S0C4, S0C5, S0C7, S0CB abends ?

Answer : Cause for S0C1 abends
  • Missing or misspelled DD name
  • Read/Write to unopened dataset
  • Write to dataset opened input
  • Called subprogram not found.
  • Read to dataset opened output
Cause for S0C4 abends
  • Missing Select statement(during compile)
  • Bad Subscript/index
  • Missing parameters on called subprogram
  • Protection Exception
  • Read/Write to unopened file
  • Move data from/to unopened file.
Cause for S0C5 abends
  • Close an un-open dataset
  • Bad exit from a perform
  • Bad Subscript/index
  • Access to I/O area(FD) before read.
Cause for S0C7 abends
  • Numeric operation on non-numeric data
  • Coding past the maximum allowed sub script.
  • Un-initialize working-storage.
Related Posts

No comments :


Aired | The content is copyrighted and may not be reproduced on other websites. | Copyright © 2009-2016 | All Rights Reserved 2016

Contact Us | About Us | Privacy Policy and Disclaimer