COBOL_Training_Class-6.ppsx

Embed Size (px)

Citation preview

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    1/33

    IBM Mainframes

    COBOL Training Class-6

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    2/33

    Edited Picture Symbols

    Edit Symbol Meaning

    ZZero suppression

    *Check protection

    ,

    Comma insertion

    - / +Plus or Minus sign insertion

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    3/33

    Edited Picture Symbols

    Edit Symbol Meaning

    $ Dollar sign insertion

    CR Credit symbol

    DB Debit symbol

    B Blank insertion

    / Slash insertion

    . Decimal point insertion

    BLANK !"N #"R Blank insertion %hen the &al'e is (ero

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    4/33

    Edit Symbol Value Edited Value

    (())) 12 *+,

    ---)) 12 ---+,

    $)))) 0123 $*+,

    )))) 1234 +,0

    1)))) 1234 1+,0

    ))2))) 1234 *+2,0

    )).)) 12.345 +,.0

    99CR/DB 12 12CR/DB

    99B99 1234 12 34

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    5/33

    REI!I"ES #"RE"#MES

    O$er$ie%

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    6/33

    &'at is Redefines

    Sometime two or more different variales defined in a program are not

    in use simultaneousl!" #heir memor! can e then saved ! sharing the

    same location for all such variales"

    $acilitates two or more data-%tems to point to the same memor!location"

    Simple wa! to save memor! while using data-items

    Should e declared at the time of data item definition in data division"

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    7/33

    &edefining variale and redefined variale should e of samelevel number.

    #he PIC Clause of redefining variale and redefined variale

    need not e same"

    Multiple&'('$%)'Sis allowed for a data-item"

    &'('$%)'Sclause must not e used for level in FILESECTION"

    Must not e used for data-items defined in level numers and, should not have an .CC&Sclause"

    0hen we use redefines we can1t use valueclause for redefining

    item"

    Rules overning RE!EFINES Clause"

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    8/33

    S#NT$%"LEVEL&NO !$T$&N$ME&' RE!EFINES !$T$&N$ME&(.

    E%$MPLE

    )'*S&!$TE PIC %+,- V$LE /('0''0''/.

    )'*S&!$T$&!M# RE!EFINES *S&!$TE. )1 *S&!! PIC 2+(-.

    )1 FILLER PIC %.

    )1 *S&MM PIC2+(-.

    )1 FILLER PIC%.

    )1 *S# PIC2+(-.

    )'CSTOMER&!$T$. )1 CSTOMER&I! PIC %+),-. )1 CSTOMER&I!&P$RTS RE!EFINES CSTOMER&I!. ') LOC$TION PIC %+3-. ') N$ME&$4REV PIC %+1.-

    Synta( #nd E(am)le

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    9/33

    REE!I"ES CL#*SE + e(am)le

    ************************************

    YEAR FOR ENTERED DATE IS : 2005

    MONTH FOR ENTERED DATE IS : 01

    DAY FOR ENTERED DATE IS : 01

    ************************************

    Output SPOOL

    WS00-YEAR2 ree!"#e$ WS00-YEAR1.

    I% "$ %&e $'(e ) +%e$ ,! "#!,r('%",#&"& WS00-YEAR2 r,"e$ "# %&e Ye'rM,#%& D'+ !,r('% "# "%$ $-"%e($.

    A#+ &'#e "# WS00-YEAR1 &'#e$'6e ,! WS00-YEAR2 '# "e-er$'.

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    10/33

    $acilitates re-grouping of elementar! data items in a record" 2fter

    the renames enforcement the elementar! items would elong to the

    original 3renamed4 group item as well as the new 3renaming4 group

    item"

    S!nta5 6 55 data&name&' REN$MES data&name&( T6R data&name&3.

    &ules #o 7e $ollowed 0hile sing &')2M'S

    &')2M'S must e used after the description of the fieldsre8uired"

    Must e coded onl! with level numer "(ata-names 9 and : should not have level numers and

    .CC&S Clause"#he elementar! items getting renamed should e contiguous"

    REN$MES Clause

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    11/33

    Example

    01 STUD-DETAILS.

    05 REG-NO PIC 9(5).

    05 S-F-NAME PIC X(15).05 S-M-NAME PIC X(12).

    05 S-L-NAME PIC X(8).

    66 STUD-NAME RENAMES S-F-NAME THRU S-L-NAME.

    REN$MES Clause E7am8le

    T&e e6e(e#%'r+ "%e($e%%"# re#'(e$&,6 e ,#%",$.

    M$% e ,e ,#6+ "%&6ee6 #(er 77.

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    12/33

    REN$MES Clause E7am8le

    0.&;%)' @"

    ? 'MP-B&2 P%C @34 A2>' :"

    : 'MP-P2=-.#B'&S"

    ? 'MP-(2P%C @3:4 A2>' "

    ? 'MP-%)C')#%A'S P%C @3:4 A2>' ?"

    : 'MP-('(C#%.)S"

    ? 'MP-P$-#D P%C @3:4 A2>' @"

    ? 'MP-P&.$-#D P%C @3:4 A2>' 9"

    0S-A2& &')2M'S 'MP-72S%C #B& 'MP-(2"

    0S-A2&9 &')2M'S 'MP-P$-#D #B& 'MP-P&.$-#D"

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    13/33

    Conditional ,erbs

    I! #nd E$aluate

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    14/33

    Introduction

    %n programming, Man! times program needs to run one or

    more sets of statements ased on some condition

    %f condition is true, one set of statements get e5ecuted" %f

    condition is false another set of statements will get e5ecuted" Conditional statements altersE the control flow of the e5ecution

    %n C.7.> the Conditional statements are IF Statement.

    E$L$TE Statement.

    Terminator/s " Im8li9itterminatorstatement ends :it; a

    8eriod +.- and e78li9itterminatora statement :;i9; ends :it;

    verb t;at 8re9eded by EN!

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    15/33

    COBOL I! ST#TEME"T

    D"!!ere#% F,r($ ,! IF S%'%e(e#%.

    S"(6e IF IF - E8SE 8'er

    IFCONDITION IF CONDITION

    $%'%e(e#% $%'%e(e#%

    END-IF. E8SE

    IF-E8SE IFCONDTION

    IF CONDITION $%'%e(e#%

    $%'%e(e#% E8SE

    E8SE $%'%e(e#%

    $%'%e(e#% END-IF

    END-IF. END-IF

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    16/33

    ifferent Ty)es Of Conditions

    1 C6'$$ ,#"%",#

    2 C,#"%",#-#'(e ,#"%",#

    3 Re6'%",# ,#"%",#

    4 S"# ,#"%",#

    5 Ne'%e $"(6e ,#"%",#

    7 C,("#e ,#"%",#$

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    17/33

    Class Condition

    Class condition determines whether the identifier contains numeric value .&

    alphaetic value"

    =Identi>ier&'? @isA @notA = numeri9 0 al8;abeti9 0 al8;abeti9&lo:er 0 al8;abeti9&u88er ?

    #his condition is ver! useful to minimiFe the program errors" 7efore doing

    arithmetic operation we want to check whether the identifier contains the numeric

    data or not"

    %$ 0S-2M# %S )M'&%C

    2(( 0S-2M# #. 0S-72)>2)C'

    '>S'

    M.A' Z'&.S #. 0S-2M#

    ')(-%$"

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    18/33

    Condition-name Condition "ame Condition.

    Condition&nameis a identifier defined with level number ,,.

    %t has onl! A2>' clause, it does not contain an!pictureclause"

    %t must alwa!s e associated to a data name called the conditional variale"

    T;is one ma' ,9"

    CB%>( A2>' : #B& 9"

    #'')-2

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    19/33

    /o% %e can use t'is in PROCE*RE I,ISIO"0

    IF INF$NT

    MOVE () TO *S&SIN$L

    PERFORM ())&INF$NT&P$R$

    EN!&IF.

    IF *S&$E B )

    MOVE () TO *S&SIN$L

    PERFORM ())&INF$NT&P$R$

    EN!&IF

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    20/33

    Relation Condition

    &elation condition compares two operands either of

    which can e an identifier, literal, arithmetic

    e5pression"

    $ormat

    .perand Grelational operatorH .perand9

    #he &elational operator specifies the t!pe of

    comparison

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    21/33

    Relational O)erator

    Re6'%",#'6Oer'%,r C'#er"%%e#'$

    IS ;REATER THAN IS ?A8 TO IS NOT @

    IS ;REATER THAN OR E>?A8 TO IS < @

    IS 8ESS THAN OR E>?A8 TO IS = @

    .

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    22/33

    Sign Condition

    #he signconditiondetermines whether the given numeric value is grater than

    the ERO +or- less t;an t;e ERO +or- eDual to ERO"

    $ormat

    o8erand&' @ISA @NOTA =POSITIVE0NE$TIVE0ERO?

    .perand- must e defined as a numeric identifier"

    %S P.S%#%A'condition will ecome true, if the operand- value grater than

    Z'&.

    %S)'

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    23/33

    "egated sim)le condition

    0e can negate the simple condition ! using ke!word).#"

    '5" %$ 2 L 7

    C.MP#' C L 2 ** 9

    ')(-%$

    if 2 7 contains the same value, C.MP#' statement will gete5ecuted"

    if we use ).# with the condition, C.MP#' wont get e5ecuted, when 2

    7 contains the same value"

    %$ ).# 2 L 7

    C.MP#' C L 2 ** 9

    ')(-%$

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    24/33

    Combined conditions

    Comined conditions contains two or more conditions

    connected using logical operators

    $N! or OR.

    $ormat

    condition- G2)(/.&H condition-9 I G2)(/.&H

    condition-: J"""

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    25/33

    Combined Conditions contd11

    Be6, %'6e "e$ %&e re$6%$ ,! $"# 6,"'6 ,er'%,r$

    AND OR e%ee# %, ,#"%",#$ COND1 COND2.

    CO"2 CO"3 CO"2 4

    CO"3

    CO"2 OR

    CO"3

    TR?E TR?E TR?E TR?E

    TR?E F8ASE F8ASE TR?E

    F8ASE TR?E F8ASE TR?E

    F8ASE F8ASE F8ASE TR?E

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    26/33

    E(am)le -2

    I! !IVISION. PROR$M&I!. IFPRO)'. ENVIRONMENT !IVISION. !$T$ !IVISION. *ORIN&STOR$R SECTION. )'*S&EN!ER PIC %+)'- V$LE SP$CE. PROCE!RE !IVISION. M$IN&P$R$. $CCEPT *S&EN!ER. IF *S&EN!ERB M/ !ISPL$# MR/

    EN!&IF. IF *S&EN!ERB F/ !ISPL$# MRs/ EN!&IF. STOP RN.

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    27/33

    E(am)le 5 2 contd1

    I! !IVISION. PROR$M&I!. IFPRO)(. ENVIRONMENT !IVISION. !$T$ !IVISION. *ORIN&STOR$R SECTION. )'*S&EN!ER PIC %+)'- V$LE

    SP$CE. PROCE!RE !IVISION. M$IN&P$R$. $CCEPT *S&EN!ER. IF *S&EN!ERB M/ !ISPL$# MR/ ELSE !ISPL$# MRs/ EN!&IF. STOP RN.

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    28/33

    E(am)le 5 2 cont+

    I! !IVISION. PROR$M&I!. IFPRO)3. ENVIRONMENT !IVISION. !$T$ !IVISION. *ORIN&STOR$R SECTION. )'*S&EN!ER PIC %+)'- V$LE SP$CE. PROCE!RE !IVISION. M$IN&P$R$. $CCEPT *S&EN!ER. IF *S&EN!ERB M/ !ISPL$# MR/ ELSE IF *S&EN!ERB F/ !ISPL$# MRs/ ELSE !ISPL$# ERROR EN!ER INPT/ EN!&IF

    EN!&IF. STOP RN.

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    29/33

    E,#L*#TE Statement

    'valuate is also used for conditional checking similar to

    %$statement"

    'valuate was designed in Cobol&,1"

    'valuate efficientl! and effectivel! re8la9es Nested&I>statements.

    'valuate is of three t!pes6

    EV$L$TE TRE

    EV$L$TE OPTION

    EV$L$TE $LSO

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    30/33

    Synta(

    EV$L$TEV$RI$4LE&N$ME TRE

    *6EN V$LE CON!ITION

    ST$TEMENT'

    ST$TEMENT(

    *6ENV$LE CON!ITION

    ST$TEMENT3

    ST$TEMENTG

    *6ENOT6ER

    ST$TEMENT1

    ST$TEMENT5

    EN!&EV$L$TE.

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    31/33

    Points to "oted

    Ma5imum we can check 9??when conditions using evaluate"

    0hen other is an optional statement ut it is highl!

    recommendale to code" 0B').#B'&is alwa!s a true

    statement, hence should e coded as last condition"

    0hen a match found the statement following the *6EN

    clause and efore the ne5t *6ENclause, are e5ecuted and

    control is then passed to statement following the

    EN!&EV$L$TE"

    %f no matching when clause is found, the statements following

    the *6ENOT6ERstatement is e5ecuted

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    32/33

    CO"TI"*E 4 "ET SE"TE"CE

    C.)#%)')'D#S')#')C' are (.

    ).#B%)< operation statement"

    Continue6 Continue passes control to )e5t Statement

    after '5plicit Scope terminator"

    Ne7tSenten9e6 %t Passes control to the )e5t

    Statement after %mplicit Scope #erminator"

  • 7/27/2019 COBOL_Training_Class-6.ppsx

    33/33

    T'an7 8ou