{"id":7292,"date":"2025-08-02T17:05:43","date_gmt":"2025-08-02T11:35:43","guid":{"rendered":"https:\/\/www.sapewmhelp.com\/?p=7292"},"modified":"2025-08-02T17:05:45","modified_gmt":"2025-08-02T11:35:45","slug":"how-can-you-extract-specific-fields-from-an-internal-table-using-for-where-inside-a-value-expression","status":"publish","type":"post","link":"https:\/\/www.sapewmhelp.com\/?p=7292","title":{"rendered":"How can you extract specific fields from an internal table using FOR \u2026 WHERE inside a VALUE expression?"},"content":{"rendered":"\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>*&---------------------------------------------------------------------*\n*& Report  ZREP_LCLCLASS\n*&---------------------------------------------------------------------*\n*& Demonstrates modern ABAP syntax: REDUCE, FILTER, FOR expressions\n*&---------------------------------------------------------------------*\n\nREPORT zrep_lclclass.\n\n*----------------------------\n* Example 1: REDUCE Operator\n*----------------------------\nTYPES: BEGIN OF ty_order,\n         id     TYPE i,\n         amount TYPE i,\n       END OF ty_order.\n\nDATA: lt_orders TYPE STANDARD TABLE OF ty_order WITH EMPTY KEY,\n      lv_total  TYPE i.\n\nlt_orders = VALUE #(\n  ( id = 1 amount = 100 )\n  ( id = 2 amount = 250 )\n  ( id = 3 amount = 150 )\n).\n\nlv_total = REDUCE i( INIT sum = 0\n                     FOR order IN lt_orders\n                     NEXT sum = sum + order-amount ).\n\nWRITE: \/ &#39;--- REDUCE Example ---&#39;,\n       \/ &#39;Total Amount:&#39;, lv_total.\n\n*----------------------------\n* Example 2: FILTER Operator\n*----------------------------\nTYPES: BEGIN OF ty_user,\n         name   TYPE string,\n         status TYPE string,\n       END OF ty_user.\n\nDATA: lt_users TYPE STANDARD TABLE OF ty_user WITH EMPTY KEY,\n      lt_active_users TYPE STANDARD TABLE OF ty_user WITH EMPTY KEY.\n\nlt_users = VALUE #(\n  ( name = &#39;Alice&#39;   status = &#39;ACTIVE&#39; )\n  ( name = &#39;Bob&#39;     status = &#39;INACTIVE&#39; )\n  ( name = &#39;Charlie&#39; status = &#39;ACTIVE&#39; )\n).\n\nlt_active_users = FILTER #( lt_users WHERE status = &#39;ACTIVE&#39; ).\n\nWRITE: \/ &#39;--- FILTER Example ---&#39;.\n\nLOOP AT lt_active_users INTO DATA(user).\n  WRITE: \/ user-name, user-status.\nENDLOOP.\n\n*------------------------------------------------------\n* Example 3: FOR Expression - Extract Specific Fields\n*------------------------------------------------------\nDATA: lt_names TYPE STANDARD TABLE OF string WITH EMPTY KEY.\n\nlt_names = VALUE string_table(\n  FOR user IN lt_users\n  WHERE ( status = &#39;ACTIVE&#39; )\n  ( user-name )\n).\n\nWRITE: \/ &#39;--- FOR Expression Example ---&#39;.\n\nLOOP AT lt_names INTO DATA(name).\n  WRITE: \/ name.\nENDLOOP.\n <\/code><\/pre><\/div>\n\n\n\n<p>This creates a new string table containing only the names of users whose&nbsp;<code>status = 'ACTIVE'<\/code>\u2014short, clean, and readable.<\/p>\n\n\n\n<p><strong>\u2014 REDUCE Example \u2014<\/strong><br>Total Amount: 500<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p><strong>\u2014 FILTER Example \u2014<\/strong><br>Alice ACTIVE<br>Charlie ACTIVE<\/p>\n\n\n\n<p><strong>\u2014 FOR Expression Example \u2014<\/strong><br>Alice<br>Charlie<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This creates a new string table containing only the names of users whose&nbsp;status = &#8216;ACTIVE&#8217;\u2014short, clean, and readable. \u2014 REDUCE Example \u2014Total Amount: 500 Output: \u2014 FILTER Example \u2014Alice ACTIVECharlie ACTIVE \u2014 FOR Expression Example \u2014AliceCharlie<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[242],"tags":[244,249,245,247,248,246],"class_list":["post-7292","post","type-post","status-publish","format-standard","hentry","category-sap-abap","tag-abap","tag-abap-7-4-example","tag-new-syntax","tag-reduce-operator-example","tag-using-for-new-syntax","tag-value-operator"],"_links":{"self":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/posts\/7292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7292"}],"version-history":[{"count":1,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/posts\/7292\/revisions"}],"predecessor-version":[{"id":7293,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=\/wp\/v2\/posts\/7292\/revisions\/7293"}],"wp:attachment":[{"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sapewmhelp.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}