Add to Favorites    Make Home Page 12907 Online  
 Language Categories  
 Our Services  
 FAQs Home  


COBOL FAQs -- Part V

Home -- FAQs Home

A D V E R T I S E M E N T

Search Projects & Source Codes:

1. What is the difference between a binary search and a sequential search? What are the pertinent COBOL commands?

Ans: In a binary search the table element key values must be in ascending or descending sequence. The table is 'halved' to search for equal to, greater than or less than conditions until the element is found. In a sequential search the table is searched from top to bottom, so (ironically) the elements do not have to be in a specific sequence. The binary search is much faster for larger tables, While sequential Search works well with smaller ones. SEARCH ALL is used for binary searches; SEARCH for sequential.

2. How do you sort in a COBOL program? Give sort file definition, sort statement syntax and meaning.

Ans: Syntax:

SORT file-1 ON ASCENDING/DESCENDING KEY key.

USING file-2

GIVING file-3.

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.

file-1 is the sort workfile and must be described using SD entry in FILE SECTION.

file-2 is the input file for the SORT and must be described using an FD entry in FILE SECTION and SELECT clause in FILE CONTROL.

file-3 is the outfile from the SORT and must be described using an FD entry in FILE SECTION and SELECT clause in FILE CONTROL.

file-1, file-2 & file-3 should not be opened explicitly.

INPUT PROCEDURE is executed before the sort and records must be Released to the sort work file from the input procedure.

OUTPUT PROCEDURE is executed after all records have been sorted. Records from the sort work file must be Returned one at a time to the output procedure.

3. How do you define a sort file in JCL that runs the COBOL program?

Ans: Use the SORTWK01, SORTWK02,..... did names in the step. Number of sort datasets depends on the volume of data being sorted, but a minimum of 3 is required.

4. Explain the difference between an internal and an external sort. The pros & cons & internal sort syntax .?

Ans: An external sort is not coded as a COBOL program; it is performed through JCL and PGM=SORT. One can use IBM utility SYNCSORT for external sort process. It is understandable without any code reference. An internal sort can use two different syntaxes: 1.) USING, GIVING sorts are comparable to external sorts with no extra file processing; 2) INPUT PROCEDURE, OUTPUT PROCEDURE sorts allow for data manipulation before and/or after the sort.

5. What is the difference between performing a SECTION and a PARAGRAPH?

Ans: Performing a SECTION will cause all the paragraphs that are part of the section, to be performed. Performing a PARAGRAPH will cause only that paragraph to be performed.

6. What is the use of EVALUATE statement?

Ans: Evaluate is like a case statement and can be used to replace nested Ifs. The difference between EVALUATE and case is that no ‘break’ is required for EVALUATE i.e. control comes out of the EVALUATE as soon as one match is made.

7. What is the difference between PERFORM ... WITH TEST AFTER and PERFORM ... WITH TEST BEFORE?

Ans: If TEST BEFORE is specified, the condition is tested at the beginning of each repeated execution of the specified PERFORM range. If TEST AFTER is specified, the condition is tested at the end of the each repeated execution of the PERFORM range. With TEST AFTER, the range is executed at least once.

8. Which is the default, TEST BEFORE or TEST AFTER for a PERFORM statement?

Ans: TEST BEFORE

9. How do you code an in-line PERFORM?

Ans: PERFORM ... ... END-PERFORM.

10. When would you use in-line perform?

Ans: When the body of the perform will not be used in other paragraphs. If the body of the perform is a generic type of code (used from various other places in the program), it would be better to put the code in a separate Para and use PERFORM paraname rather than in-line perform.

11. In an EVALUTE statement is the order of the WHEN clauses significant?

Ans: Yes , evaluation of the when clause proceeds from top to bottom

12. How do you come out of an EVALUATE statement?

Ans: After the execution of one of the when clauses, the control is automatically passed on to the next sentence after the EVALUATE statement. There is no need of any extra code.

13. What is the default value(s) for an INITIALIZE and what keyword allows for an override of the default.

Ans: INITIALIZE sets spaces to alphabetic and alphanumeric fields. Initialize sets Zeroes to numeric fields. FILLER, OCCURS DEPENDING ON items are left untouched. The REPLACING option can be used to override these defaults.

14. What is SET TO TRUE all about, anyway?

Ans: In COBOL II the 88 levels can be set rather than moving their associated values to the related data item.

15. What is LENGTH in COBOL II?

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

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

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

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

19.

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.

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

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

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

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

Ans: No

24. Can I redefine an X(100) field with a field of X(200)?

Ans: Yes. Redefines just causes both fields to start at the same location. For example:01 WS-TOP PIC X(1)

01 WS-TOP-RED REDEFINES WS-TOP PIC X(2).

If you MOVE ‘12’ to WS-TOP-RED,

DISPLAY WS-TOP will show 1 while

DISPLAY WS-TOP-RED will show 12.

25. 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).

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

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

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

Ans: I-O mode

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

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

31. 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?

Ans: Use START

START filename KEY IS EQ/GT/LT.. dataname

INVALID KEY ...

32. What are the access mode requirements of START statement?

Ans: Access mode must be SEQUENTIAL or DYNAMIC.

33. What is the LINKAGE SECTION used for?

Ans: 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.

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

Ans: It's not 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.

35. What is the difference between a subscript and an index in a table definition?

Ans: 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 decrement 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.

36. What is the difference between comp and comp-3 usage? Explain other COBOL usages.

Ans: Comp is a binary usage, while comp-3 indicates 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.'

37. What is COMP-1? COMP-2?

Ans: COMP-1 - Single precision floating point. Uses 4 bytes.

COMP-2 - Double precision floating point. Uses 8 bytes.

38. How do you define a variable of COMP-1? COMP-2?

Ans: No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.

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

Ans: 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.

40. How many bytes does a S9(7) SIGN trailing separate field occupy ?

Ans: Will occupy 8 bytes (one extra byte for sign).

41. What is the maximum value that can be stored in S9(8) COMP?

Ans: 99999999

42. What is COMP SYNC?

Ans: Causes the item to be aligned on natural boundaries. Can be SYNCHRONIZED LEFT or RIGHT. For binary data items, the address resolution is faster if they are located at word boundaries in the memory. For example, on main frame the memory word size is 4 bytes. This 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. You might see some wastage of memory, but the access to this computational field is faster.

43. What is the maximum size of a 01 level item in COBOL I? in COBOL II?

Ans: 16777215

44.What is the difference between PIC 9.99 and 9v99?

Ans: 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.

45.How is PIC 9.99 is different from PIC 9v99?

Ans: 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.

46.What does PIC 9v99 Indicate?

Ans: 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.

47. What happens when we move a comp-3 field to an edited ( say z(9).zz-)

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

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

Ans:

S0C1 - May be due to

· Missing or misspelled DD name

· Read/Write to unopened dataset

· Read to dataset opened output

· Write to dataset opened input

· Called subprogram not found.

S0C4 may be due to

· 1.Missing Select statement(during compile)

· Bad Subscript/index

· Protection Exception

· Missing parameters on called subprogram

· Read/Write to unopened file

· Move data from/to unopened file.

S0C5 May be due to

· Bad Subscript/index

· Close an unopen dataset

· Bad exit from a perform

· Access to I/O area(FD) before read.

S0C7 may be due to

· Numeric operation on non-numeric data

· Un-initialize working-storage

· Coding past the maximum allowed sub script.

49. What is the difference between an External and a Global Variable 's?

Ans: Global variables are accessible only to the batch program whereas external variables can be referenced from any batch program residing in the same system library.

50. What is PSB & ACB?

Ans: PSB : Program specification block. Inform about how a specific program is to be access one or more IMS DB. It consists of PCB(Prg Communication Block). Information to which segment in DB can be accessed, what the program is allowed to do with those segment and how the DB is to be accessed.

ACB : Access Control Blocks are generated by IMS as an expansion of information contained in the PSB in order to speed up the access to the applicable DBD's.

51. What's a LDS(Linear Data Set) and what's it used for ?

Ans: LDS is a VSAM dataset in name only. It has unstructured 4k (4096 bytes) fixed size CIs which do not contain control fields and therefore from VSAM's standpoint they do not contain any logical records. There is no freespace, and no access from Cobol. Can be accessed by DB2 and IMS fast path datasets. LDS is essentially a table of data maintained on disk. The 'table entries' must be created via a user program and can only be logically accessed via a user program. When passed, the entire LDS must be mapped into storage, then data is accessed via base and displacement type processing.

52. What is the Importance of GLOBAL clause According to new standards of COBOL

Ans: When any data name, file-name , Record-name, condition name or Index defined in an Including Program can be referenced by a directly or indirectly in an included program, Provided the said name has been declared to be a global name by GLOBAL Format of Global Clause is01 data-1 PIC 9(5) IS GLOBAL.

53. What is the Purpose of POINTER Phrase in STRING command

Ans: The Purpose of POINTER phrase is to specify the leftmost position within receiving field where the first transferred character will be stored

54. How do we get currentdate from system with century?

Ans: By using Intrinsic function, FUNCTION CURRENT-DATE

55.How many Sections are there in Data Division?.

Ans: SIX SECTIONS 1.'FILE SECTION' 2.'WORKING-STORAGE SECTION' 3.'LOCAL-STORAGE SECTION' 4.'SCREEN SECTION' 5.'REPORT SECTION' 6.'LINKAGE SECTION'

In COBOL II, there are only 4 sections. 1.'FILE SECTION' 2.'WORKING-STORAGE SECTION' 3.'LOCAL-STORAGE SECTION' 4.'LINKAGE SECTION'.

56. What is the difference between a DYNAMIC and STATIC call in COBOL.?

Ans: To correct an earlier answer:All called modules cannot run standalone if they require program variables passed to them via the LINKAGE section. Dynamically called modules are those that are not bound with the calling program at link edit time (IEWL for IBM) and so are loaded from the program library (joblib or steplib) associated with the job. For DYNAMIC calling of a module the DYNAM compiler option must be chosen, else the linkage editor will not generate an executable as it will expect null address resolution of all called modules. A Statically called module is one that is bound with the calling module at link edit, and therefore becomes part of the executable load module.

57. How can I tell if a module is being called DYNAMICALLY or STATICALLY?

Ans: The ONLY way is to look at the output of the linkage editor (IEWL)or the load module itself. If the module is being called DYNAMICALLY then it will not exist in the main module, if it is being called STATICALLY then it will be seen in the load module. Calling a working storage variable, containing a program name, does not make a DYNAMIC call. This type of calling is known as IMPLICITE calling as the name of the module is implied by the contents of the working storage variable. Calling a program name literal (CALL).

FAQs Home||COBOL FAQs


A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions
Copyright ©2003-2017 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/faqs/cobol-faq-part5.asp


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review