TABLES (chp. 12) group of storage locations (i.e.

TABLES (chp. 12)  group of storage locations (i.e.

TABLES (chp. 12) group of storage locations (i.e. elements) with the same name accessed by name and subscript ex. var-name (sub) similar to arrays in other languages Tables 1 OCCURS Clause Defines the number of elements in the table for each level Defines the maximum subscript for each level Up to seven levels of OCCURS permitted in COBOL Can not be used on 01 level item SUBSCRIPTS Integer values from 1 to occurs clause value (specifies maximum value) Up to 7 subscripts are permitted in COBOL Subscripts are listed in parenthesis following the table name Each time the value of a subscript changes, data-name (sub) refers to a different element in the array

Using a data-name as a subscript enables its contents to be varied Relative subscripting is used when what is in parenthesis can be an arithmetic expression if using subscript constants (named or literal) compiler will detect error if using subscript variables, error won't be detected until run-time Tables 2 TABLE examples If item defined by OCCURS has PIC clause, it defines a series of elementary items 01 Totals. 05 Month-Totals Occurs 12 Times Pic 9(5)V99. For your information When a variable name has an OCCURS clause on it or above it with a smaller level number, it must have one subscript when referencing that memory location for

each OCCURS. Tables 3 TABLE examples Identifier used with OCCURS may also be group item 01 Tax-Table. 05 Group-X Occurs 20 Times. 10 City Pic X(6). 10 Tax-Rate Pic V999. Tables 4 More TABLE examples EXAMPLE #1

01 DAYS-OF-MONTH-TABLE. 03 MONTHS OCCURS 12 times. 05 Month-Name PIC X(15). 05 Month-Num-Days PIC 99. Move January to Month-Name (1) Move 31 to Month-Num-Days (1) How else initialize Month-Name and Month-Num-Days?! EXAMPLE #2 01 DAYS-OF-MONTH-TABLE. 05 Month-Name PIC X(15) OCCURS 12 TIMES. 05 Month-Num-Days PIC 99 OCCURS 12 TIMES. Move January to Month-Name (1) Move 31 to Month-Num-Days (1) Tables

5 One More TABLE example 01 GRADE-TABLE. 05 QUIZ-TABLE OCCURS 40 TIMES. 10 QUIZ1 PIC 9(2). 10 QUIZ2 PIC 9(2). 10 QUIZ3 PIC 9(2). 10 QUIZ4 PIC 9(2). How do we average all the quiz scores for QUIZ4? Compute-Average-Quiz4. ***Convert to MOVE ZERO TO Total-Grade Perform-Varying MOVE 1 TO Sub PERFORM UNTIL Sub > Num-Quizzes ADD QUIZ4(Sub) TO Total-Grade ADD 1 TO Sub END-PERFORM DIVIDE Total-Grade BY Num-Quizzes

GIVING Average-Score Tables 6 INITIALIZING TABLES Two ways to use VALUE clause to initialize all elements to zero: 01 Array-1 Value Zero. 05 Totals Occurs 50 Times Pic 9(5). 01 Array-1. 05 Totals Occurs 50 Times Pic 9(5) Value Zero. Can also initialize each element to different value 01 Day-Names Value 'SUNMONTUEWEDTHUFRISAT'. 05 Days Occurs 7 Times Pic X(3). ??? Can an initialization be done on the 05 directly above??? INITIALIZE STATEMENT (i.e. in Procedure Division) A series of elementary items contained within a group item can all be initialized. Numeric items will be initialized to zero and nonnumeric items will be initialized to blank.

FORMAT: INITIALIZE {identifier-1} Tables 7 REDEFINES Purpose: Used to define a field with a value clause then redefine it as an array. However, you cannot do the reverse; that is, once an entry has been defined by an OCCURS clause, it may NOT be redefined. FORMAT in Data Division: L# identifier-1 REDEFINES identifier-2 [finish declaration] where: L# means level number Identifier-1 and identifier-2 must be on the same level EXAMPLES: See table example program 01 Rates. 05 10Rate PIC 99V999 value 12.345. 05 100Rate REDEFINES 10Rate PIC 999V99.

05 1000Rate REDEFINES 10Rate PIC 9999V9. Result 100Rate = 123.45 and 1000Rate = 1234.5 01 HoldDate. 02 EuroDate. 03 EuroDay PIC 99 value 11. 03 EuroMonth PIC 99 value 3. 03 EuroYear PIC 9(4) value 2003. 02 USDate REDEFINES EuroDate. 03 USMonth PIC 99. 03 USDay PIC 99. 03 USYear PIC 9(4). USMonth = 3 and USDay = 11 Tables 8

2 dimensional TABLES (ex#1) Define array as follows: 01 Temperature-Array. 05 Day-In-Week Occurs 7 Times. 10 Hour Occurs 24 Times. 15 Temp Pic 9(3). For your information: If reading in from file, what does input file look like?! FD input file 01 input-rec pic 999. Find the average temp for: each day. Find the average temp for each hour. Perform a from 1 by 1 until a > 7 PARTICIPATION POINTS (5) perform b from 1 by 1 until b > 24

(due in one week graded on if works!) What if have negative temperatures? How solve?! That is, what does input file look like? What does declaration look like? read input-file at end.. move input-rec to temp (a b) end-perform End-perform Tables 9 2 dimensional TABLES (ex#2) 01 Jeans-Table. 05 Jean-Gender OCCURS 2 TIMES. 10 Jean-Color OCCURS 3 TIMES. 15 Jean-SalesValue PIC 9(8)V99.

15 Jean-NumSold PIC 9(7). Tables 10 2 dimensional TABLES (ex#3) 01 Jeans-Table. 05 Jean-Size OCCURS 10 TIMES. 10 Exact-Size PIC 99. 10 Jean-Style PIC X. 10 Jean-Color OCCURS 3 TIMES. 15 Jean-SalesValue PIC 9(8)V99. 15 Jean-NumSold PIC 9(7). Tables 11

Recently Viewed Presentations

  • Song of Songs: The Song of Solomon - 1 Kings 1-11

    Song of Songs: The Song of Solomon - 1 Kings 1-11

    And now, O LORD my God, you have made your servant king in place of David my father, although I am but a little child. ... made us alive together with Christ — by grace you have been saved —...
  • Social Media

    Social Media

    From the Founder of General Systems Theory. Ludwig von Bertalanffy. A system may be defined as a set of elements standing in interrelation among themselves and with environment. We term a system 'closed' if no material enters or leave it;...
  • MINE SWEEPER - University of Florida

    MINE SWEEPER - University of Florida

    Project Abstract The main objectives of this project are To move to the center of the playing surface and starting to look for IR. To find and deactivate four IR emitters, while avoiding 4 fixed mines and a random mine....
  •  Hodge Test * EDTA TEST + +  (

    Hodge Test * EDTA TEST + + (

    Εργαστηριακή διάγνωση κα προκαταρκτική διαφοροποίηση Καρβαπενεμασών Πιθανό ένζυμο
  • Death of a SalesmanAn American Tragedy by Arthur

    Death of a SalesmanAn American Tragedy by Arthur

    Death of a Salesman is not un-American; it celebrates the life of Willy Loman. Miller believes that tragedy is "inherently optimistic." The Common Man as Hero Miller's thoughts: "Everyone knows Willy Loman." (allusion to the morality play, Everyman.) "The common...
  • The Aztecs, Incas, and Maya - Making it with McClintock

    The Aztecs, Incas, and Maya - Making it with McClintock

    Their writing system has 800 glyphs - or symbols . ... The Toltec ruler Topiltzin tires to change the religion and end human sacrifices by encouraging the worship of Quetzalcoatl - a feathered serpent. ... The Aztecs, Incas, and Maya
  • Corporation for National and Community Service

    Corporation for National and Community Service

    The member selects the link from email to login to their My AmeriCorps account and complete the Exit Form and Member Exit Survey. After the member completes the Exit Form, the Member Exit Survey will automatically begin. The member will...
  • Basic Logic Gates - Oakland University

    Basic Logic Gates - Oakland University

    Times New Roman Courier New Arial Blank Presentation Microsoft Visio Drawing Basic Gates Verilog Basic Gates Slide 3 NOT Gate AND Gate 4-Input AND Gate OR Gate 4-Input OR Gate Exclusive-OR (XOR) Gate 2-Input XOR Gate 4-Input XOR Gate Exclusive-NOR...