cobol good interview questions: ques1: Can we reverse the string in cobol? ans1: IDENTIFICATION DIVISION. PROGRAM-ID.

MID. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 STR1 PIC X(7) VALUE IS 'MANOJ'. 01 STR2 PIC X(1). 01 STR3 PIC X(7) VALUE SPACE. *01 STR4 PIC X(7). 01 STRLEN PIC 9(1). 01 CTR1 PIC 9(1) VALUE IS 1. PROCEDURE DIVISION. INSPECT STR1 TALLYING STRLEN FOR CHARACTERS. DISPLAY STRLEN. PERFORM UNTIL STRLEN < 1 MOVE STR1(STRLEN:1) TO STR2 DISPLAY STR2 STRING STR3 DELIMITED BY SPACE STR2 DELIMITED BY SPACE INTO STR3 COMPUTE STRLEN = STRLEN - 1 DISPLAY STR3 END-PERFORM. DISPLAY STR3. STOP RUN. or 01 name pic x(4). 01 rname pic x(4). move name(1:1) to rname(4:1). move name(2:1) to rname(3:1). move name(3:1) to rname(2:1). move name(4:1) to rname(1:1). ques2:Where do use LOW-VALUE and HIGH-VALUE in COBOL. Also explain which kind of values they represent? ans2:One of the use cases of HIGH-VALUE and LOW-VALUE are in the Binary Search u sing SEARCH ALL. If the table to be searched is only partially populated, the SE ARCH ALL may not work correctly. If the table is ordered in ascending sequence t hen, to get the SEARCH ALL to function correctly, the unpopulated elements must be filled with HIGH-VALUES. If the table is in descending sequence, the unpopula ted elements should be filled with LOW-VALUES. and LOW-VALUE represents X'00' and HIGH-VALUE represents X'FF'. These equate to the

xsum /* Using JCL : Step 1: using pgm SORT.d. Say you wanted to know who had the highest and lowest sales for the month. Suggest the an swer using COBOL as well as through JCL.file3. sort and merge the two files SORTIN DD file 1 (i/p file 1) SORTIN DD file 2 (i/p file 2) SORTOUT DD file 3 (o/p file containing the sorted and merged recs o f both the i/p files) Step 2: Using SUM FIELDS = NONE. .file2. ans3://sortin dd dsn=a. cod e the logic for eliminating the duplicates and writing them in to an output file . There are many uses. Many people have specific "first time code" to read the first re cord and move the sales amount to the HIGH-SALE and LOW-SALE fields. and 05 LOW-SALE PIC X(5) VALUE HIGH-VALUES.dsn=old //sysin dd * sort fields=(1. All other values fall in betw een. These 2 files contains some common (duplicate) records.ch. Define the fields as 05 HIGH-SALE PIC X(5) VALUE LOW-VALUES. How do you copy these common (matching) records into third file.STOPAFT=49 then copy the rest of the records starting from 51 to another file SORT FIELDS=COPY.b.3.a) sum fields=none.XSUM : the duplicates will be eliminated and wri tten in to the file defined in the SORTXSUM DD step Using COBOL : Use the MERGE verb along with the OUTPUT PROCEDURE. In the OUTPUT PROCEDURE.lower and upper limits of the collating sequence.dsn=shr //sortout dd dsn=a.b.dsn=shr // dd dsn=a. ques4:How do you delete specific record using COBOL? ans4:You can use SORT: copy first 49 record to a file SORT FIELDS=COPY.SKIPREC=50 then concatinate them to output file.file1. Then simply compare the input sales amount to HIGH-SALE and LOW-SALE and move it to HIGH-SALE when it is higher than the current value and to LOW-SALE when it i s lower than the current value ques3:There are 2 files.

ie. it is a half-word (2 bytes). INSPECT can be used with CONVERTI NG. eg: INSPECT WS-A TALLYING WS-COUNT FOR ALL $ REPLACING ALL $ BY * To convert all uppercase letters to lowercase. You will get file status 39 on an OPEN. ques7:What is difference between comp & comp-4? ans7: For all of you out who have not heard about comp-4. eg: INSPECT WS-NAME CONVERTING ABCDEFGHIJKLMNOPQRSTUVWXYZ TO abcdefghijklmnopqrstuvwxyz ques6:what is file status 39 in cobol? ans6:Mismatch in LRECL or BLOCKSIZE or RECFM between your COBOL pgm & the JCL (o r the dataset label). Comp-4 does exist a nd it is just like comp . 5 to 9= 4 bytes 10 to 18 = 8 bytes single word 4 bytes double word 8 bytes (use n/2 +1) where n=length of field half word same as COMP ques8:difference between include and copy? ques9:skip alternate records? ans9:Read input file If not End-of-file Add 1 to ws-counter If ws-counter = 2 write record to output file move 0 to ws-counter . TALLYING and REPLACING can be used together as well. eg: INSPECT WS-B REPLACING LEADING BY 0 With INSPECT. This might help those of you who are confused about comp fields: COMP COMP-1 COMP-2 COMP-3 COMP-4 half word 1 to 4 = 2bytes. But this doesnt work for all versions of COBOL.ques5:What is inspect in COBOL ? ans5:INSPECT is used with TALLYING option to count designated characters. Wake up. eg: INSPECT WS-A TALLYING WS-COUNT FOR ALL $ INSPECT is used with REPLACING option to change designated characters.

but i want to output having 1. the pros and cons.THERE ARE 7 SECTION FOR DATA DIVISION: 1. 7.6:11.35) /* // ques11:Explain the difference between an internal and an external sort.7 fields only.5.OUTREC=(1:1.LOCAL STORAGE SECTION.D).. 4. 2. assume i have 8 fields in one rec of i/p file each field length 5 bytes.5. 3.WORKING-STORAGE SECTION.11:21. see //sysin dd * sort fields=copy outrec fields=(1:1.15...length .6.ZD.starting position in o/p file:starting field in i/p file.. q&a 13: .LINKAGE SECTION.5. 5.3.REPORT SECTION.COMMUNICATION SECTION.FILE SECTION.ZD).3.SCREEN SECTION. For example if the input file contains 80 reco rd length then In sort.25.e 000100. //sysin dd * sort fields=copy outrec fields=(starting position in o/p file:starting field in i/p file.6.write records form bottom from a sequential file in cobol? ans13:It is possible through jcl. 6.80) 1) Using inrec we need to generate the sequential number starts from position 8 1.80..g.. as he ask i want 1.16:31.goback and cancel. then how can i achieve this criteria?? ans10:in sort jcl...end-if end-if end-read ques10:Reformat Output file---i have a file having 1000 records and each record having 8 fields. ques13:How to read. internal sort syntax etc? ans11: ques12:stoprun.81:SEQNUM.. INREC=(1:1. For example 1) First 1-80 bytes contains the actual record and from position 81 w e need to generate sequential number using inrec i. 000200 upto 50 reco .length.SORT FIELDS=(81.) /* // e.7 fields only..

3) Using outrec we have to move the first 80 bytes to the output file . you can read the output file in seco nd step and write it in the output file generated in second step. sort we takes place in descend ing order. ques14: .rds. After doing this sort in first step in jcl. 2) After generating all those numbers.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.