cobol basics faq

Upload: karthikksk

Post on 03-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Cobol Basics Faq

    1/29

    COBOL FAQ

  • 7/29/2019 Cobol Basics Faq

    2/29

    Table of Contents

    Divisions.....................................................................................................................................................1Levels......................................................................................................................................................... 2Data Types.................................................................................................................................................. 4Procedure Division Commands.................................................................................................................. 6Performs...................................................................................................................................................11Usage........................................................................................................................................................ 13

    Table Handling......................................................................................................................................... 16Subscripts and Indexes............................................................................................................................. 17Sorting......................................................................................................................................................19File Handling............................................................................................................................................20Subroutines............................................................................................................................................... 21Compiler Options.....................................................................................................................................23Character Handling................................................................................................................................... 24Misc..........................................................................................................................................................26

  • 7/29/2019 Cobol Basics Faq

    3/29

    1

    Divisions

    1. What are the Different components of COBOLCharacter : Lowest component

    Word : One or more charactersClause : Words and characters specifying attribute of entryStatement : Syntactically valid combination of words and clausesSentence : Sequence of one or more statements terminated by

    periodParagraph : one or more sentencesSection : one or more paragraphsDivision : One or more paragraphs or sectionsProgram : Made up of divisions

    2. Name the divisions in a COBOL program?Identification Division : Identifies Program

    Environment Division : Defines Computer usedDefines Files

    Data Division : Describes FilesDefines Variables, Constants

    Procedure Division : Actual logic of program

    3. HOW MANY SECTIONS ARE IN DATA DIVISION?Three main sections1.FILE SECTION2.WORKING-STORAGE SECTION3.LINKAGE SECTION

  • 7/29/2019 Cobol Basics Faq

    4/29

    2

    Levels

    4. What are the different levels available in COBOL?Level Numbers available are 01-49, 66, 77, 88

    01-49 Group or elementary items66 Renames clause77 Independent elementary data items88 Condition names

    5. What is 77 level used for?Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor canthey be subdivided themselves.

    6. What is 88 level used for?88 level is used for condition names.

    The level 88 in the Data Division can be used to give condition names to the values that afield contains. A condition name entry specifies either a single value or a set of values forthe conditional variable. When this level is specified you can use the condition name insteadof is equal to in the IF statement. Condition name should be specified under Level 88immediately following the field description.

    Example:

    01 WS-MARITAL-STATUS PIC X.88 SINGLE VALUE Y.88 MARRIED VALUE N.

    01 WS-REPLY PIC X.88 REPLY-YES VALUE Y.88 REPLY-N0 VALUE N.

    01 WS-MARKS PIC 999.88 PASSED

    VALUE 40 THRU 100.88 FAILED

    VALUE 0 THRU 39.

    7. What are level 66 used for?For RENAMES clause.

    8. What is the difference between level 77 and 01? And which is more efficient?Level 77 can be used to describe independent elementary items in the Working Storage or

    Linkage Sections. Level 77 cannot use Redefines.

    Level 01 can be used to describe both elementary and group items. Any item described inLevel 01, the system is putting on Double-Word boundary and inserts slack bytes ifnecessary

    9. How many different level numbers can be used in COBOL to describe a record?01-49.

  • 7/29/2019 Cobol Basics Faq

    5/29

    3

    10. Give some advantages of REDEFINES clause.1.You can REDEFINE a Variable from one PICTURE class to another PICTURE class by usingthe same memory location. Multiple REDEFINES of same area possible2. By REDEFINES we can INITIALISE the variable in WORKING-STORAGE Section itself.3. We can REDEFINE a Single Variable into many sub-variables.

    Syntax: REDEFINES

    Example:

    01 Sales-Record.02 Sales-Type Pic X.02 Sales-By-Unit.

    03 Qty Pic 9(4).03 Unit-Price Pic 9(8)V99.

    02 Total-Sales REDEFINES Sales-By-Unit.03 Amount Pic 9(10)V99.03 Filler Pic X(2).

    11. Can I redefine an X (100) field with a field of X (200)?Yes.Redefines just cause 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 whileDISPLAY WS-TOP-RED will show 12.

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

  • 7/29/2019 Cobol Basics Faq

    6/29

    4

    Data Types

    13. What are the different data types available in COBOL?Numeric,Alphabetic ,Alpha-numeric ,

    Numeric Edited andAlphanumeric Edited.

    Symbols usedNumeric 9 P S VAlphabetic A BAlphanumeric X 9 ANumeric Edited 9 P V and at least one of the editing symbols

    B / Z 0 + - * , . CR DB $Alphanumeric Edited X 9 A B 0 /

    Example:,77 WS-MESSAGE PIC X(30).77 WS-NUMBER PIC 9999.

    14. What are the permissible character sets in COBOL?Digits 0,1,29Letters A,B,ZSpace/Blank BSpecial Symbols + - * / ( ) $ . < > =

    15. What are all the figurative constants available in COBOL?Zero, Zeroes, ZerosQuote, QuotesSpace, SpacesHigh-Value, Highest-ValueLow-Value, Lowest-ValueAll

    16. What are all the possible Editing Characters used in COBOL. Explain them withexamples?

    Numeric DataZ Zero Suppression* Asterisk$ Currency Sign- Minus Sign+ Plus SignCR DB Credit Debit SignPeriod (.)Comma ,)

  • 7/29/2019 Cobol Basics Faq

    7/29

    5

    Blank (b)Zero (0)Slash (/)Blank When Zero

    Inserts blanks when data value is zeroAlpha Numeric Data

    Blank, Zero,Slash Insertion

    Note:Mutually Exclusive PIC Clauses

    CR and DB$ + _ Z *V.

    Example:

    PIC Numeric EditedValue Value

    ZZZV99 38^4 b3840

    * * 999 00052 * * 052$ * *999 985 $**985-ZZZV99 -46^52 -b4652+999 -382 -382+999 382 +3829999+ -382 0382-ZZ,Z99 2456 b2,456ZZZZ.ZZ 0^05 bbbb.05$$$$9.99 342 b$342.0099B99B99 46 00b00b4609990 456 04560999/999/99 3254 000/032/54

    17. What is the difference between PIC 9.99 and 9v99?PIC 9.99 is a FOUR-POSITION field that actually contains a decimal point where as PIC 9v99is THREE-POSITION numeric field with implied or assumed decimal position.

    18. What is PIC 9v99 Indicates?PICTURE 9v99 is a three position Numeric field with an implied or assumed decimal pointafter the first position; the v means an implied decimal point.

    19. Can JUSTIFIED be used for all the data types?No, it can be used only with alphabetic and alphanumeric data types.

  • 7/29/2019 Cobol Basics Faq

    8/29

    6

    Procedure Division Commands

    20. Write a Sample Program in COBOLIDENTIFICATION DIVISION.

    PROGRAM-ID. SAMPLE.ENVIRONMENT DIVISION.SOURCE-COMPUTER. ES-9000.OBJECT-COMPUTER. ES-9000.DATA DIVISION.WORKING-STORAGE SECTION.77 WS-NAME PIC X(30).PROCEDURE DIVISION.MAIN-LOGIC.

    PERFORM DISPLAY-ACCEPT-PARA.STOP RUN.

    DISPLAY-ACCEPT-PARA.

    DISPLAY Enter your name:.ACCEPT WS-NAME.DISPLAY Welcome , WS-NAME.

    21. Explain the four COBOL statement categories?ImperativeConditionalCompiler DirectingExplicit Scope Terminator

    Imperative Statement

    Directs program to take specific action during execution

    ADD 1 TO A.MOVE 2 TO A.Conditional StatementDirects program to examine the truth of a condition and take subsequent action dependingon truthIF A > B

    DISPLAY A IS GREATERELSE

    DISPLAY B IS GREATEREND-IF.Compiler-directing Statement

    Directs COBOL compiler and no corresponding statement is generated for these in the objectprogram

    COPYUSE

    Explicit Scope Terminators

    Statements used to terminate the scope of a COBOL verb explicitlyEND-IFEND-PERFORM

  • 7/29/2019 Cobol Basics Faq

    9/29

    7

    What are the two types of control transfer statements?

    1. Conditional Transfer statementsBased on result of condition checkIF

    EVALUATEGOTO..DEPENDING ON2. Unconditional Transfer

    PERFORMGOTO

    22. Explain the Syntax and Usage of GOTO DEPENDING ON STATEMENT?Syntax:GOTO Procedure-Name-1

    [Procedure-Name-2]Procedure-Name-N

    DEPENDING ON Identifier

    Control transferred depending on value of identifierIdentifier must be numeric,integral elementary itemControl transferred to next statement if value of identifier is not in range specified

    Example:

    GOTO RECEIPT-PARA,ISSUE-PARA,ADJUSTMENT-PARA

    DEPENDING ON TRAN-TYPE.Equivalent toIF TRAN-TYPE = 1

    GOTO RECEIPT-PARA.

    IF TRAN-TYPE = 2GOTO ISSUE-PARA.

    IF TRAN-TYPE = 3GOTO ADJUSTMENT-PARA.

    23. Give the syntax for ADD/SUBTRACT STATEMENTS?ADD

    [CORRESPONDING][Identifier-1 / Literal-1] [Identifier-2 / Literal-2][TO / GIVING] Identifier-3, Identifier-4, ...

    SUBTRACT[CORR][Identifier-1 / Literal-1] [Identifier-2 / Literal-2][FROM / GIVING] Identifier-3, iodentifier-4, ...

  • 7/29/2019 Cobol Basics Faq

    10/29

    8

    24. Give the syntax for MULTIPLY AND DIVIDE STATEMENTS?MULTIPLY

    {Identifier-1 BY Identifier-2

    [ , Identifier-3]... Literal - 1}[GIVING Identifier-4 [ , Identifier-5]...]DIVIDE {Identifier-1 / Literal-1}

    INTO[BY] Identifier-2 { ,Identifier-3}....[GIVING Identifier-4 [ ,Identifier-5]...][REMAINDER Identifier-6].

    25. Explain the applications of ROUNDED VERB in COBOL?Rounded clause could be used to get the output rounded to specified sizeApplicable only for receiving fieldsCannot be specified after Remainder

    E.g.,ADD A B GIVING C ROUNDED.

    26. Explain the applications of ON SIZE ERROR in COBOL?If after an arithmetic operation, the result exceeds the largest value that can beaccommodated in the result field, the error is called a size error. Programmers can controlSize Error in any arithmetic statement using this phrase.E.g.,

    ADD A TO B ON SIZE ERRORGO TO ERROR-PARA.

    27. Give the Syntax for COMPUTE VERB?COMPUTE {Identifier-1 [ROUNDED]}

    [Identifier-2 [ROUNDED]]Arithmetic Expression[ON SIZE ERRORImperative Statement]

    28. What is the use of EVALUATE statement? -Evaluate is like a case statement and can be used to replace nested Ifs. The differencebetween EVALUATE and case is that no break is required for EVALUATE i.e. control comesout of the EVALUATE as soon as one match is made.

    29. What are the different forms of EVALUATE statement? Give the Syntax andExample

    Syntax:

    EVALUATE Subject-1 [ALSO Subject-2]...{WHEN Object-1 [ALSO Object-2]....{Imperative-Statement1}...}{WHEN OTHER{Imperative-Statement2}...]

    [END-EVALUATE.]

  • 7/29/2019 Cobol Basics Faq

    11/29

    9

    Example:EVALUATE TRUE

    WHEN MONTH = 4 OR 6 OR 9 OR 11

    MOVE 30 TO NO-OF-DAYSWHEN MONTH = 2

    MOVE 28 TO NO-OF-DAYSWHEN OTHER

    MOVE 31 TO NO-OF-DAYSEND-EVALUATE.

    EVALUATE PRODUCT-TYPE ALSO CUSTOMER-TYPEWHEN 1 ALSO ANY

    MOVE 0 TO COMMISSIONWHEN 2 ALSO 1 THRU 5

    MOVE 10 TO COMMISSIONWHEN 3 ALSO 1 THRU 5

    MOVE 5 TO COMMISSIONWHEN OTHER

    MOVE 20 TO COMMISSIONEND-EVALUATE.

    30. How do you come out of an EVALUATE statement? -After the execution of one of the when clauses, the control is automatically passed on to thenext sentence after the EVALUATE statement. There is no need of any extra code.

    31. In an EVALUATE statement, can I give a complex condition on a when clause?Yes.

    32. What is a scope terminator? Give examples.Scope terminator is used to mark the end of a verb e.g. EVALUATE, END-EVALUATE; IF,END-IF.

    33. What does the INITIALIZE verb does?Alphabetic, Alphanumeric fields & alphanumeric edited items are set to SPACES.Numeric, Numeric edited items set to ZERO. FILLER and OCCURS DEPENDING ON items leftuntouched.

    34. What does the IS NUMERIC clause establish?IS NUMERIC can be used on alphanumeric items, signed numeric & packed decimal itemsand unsigned numeric & packed decimal items. IS NUMERIC returns TRUE if the item onlyconsists of 0-9. However, if the item being tested is a signed item, then it may contain 0-9,+ and -.

  • 7/29/2019 Cobol Basics Faq

    12/29

    10

    35. What are all the arithmetic Verbs and Arithmetic Operations?Arithmetic Verbs

    AddSubtract

    MultiplyDivideCompute

    ARITHMETIC OPERATORS

    Addition +Subtraction -Multiplication *Division /Exponentiation **HIERARCHY( ) ** * OR / + OR - From Left to Right

    36. What is difference between next sentence and continue?CONTINUE is like a null statement (do nothing), while NEXT SENTENCE transfers control tothe next sentence. (A sentence is terminated by a period)

    37. What does EXIT do?Does nothing. If used, must be the only sentence within a paragraph.

  • 7/29/2019 Cobol Basics Faq

    13/29

    11

    Performs

    38. Name the different PERFORM statement?PERFORM

    PERFORM THRUPERFORM 'n' TIMESPERFORM UNTILPERFORM VARYING with UNTIL Option.

    PERFORMPERFORM [Procedure-Name-1END-PERFORM.

    PERFORM THRUPERFORM [Procedure-Name-1

    [{Thru} Procedure-Name-2]][Imperative-Statement-1END-PERFORM.]

    PERFORM 'n' TIMESPERFORM [Procedure-Name-1

    [{Thru} Procedure-Name-2]]{Identifier-1/Integer} TIMES[Imperative-Statement-1]

    END-PERFORM.]

    PERFORM UNTIL

    PERFORM [Procedure-Name-1

    [{THRU} Procedure-Name-2]][WITH TEST {BEFORE AFTER} UNTIL cond-1][Imperative-Statement-1

    END-PERFORM.]E.g.,PERFORM COUNT-PARA

    WITH TEST AFTERUNTIL WS-COUNT > 10.

    39. How do you do in-line PERFORM? -PERFORM ... ...

    END PERFORM

    40. When would you use in-line perform?When the body of the perform will not be used in other paragraphs. If the body of theperform is a generic type of code (used from various other places in the program), it wouldbe better to put the code in a separate PARA and use PERFORM para-name rather than in-line perform.

  • 7/29/2019 Cobol Basics Faq

    14/29

    12

    41. Read the following code and tell how many times will B-PARA be executed ?01 ws-n pic 9(2) value zero.

    a-paraMove 5 to ws-n.perform b-para ws-n times.

    B-PARA.move 10 to ws-n.

    5 times only. it will not take the value 10 that is initialised inthe loop.

  • 7/29/2019 Cobol Basics Faq

    15/29

    13

    Usage

    42. How many different data USAGEs can be used in COBOL?DISPLAY, COMP, COMP-3, INDEX, POINTER.

    43. Explain the USAGE of COMP/COMP1/COMP2/COMP3USAGE COMPMaintained in binaryOnly integral numbersDepending on the size of the data item, stored either in half word or full wordShould be numeric only

    PIC Length in bytes1 TO 4 25 TO 9 410 TO 18 8

    USAGE COMP1

    One word in floating point formNumber represented in hexadecimalPicture clause cannot be specifiedSuitable for arithmetic operations

    COMP-2 USAGE

    Same as COMP-1 except that data represented internally in two wordsIncreases precision of the data. Picture clause cannot be specified.COMP-3 USAGE

    Internal Representation In Packed Decimal FormEach digit and sign occupy 1/2 byte

    Hexadecimal number C or F denotes positive signHexadecimal number D denotes negative sign

    44. What is a USAGE IS INDEX?USAGE IS INDEX represents an index data item which is Full-Word binary and is used tosave the value of the index. That Index Data Item can be set to the value of the Index thruthe SET statement, ex. SET WS-IND-SAVE-FLD TO ITEM-IND. Index data item is not directlyrelated to any table.

    45. PIC S9(4)COMP IS USED INSPITE OF COMP-3 WHICH OCCUPIES LESS SPACE forthis particular case and WHY?

    9(4) COMP uses only 2 bytes.9(4) COMP-3 uses 3 bytes.3 bytes is more than 2 bytes. Hence COMP is preferred over COMP-3 in this case.

    46. How to display the fields whose usage is COMP?When we try to display a data item with usage as computational it does not give the desireddisplay format because the data item is stored as packed decimal. So if we want thisparticular data item to be displayed, we have to move it into a data item whose usage isdisplay and then have that particular data item edited in the format desired.

  • 7/29/2019 Cobol Basics Faq

    16/29

    14

    47. What is the maximum length of a field you can define using COMP-3?10 Bytes (S9(18) COMP-3).

    48. How is sign stored in Packed Decimal fields and Zoned Decimal fields?Packed Decimal fields: Sign is stored as a hex value in the last nibble (4 bits ) of the

    storage.Zoned Decimal fields: As a default, sign is over punched with the numeric value storedin the last bite.

    49. How is sign stored in a comp-3 field? -It is stored in the last nibble. For example if your number is +100, it stores hex 0C in thelast byte, hex 1C if your number is 101, hex 2C if your number is 102, hex 1D if the numberis -101, hex 2D if the number is -102 etc...

    50. How is sign stored in a COMP field ? -In the most significant bit. Bit is on if -ve, off if +ve.

    51. What is the difference between COMP & COMP-3 ?COMP is a binary storage format while COMP-3 is packed decimal format.

    52. How do you define a variable of COMP-1? COMP-2?No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.

    53. How many bytes does a S9(7) COMP-3 field occupy ?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.

    54. How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ?Will occupy 8 bytes (one extra byte for sign).

    55. How many bytes will a S9(8) COMP field occupy ?4 bytes.

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

    57. What is the maximum size of a 01 level item in COBOL I? in COBOL II?In COBOL II: 16777215

    58. What is COMP SYNC?Causes the item to be aligned on natural boundaries. Can be SYNCHRONIZED LEFT orRIGHT.For binary data items, the address resolution is faster if they are located at word boundariesin the memory. For example, on main frame the memory word size is 4 bytes. This meansthat each word will start from an address divisible by 4. If my first variable is x(3) and next

  • 7/29/2019 Cobol Basics Faq

    17/29

    15

    one is s9(4) comp, then if you do not specify the SYNC clause, S9(4) COMP will start frombyte 3 ( assuming that it starts from 0 ). If you specify SYNC, then the binary data item willstart from address 4. You might see some wastage of memory, but the access to thiscomputational field is faster.

    59. Explain the usage of SIGN CLAUSE?[SIGN IS] [LEADING] [SEPARATE CHAR ] [TRAILING]

    Specifies position and mode of representationPicture string should contain SAny input field for negative value should contain SEPARATE CHAROnly for numeric elementary items Usage should be DISPLAYDefault TRAILING without separate character

    PIC VALUE SIGN REPRESENTATIONS9(3) -243 LEADING K 4 3S9(3) -243 TRAILING 2 4 L

  • 7/29/2019 Cobol Basics Faq

    18/29

    16

    Table Handling

    60. Why occurs can not be used in 01 level?Occurs clause is there to repeat fields with same format, not the records.

    61. What is the maximum number of dimensions that an array can have in COBOL?.SEVEN in COBOL - 85 and THREE in COBOL - 84

    62. How do you define a table/array in COBOL?01 ARRAYS.05 ARRAY1 pic X(9) OCCURS 10 TIMES.05 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX.

  • 7/29/2019 Cobol Basics Faq

    19/29

    17

    Subscripts and Indexes

    63. What is a subscript?Subscript represents occurrence # of the Table Entry. Subscript can be represented explicitlyand implicitly. Explicitly means thru occurrence # of the table entry; implicitly means thru adata name. That data name should be defined as an independent item in the Working-Storage Section. The most efficient definition of Subscript is Full-Word binary.

    64. What is an index?Index is assigned to specific table thru INDEXED BY clause. Internally is represented byIndex register, which is Full-Word binary. Specific index name can be used to reference afield from the table to which that index is assigned to index represents displacement valueof the table entry from the beginning of the table.

    65. What is the difference between Subscript and Index?Index represent displacement value of the table entry from the beginning of the table,subscript - occurrence # of the table entry. To calculate the displacement of the table entryfrom its beginning when subscript is used takes 16 additional instructions from the systembecause of that the usage of the index is more efficient.An index can only be modified using PERFORM, SEARCH & SET.Need to have index for a table in order to use SEARCH, SEARCH ALL.

    66. What are the different ways of an internal table search?a. Sequential Search statement. (SEARCH)b. Binary search statement. (SEARCH ALL)

    67. What is the difference between SEARCH and SEARCH ALL?Serial search (SEARCH) examines each table entry starting at the beginning, whereas abinary search (SEARCH ALL) starts looking at the mid-point of the table and works its waytoward the argument depending upon if its too high or too low. A serial search can be usedfor unsorted tables, while a binary search is only useful if the tables are sorted.

    SEARCH ALL is more efficient for tables larger than 70 items.

    68. What should be the sorting order for SEARCH ALL? -It can be either ASCENDING or DESCENDING. ASCENDING is default. If you want thesearch to be done on an array sorted in descending order, then while defining the array, you

    should give DESCENDING KEY clause. (You must load the table in the specified order).

    69. What is binary search?Search on a sorted array. Compare the item to be searched with the item at the middle. Ifit matches, fine else repeat the process with the left half or the right half depending onwhere the item lies.

  • 7/29/2019 Cobol Basics Faq

    20/29

    18

    70. My program has an array defined to have 10 items. Due to a bug, I find that evenif the program access the 11th item in this array, the program does not ABEND.What is wrong with it?

    Must use compiler option SSRANGE if you want array bounds checking. Default isNOSSRANGE.

    71. How to change the value of an index in a COBOL programs?A SET statement.

  • 7/29/2019 Cobol Basics Faq

    21/29

    19

    Sorting

    72. What is the different types of sorting available?Internal sort and external sort.

    73. How do you sort in a COBOL program? Give sort file definition, sort statementsyntax and meaning. -

    Syntax:

    SORT file-1 ON ASCENDING/DESCENDING KEY....USING file-2GIVING file-3.

    USING can be substituted by INPUT PROCEDURE IS para-1 THRU para-2GIVING can be substituted by OUTPUT PROCEDURE IS para-1 THRU para-2.

    file-1 is the sort work-file 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 FILESECTION and SELECT clause in FILE CONTROL.file-3 is the out-file from the SORT and must be described using an FD entry in FILESECTION 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 sortwork file from the input procedure.OUTPUT PROCEDURE is executed after all records have been sorted. Records from the sortwork file must be RETURNed one at a time to the output procedure.

    74. How do you define a sort file in JCL that runs the COBOL program?Use the SORTWK01, SORTWK02,..... DD names in the step. Number of sort Datasetsdepends on the volume of data being sorted, but a minimum of 3 is required.

    75. What is the difference between performing a SECTION and a PARAGRAPH? -Performing a SECTION will cause all the paragraphs that are part of the section, to beperformed.Performing a PARAGRAPH will cause only that paragraph to be performed.

  • 7/29/2019 Cobol Basics Faq

    22/29

    20

    File Handling

    76. How do you reference the following file formats from COBOL programs:Fixed Block File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS F,

    BLOCK CONTAINS 0 .Fixed Unblocked - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS F,do not use BLOCK CONTAINS

    Variable Block File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS V,BLOCK CONTAINS 0. Do not code the 4 bytes for record length in FD i.e. JCL REC length willbe max rec. length in pgm + 4

    Variable Unblocked - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS V,do not use BLOCK CONTAINS. Do not code 4 bytes for record length in FD i.e. JCL reclength will be max rec length in pgm + 4.ESDS VSAM file - Use ORGANISATION IS SEQUENTIAL.KSDS VSAM file - Use ORGANISATION IS INDEXED, RECORD KEY IS, ALTERNATERECORD KEY IS

    RRDS File - Use ORGANISATION IS RELATIVE, RELATIVE KEY ISPrinter File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS F, BLOCKCONTAINS 0. (Use RECFM=FBA in JCL DCB).

    77. What are different file OPEN modes available in COBOL?INPUT,OUTPUT,I-O,EXTEND.

    78. What is the mode in which you will OPEN a file for writing? -OUTPUT, EXTEND

    79. In the JCL, how do you define the files referred to in a subroutine ?Supply the DD cards just as you would for files referred to in the main program.

    80. Can you REWRITE a record in an ESDS file? Can you DELETE a record from it?Can rewrite(record length must be same), but not delete.

    81. What is file status 92? -Logic error. e.g., a file is opened for input and an attempt is made to write to it.

    82. What is file status 39 ?Mismatch in LRECL or BLOCKSIZE or RECFM between your COBOL pgm & the JCL (or theDataset label). You will get file status 39 on an OPEN.

  • 7/29/2019 Cobol Basics Faq

    23/29

    21

    Subroutines

    83. What is the LINKAGE SECTION used for?The linkage section is used to pass data from one program to another program or to pass

    data from a PROC to a program.

    84. What is the difference between static call and dynamic call in COBOL?A statically called program is link-edited into the same load module as the calling program; astatic call is faster than a dynamic call. A static call is the preferred method if yourapplication does not require the services of the dynamic call.

    Statically called programs cannot be deleted (using CANCEL), so static calls might take moremain storage. If storage is a concern, think about using dynamic calls. Storage usage of callsdepends on whetherThe subprogram is called only a few times. Regardless of whether it iscalled, a statically called program is loaded into storage; a dynamically called program isloaded only when it is called.

    You subsequently delete the dynamically called subprogram with a CANCEL statement.

    You cannot delete a statically called program, but you can delete a dynamically calledprogram. Using a dynamic call and then a CANCEL statement to delete the dynamicallycalled program after it is no longer needed in the application (and not after each call to it)might require less storage than using a static call.

    Dynamically called modules are those that are not bound with the calling program at linkedit time (IEWL for IBM) and so are loaded from the program library (job lib or step lib)associated with the job. For DYNAMIC calling of a module the DYNAM compiler option mustbe 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 withthe calling module at link edit, and therefore becomes part of the executable load module.

    85. How can I tell if a module is being called DYNAMICALLY or STATICALLY?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 isbeing called STATICALLY then it will be seen in the load module.Calling a working storage variable, containing a program name, does not make a DYNAMICcall. This type of calling is known as IMPLICITE calling as the name of the module is impliedby the contents of the working storage variable.

    86. PGM-A calls PGM-B. What will happen when PGM-B issues STOP RUN?The control will not come back to PGM-A after the execution of PGM-B and hence PGM-B willstop abruptly.

  • 7/29/2019 Cobol Basics Faq

    24/29

    22

    87. PGM-A calls PGM-B recursively. What will happen to the Data Items declared inPGM-B?

    The status of Data Items will get changed whenever the PGM-B is called. Thus when controlleaves a subroutine, it is not likely to be in the same state in which it was entered. If the

    same sub routine is called again, it will be entered in its last used state.Note:If you want to have the subroutine in its initial state, the subroutine should be called afterhaving cancelled its current state by means of a CANCEL statement.

  • 7/29/2019 Cobol Basics Faq

    25/29

    23

    Compiler Options

    88. What compiler option would you use for dynamic linking?DYNAM.

    89. What is SSRANGE, NOSSRANGE ?These are compiler options wrt subscript out of range checking. NOSSRANGE is the defaultand if chosen, no run time error will be flagged if your index or subscript goes out of thepermissible range.

    90. What care has to be taken to force program to execute above 16-MB line?Make sure that link option is AMODE=31 and RMODE = ANY.Compile option should never have SIZE(MAX).BUFSIZE can be 2K, efficient enough.

    91. What are AMODE and RMODE? What is AMODE(24), AMODE(31), RMODE(24) andRMODE(ANY)? What do 24 or 31 mean to it? ( applicable to only MVS/ESAEnterprise Server).

    Addressing Mode/Access ModeAMODE(24) indicates 24-bit (three-byte) addressing - memory below the line.AMODE(31) indicates 31-bit addressing - memory above and below the line.AMODE=ANY indicates the program may use either of the addressing technique.

    Run Mode/Residency ModeRMODE(24) indicates that the program must be loaded into memory below the line. Residesin virtual storage below 16-MB line. Use this for 31 bit programs that call 24 bit programs.

    (OS/VS Cobol programs use 24 bit addresses only).

    RMODE(31) indicates that the program can be loaded either below or above the line.RMODE=ANY indicates that the program can be run in either 24 bit (below)or 31 bitmemory (above).These are compile/link edit options.

    AMODE - Addressing mode. RMODE - Residency mode.AMODE(24) - 24 bit addressing.AMODE(31) - 31 bit addressing.AMODE(ANY) - Either 24 bit or 31 bit addressing depending on RMODE.

    RMODE(24) - Resides in virtual storage below 16-MB line. Use this for 31 bit programs thatcall 24 bit programs. (OS/VS Cobol programs use 24 bit addresses only).RMODE(ANY) - Can reside above or below 16 MB line.

  • 7/29/2019 Cobol Basics Faq

    26/29

    24

    Character Handling

    92. What is the Purpose of POINTER Phrase in STRING command?The Purpose of POINTER phrase is to specify the leftmost position within receiving field

    where the first transferred character will be stored

    93. How will you move the part of character field to other character field?By Reference modificatione.g.,.To move the first 4 Chars of a variable ABC to XYZ:MOVE ABC (1:4) TO XYZ

  • 7/29/2019 Cobol Basics Faq

    27/29

    25

    Abends94. What are the causes for S0C1, S0C4, S0C5, S0C7, and S0CB ABENDs?

    S0C1 - May be due to1.Missing or misspelled DD name

    2.Read/Write to unopened DataSet3.Read to DataSet opened output4.Write to DataSet opened input5.Called subprogram not foundS0C4 - May be due to1.Missing Select statement (during compile)2.Bad Subscript/index3.Protection Exception4.Missing parameters on called subprogram5.Read/Write to unopened file6.Move data from/to unopened fileS0C5 - May be due to1.Bad Subscript/index2.Close an unopened DataSet3.Bad exit from a perform4.Access to I/O area (FD) before readS0C7 - May be due to1.Numeric operation on non-numeric data2.Un-initialize working-storage3.Coding past the maximum allowed sub scriptS0CB - May be due to1.Division by Zero

    95. What do you do to resolve SOC-7 error? -Basically you need to correct the offending data.

    Many times the reason for SOC7 is an uninitialized numeric item. Examine that possibilityfirst.

    Many installations provide you a dump for run time ABENDs ( it can be generated also bycalling some subroutines or OS services thru assembly language). These dumps providethe offset of the lastinstruction at which the ABEND occurred. Examine the compilationoutput XREF listing to get the verb and the line number of the source code at this offset.Then you can look at the source code to find the bug. To get capture the runtime dumps,you will have to define some Data Sets (SYSABOUT etc ) in the JCL.

    If none of these are helpful, use judgement and DISPLAY to localise the source of error.

    Some installation might have batch program debugging tools. Use them.

    96. What is SOC1 and SOC4?A S0C1 occurs if the CPU attempts to execute binary code that isn't a valid machineinstruction; e.g. if you attempt to execute data. A S0C4 is a memory protection violation.This occurs if a program attempts to access storage beyond the areas assigned to it.

  • 7/29/2019 Cobol Basics Faq

    28/29

    26

    Misc.

    97. What is the Structured programming and how do you identify it?The difference between regular programming approach and structured programming is that

    structured programs get rid of GO TO statements and the whole programs can berepresented in a Top-Down design. This design is possible because of existence of 3 basicstructures:

    a. Sequence Structure: Within sequence structure all functions are executed in their physicalorder. The structure has one entry point and one exit point.

    b. Selection Structure: Within selection structure execution of the function depends onwhether conditions true or false. The structure has one entry point and one exit point.

    c. Iteration Structure: Within iteration structure the execution of the function will bereiterated over and over again until condition becomes true. The structure has one entry

    point and one exit point. All these structures have one entry point and one exit point.Because of this if the programs is written by using only these structures, the wholeprograms will have one entry point and one exit point.

    98. What are advantages of Structured Programming?The programs gets rid of GO TO statements and is represented by Top-Down Structurewhich is visible and easy to understand, because the programs has a specific (hierarchical)structure, it is easy to debug the programs.

    99. What is the difference between Structured Cobol Programming and ObjectOriented COBOL programming?

    Structured programming is a logical way of programming; you divide the functionalities intomodules and code logically. OOP is a Natural way of programming; you identify the objectsfirst, and then write functions, procedures around the objects.

    100. What will happen if you code GO BACK instead of STOPRUN in a stand alone COBOL program i.e. a program, which is not calling any otherprogram. Both give the same results when a program is not calling any other program.

    101. How can you submit a job from COBOL programs?Write JCL cards to a DataSet with//xxxxxxx SYSOUT=(A,INTRDR) where A is output class, and DataSet should be opened foroutput in the program. Define a 80 byte record layout for the file.

    102. What is difference between COBOL and VS COBOL II?.OS/VS Cobol pgms can only run in 24 bit addressing mode, VS Cobol II pgms can run eitherin 24 bit or 31 bit addressing modes.Report writer is supported only in OS/VS Cobol.

  • 7/29/2019 Cobol Basics Faq

    29/29

    USAGE IS POINTER is supported only in VS COBOL II.Reference modification e.g.: WS-VAR(1:2) is supported only in VS COBOL II.EVALUATE is supported only in VS COBOL II.Scope terminators are supported only in VS COBOL II.OS/VS Cobol follows ANSI 74 stds while VS COBOL II follows ANSI 85 stds.Under CICS Calls between VS COBOL II programs are supported.

    Note: In using COBOL on PC we have only flat files and the programs can access onlylimited storage, whereas in VS COBOL II on M/F the programs can access up-to 16MB or2GB depending on the addressing and can use VSAM files to make I/O operations faster.

    103. Can you call an OS VS COBOL pgm from a VS COBOL II pgm ?In non-CICS environment, it is possible. In CICS, this is not possible.

    104. What's a LDS(Linear Data Set) and what's it used for ?(VSAM)LDS is a VSAM DataSet in name only. It has unstructured 4k (4096 bytes) fixed size CIswhich 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 beaccessed by DB2 and IMS fast path DataSet. LDS is essentially a table of data maintained ondisk. The 'table entries' must be created via a user program and can only be logicallyaccessed via a user program. When passed, the entire LDS must be mapped into storage,then data is accessed via base and displacement type processing.

    106. What are the steps you go through while creating a COBOL program executable?

    DB2 precompiler (if embedded SQL used),CICS translator (if CICS pgm),Cobol compiler,Link editor.

    If DB2 program, create plan by binding the DBRMs.