FALSE

Page Nav

HIDE

Grid

GRID_STYLE

Procedure Division Commands COBOL

Procedure Division Commands      1.      Write a Sample Program in COBOL IDENTIFICATION DIVISION. PROGRAM-ID.     SAMPLE. ENVIRONMENT DIVIS...

Procedure Division Commands

     1.     Write a Sample Program in COBOL
IDENTIFICATION 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-N
ame
AME.
     2.     Explain the four COBOL statement categories?
Imperative
Conditional
Compiler Directing
Explicit Scope Terminator

Imperative Statement
Directs program to take specific action during execution
ADD       1     TO      A.
MOVE     2     TO     A.
Conditional Statement
Directs program to examine the truth of a condition and take subsequent action depending on truth
IF   A > B
      DISPLAY “A IS GREATER”
ELSE
      DISPLAY “B IS GREATER’
END-IF.
Compiler-directing Statement
Directs COBOL compiler and no corresponding statement is generated for these in the object program
    COPY
    USE
Explicit Scope Terminators
Statements used to terminate the scope of a COBOL verb explicitly
    END-IF
    END-PERFORM
     3.     What are the two types of control transfer statements?
1. Conditional Transfer statements
    Based on result of condition check
    IF
    EVALUATE
    GOTO..DEPENDING ON
2. Unconditional Transfer
    PERFORM
    GOTO
     4.     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 identifier
Identifier must be numeric,
 
integral, elementary item
Control 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 to
IF TRAN-TYPE = 1
    GOTO RECEIPT-PARA.
IF TRAN-TYPE = 2
    GOTO ISSUE-PARA.
IF TRAN-TYPE = 3
    GOTO ADJUSTMENT-PARA.

     5.     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, ...

     6.     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].

     7.     Explain the applications of ROUNDED VERB in COBOL?
Rounded clause could be used to get the output rounded to specified size
Applicable only for receiving fields
Cannot be specified after Remainder
E.g.,
       ADD  A  B GIVING   C  ROUNDED.
     8.     Explain the applications of ON SIZE ERROR in COBOL?

If after an arithmetic operation, the
resultexceeds the largest value that can be accommodated in the result field, the error is called a size error. Programmers can control Size Error in any arithmetic statementusing this phrase.
E.g.,
    ADD A TO B ON SIZE ERROR
    GO TO ERROR-PARA.
     9.     Give the Syntax for COMPUTE VERB?
COMPUTE {Identifier-1 [ROUNDED]}
    [Identifier-2  [ROUNDED]]
    Arithmetic Expression
    [ON SIZE ERROR
    Imperative Statement]

 10.     What is the use of EVALUATE statement? -
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.
 11.     What are the different forms of EVALUATE statement? Give the Syntax and Example
Syntax:
EVALUATE Subject-1 [ALSO Subject-2]...
     {WHEN Object-1 [ALSO Object-2]....
    {Imperative-Statement1}...}
     {WHEN OTHER
    {Imperative-Statement2}...]
[END-EVALUATE.]



Example:
EVALUATE TRUE
    WHEN MONTH = 4 OR 6 OR 9 OR 11
             MOVE 30 TO NO-OF-DAYS
    WHEN MONTH = 2
             MOVE 28 TO NO-OF-DAYS
    WHEN OTHER
             MOVE 31 TO NO-OF-DAYS
END-EVALUATE.

EVALUATE PRODUCT-TYPE ALSO CUSTOMER-TYPE
    WHEN 1 ALSO ANY
             MOVE 0 TO COMMISSION
    WHEN 2 ALSO 1 THRU 5
             MOVE 10 TO COMMISSION
    WHEN 3 ALSO 1 THRU 5
             MOVE 5 TO COMMISSION
    WHEN OTHER
             MOVE 20 TO COMMISSION
END-EVALUATE.

 12.     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 the next sentence after the EVALUATE statement.  There is no need of any extra code.
 13.     In an EVALUATE statement, can I give a complex condition on a when clause?
Yes.
 14.     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.
 15.     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 left untouched.
 16.     What does the IS NUMERIC clause establish?
IS NUMERIC can be used on alphanumeric items, signed numeric & packed decimal items and unsigned numeric & packed decimal items. IS NUMERIC returns TRUE if the item only consists of 0-9. However, if the item being tested is a signed item, then it may contain 0-9,  + and -.
 17.     What are all the arithmetic Verbs and Arithmetic Operations?
Arithmetic Verbs
Add
Subtract
Multiply
Divide
Compute

ARITHMETIC OPERATORS
Addition                      +
Subtraction                 
         
-
Multiplication                *
Division                      
         
/
Exponentiation             **
HIERARCHY
( )   **    * OR /   + OR -            From Left to Right
 18.     What is difference between next sentence and continue?
CONTINUE is like a null statement (do nothing), while NEXT SENTENCE transfers control to the next sentence
)
. (A sentence is terminated by a period)
 19.     What does EXIT do?
Does nothing. If used, must be the only sentence within a paragraph.

No comments