COBOL_Training_Class-10.ppsx

Embed Size (px)

Citation preview

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    1/15

    IBM Mainframes

    COBOL Training Class-11

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    2/15

    Understand the Problem

    01 TEMP-REC. 05 ONE-AMPIC S9(3).

    05 TWO-AMPIC S9(3).

    05 THREE-AMPIC S9(3). 05 FOUR-AMPIC S9(3).

    05 MIDNIGHTPIC S9(3).

    CALCULATION:

    COMPUTE AVG-TEMP ( ONE-AM! TWO-AM! THREE-

    AM! . ! MIDNIGHT) " #$.

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    3/15

    Introduction to OCCURS Clause

    We use an OCCURSClause in COBOL to indicate the

    repeated occurrence of fields with same format (Type & Size).

    Some of the ses are!

    "efinin# a series of $%O fields of same format

    "efinin# a series of totals in worin#'stora#e section

    "efinin# a tale to accessed y each record.

    * T+,-'+C.

    / WS'T+,- OCCS 01T$,+S -$C S2(3).

    * 445'* 64L+ 7+O. / TOT4LS OCCS /T$,+S -$C 2(/).

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    4/15

    Rules to use

    4n occurs clause may e used on le8els 0 9 12

    only i.e.: occurs is not 8alid for *%;;%

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    5/15

    Subscrit

    A SUBSCRIPTis used in the procedure division to

    indicate which specified item within the array we wish

    to access.

    We use subscript aon! with the identifier that is

    defined with in occurs " to refer to an item with in thearray

    #$ampe%

    !CC"PT #S-T"MP $1% & !CC"PT #S-T"MP $'(%

    In between & and '( ony but not ) or '*.

    Rules% one space after the variabe and eft

    parenthesis and no space after or before the

    parenthesis.

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    6/15

    #e can resol)e the other roblem

    +,-# & T, SUB. +,-# #R,S T,T,TA/0T#+P.

    P#R1,R+ U2TI/ SUB3 '(

    A44 WS0T#+P5 SUB6 T, T,TA/0T#+P

    A44 & T, SUB

    #240P#R1,R+.

    P#R1,R+ CA/0PARA -AR7I28 SUB 1R,+ & B7 & U2TI/ SUB

    3'(.

    CA/0PARA

    C,+PUT# T,TA/0T#+P9T,TA/0T#+P: WS0T#+P5SUB6 .

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    7/15

    COBOL OCCURS***+"P",+I, O,

    This is similar to the COBOL OCCS clause: e?cept the

    numer of times it occurs 8aries from record to record.

    / L$>+'$T+,'CO>T-$C 22.

    / L$>+'$T+,SOCCS TO 0/T$,+S "+-+>"$>@O> L$>+'$T+,'CO>T.

    * A4>T$T5-$C 2222.

    * "+SC$-T$O>-$C (3).

    * >$T'-$C+-$C S2(/)622.The tale L$>+'$T+,Scontains three fields A4>T$T5:

    "+SC$-T$O>: >$T'-$C+) which mae up one line on an

    in8oice. +ach in8oice can ha8e from to 0/ line items.

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    8/15

    S"!RC. T"C.,I/U"S

    Search is used to find on element from the tale.

    There are 0types of search techniues.

    S+4CD & S+4CD 4LL

    SEARCH: $n Search the records will e checed in a linear orseuential fashion until a match is found or until end of the

    tale (+OT).

    SEARCHALL: $n Search all it di8ides the tale into 0 euals

    half and it checs for the element either in first half or second

    half ased on element. $t eeps on di8idin# the tale into 0

    eual half until a match is found or until tale looup is

    completed.

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    9/15

    The I,+"0"+ B Clause

    When usin# a S+4CDstatement: tale entries must e specified

    with an inde?rather than a suscript.

    4n inde? is similar to a suscript: ut it is defined alon# with the tale

    entries as part of the OCCSdescription!

    * S4L+S'T4'T4BL+.

    / T4BL+'+>T$+S OCCS * T$,+S

    $>"++" B5 *.

    * WS'7$-CO"+ -$C 2(/).

    * WS'T4'4T+ -$C 6222.

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    10/15

    S"!RC.

    DATA DIVISION.01 ACCT-DETAILS.

    05 ACCT-DETAILS OCCURS 100 TIMES INDE%ED &' A1.

    10 ACCT-NO PIC 9(10).

    10 CUST-NAME PIC %(#0).

    WS-NAME PIC %(#0) VALUE SPACE.

    PROCEDURE DIVISION.

    SEARCH-PARA.

    SET A1 TO 1.

    SEARCH ACCT-DETAILS

    AT END DISPLA' RECORD NOT FOUND*

    WHEN WS-NAME CUST-NAME(A1)

    DISPLA' ACCT-DETAILS(A1)

    END-SEARCH.

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    11/15

    S"!RC. !LL

    DATA DIVISION.

    01 ACCT-DETAILS.

    05 ACCT-DETAILS OCCURS 100 TIMES ASCENDING +E' IS

    ACCT-NO INDE%ED &' A1.

    10 ACCT-NO PIC 9(10).

    10 CUST-NAME PIC %(#0). WS-NAME PIC %(#0) VALUE SPACE.

    PROCEDURE DIVISION.

    SEARCH-PARA.

    ACCEPT WS-NAME.SEARCH ALL ACCT-DETAILS

    AT END DISPLA' RECORD NOT FOUND*

    WHEN WS-NAME CUST-NAME(A1)

    DISPLA' ACCT-DETAILS(A1)

    END-SEARCH.

    SEARCH SEARCH ALL

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    12/15

    SEARCH SEARCH ALL

    LINEAR " SE,UENTIAL SEARCH. &INAR' SEARCH.

    I /2 /24 // 46 7/ 8 46/4/.

    R/24 4 7/ 8 46/ 4/.

    W/ ;/ 64 /6 8/< ;87/ 64 1 7/=4/

    >/=4?8@ /2.

    N4 // 64 /6 8/< ;87/ 64 1 6/

    /24 / 8 46/ 4/.

    AB 4@82 4>/684 2 7/ >/=4?/.

    ( N46)

    OB 4>/64 8 >487/.

    M68>/ /* 248684 2 7/ 24/. OB 8@/ /* 248684 2 7/

    24/.

    S/2 8 >/=/7/ / 67/ 8 ?. P/=/7/ / 67/ 8 @/.

    W/ 4*6 24/ ASC-+E' OR DSC-+E'. S4 24/ ASC-+E' OR DSC-+E'.

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    13/15

    +ifference Bet2een

    SU&SCRIPT INDE%

    O22/2/: 86 86/B 24;/6 648>2/?/6 =/62/ 6/ ;/.

    D8>2/?/6: 86 4 6/ / 4= 6/;/ 8/26B =/62/ 6/ ;/.

    S4/. F6/.

    S728>6 8 48@-64@/ ;87/. I/< 8 86/ 86/?.

    I6 4 7/ /2/ 8 48@-64@/

    /2684.

    N4 // 64 /2/ 8/< ;87/.

    I6 2 7/ I2/?/6/"D/2/?/6/

    86 24?>6/ 4 >/=4?.

    COMPUTE ++!1 (OR)

    COMPUTE ++-1 (OR)

    PERFORM VAR'ING.

    T4 82/?/6 8/< / ;/ 64 / SET

    ;/7.

    SET INDE%-VAR TO 1 OR

    SET INDE%-VAR UP &' 1"(++!1)

    OR

    SET INDE%-VAR DOWN &' 1"(++-

    1)

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    14/15

    Limitations of the S"!RC. !LLStatement

    *. The condition followin# the word WD+> can test only foreuality!

    V8: WHEN T-CUSTOMER-NO (%1) CUST-NO-IN

    I;8: WHEN T-WEIGHT-MA% (%1) WEIGHT-MAILED

    0. . Only one WD+> clause can e used with aS+4CD 4LL.

    3. The 645$>@option may not e used with the

    S+4CD 4LL.

    1. The OCCS item and its inde?: which define the talear#ument: must appear to the left of the eual si#n.

    V8: WHEN S-AMT (%1) AMT1...

    I;8: WHEN AMT1 S-AMT (%1)...

  • 7/27/2019 COBOL_Training_Class-10.ppsx

    15/15

    Than3 ou