skip to main content

Procedure Division Statements : SEARCH

SEARCH
General Format
Format 1
SEARCH Identifier-1 [ VARYING {Identifier-2} ] 
  [ AT END Imperative-Statement-1 ] 
  { WHEN Condition-1 { Imperative-statement-2 } } ... 
                     { NEXT SENTENCE          } 
  [END-SEARCH]
Format 2
SEARCH ALL Identifier-1
  [ AT END Imperative-Statement-1 ] 
  WHEN {Data-Name-1 {IS EQUAL TO} {Identifier-3           } }
  [AND {Data-Name-2 {IS EQUAL TO} {Identifier-4           } } ] ...
  { NEXT SENTENCE          } 
  [END-SEARCH]
Syntax rules
All Formats
1.
Format 1
2.
3.
Format 2
4.
5.
6.
7.
8.
General rules
All Formats
1.
 
Upon completion of the search operation, one of the following occurs:
A.
B.
i.
ii.
iii.
2.
Format 1
3.
A.
B.
i.
ii.
C.
i.
ii.
 
Only the data item and indexes indicated are varied by the search operation. All other indexes associated with identifier-1 are unchanged by the search operation.
4.
Format 2
5.
A.
B.
6.
A.
i.
ii.
 
It is undefined which of these alternatives occurs.
B.
7.
8.
Examples
Format 1 - Search by name on a staff table
 working-storage section.
 01 staff-table occurs 5 times indexed by table-idx.
    05 tbl-code pic 9(2).
    05 tbl-name pic x(10).
    05 tbl-salary pic 9(6).
 77 search-name pic x(10).
 procedure division.
   perform fill-table
   perform search-table
   goback.
   move 1        to tbl-code(1
   move "Adam"   to tbl-name(1)
   move 84000    to tbl-salary(1)
   move 2        to tbl-code(2
   move "Eve"    to tbl-name(2)
   move 74000    to tbl-salary(2)
   move 3        to tbl-code(3
   move "Jack"   to tbl-name(3)
   move 93500    to tbl-salary(3)
   move 4        to tbl-code(4
   move "Allan"  to tbl-name(4)
   move 63400    to tbl-salary(4)
   move 5        to tbl-code(5
   move "Lilian" to tbl-name(5)
   move 53300    to tbl-salary(5)
   move "Jack" to search-name
   move 1 to table-idx
   search staff-table 
     at end display message "Name not found"
     when tbl-name(table-idx) = search-name
            display message 
              tbl-code(table-idx) ", " tbl-name(table-idx) ", " tbl-salary(table-idx)
   end-search.
Format 2 - Search all by name on staff table
 working-storage section.
 77 search-name pic x(10).
 01 staff-table occurs 5 times 
                ascending key is tbl-first-name
                indexed by table-idx.
    05 tbl-code       pic 9(2).
    05 tbl-first-name pic x(10).
    05 tbl-last-name  pic x(10).
    05 tbl-salary     pic 9(6).
 procedure division.
   perform fill-table
   perform search-all-table
   goback.
   move 1        to tbl-code(1
   move "Adam"   to tbl-first-name(1)
   move "Smith"  to tbl-last-name(1)
   move 84000    to tbl-salary(1)
   move 2        to tbl-code(2
   move "Eve"    to tbl-first-name(2)
   move "Green"  to tbl-last-name(2)
   move 74000    to tbl-salary(2)
   move 3        to tbl-code(3
   move "Jack"   to tbl-first-name(3)
   move "Yellow" to tbl-last-name(3)
   move 93500    to tbl-salary(3)
   move 4        to tbl-code(4
   move "Allan"  to tbl-first-name(4)
   move "Poe"    to tbl-last-name(4)
   move 63400    to tbl-salary(4)
   move 5        to tbl-code(5
   move "Jack"   to tbl-first-name(5)
   move "Samco"  to tbl-last-name(5)
   move 53300    to tbl-salary(5)
   display "----- Search All"
   move "Jack" to search-name
   move 1 to table-idx
   search all staff-table 
     at end display "Name not found"
     when tbl-first-name(table-idx) = search-name
              tbl-code(table-idx) ", " tbl-first-name(table-idx) ", " 
   end-search.

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left