{"id":7424,"date":"2025-08-06T00:41:51","date_gmt":"2025-08-05T19:11:51","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?question=join-vs-for-all-entries"},"modified":"2025-08-06T00:41:51","modified_gmt":"2025-08-05T19:11:51","slug":"join-vs-for-all-entries","status":"publish","type":"question","link":"https:\/\/www.sapewmhelp.com\/?question=join-vs-for-all-entries","title":{"rendered":"Join VS For all Entries"},"content":{"rendered":"<p><strong>Joins<\/strong><\/p>\n<p>combine rows from two or more tables based on a related column, usually a key field. ABAP supports various join types (INNER JOIN, LEFT OUTER JOIN, etc.) mostly used inside <strong>Open SQL<\/strong> queries.<\/p>\n<h4><strong>How to Use Joins:<\/strong><\/h4>\n<p>SELECT a~vbeln, a~erdat, b~posnr, b~matnr<span><br \/>\n<\/span>\u00a0 FROM vbak AS a<span><br \/>\n<\/span>\u00a0 INNER JOIN vbap AS b ON a~vbeln = b~vbeln<span><br \/>\n<\/span>\u00a0 INTO TABLE @DATA(result).<span><\/p>\n<p><\/span><\/p>\n<ul>\n<li>Here, sales order header (vbak) is joined with sales order items (vbap) on the sales order number (vbeln).<\/li>\n<li>Result is fetched in one go, improving performance by reducing database calls.<\/li>\n<\/ul>\n<p><strong>FOR ALL ENTRIES<\/strong><\/p>\n<p>is a clause in ABAP that allows you to select records from a table where a field matches any entry in an internal table, acting like an \u201cIN\u201d condition.<\/p>\n<h4><strong>How to Use FOR ALL ENTRIES:<\/strong><\/h4>\n<p>DATA: lt_vbak TYPE TABLE OF vbak,<span><br \/>\n<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0 lt_vbap TYPE TABLE OF vbap.<span><\/p>\n<p><\/span>&#8221; First select sales orders into internal table<span><br \/>\n<\/span>SELECT vbeln erdat vkorg kunnr FROM vbak<span><br \/>\n<\/span>\u00a0 INTO TABLE lt_vbak<span><br \/>\n<\/span>\u00a0 WHERE vkorg = &#8216;1000&#8217;.<span><\/p>\n<p><\/span>&#8221; Use FOR ALL ENTRIES to select matching items<span><br \/>\n<\/span>IF lt_vbak IS NOT INITIAL.<span><br \/>\n<\/span>\u00a0 SELECT vbeln posnr matnr FROM vbap<span><br \/>\n<\/span>\u00a0\u00a0\u00a0 INTO TABLE lt_vbap<span><br \/>\n<\/span>\u00a0\u00a0\u00a0 FOR ALL ENTRIES IN lt_vbak<span><br \/>\n<\/span>\u00a0\u00a0\u00a0 WHERE vbeln = lt_vbak-vbeln.<span><br \/>\n<\/span>ENDIF.<span><\/p>\n<p><\/span><\/p>\n<ul>\n<li>The first SELECT fetches sales orders for a sales org.<\/li>\n<li>The second SELECT fetches all items related to these orders.<\/li>\n<li>This reduces database hits compared to looping with multiple selects.<\/li>\n<\/ul>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","question-category":[158],"question_tags":[178,314,305,177],"class_list":["post-7424","question","type-question","status-publish","hentry","question-category-abap","question_tags-abap","question_tags-for-all-entries","question_tags-joins","question_tags-sap"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question\/7424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/question"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7424"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7424"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion-category&post=7424"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fquestion_tags&post=7424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}