Sequential search means starting at row one and checking every row until you find a match or reach end of file. It is the natural way humans flip through an unsorted pile of papers. Easytrieve TABLE processing deliberately avoids that pattern for reference lookups: SEARCH uses binary search over sorted ARG keys in memory. Yet sequential search still appears in real shops when developers treat a small reference sequential file like a miniature database—GET until match for every payroll record, every night, for years. This page clarifies what sequential search means in Easytrieve terms, why TABLE SEARCH replaced improvised linear scans, how to recognize anti-patterns in legacy code, when sequential I/O is still the right model, performance mathematics beginners underestimate, and migration steps from GET-loop lookup to FILE TABLE plus SEARCH without changing business outcomes.
Mainframe beginners confuse two ideas. Sequential file processing reads a transaction file from beginning to end once—every employee record in payroll, every order in sales. That is correct Easytrieve design for JOB INPUT. Sequential search for lookup re-scans a reference file from the beginning for each transaction row hunting one code. That is almost always wrong when TABLE plus SEARCH exists. This page focuses on the second meaning and contrasts it with sanctioned TABLE lookup.
SEARCH never walks row 1, row 2, row 3 until match. After TABLE load, keys reside in memory in ascending ARG order and binary search partitions the key space. Sequential scan would examine up to n rows per lookup; binary search examines at most log₂(n). No Language Reference option switches TABLE SEARCH to linear mode for small tables or unsorted data—unsorted data is a data defect, not a cue to fall back to sequential search inside SEARCH.
12345678910111213141516171819JOB INPUT PAYROLL PERFORM DEPT-LOOKUP PRINT PAYRPT DEPT-LOOKUP. PROC MOVE 1 TO FOUND-FLAG GET REFDEPT DO WHILE NOT EOF REFDEPT AND FOUND-FLAG = 0 IF REF-DEPT = EMP-DEPT MOVE REF-NAME TO DEPT-NAME MOVE 1 TO FOUND-FLAG ELSE GET REFDEPT END-IF END-DO IF FOUND-FLAG = 0 DEPT-NAME = 'NOT FOUND' END-IF END-PROC
This PROC reads REFDEPT from the start for every payroll row. After processing employee 50,000, the job has executed millions of GET and compare operations. REFDEPT file position resets each PERFORM, so no benefit accumulates across employees. CPU and elapsed time grow with product of input count and reference count. TABLE load once plus SEARCH per employee reduces reference access to in-memory binary comparisons.
| Scenario | Sequential GET loop | TABLE SEARCH |
|---|---|---|
| 100 input × 50 row ref | Up to 5,000 compares | Up to ~600 compares |
| 100,000 input × 5,000 row ref | Up to 500 million compares | Up to ~1.4 million compares |
| Load cost | Re-read ref file per input row | One load at initiation |
Real runs average fewer than worst-case sequential comparisons if keys appear early in reference file, but worst-case planning drives batch capacity. Operations schedules assume peak files.
None of these are lookup by key on every input row. They are linear workflows where each reference row is consumed at most once per pass by design.
External FILE TABLE reads maintenance data sequentially at JOB initiation—that single sequential pass is required and efficient. Data lands in memory; subsequent SEARCH calls use binary search. Confusing initiation load with per-record sequential scan is a common beginner mistake when reading Table Processing chapter diagrams.
12345678910FILE REFDEPT TABLE 500 ARG 1 3 N DESC 5 25 A JOB INPUT PAYROLL SEARCH REFDEPT WITH EMP-DEPT GIVING DEPT-NAME IF NOT REFDEPT DEPT-NAME = 'NOT FOUND' END-IF PRINT PAYRPT
Some legacy programs search variable-length text files or non-tabular reference extracts TABLE cannot model. ACCESS or SQL may fit better than forcing TABLE. If reference data is genuinely unsortable or keys are not fixed layout, sequential scan might remain—but that is a data modeling problem, not a reason to avoid sorting decodable code tables. Document exceptions rather than treating GET loops as default style.
Teams sometimes ask whether unsorted reference files force sequential search. Easytrieve answer: sort the file and use TABLE. Binary search requires order; sequential GET loops tolerate disorder but punish CPU. A one-time SORT in maintenance JCL is cheaper than millions of extra comparisons nightly. If sort is impossible because keys are not comparable, redesign reference extract—not the search algorithm inside Easytrieve.
Sequential search is reading every page of a book from the beginning until you find your word. Binary TABLE search is opening the book in the middle because words are in order. Easytrieve wants the ordered book trick. Reading every page for every question is slow homework nobody should do five million times per night.
1. Does Easytrieve SEARCH offer sequential scan mode?
2. Sequential GET through a reference file per input record is:
3. When is sequential file processing correct?
4. A 5,000-row reference GET loop on 100,000 input records compares up to:
5. Best alternative to sequential reference scan: