1 / 19

Chapter 12 (part 2)

Chapter 12 (part 2). Table Handling and Search Techniques. Table. 01 WS-IFS-FACULTY-TABLE. 05 IFS-FACULTY OCCURS 12 TIMES. 10 FAC-NAME PIC X(20). 10 FAC-OFFICE PIC X(6). 10 FAC-PHONE-NBR PIC X(10). 10 FAC-EMAIL-ID PIC X(25).

reuben-webb
Download Presentation

Chapter 12 (part 2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 12 (part 2) Table Handling and Search Techniques

  2. Table 01 WS-IFS-FACULTY-TABLE. 05 IFS-FACULTY OCCURS 12 TIMES. 10 FAC-NAME PIC X(20). 10 FAC-OFFICE PIC X(6). 10 FAC-PHONE-NBR PIC X(10). 10 FAC-EMAIL-ID PIC X(25). 10 FAC-WEB-PAGE PIC X(15). Suppose there are 12 faculty members in the IFS department. We can define 12 separate 01-levels in WORKING-STORAGE. However, since each will have the same structure, we can define a table. Now, we have enough memory reserved for twelve faculty members. This table can store the data we need.

  3. Table Processing 01 WS-IFS-FACULTY-TABLE. 05 IFS-FACULTY OCCURS 12 TIMES. 10 FAC-NAME PIC X(20). 10 FAC-OFFICE PIC X(6). 10 FAC-PHONE-NBR PIC X(10). 10 FAC-EMAIL-ID PIC X(25). 10 FAC-WEB-PAGE PIC X(15). MOVE “TORU SAKAGUCHI” TO FAC-NAME (1) MOVE “DAVID MANNING” TO FAC-NAME (2)

  4. Table Processing 01 WS-IFS-FACULTY-TABLE. 05 IFS-FACULTY OCCURS 12 TIMES. 10 FAC-NAME PIC X(20). 10 FAC-OFFICE PIC X(6). 10 FAC-PHONE-NBR PIC X(10). 10 FAC-EMAIL-ID PIC X(25). 10 FAC-WEB-PAGE PIC X(15). 01 FAC-SUBSCRIPT PIC 99. MOVE 1 TO FAC-SUBSCRIPT PERFORM UNTIL FAC-SUBSCRIPT > 12 DISPLAY FAC-NAME (FAC-SUBSCRIPT) ADD 1 TO FAC-SUBSCRIPT END-PERFORM

  5. Serial Search Each entry (usually starting with first) checked in order until • Condition is met • Table completely searched

  6. Serial Search Best used when • Entries not in order by table argument value (not in numerical or alphabetical order) • Entries can be organized so first values are ones searched for most frequently, minimizing search time

  7. Binary Search • Most efficient type of look-up when table entries in sequence by some table field • On average, takes fewer comparisons to find match than serial search • Called binary search because each comparison eliminates half of entries under consideration

  8. Binary Search Example • Assume a table contains 50 customer numbers in ascending sequence • Search table to find match for customer number 5000 stored in input field Cust-No-In

  9. Binary Search Example Comparison Entry # T-Customer-No 1. 0100 2. 0200 … ... 1st 25. 4300 … ... 3rd 31. 4890 … ... 4th 34. 5000 … ... 2nd 37. 5310 … ...

  10. Binary Search Method • Serial search would require 34 comparisons in this example • Binary search requires only four • Use binary search for large table (50 or more entries) • Table entries must be arranged in sequence by some table field

  11. Binary Search Statement SEARCHALL identifier-1 [AT END imperative-statement-1] WHEN data-name-1 = identifier-2 literal-1 condition-1 arithmetic- expression-1 imperative-statement-2 CONTINUE [END-SEARCH] Format (partial)

  12. SEARCH ALL Limitations • Condition in WHEN can test only for equality between table and search argument • Condition following WHEN may be compound • Only ANDs permitted, not Ors • Each relational test can test only for equality

  13. SEARCH ALL Limitations • Only one WHEN clause can be used • VARYING option may not be used • Table argument and its index must appear to left of equal sign • Valid: When T-Customer-No (X1) = Cust-No-In • Invalid: When Cust-No-In = T-Customer-No (X1)

  14. Key Field • Must include clause to indicate which table entry serves as key field (either ASCENDING KEY or DESCENDING KEY) 05 identifier-1 OCCURS ## TIMES ASCENDING KEY IS data-name-1DESCENDINGINDEXED BY index-name-1 Format

  15. Multiple-Level OCCURS • Up to seven levels of OCCURS permitted in COBOL • For example, define an array to store hourly temperature readings for each day during a given week • Need two-dimensional array with 7 rows, each with 24 columns

  16. Multiple-Level OCCURS • Define array as follows: 01 Temperature-Array. 05 Day-In-Week Occurs 7 Times. 10 Hour Occurs 24 Times. 15 Temp Pic S9(3). • For each Day-In-Week there are 24 Hour figures, each consisting of a Temp three integers long

  17. Table with Subscripts

More Related