Adsnese

Ad

Wednesday, September 17, 2008

Cobol Interview Questions Part-4

51. What is LENGTH in COBOL II?

Ans: LENGTH acts like a special register to tell the length of a group or an elementary item.

52. What is the function of a delimiter in STRING?

Ans: A delimiter in STRING causes a sending field to be ended and another to be started.

53. What is the function of a delimiter in UNSTRING?

Ans: A delimiter when encountered in the sending field causes the current receiving field to be switched to the next one indicated.

54. How will you count the number of characters in a null-terminated string?

Ans: MOVE 0 TO char-count

INSPECT null-terminated-string TALLYING char-count FOR CHARACTERS BEFORE X"00"

55. Which statement will you use to move non-null characters from a null-terminated String?

Ans: UNSTRING null-terminated-string DELIMITED BY X"00" INTO target-area

COUNT IN char-count. (There are other methods, such as 1) using PERFORM 2) using SEARCH 3) using INSPECT and MOVE etc...)

56. 77 COUNTR PIC 9 VALUE ZERO.

01 DATA-2 PIC X(11). . .

INSPECT DATA-2

TALLYING COUNTR FOR LEADING "0"

REPLACING FIRST "A" BY "2" AFTER INITIAL "C"

If DATA-2 is 0000ALABAMA, what will DATA-2 and COUNTER be after the execution of INSPECT verb?

Ans: Counter=4. Data-2 will not change as the Initial 'C' is not found.

57. 01 DATA-4 PIC X(11).

:::

INSPECT DATA-4 CONVERTING

"abcdefghijklmnopqrstuvwxyz" TO "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

AFTER INITIAL "/" BEFORE INITIAL"?"

What will the contents of DATA-4 be after the conversion statement is performed, if before conversion

a) DATA-4 = a/five/?six b) DATA-4 = r/Rexx/RRRr c) DATA-4 = zfour?inspe

Ans: a) a/FIVE/?six b) r/REXX/RRRR c) zfour?inspe (no change at all)

58. What kind of error is trapped by ON SIZE ERROR option?

Ans: Fixed-point overflow. Zero raised to the zero power.

Division by 0. Zero raised to a negative number.

A negative number raised to a fractional power.

59. What is the point of the REPLACING option of a copy statement?

Ans: REPLACING allows for the same copy to be used more than once in the same code by changing the replace value. COPY xxx REPLACING BY .

60. When is a scope terminator mandatory?

Ans: Scope terminators are mandatory for in-line PERFORMS and EVALUATE statements. For readability, it's recommended coding practice to always make scope terminators explicit.

61. Can you use REDEFINES clause in the FILE SECTION?

Ans: No

62. How will you define your record descriptions in the FILE SECTION if you want to use three different record descriptions for the same file?

Ans: FD filename

DATA RECORDS ARE rd01, rd02, rd03.

01 rd01 PIC X(n).

01 rd02 PIC X(n).

01 rd03 PIC X(n).

63. When will you open a file in the EXTEND mode?

Ans:When an existing file should be appended by adding new records at its end. EXTEND mode opens the file for output, but the file is positioned following the last record on the existing file.

64. What does a CLOSE WITH LOCK statement do?

Ans: The statement closes an opened file and it prevents the file from further being opened by the same program.

65. Which mode of opening is required when REWRITE is used?

Ans: I-O mode

66. Why is it necessary that the file be opened in I-O mode for REWRITE?

Ans:Before the REWRITE is performed, the record must be read from the file. Hence REWRITE includes an input operation and an output operation. Therefore, the file must be opened in I-O mode.

67. Which clause can be used instead of checking for FILE STATUS = 10?

Ans: FILE STATUS 10 is the end of file condition. Hence AT END clause can be used.

68. What is the format of a simple SORT verb? What kinds of files can be sorted using SORT?

Ans: SORT workfile ON ASC/DESC KEY key1, ASC/DESC KEY key2 ...

USING inputfile GIVING outputfile

Only sequential files can be sorted in this way.

69. What are the different rules of SORT that needs to be considered?

Ans: The input and output files must remain closed because SORT opens them and closes during the operation, The work file must have a SELECT clause. The work file must have sort description SD entry in the FILE SECTION. Input and Output files must have FD entries. 

No comments:

My Ad

.