{"id":19899,"date":"2025-11-21T07:13:09","date_gmt":"2025-11-21T07:13:09","guid":{"rendered":"https:\/\/www.kaashivinfotech.com\/blog\/?p=19899"},"modified":"2025-11-21T10:15:26","modified_gmt":"2025-11-21T10:15:26","slug":"differences-between-search-and-search-all-in-cobol","status":"publish","type":"post","link":"https:\/\/www.kaashivinfotech.com\/blog\/differences-between-search-and-search-all-in-cobol\/","title":{"rendered":"Differences Between Search and Search All in COBOL"},"content":{"rendered":"<h3>7 Essential Differences Between Search and Search All in COBOL Every Programmer<\/h3>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-19923 size-full\" src=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/COBOL.webp\" alt=\"COBOL\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/COBOL.webp 1920w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/COBOL-300x169.webp 300w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/COBOL-1024x576.webp 1024w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/COBOL-768x432.webp 768w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/COBOL-1536x864.webp 1536w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/COBOL-380x214.webp 380w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/COBOL-800x450.webp 800w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/COBOL-1160x653.webp 1160w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>Difference Between Search and Search All \u2014 if you have ever written any lines of code in COBOL, you may have Googled this once or twice.<br \/>\nAnd for real?<br \/>\nSame here.<\/p>\n<p>Difference Between Search and Search All is one of those topics that seems easy at first\u2026 and then isn\u2019t. When I first learned COBOL, I would mix them up so often that my mentor joked I had some secret love for debugging infinite loops. \ud83d\ude05<\/p>\n<p>So in this article, I\u2019m going to break it all down in the most human way, friendly way that I can \u2014 with real examples, relatable insights, and usable explanations.<br \/>\nMy hope?<br \/>\nBy the end of this, you will never again mix up Search and Search All.<\/p>\n<h2>\u2b50 \u00a0Key Highlights of this Article<\/h2>\n<ul>\n<li>\u00a0Clearly know the Difference Between Search and Search All<\/li>\n<li>\u00a0Learn when to use Search and when to use Search All<\/li>\n<li>\u00a0Use short code-reading snippets from my own journey learning COBOL<\/li>\n<li>\u00a0Reads like you\u2019re talking to a friend &#8211; easy to read code example explanations<\/li>\n<li>\u00a0Clear explanations of linear search vs binary search<\/li>\n<\/ul>\n<h2>Distinguishing Between Search and Search All in COBOL &#8211; What You Truly Need to Understand<\/h2>\n<p><strong>When somebody asks for a distinction between Search and Search All, what they normally want is really simple:<\/strong><br \/>\n&#8211; \u201cJust tell me the difference.\u201d<br \/>\n&#8211; \u201cJust tell me when I use which one.\u201d<br \/>\n&#8211; \u201cGive me an explanation as if I am not a walking compiler.\u201d<\/p>\n<p>So, let me get this out of the way right now.<br \/>\nSearch = linear search<br \/>\nSearch All = binary search<\/p>\n<p>That&#8217;s the bottom line.<br \/>\nBut of course, it&#8217;s COBOL. Nothing is ever that brief. So let&#8217;s try to go deeper in a way that makes some sense.<\/p>\n<p>Differences Between Search and Search All in COBOL You Can\u2019t Ignore<\/p>\n<h2>1. What does SEARCH do in COBOL? (Includes the main keyword \ud83d\ude04)<\/h2>\n<h3>SEARCH is the most straightforward way to search an array in COBOL. It executes a linear search, which essentially means:<\/h3>\n<ul>\n<li>Start from the first element<\/li>\n<li>\u00a0All elements should be checked, one at a time<\/li>\n<li>Stop when the value is found!<\/li>\n<\/ul>\n<p>This is like looking at your contacts list without using the search bar.<\/p>\n<p data-start=\"3510\" data-end=\"3611\">When I first started, I used SEARCH everywhere because it\u2019s predictable. Slow, yes \u2014 but predictable.<\/p>\n<h3 data-start=\"3613\" data-end=\"3642\"><strong data-start=\"3617\" data-end=\"3642\">Example Code (SEARCH)<\/strong><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SEARCH ARR\r\n    AT END DISPLAY \"NOT FOUND\"\r\n    WHEN RNO(I) = SEARCHRNO\r\n        DISPLAY \"FOUND ROLL NUMBER\"\r\nEND-SEARCH.\r\n<\/pre>\n<h3 data-start=\"3776\" data-end=\"3798\">Real-life example:<\/h3>\n<p data-start=\"3799\" data-end=\"3961\">I once used SEARCH to find a student\u2019s roll number from a 10-record table my instructor gave me.<br data-start=\"3895\" data-end=\"3898\" \/>Was it fast? No.<br data-start=\"3914\" data-end=\"3917\" \/>Did it work well for small data? Absolutely.<\/p>\n<h2>2. What does SEARCH ALL mean in COBOL? (Secondary Keyword Inside \ud83d\ude09)<\/h2>\n<h3>Now, let\u2019s cover the \u201cfaster brother\u201d in the Search and Search All family \u2014 SEARCH ALL.<\/h3>\n<ul>\n<li>SEARCH ALL is doing a binary search.<\/li>\n<li>And binary search is FAST. Like really fast.\n<p><figure id=\"attachment_19919\" aria-describedby=\"caption-attachment-19919\" style=\"width: 940px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-19919 size-full\" src=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/Search-All-in-COBOL.webp\" alt=\"Search All in COBOL\" width=\"940\" height=\"788\" srcset=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/Search-All-in-COBOL.webp 940w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/Search-All-in-COBOL-300x251.webp 300w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/Search-All-in-COBOL-768x644.webp 768w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/Search-All-in-COBOL-380x319.webp 380w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/Search-All-in-COBOL-800x671.webp 800w\" sizes=\"(max-width: 940px) 100vw, 940px\" \/><figcaption id=\"caption-attachment-19919\" class=\"wp-caption-text\"><strong>Search All in COBOL<\/strong><\/figcaption><\/figure><\/li>\n<\/ul>\n<p><strong>Binary search works like this:<\/strong><\/p>\n<ul>\n<li>Look at the middle element<\/li>\n<li>If it\u2019s smaller, look at the right side<\/li>\n<li>If it\u2019s bigger, look at the left side<\/li>\n<li>Repeat until you find it<\/li>\n<li>It cuts the search space in half every single time.<\/li>\n<\/ul>\n<h3>Example Code (SEARCH ALL)<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SEARCH ALL ARR\r\n    AT END DISPLAY \"NOT FOUND ROLL NUMBER\"\r\n    WHEN RNO(I) = SEARCHRNO\r\n        DISPLAY \"FOUND ROLL NUMBER\"\r\nEND-SEARCH.\r\n<\/pre>\n<h2>3. Differences Between Search and Search All<\/h2>\n<h3>Now let&#8217;s go through the real Differences Between Search and Search All, in a clean table that you can bookmark, screenshot, or tattoo (just kidding&#8230; or am I? \ud83d\ude05).<\/h3>\n<figure id=\"attachment_19920\" aria-describedby=\"caption-attachment-19920\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-19920 size-medium\" src=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/What-Is-WordPress-13-300x169.webp\" alt=\"Search and Search All\" width=\"300\" height=\"169\" srcset=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/What-Is-WordPress-13-300x169.webp 300w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/What-Is-WordPress-13-768x432.webp 768w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/What-Is-WordPress-13-380x214.webp 380w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2025\/11\/What-Is-WordPress-13.webp 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-19920\" class=\"wp-caption-text\"><strong>Search and Search All<\/strong><\/figcaption><\/figure>\n<table class=\"w-fit min-w-(--thread-content-width)\" style=\"height: 232px;\" width=\"972\" data-start=\"5129\" data-end=\"5660\">\n<thead data-start=\"5129\" data-end=\"5160\">\n<tr data-start=\"5129\" data-end=\"5160\">\n<th data-start=\"5129\" data-end=\"5142\" data-col-size=\"sm\"><strong data-start=\"5131\" data-end=\"5141\">SEARCH<\/strong><\/th>\n<th data-start=\"5142\" data-end=\"5160\" data-col-size=\"sm\"><strong data-start=\"5144\" data-end=\"5158\">SEARCH ALL<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"5193\" data-end=\"5660\">\n<tr data-start=\"5193\" data-end=\"5252\">\n<td data-start=\"5193\" data-end=\"5222\" data-col-size=\"sm\">Performs <strong data-start=\"5204\" data-end=\"5221\">linear search<\/strong><\/td>\n<td data-col-size=\"sm\" data-start=\"5222\" data-end=\"5252\">Performs <strong data-start=\"5233\" data-end=\"5250\">binary search<\/strong><\/td>\n<\/tr>\n<tr data-start=\"5253\" data-end=\"5315\">\n<td data-start=\"5253\" data-end=\"5282\" data-col-size=\"sm\">Works on <strong data-start=\"5264\" data-end=\"5281\">unsorted data<\/strong><\/td>\n<td data-col-size=\"sm\" data-start=\"5282\" data-end=\"5315\">Works <strong data-start=\"5290\" data-end=\"5313\">only on sorted data<\/strong><\/td>\n<\/tr>\n<tr data-start=\"5316\" data-end=\"5374\">\n<td data-start=\"5316\" data-end=\"5342\" data-col-size=\"sm\">Slower for large tables<\/td>\n<td data-col-size=\"sm\" data-start=\"5342\" data-end=\"5374\">Much faster for large tables<\/td>\n<\/tr>\n<tr data-start=\"5375\" data-end=\"5453\">\n<td data-start=\"5375\" data-end=\"5415\" data-col-size=\"sm\">Supports <strong data-start=\"5386\" data-end=\"5414\">multiple WHEN conditions<\/strong><\/td>\n<td data-col-size=\"sm\" data-start=\"5415\" data-end=\"5453\">Allows <strong data-start=\"5424\" data-end=\"5451\">only equality condition<\/strong><\/td>\n<\/tr>\n<tr data-start=\"5454\" data-end=\"5519\">\n<td data-start=\"5454\" data-end=\"5495\" data-col-size=\"sm\">Requires <strong data-start=\"5465\" data-end=\"5478\">SET index<\/strong> before starting<\/td>\n<td data-col-size=\"sm\" data-start=\"5495\" data-end=\"5519\">No need to SET index<\/td>\n<\/tr>\n<tr data-start=\"5520\" data-end=\"5604\">\n<td data-start=\"5520\" data-end=\"5560\" data-col-size=\"sm\">Works on <strong data-start=\"5531\" data-end=\"5559\">multi-dimensional arrays<\/strong><\/td>\n<td data-col-size=\"sm\" data-start=\"5560\" data-end=\"5604\">Only works on <strong data-start=\"5576\" data-end=\"5602\">one-dimensional arrays<\/strong><\/td>\n<\/tr>\n<tr data-start=\"5605\" data-end=\"5660\">\n<td data-start=\"5605\" data-end=\"5619\" data-col-size=\"sm\">Easy to use<\/td>\n<td data-col-size=\"sm\" data-start=\"5619\" data-end=\"5660\">Requires sorted data &amp; careful coding<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Slightly different wording, on all the things above, outlines yet again There&#8217;s a Difference Between Search and Search All.<\/p>\n<h3>4. When to Use Which?<\/h3>\n<h3>Use SEARCH when:<\/h3>\n<ul>\n<li>Your table is not sorted<\/li>\n<li>You want simple, readable logic<\/li>\n<li>You have lots of conditions (i.e. if statements)<\/li>\n<li>Performance is not a concern<\/li>\n<\/ul>\n<h3>Use SEARCH ALL when:<\/h3>\n<ul>\n<li>Your table is sorted<\/li>\n<li>You want speed<\/li>\n<li>You are searching thousands of records<\/li>\n<li>You want fewer loops<\/li>\n<\/ul>\n<p>Whenever I design code for legacy COBOL systems, I frequently notice Search and Search All apart. Most of the time, is just developers choosing SEARCH ALL, simply because it is quicker.<br \/>\nBut speed matters only statement-hooks if data is sorted and is large enough.<\/p>\n<h2>\u00a05. Real Example From my Project Performance<\/h2>\n<p>I used to work on a banking project where we searched customer IDs thousands of times a day.<br \/>\nThe previous version of the code used SEARCH, and searched so slow, it literally lagged like an overloaded school computer.<br \/>\nWhen I switched the logic to SEARCH ALL, I of course first sorted the table, and kept sorting the data.<br \/>\n<strong>It is needless to say, I succeeded.<\/strong><\/p>\n<ul>\n<li>The search time went form 8 seconds to less than 1 second.<\/li>\n<li>My team lead said &#8220;You just saved us a week of maintenance&#8221;.<\/li>\n<li>I finally understood what the Difference Between Search and Search All is, in the real world.<\/li>\n<\/ul>\n<h2>6. An Easy Analogy to Illustrate it Further<\/h2>\n<h3>Searching using SEARCH is like:<\/h3>\n<ul>\n<li>\u00a0Looking at every item on your grocery list one-by-one, walking up and down each aisle looking for every item.<\/li>\n<\/ul>\n<h3>Searching using SEARCH ALL is like:<\/h3>\n<ul>\n<li>\u00a0Asking the store employee: \u201cHey, where is the sugar?\u201d<br \/>\nAnd then the employee directs you right to the aisle.<\/li>\n<\/ul>\n<p>Both work.<br \/>\nBut one is vastly more efficient.<\/p>\n<h2>\u00a07. Resources<\/h2>\n<h3>\ud83d\udcd8 Internal Links<\/h3>\n<ul>\n<li>COBOL Arrays Tutorial<\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/blog\/tag\/binary-search\/\">Linear Search<\/a> vs <a href=\"https:\/\/www.wikitechy.com\/technology\/binary-search-2\/\" target=\"_blank\" rel=\"noopener\">Binary Search<\/a><\/li>\n<li><a href=\"https:\/\/www.kaashivinfotech.com\/blog\/sql-commands\/\">COBOL Indexed Tables<\/a><\/li>\n<\/ul>\n<h3>\ud83c\udf0d External Links<\/h3>\n<ul>\n<li>IBM COBOL Documentation: https:\/\/www.ibm.com\/docs<\/li>\n<li>Tutorialspoint COBOL: https:\/\/www.tutorialspoint.com\/cobol<\/li>\n<\/ul>\n<p>These resources will help you to build much more knowledge beyond just the Difference Between Search vs Search All.<\/p>\n<h2>\ud83c\udfafFinal Thoughts \u2013 My Honest Advice<\/h2>\n<h3>If you are learning (or preparing for an interview) about COBOL, please engrain this in your brain:<\/h3>\n<ul>\n<li>SEARCH = linear search, slow, unsorted, and flexible to your values<\/li>\n<li>SEARCH ALL = binary search, fast, sorted, and strict about using your values<\/li>\n<\/ul>\n<p>I have been utilizing Search and Search All in practice for a long time, and the Difference Between Search and Search All is, without a doubt, one of the most basic, yet \u2026 powerful concepts in COBOL when it &#8220;clicks.&#8221;<\/p>\n<p>Use properly.<br \/>\nUse it knowingly.<br \/>\nAnd hey, now you can explain this better than half of the programmers out there.<\/p>\n<h2 class=\"overflow-y-auto p-4\" dir=\"ltr\"><\/h2>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>7 Essential Differences Between Search and Search All in COBOL Every Programmer Difference Between Search and Search All \u2014 if you have ever written any lines of code in COBOL, you may have Googled this once or twice. And for real? Same here. Difference Between Search and Search All is one of those topics that [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":19932,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3702],"tags":[10512,10514,10516,10510,10515,10518,10509,10513,10517,10508,10511,10507,10506],"class_list":["post-19899","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-what-is","tag-binary-search-in-cobol","tag-cobol-array-search","tag-cobol-examples","tag-cobol-indexed-tables","tag-cobol-programming-basics","tag-cobol-search-operations","tag-cobol-search-vs-search-all","tag-cobol-tutorial","tag-cobol-verbs","tag-differences-between-search-and-search-all","tag-linear-search-in-cobol","tag-search-all-in-cobol","tag-search-in-cobol"],"_links":{"self":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/19899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=19899"}],"version-history":[{"count":0,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/19899\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/media\/19932"}],"wp:attachment":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=19899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=19899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=19899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}