Wednesday, October 6, 2010

COBOL Interview Questions

01. Name the divisions in a COBOL Program. The four divisions in a COBOL Program are IDENTIFICATION DIVISION, ENVIRONME DIVISION, DATA DIVISION and PROCEDURE DIVISION. 02. Tell us briefly about each division. IDENTIFICATION DIVISION is used to establish the Identity of the program, a assigns a unique name to the Program.

ENVIRONMENT DIVISION tells the environment – SOURCE-COMPUTER and OBJECT-COMP which the COBOL Program would run. It also declares the Input and Output fil names, accessed by the COBOL Program.

DATA DIVISION is the place in the COBOL Program, that creates Storage areas Variables) for storing Data. Generally, COBOL Programs read data-records fro Input-File, or Write records to Output-file. When the data-record from the file is read, there's got to be a place in the COBOL Program, where the Inpu Data arrives, its received and it has to be stored. COBOL Programs may do so rough-work. Such variables which act like a temporary scratch-pad, where you do some rough-work, and which are there only as long as the COBOL Program ru called WORKING-STORAGE Areas.

PROCEDURE DIVISION is the starting-point of the COBOL Program, where the Pro begins to run. You code the Instructions that you to perform one-by-one in t PROCEDURE DIVISION. 03. What are the different data-types in COBOL? Alpha-numeric (X), alphabetic (A) and numeric (9). 04. What does the INITIALIZE Verb do? Alphabetic, Alpha-numeric fields and alpha-numeric edited items are initiali SPACES. Numeric and Numeric-edited items are set to ZEROES. FILLER and OCCURS Claus are left untouched.

ADDRESS But. level . I c provide an extra-level of detailed breakup. Middle Employee-Address Data consists of Street(10). 05. To store Employee d RECORD the COBOL Program. The output of the above code is shown in the below. City(10) and Pin Address Pin-code(06). What is 77 level used for ? Say.In the above code. I break down EMPLOYEE EMPLOYEE-RECORD into NAM EMP-ADDRESS Fields as follows. EMPLOYEE-RECORD Are I know that. I create an EMPLOYEE RECORD Storage Area as follows. Middle-name(10) and Last-n First-name(10). WS-NAME variable would be filled up with SPACES. that you want to store the details about the Employees working in the C Each EMPLOYEE-RECORD detail is generally 56 characters. WS-PHONE -NAME WS variable would be zeroed out. EMPLOYEE-RECORD data contains the Name of the Employee(30 char -RECORD the address of the employee(26 chars). the name itself consists of First name(10).

real(fractional) number with Integer part before the decimal-pt and Fractio Integer-part decimal after the decimal-pt in all Arithmetic-Operations. they cannot be broken dow areas data-items. you can take a 01 s 01-Level Data-item. tr number as Decimal-number. number. do further into smaller storage areas. Note that. COBOL assumes a decimal point. 77-level storage-areas are independent data items. Moreover.9 and PIC 9V9? When you use PIC 9V9.' charac Point display-formatting chara simply force-inserted in between the 2 digits. T decimal-Point is merely used for displa formatting purposes. depending on the granularity areas. they cannot participate under ler bigger storage area. It does not tell COBOL to tre inserted 2-digits. COBOL does not treat it like a Real(Decimal) Number. and treats the number a decimal-point.This way. now you can’t chop it! 06. . Is there a difference between PIC 9. granularity-of-detail. pt When you use PIC 9. the '. If EMPLOYEE-RECORD were to be an 77 Level Independent Variable. storage-areas. and break it down further into . it would loo 77-Level lo this. detail. you wish to capture.9.

When WS A is displayed on the screen. as you have force inserted the decimal-po bytes force-inserted decimal character(which occupies 1 byte). Can you pass an Index to another COBOL Program.' symbol to be display between 2 a Also note that. Output You can pass a Subscript to another COBOL Program. What is the difference between STOP RUN. 88 HIGH-TEMPERATURE VALUES 75 THRU 100. it shows up as . WS-B on the ot A 2-bytes WS occupies 3-bytes of storage space. but WS-B as 23. TEMPERATURE MOVE 60 TO TEMPERATURE IF MEDIUM-TEMPERATURE(You need not write TEMPERATURE=60) ERATURE(You . only send the data which is in Working-storage areas(Rough-work area) or in storage areas(Rough Input-Output Areas to a COBOL Program.In the above code. WS-A B shows up as 2. GO BACK and EXIT PROGRAM? .. Ver useful in detecting special special-conditions.3. They work like flags or switches. in all B arithmetic-Operations. COBOL treats WS WS-A as 2. WS-A occupies just 2 bytes of Storage space. It is maintained by the System. as you have forced a '. 01 TEMPERATURE PIC 9(03).. What is 88-Level used for? Level Used for assigning labels to data-values that a COBOL-Variable can take. END-IF 08. . 09. an INDEX is not a Working-storage area. TEMPERATURE 88 MEDIUM-TEMPERATURE VALUES 50 THRU 74.3. 07. via LINKAGE SECTION? No. TEMPERATURE 88 LOW-TEMPERATURE VALUES 32 THRU 49.

What is level 66 used for ? Level-66 Data-item is used for RENAMES Clause. 3 10 FIELD-4 PIC 9(02). 01 WS-I USAGE IS INDEX. B is stored as 1100 0010 or X'C2' in H Similarly. EXIT only works in sub-programs. If programs. the first 5 characters are HIGH-VALUES. Understand. Is this a valid Working storage definition? I Working-storage Yes this is a valid working working-storage definition of an Index. 01 RECORDS. C 13. to VALUES represent Infinitely large or Infinitely small data. 10 FIELD-3 PIC 9(02). programs. returns the control back to the OS. GO BACK returns the control back to the calling program. HIGH-VALUES and LOW-VALUES characters are used in COBOL. when used the Main Driver Program. IF WS-TEXT IS NUMERIC DISPLAY 'NUMBER' ELSE DISPLAY 'TEXTUAL CHARACTERS’ . it causes 4038 Abend. For example. 10. 05 GROUP-A. In the picture above. What are HIGH-VALUES and LOW-VALUES in COBOL? VALUES How does the Mainframe Computer store data and information? Every character alphabet is represented as a unique 8 bit pattern of 0s and 1s. Index 11. the LOW-VALUE character is stored as 0000 0000 or X'00' in Hex. T VALUE HIGH-VALUE Character is stored as 1111 1111 or X'FF' in Hex. 1 10 FIELD-2 PIC 9(02). The next 5 ch are LOW-VALUES. RENAMES clause is used to item regroup(Re-arrange). and transfers control to the calling Program. 8-bit example stored as 1100 0001 or X'C1' in hex. 2 05 GROUP-B. 01 WS-TEXT PIC X(05). What does the IS NUMERIC clause establish ? IS NUMERIC is used to check if the data is numeric or not. 10 FIELD-1 PIC 9(02). 12. arrange). TEXT MOVE '15623' TO WS-TEXT.STOP RUN terminates the entire ru run-unit – the Main Driver Program along with wit its sub-programs. th are non-displayable characters. club together existing fields under a new name. 4 66 GROUP-C RENAMES FIELD-2 THRU FIELD-3. TEXT. I in the Main Driver Program.

Output: TEXTUAL CHARACTERS 14. What is the difference between Index and Sub-script? Subscript is the slot-no. ----------------------- Since index is much more efficient. you should declare a table and Index it. Subscripts have to be converted internally to the ad For example. . How do you define a table or array in COBOL? 01 CONTACT-LIST. 17.. 01 WS-TABLE. At a minimum. or position in the table. 05 CONTACT-RECORD OCCURS 5 TIMES. ----------------------Subscript Index ----------------------0 0 1 10 2 20 3 30 . Can the OCCURS clause be at the 01 level? No. 05 WS-NAME OCCURS 5 TIMES PIC X(10). Index is the displaceme no of bytes)/actual address from the beginning of the array.. what are the divisions you are required to code in COBOL? IDENTIFICATION DIVISION entry is required at a minimum to build a working C Program. Indexes are muc faster than subscripts. 10 PHONE PIC 9(08). 15. . 10 NAME PIC X(10).END-IF. Output: NUMBER MOVE 'HE123' TO WS-TEXT IF WS-TEXT IS NUMERIC DISPLAY 'NUMBER' ELSE DISPLAY 'TEXTUAL CHARACTERS’ END-IF. 16.

05 FILLER PIC X(10) VALUE 'RAMESH'. You use indexes just like subscripts. 10 WS-CITY PIC X(10). 10 WS-NAME PIC X(10). 10 WS-PHONE PIC X(08).is a Linear(sequential) search. What is the difference between SEARCH and SEARCH ALL? SEARCH . 01 WS-CONTACT-LIST REDEFINES WS-CONTACT-LIST-VALUES.01 WS-TABLE. by names you have to code SEARCH WS-CONTACT-RECORD VARYING I AT END GO TO 2000-SEARCH-EXIT WHEN WS-NAME(I) = 'RAMESH' DISPLAY 'NAME : ' WS-NAME(I) DISPLAY 'PHONE : ' WS-PHONE(I) . 05 FILLER PIC X(10) VALUE 'QUASAR'. PERFORM 1000-DISPLAY-DATA VARYING I FROM 1 BY 1 UNTIL I > 5 1000-DISPLAY-DATA. except for the fact that they are much and efficient. 05 FILLER PIC X(08) VALUE '42334160'. 05 FILLER PIC X(10) VALUE 'ARJUN'. You cannot MOVE data to Indexes. 05 FILLER PIC X(08) VALUE '28941365'. You also cannot perform Arithmetic Operati an Index. 05 FILLER PIC X(10) VALUE 'MUMBAI'. SET I TO 1. 05 FILLER PIC X(08) VALUE '28941305'. DISPLAY WS-NAME(I). *---------------------------------------------------------------* * PRE-FILLED CONTACT-LIST COBOL ARRAY * *---------------------------------------------------------------* 01 WS-CONTACT-LIST-VALUES. It performs a full top-to-bottom sc the data. 05 FILLER PIC X(10) VALUE 'PUNE'. To increment or decrement an Index. 05 WS-NAME OCCURS 5 TIMES PIC X(3) INDEXED BY I. To search the Contact-List. 18. SET I UP BY WS-LIT-ONE. SET Verb is used. 05 FILLER PIC X(10) VALUE 'DELHI'. 05 WS-CONTACT-RECORD OCCURS 3 TIMES INDEXED BY I.

I find t even if the program access the 11th item in this array.5. A contains a few records like 1. 21.6. 05 JCL-PARM-DEBUG-SWITCH PIC X.is a binary search & the table must be sorted ( ASCENDING/DESCE KEY clause to be used & data loaded in this order) before using SEARCH ALL. What is binary search? Search on a sorted array.9. My program has an array defined to have 10 items. How do you access SYSIN Data and PARM Parameters passed to a COBOL Progr You can access SYSIN Data in a COBOL Program using the ACCEPT Verb.PARMS='GEMIMG8LN’ LINKAGE SECTION. SEARCH ALL . then while definin array. What should be the sorting order for SEARCH ALL? It can be either ASCENDING or DESCENDING. Due to a bug.8. you code a LINKAGE SECTION Entry after the Working Storage Areas. <--First 2bytes store length 05 JCL-PARMS-STEPID PIC X(08).2.4. contains a few records like 1.12. (You must load the table in th specified order). 05 JCL-PARMS-LENGTH PIC 9(04) COMP.5. //STEP010 EXEC PGM=PROG01. If you want search to be done on an array sorted in descending order. Compare the item to be searched with the item at t center.10.3. the program does no What is wrong with it? Use the compiler option SSRANGE if you want array bounds checking. you should give DESCENDING KEY clause. 22. For example. 20. ASCENDING is default. fine else repeat the process with the left half or th half depending on where the item lies. ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-READ FILE-1 READ FILE-2 PERFORM UNTIL AT-END-FILE1 OR AT-END-FILE2 EVALUATE TRUE WHEN KEY-1 > KEY-2 DISPLAY 'COMPARE' KEY-1 '>' KEY-2 READ FILE-2 AT END SET AT-END-FILE2 TO TRUE NOT AT END CONTINUE END-READ . 01 JCL-PARMS. If it matches. Write a Program to create an Out File C.7. 19. To acces PARM Data.7. There are 2 files A and B.DISPLAY 'CITY : ' WS-CITY(I) END-SEARCH. That contains the matching records from the 2 files. Default i NOSSRANGE. 23.

sort stat syntax and meaning? SORT file-1 ON ASCENDING/DESCENDING KEY key. How do you come out of an EVALUATE statement? After the execution of one of the when clauses.WHEN KEY-1 < KEY-2 DISPLAY 'COMPARE' KEY-1 '<' KEY-2 READ FILE-1 AT END SET AT-END-FILE1 TO TRUE NOT AT END CONTINUE END-READ WHEN KEY-1 = KEY-2 DISPLAY 'COMPARE' KEY-1 '=' KEY-2 MOVE INPUT-RECORD1 TO OUTPUT-RECORD WRITE OUTPUT-RECORD READ FILE-1 AT END SET AT-END-FILE1 TO TRUE END-READ READ FILE-2 AT END SET AT-END-FILE2 TO TRUE END-READ END-EVALUATE END-PERFORM 24. the control is automaticall . Performing a PARAGRAPH will cause only that paragraph to be performed. 27. file-1 is the sort workfile and must be described using SD entry in FILE SE file-2 is the input file for the SORT and must be described using an FD ent FILE SECTION and SELECT clause in FILE CONTROL. 25. How do you sort in a COBOL program? Give sort file definition.. file-3 is the outfile from the SORT and must be described using an FD entry SECTION and SELECT clause in FILE CONTROL.. 26. control comes out of the EVALUATE as soon as one match is made. USING file-2 GIVING file-3.. Th difference between EVALUATE and case is that no 'break' is required for EVAL i. USING can be substituted by INPUT PROCEDURE IS para-1 THRU para-2 GIVING can be substituted by OUTPUT PROCEDURE IS para-1 THRU para-2. What is the use of EVALUATE statement? Evaluate is like a case statement and can be used to replace nested Ifs. What is the difference between performing a SECTION and a PARAGRAPH? Performing a SECTION will cause all the paragraphs that are part of the sec be performed.e.

DISPLAY 'SENTENCE-2'. How do you do in-line PERFORM? PERFORM [varying I from 1 BY 1] [UNTIL Boundary-condition|5 TIMES] Instruction-1 Instruction-2 . END PERFORM 30. STOP RUN. Output: SENTENCE-2 IF WS-NUMBER > 3 CONTINUE ELSE DISPLAY 'WS-NUMBER IS MORE THAN 3' END-IF DISPLAY 'SENTENCE-1'.. Redefines just causes both fields to start at the same location. must be the only sentence within a paragraph. while NEXT SENTENCE transf control to the next sentence (!!) (A sentence is terminated by a period) IF WS-NUMBER > 3 NEXT SENTENCE ELSE DISPLAY 'WS-NUMBER IS MORE THAN 3' END-IF DISPLAY 'SENTENCE-1'. What does EXIT do? Does nothing! If used. 32.. Can I redefine an X(100) field with a field of X(200)? Yes. 28. can I give a complex condition on a when claus Yes. STOP RUN. For ex . Output: SENTENCE-1 SENTENCE-2 31. 29. What is the difference between CONTINUE & NEXT SENTENCE ? CONTINUE is like a null statement (do nothing) . In an EVALUATE statement. DISPLAY 'SENTENCE-2'. There is no need of an code. It is generally used as an exit-point for the Paragraphs.on to the next sentence after the EVALUATE statement.

S0CB Errors in COBOL? S0C1 error is an Operation Operation-Exception. exec invalid machine-instruction. You try to access Storage-area. 34. How do you resolve S0C7 Error? When a COBOL Program terminates pre maturely. You can hit a Listing. In the Compile-Listing. you must loo lo this in the Compile-Listing to find out.Table-handling overlay( handling overlay(MOVEs to table/sub-scripts out of range – and which scripts write PROCEDURE DIVISION Instructions). S0C4 error is an Address Address-Exception. due to Bad-data. most install pre-maturely.FLAG(W.OFFSET. This happens when you attempt to execu . Storage restricted. . If you MOVE '12' to WS WS-TOP-RED. occur . S0C1 errors occur in COBOL.CALLs to an invalid or un un-available module-name. S0C4. . COBOL Verb coded on Line-no. F ALL 'HEXLOC' in the Compile-Listing to locate this. Compile-Listin the following options 'SSRANGE. Can I redefine an X(200) field with a field of X(100) ? Yes. These dumps provide the offset of the instruction at which the abend occurred. This generally occurs when you try tr divide by zero in COBOL. Error S0C7 error is a Data-Exception. . the program was terminated. What are S0C1. DISPLAY WS-TOP will show 1 while TOP DISPLAY WS-TOP-RED will show 12. perf Arithmetic-Operation on non non-numeric data.MAP.(LINE).01 WS-TOP PIC X(1) 01 WS-TOP-RED REDEFINES WS RED WS-TOP PIC X(2). jump to Condensed-Verbs Listing. RED 33. S0C7. 35. at which COBOL Line-of-code or COBO Listing Line Instruction. Once you have the offset of the abending-Instruction +00000440. This generally happens when you try to perfo Exception. which is . I have generated the Compile . The condensed-Verbs Listing gives the COBOL Line no.XREF. due to: instruction. Bad provide you a dump for run time abend.W)'.Statements referencing LINKAGE SECTION Fields incorrectly.(LINE). S0CB error is a Divide Divide-by-Zero exception. Any storage storage-access violation results in S0C4 Error.

note down the name of the fields occurring in the Abending ote Line.28. Now. you generally process two types of da data – (i) Textual Character St S like 'Hello'. Explain the different USAGEs in COBOL.'RAM MUMBAI'. In the picture. the Compile Listing.line(VERB). Hex-address of the COBOL Verb from the origin of the Program(HE address Hex-address 440 lies between Line# 33 ADD and Line# 34 DISPLAY Instructions address implies. the COBOL storage area WS TEXT stores the Textual String-dat WS-TEXT String 'HELLO' and the COBOL Storage Area WS NUMBER stores the Number 67542.'1000. The Memory Space calculation – how much storage space. you can use the Data Division is.00' and (ii) Numeric Data that is used in arithmetic computations such as 1456. at which the Program fail fai some error. 3 bytes. We need to establish wher whe fields are located in the Memory. The abending COBOL Instruction is ADD +1 TO WS-NUMBER WS-NUMBER is populated from NUMBER-IN of the file. –123. The qu L WS-NUMBER q is to tell. To do this. the ADD instruction was last instruction. how much . Clause In COBOL. how much space in bytes does WS TEXT and WS-NUMBER occupy in th WS-TEXT WS Memory? . a COBOL Variable occu occ 1 byte. 2 bytes.is done by looking at the USAGE Clause. 36.

no USAGE Clause has been sp When no explicit-usage is mentioned. So. computationally storing Integer-data in COBOL. "I want the data to be stored in DISPLAY Format. 'HELLO' occupies 5 byt 67542 also occupies 5 Bytes. 2) COMP : Whilst DISPLAY Format is easy easy-to-use. In other words. 67542 is stored as 000 . the num acter character '1' is not the same as numeric Digit 1. which is used in arithmetic arithmetic-Computations. it defaults to DISPLAY Format. The character 'E' is stored as 1100 0101 or x'C5'. In EBCDIC System. when Format.1) USAGE IS DISPLAY : In the above declaration. by writin IS DISPLAY Clause." What’s DISPLAY Format? When you store data in DISPLAY Format. This way each character is i in 1 byte – simple – stored as it is DISPLAY'ed. For example. The represented as 1101 0101 or x'D3'. Note that. as it is DISPLAYed – 1 DISPLAY character. represented on the Mainframe Computer. find out what is the Bi B equivalent for the Decimal number 67542. In EBCDIC System. The COMPUTATIONAL or COMP format. when store data like 'HELLO' or 67542 on a Mainframe. This is how it looks. stores store entire-Number in pure-binary Format. yo store them in COMPUTATIONAL Format. the character 'H' is represent represented x'C8'. x'F1' character '2' is stored as 1111 0010 or x'f2' and so on. when numeric data like 67542 stored in DISPLAY-Format. it is not very computationally-efficient. You can usage tell explicitly. the numeric-character '1' is stored as 1111 0001 or x'F1'. So. 'O' is stored as 1101 0110 the data is st Byte for each as 1100 0100 character 'L' or x'D6'.

Its packing-density is very good. COMP-3 What’s BCD? The idea stems from the fact that. This is how 67542 looks. This occupies 8 Bytes. As opposed to this if you store the number numbe 12345678 in PIC 9(08) COMP. COMP 3 Format stores the ce. This occupies 4 bytes only. packing-ability or compressio packing Format can pack upto 2 digits digit number as BCD(Binary Coded De D to store any numeric numeric-digit(fr . say you are storing the number 12345678 in PIC 9(08).0000 0001 0000 0111 1101 0110 or x'000107D6'. just 4-Bytes. it occupies far lesser space. you can tell how much storage space a COMP COMP-Va will occupy. By looking at the below chart. Now. COMP-3 density single-byte of space. He how you store 67542 in COMP COMP-Format. on a computer you just need half half-byte(nibble). 3) COMP-3 – COMP-3 Format provides the maximum 3 data. when you store it in WS NUMBER COBOL Variable – WS-NUMBER a PIC 9(05) COMP.

COMP-1 is Single-precision Floating Point F precision It always occupies 4 Bytes.What’s the BCD for 67542? Here’s how you calculate it. 6 7 5 4 2 0000 0110 0111 0101 0100 0010 (3-Bytes) When 67542 is stored in COMP-3 Format. it occupies even lesser space – just . . how you code it in COBOL - This is how 67542 would look. COMP COMP-2 is Double-precision Floating Point Format precision Forma 2 occupies 8 Bytes. Look Look-up the Binary-c each digit of the number separately. Numbers). What is COMP-1 and COMP 1 COMP-2? COMP-1 and COMP-2 Formats are meant for storing numbers with a Decimal Poin Numbers(Floating-Pt. when you store it COMP 3 Format. COMP Pt. Bytes. Here’s. COMP-3 37.

This is because. How many bytes does PIC S9(07) occupy? PIC S9(07) would occupy 7 bytes of storage space. The below picture shows. on Mainfram Mainfra reading data from a word boundary is computationally efficient. how +67542 and –67542 looks. since two digits can be packed into one by 3 byte. word-boundary 42. 3 . the sign is stored in the last nibble. How is Sign stored in a COMP COMP-3 Field? In the COMP-3 Format. How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ? S9(07) SIGN TRAILING SEPARATE Field occupies 8 bytes(1 extra byte for the si s 41. 39. In general. 40. Positive numbe 3 contain 1100 or x'C' in the Last nibble. Negative numbers contain 1101 or x' x the last nibble. How many bytes does S9(07) COMP COMP-3 occupy? In COMP-3 Format. the space occupied by a PIC 9(n) COMP COMP-3 Var is (n+1)/2. What is COMP SYNC? SYNC Keyword is used in COBOL to align the data(storage data(storage-area) to a WordBoundary(Any address which is a multiple of 4). 7 digits ca packed into 4 bytes. when +67542 in the COMP-3 Format.38.

Sign up to vote on this title
UsefulNot useful