<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fahim Al Jadid on Medium]]></title>
        <description><![CDATA[Stories by Fahim Al Jadid on Medium]]></description>
        <link>https://medium.com/@fahimaljadid?source=rss-261d1b1638db------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Fahim Al Jadid on Medium</title>
            <link>https://medium.com/@fahimaljadid?source=rss-261d1b1638db------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 01:05:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fahimaljadid/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SAP ABAP ALV Filtering: Part 2 #16]]></title>
            <link>https://medium.com/@fahimaljadid/sap-abap-alv-filtering-part-2-16-a25e1d875d88?source=rss-261d1b1638db------2</link>
            <guid isPermaLink="false">https://medium.com/p/a25e1d875d88</guid>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[alv]]></category>
            <category><![CDATA[erp]]></category>
            <category><![CDATA[abap]]></category>
            <dc:creator><![CDATA[Fahim Al Jadid]]></dc:creator>
            <pubDate>Mon, 30 Dec 2024 08:20:32 GMT</pubDate>
            <atom:updated>2024-12-30T08:20:32.491Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be0I7D8I26CCCPK0uqy8EQ.png" /></figure><p>Hello everyone! Welcome back to our series on ALV (Application List Viewer) in SAP ABAP. In the previous article, we learned how to filter ALV output based on a single username. Today, we will expand our knowledge by exploring how to filter data based on a range of values and how to exclude specific values from the output.</p><h3>Understanding the Requirement</h3><p>Filtering is a powerful feature in ALV that allows users to display only the records that meet certain criteria. In this session, we will cover two main scenarios:</p><ol><li><strong>Filtering based on a range of values:</strong> For example, displaying records where the sales category falls between ‘A’ and ‘B’.</li><li><strong>Excluding specific values:</strong> For instance, removing records with a line item number of ‘30’ from the output.</li></ol><h3>Example Scenario</h3><p>Let’s say we have a report that displays sales data, and the customer wants to see only the records where the sales category is between ‘A’ and ‘B’, while excluding any records with a line item number of ‘30’.</p><h3>Step-by-Step Implementation</h3><h3>Step 1: Set Up the Program</h3><p>We will make a copy of our existing ALV program to implement the filtering functionality. This allows us to modify the new program without affecting the original.</p><ol><li>Open your existing ALV program in the SAP GUI.</li><li>Use the “Copy” function to create a new program (e.g., Z_FILTER_RANGE_EXCLUDE).</li><li>Save the new program as a local object.</li></ol><h3>Step 2: Filtering Based on a Range</h3><p>Now, we will implement the filtering based on a range of values for the sales category.</p><ol><li>Declare the Internal Table for Filtering:</li></ol><ul><li>We will use the same internal table and work area structure as before.</li></ul><pre>DATA: lt_filter TYPE TABLE OF lvc_s_filt, &quot; Internal table for filtering<br>      ls_filter TYPE lvc_s_filt.         &quot; Work area for filtering</pre><p>2. Define the Range Filtering Criteria:</p><ul><li>We want to filter the sales category from ‘A’ to ‘B’.</li></ul><pre>ls_filter-fieldname = &#39;VBTYP&#39;.<br>ls_filter-tabname = &#39;LT_FINAL&#39;.<br>ls_filter-sign0 = &#39;I&#39;.     <br>ls_filter-optio = &#39;EQ&#39;.    <br>ls_filter-valuf_int = &#39;A&#39;. <br>ls_filter-valut_int = &#39;D&#39;. <br>APPEND ls_filter TO lt_filter.<br>CLEAR ls_filter.</pre><h3>Step 3: Excluding Specific Values</h3><p>Next, we will implement the functionality to exclude records with a specific line item number.</p><ol><li>Clear the Work Area: It’s important to clear the work area after each append to avoid carrying over values from previous entries.</li></ol><pre>CLEAR ls_filter. &quot; Clear the work area</pre><p>2. Define the Exclusion Criteria:</p><ul><li>We want to exclude records with line item number ‘30’.</li></ul><pre>ls_filter-fieldname = &#39;POSNR&#39;.<br>ls_filter-tabname = &#39;LT_FINAL&#39;.<br>ls_filter-sign0 = &#39;E&#39;.     <br>ls_filter-optio = &#39;EQ&#39;.    <br>ls_filter-valuf_int = &#39;000030&#39;. <br>APPEND ls_filter TO lt_filter.<br>CLEAR ls_filter.</pre><h3>Step 4: Pass the Filtering Parameter to the Function Module</h3><p>Now that we have defined our filtering criteria, we need to pass the filtering internal table to the grid display function module.</p><pre>CALL FUNCTION &#39;REUSE_ALV_GRID_DISPLAY&#39;<br>  EXPORTING<br>*   I_INTERFACE_CHECK              = &#39; &#39;<br>*   I_BYPASSING_BUFFER             =<br>*   I_BUFFER_ACTIVE                = &#39; &#39;<br>*   I_CALLBACK_PROGRAM             = &#39; &#39;<br>*   I_CALLBACK_PF_STATUS_SET       = &#39; &#39;<br>*   I_CALLBACK_USER_COMMAND        = &#39; &#39;<br>*   I_STRUCTURE_NAME               = &#39;ZSTR_SALES&#39;<br>*   IS_LAYOUT   =<br>    it_fieldcat = lt_fieldcat<br>*   IT_EXCLUDING                   =<br>*   IT_SPECIAL_GROUPS              =<br>*    it_sort     = lt_sort<br>   IT_FILTER   = lt_filter<br>*   IS_SEL_HIDE =<br>*   I_DEFAULT   = &#39;X&#39;<br>*   I_SAVE      = &#39; &#39;<br>*   IS_VARIANT  =<br>*   IT_EVENTS   =<br>*   IT_EVENT_EXIT                  =<br>*   IS_PRINT    =<br>*   IS_REPREP_ID                   =<br>*   I_SCREEN_START_COLUMN          = 0<br>*   I_SCREEN_START_LINE            = 0<br>*   I_SCREEN_END_COLUMN            = 0<br>*   I_SCREEN_END_LINE              = 0<br>*   IR_SALV_LIST_ADAPTER           =<br>*   IT_EXCEPT_QINFO                =<br>*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE<br>* IMPORTING<br>*   E_EXIT_CAUSED_BY_CALLER        =<br>*   ES_EXIT_CAUSED_BY_USER         =<br>  TABLES<br>    t_outtab    = lt_final<br>* EXCEPTIONS<br>*   PROGRAM_ERROR                  = 1<br>*   OTHERS      = 2<br>  .<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.</pre><h3>Step 5: Test the Program</h3><ol><li>Activate the Program: Make sure to activate your changes.</li><li>Execute the Program: Run the program without any input.</li><li>Check the Output: You should see that the output is filtered to show only the records where the sales category is between ‘A’ and ‘B’, and line item number ‘30’ is excluded.</li></ol><h3>Step 6: Debugging</h3><p>To better understand how the filtering works, you can set breakpoints in your code. This will allow you to inspect the values in your internal tables and see how the filtering is applied.</p><h3>Conclusion</h3><p>In this part of our tutorial, we successfully implemented filtering in an ALV report using ABAP. We learned how to filter based on a range of values and how to exclude specific values from the output.</p><p>Filtering is a valuable feature that enhances the usability of ALV reports, allowing users to focus on the data that matters most to them.</p><p>In the next lecture, we will explore additional functionalities to improve our ALV reports further. Thank you for joining me today! If you have any questions or need further clarification, feel free to ask. Happy coding, and see you in the next session!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a25e1d875d88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SAP ABAP ALV Filtering: Part 1 #15]]></title>
            <link>https://medium.com/@fahimaljadid/sap-abap-alv-filtering-part-1-15-195b2840b3b2?source=rss-261d1b1638db------2</link>
            <guid isPermaLink="false">https://medium.com/p/195b2840b3b2</guid>
            <category><![CDATA[erp]]></category>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[alv]]></category>
            <dc:creator><![CDATA[Fahim Al Jadid]]></dc:creator>
            <pubDate>Sun, 29 Dec 2024 06:48:35 GMT</pubDate>
            <atom:updated>2024-12-29T06:48:35.357Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be0I7D8I26CCCPK0uqy8EQ.png" /></figure><p>Hello everyone! Welcome back to our series on ALV (Application List Viewer) in SAP ABAP. In our previous sessions, we explored sorting functionalities. Today, we will dive into another important feature: filtering the ALV output based on specific criteria.</p><h3>Understanding the Requirement</h3><p>In ALV, filtering allows users to display only the records that meet certain conditions. For example, if you want to see records for a specific user, you can filter the output to show only those records.</p><h3>Example Scenario</h3><p>Imagine you have a report that displays user activity, and you want to filter the results to show only the records for user “OCD50”. Instead of requiring users to manually apply a filter after the report is generated, we will implement a feature that automatically filters the output based on this user ID when the report is executed.</p><h3>Step-by-Step Implementation</h3><h3>Step 1: Copy the Existing Program</h3><p>We will first make a copy of our existing ALV program to implement the filtering functionality. This allows us to modify the new program without affecting the original.</p><ol><li>Open your existing ALV program in the SAP GUI.</li><li>Use the “Copy” function to create a new program (e.g., Z_FILTER_ALV).</li><li>Save the new program as a local object.</li></ol><h3>Step 2: Modify the Program for Filtering</h3><p>Now, we will modify the new program to include the filtering functionality.</p><ol><li>Locate the Grid Display Function Module: In your program, find the section where you call the grid display function module (e.g., REUSE_ALV_GRID_DISPLAY).</li><li>Uncomment the Filtering Parameter: The grid display function module has a parameter called ID_FILTER that we will use to specify the filtering criteria.</li><li>Declare the Internal Table for Filtering:</li></ol><ul><li>First, we need to declare an internal table and a work area for filtering.</li></ul><pre>&quot; Filter<br>DATA : lt_filter type SLIS_T_FILTER_ALV. &quot; Internal table for filtering<br>DATA : ls_filter type slis_filter_alv. &quot; Work area for filtering</pre><p>4. Define the Filtering Criteria: We want to filter the data based on the username. Here’s how to do it:</p><pre>&quot; Filtering Logic<br>ls_filter-fieldname = &#39;ERNAM&#39;.  <br>ls_filter-tabname = &#39;LT_FINAL&#39;.  <br>ls_filter-sign0 = &#39;I&#39;.             &quot; &#39;I&#39; for include<br>ls_filter-optio = &#39;EQ&#39;.            &quot; &#39;EQ&#39; for equal<br>ls_filter-valuf_int = &#39;USEROCD50&#39;. &quot; The value we want to filter by<br>APPEND ls_filter TO lt_filter.     &quot; Append to the filtering internal table</pre><h3>Step 3: Pass the Filtering Parameter to the Function Module</h3><p>Now that we have defined our filtering criteria, we need to pass the filtering internal table to the grid display function module.</p><pre>CALL FUNCTION &#39;REUSE_ALV_GRID_DISPLAY&#39;<br>  EXPORTING<br>*   I_INTERFACE_CHECK              = &#39; &#39;<br>*   I_BYPASSING_BUFFER             =<br>*   I_BUFFER_ACTIVE                = &#39; &#39;<br>*   I_CALLBACK_PROGRAM             = &#39; &#39;<br>*   I_CALLBACK_PF_STATUS_SET       = &#39; &#39;<br>*   I_CALLBACK_USER_COMMAND        = &#39; &#39;<br>*   I_STRUCTURE_NAME               = &#39;ZSTR_SALES&#39;<br>*   IS_LAYOUT   =<br>    it_fieldcat = lt_fieldcat<br>*   IT_EXCLUDING                   =<br>*   IT_SPECIAL_GROUPS              =<br>*    it_sort     = lt_sort<br>   IT_FILTER   = lt_filter<br>*   IS_SEL_HIDE =<br>*   I_DEFAULT   = &#39;X&#39;<br>*   I_SAVE      = &#39; &#39;<br>*   IS_VARIANT  =<br>*   IT_EVENTS   =<br>*   IT_EVENT_EXIT                  =<br>*   IS_PRINT    =<br>*   IS_REPREP_ID                   =<br>*   I_SCREEN_START_COLUMN          = 0<br>*   I_SCREEN_START_LINE            = 0<br>*   I_SCREEN_END_COLUMN            = 0<br>*   I_SCREEN_END_LINE              = 0<br>*   IR_SALV_LIST_ADAPTER           =<br>*   IT_EXCEPT_QINFO                =<br>*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE<br>* IMPORTING<br>*   E_EXIT_CAUSED_BY_CALLER        =<br>*   ES_EXIT_CAUSED_BY_USER         =<br>  TABLES<br>    t_outtab    = lt_final<br>* EXCEPTIONS<br>*   PROGRAM_ERROR                  = 1<br>*   OTHERS      = 2<br>  .<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.</pre><h3>Step 4: Test the Program</h3><ol><li>Activate the Program: Make sure to activate your changes.</li><li>Execute the Program: Run the program and provide the necessary input.</li><li>Check the Output: You should see that the output is filtered to show only the records for user “OCD50”.</li></ol><h3>Step 5: Debugging</h3><p>You can set breakpoints in your code if you want to see how the filtering works in real time. This will allow you to inspect the values in your internal tables and see how the filtering is applied.</p><h3>Conclusion</h3><p>In this part of our tutorial, we successfully implemented filtering in an ALV report using ABAP. By utilizing the ID_FILTER parameter in the grid display function module, we can ensure that the data is presented according to the specified criteria without requiring user interaction.</p><p>In the next part, we will explore how to implement more complex filtering options, such as excluding certain values and filtering based on ranges.</p><p>Thank you for joining me today! If you have any questions or need further clarification, feel free to ask. Happy coding, and see you in the next session!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=195b2840b3b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SAP ABAP ALV Sorting: A Step-by-Step Guide #14]]></title>
            <link>https://medium.com/@fahimaljadid/sap-abap-alv-sorting-a-step-by-step-guide-14-86966fe6a9a4?source=rss-261d1b1638db------2</link>
            <guid isPermaLink="false">https://medium.com/p/86966fe6a9a4</guid>
            <category><![CDATA[sap-training]]></category>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[alv]]></category>
            <category><![CDATA[sap]]></category>
            <dc:creator><![CDATA[Fahim Al Jadid]]></dc:creator>
            <pubDate>Sun, 29 Dec 2024 06:47:58 GMT</pubDate>
            <atom:updated>2024-12-29T06:47:58.360Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be0I7D8I26CCCPK0uqy8EQ.png" /></figure><p>Hello everyone! Welcome back to our series on ALV (Application List Viewer) in SAP ABAP. Our previous sessions explored various ways to create a field catalog and display ALV output. Today, we will focus on a common requirement that many customers have: sorting the ALV output automatically based on specific criteria.</p><h3>Understanding the Requirement</h3><p>In our ALV program, we have already set up a manual method for creating a field catalog and displaying the output using a grid display. The built-in feature of ALV allows users to sort data in ascending or descending order by clicking on the column headers. However, our customer has a specific request: they want the data to be automatically sorted in ascending or descending order based on the creation date as soon as the output is displayed, without any user interaction.</p><h3>Example Scenario</h3><p>Imagine a sales report where the customer wants to see the most recent sales orders at the top of the list. Instead of requiring users to click on the “Creation Date” column to sort the data, the report should automatically display the data sorted by creation date in descending order.</p><h3>Step-by-Step Implementation</h3><h3>Step 1: Copy the Existing Program</h3><p>To implement the sorting functionality, we will first make a copy of our existing ALV program. This way, we can modify the new program without affecting the original.</p><ol><li>Open your existing ALV program in the SAP GUI.</li><li>Use the “Copy” function to create a new program (e.g., Z_SORT_ALV).</li><li>Save the new program as a local object.</li></ol><h3>Step 2: Modify the Program for Sorting</h3><p>Now, we will modify the new program to include the sorting functionality.</p><ol><li>Locate the Grid Display Function Module: In your program, find the section where you call the grid display function module (e.g., REUSE_ALV_GRID_DISPLAY).</li><li>Uncomment the Sorting Parameter: The grid display function module has a parameter called ID_SORT that we will use to specify the sorting criteria.</li><li>Declare the Internal Table for Sorting:</li></ol><ul><li>First, we need to declare an internal table and a work area for sorting.</li></ul><pre>DATA : lt_sort TYPE slis_t_sortinfo_alv.<br>DATA : ls_sort TYPE slis_sortinfo_alv.</pre><p>4. Specify the Sorting Criteria: We want to sort the data based on the creation date in descending order. Here’s how to do it:</p><pre>&quot; Sorting<br>ls_sort-fieldname = &#39;ERDAT&#39;.  &quot; Field name for creation date<br>ls_sort-down = &#39;X&#39;.  &quot; &#39;down&#39; for descending order<br>APPEND ls_sort to lt_sort.  &quot; Append to the sorting internal table</pre><h3>Step 3: Pass the Sorting Parameter to the Function Module</h3><p>Now that we have defined our sorting criteria, we need to pass the sorting internal table to the grid display function module.</p><pre>CALL FUNCTION &#39;REUSE_ALV_GRID_DISPLAY&#39;<br>  EXPORTING<br>*   I_INTERFACE_CHECK              = &#39; &#39;<br>*   I_BYPASSING_BUFFER             =<br>*   I_BUFFER_ACTIVE                = &#39; &#39;<br>*   I_CALLBACK_PROGRAM             = &#39; &#39;<br>*   I_CALLBACK_PF_STATUS_SET       = &#39; &#39;<br>*   I_CALLBACK_USER_COMMAND        = &#39; &#39;<br>*   I_STRUCTURE_NAME               = &#39;ZSTR_SALES&#39;<br>*   IS_LAYOUT   =<br>    it_fieldcat = lt_fieldcat<br>*   IT_EXCLUDING                   =<br>*   IT_SPECIAL_GROUPS              =<br>    it_sort     = lt_sort<br>*   IT_FILTER   =<br>*   IS_SEL_HIDE =<br>*   I_DEFAULT   = &#39;X&#39;<br>*   I_SAVE      = &#39; &#39;<br>*   IS_VARIANT  =<br>*   IT_EVENTS   =<br>*   IT_EVENT_EXIT                  =<br>*   IS_PRINT    =<br>*   IS_REPREP_ID                   =<br>*   I_SCREEN_START_COLUMN          = 0<br>*   I_SCREEN_START_LINE            = 0<br>*   I_SCREEN_END_COLUMN            = 0<br>*   I_SCREEN_END_LINE              = 0<br>*   IR_SALV_LIST_ADAPTER           =<br>*   IT_EXCEPT_QINFO                =<br>*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE<br>* IMPORTING<br>*   E_EXIT_CAUSED_BY_CALLER        =<br>*   ES_EXIT_CAUSED_BY_USER         =<br>  TABLES<br>    t_outtab    = lt_final<br>* EXCEPTIONS<br>*   PROGRAM_ERROR                  = 1<br>*   OTHERS      = 2<br>  .<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.</pre><h3>Step 4: Test the Program</h3><ol><li>Activate the Program: Make sure to activate your changes.</li><li>Execute the Program: Run the program and provide the necessary input.</li><li>Check the Output: You should see that the data is automatically sorted in descending order based on the creation date.</li></ol><h3>Step 5: Implement Ascending Order (Optional)</h3><p>If you want to allow for ascending-order sorting as well, you can modify the ls_sort-sort_order value to &#39;A&#39; (for ascending) and test the program again.</p><pre>ls_sort-up = &#39;X&#39;.    &quot; &#39;up&#39; for ascending order</pre><h3>Final Code:</h3><pre>*&amp;---------------------------------------------------------------------*<br>*&amp; Report ZPRG_ALV<br>*&amp;---------------------------------------------------------------------*<br>*&amp;<br>*&amp;---------------------------------------------------------------------*<br>REPORT zprg_alv.<br><br>&quot; Structure for VBAK<br>TYPES : BEGIN OF lty_vbak,<br>          vbeln TYPE vbeln_va,<br>          erdat TYPE erdat,<br>          erzet TYPE erzet,<br>          ernam TYPE ernam,<br>          vbtyp TYPE vbtyp,<br>        END OF lty_vbak.<br><br>DATA : lt_vbak TYPE TABLE OF lty_vbak. &quot; Internal Table for VBAK<br>DATA : ls_vbak TYPE lty_vbak. &quot; Work Area for VBAK<br><br>&quot; Structure for VBAP<br>TYPES : BEGIN OF lty_vbap,<br>          vbeln TYPE vbeln_va,<br>          posnr TYPE posnr_va,<br>          matnr TYPE matnr,<br>        END OF lty_vbap.<br><br>DATA : lt_vbap     TYPE TABLE OF lty_vbap. &quot; Internal Table for VBAP<br>DATA : ls_vbap     TYPE lty_vbap. &quot; Work Area for VBAP<br><br>DATA : lt_fieldcat TYPE slis_t_fieldcat_alv. &quot; Internal Table<br>DATA : ls_fieldcat TYPE slis_fieldcat_alv. &quot; Work area for field catalog<br><br>DATA : lt_final TYPE TABLE OF zstr_sales.<br>DATA : ls_final TYPE zstr_sales.<br><br>DATA : lt_sort TYPE slis_t_sortinfo_alv.<br>DATA : ls_sort TYPE slis_sortinfo_alv.<br><br>DATA : lv_vbln TYPE vbeln_va.<br><br>SELECT-OPTIONS : s_vbln FOR lv_vbln. &quot; character<br><br>SELECT vbeln erdat erzet ernam vbtyp<br>  FROM vbak<br>  INTO TABLE lt_vbak<br>  WHERE vbeln IN s_vbln.<br><br>IF lt_vbak IS NOT INITIAL.<br>  SELECT vbeln posnr matnr<br>  FROM vbap<br>  INTO TABLE lt_vbap<br>  FOR ALL ENTRIES IN lt_vbak<br>    WHERE vbeln = lt_vbak-vbeln.<br>ENDIF.<br><br>LOOP AT lt_vbak INTO ls_vbak.<br>  LOOP AT lt_vbap INTO ls_vbap WHERE vbeln = ls_vbak-vbeln.<br>    ls_final-vbeln = ls_vbak-vbeln.<br>    ls_final-erdat = ls_vbak-erdat.<br>    ls_final-erzet = ls_vbak-erzet.<br>    ls_final-ernam = ls_vbak-ernam.<br>    ls_final-vbtyp = ls_vbak-vbtyp.<br>    ls_final-posnr = ls_vbap-posnr.<br>    ls_final-matnr = ls_vbap-matnr.<br>    APPEND ls_final TO lt_final.<br>    CLEAR : ls_final.<br>  ENDLOOP.<br>ENDLOOP.<br><br>&quot; Manual Catalog<br>ls_fieldcat-col_pos = 1. &quot; First column position<br>ls_fieldcat-fieldname = &#39;VBELN&#39;. &quot; Field name for Sales Document Number<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;. &quot; Internal table name<br>ls_fieldcat-seltext_l = &#39;Sales Document Number&#39;. &quot; Long label<br>APPEND ls_fieldcat TO lt_fieldcat. &quot; Append to field catalog<br>CLEAR ls_fieldcat. &quot; Clear work area for next entry<br><br>ls_fieldcat-col_pos = 2.<br>ls_fieldcat-fieldname = &#39;ERDAT&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Creation Date&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 3.<br>ls_fieldcat-fieldname = &#39;ERZET&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Time&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 4.<br>ls_fieldcat-fieldname = &#39;ERNAM&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;User&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 5.<br>ls_fieldcat-fieldname = &#39;VBTYP&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Category&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 6.<br>ls_fieldcat-fieldname = &#39;POSNR&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Item Number&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 7.<br>ls_fieldcat-fieldname = &#39;MATNR&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Material Number&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>&quot; Sorting<br>ls_sort-fieldname = &#39;ERDAT&#39;.<br>ls_sort-down = &#39;X&#39;.<br>APPEND ls_sort to lt_sort.<br><br>CALL FUNCTION &#39;REUSE_ALV_GRID_DISPLAY&#39;<br>  EXPORTING<br>*   I_INTERFACE_CHECK              = &#39; &#39;<br>*   I_BYPASSING_BUFFER             =<br>*   I_BUFFER_ACTIVE                = &#39; &#39;<br>*   I_CALLBACK_PROGRAM             = &#39; &#39;<br>*   I_CALLBACK_PF_STATUS_SET       = &#39; &#39;<br>*   I_CALLBACK_USER_COMMAND        = &#39; &#39;<br>*   I_STRUCTURE_NAME               = &#39;ZSTR_SALES&#39;<br>*   IS_LAYOUT   =<br>    it_fieldcat = lt_fieldcat<br>*   IT_EXCLUDING                   =<br>*   IT_SPECIAL_GROUPS              =<br>    it_sort     = lt_sort<br>*   IT_FILTER   =<br>*   IS_SEL_HIDE =<br>*   I_DEFAULT   = &#39;X&#39;<br>*   I_SAVE      = &#39; &#39;<br>*   IS_VARIANT  =<br>*   IT_EVENTS   =<br>*   IT_EVENT_EXIT                  =<br>*   IS_PRINT    =<br>*   IS_REPREP_ID                   =<br>*   I_SCREEN_START_COLUMN          = 0<br>*   I_SCREEN_START_LINE            = 0<br>*   I_SCREEN_END_COLUMN            = 0<br>*   I_SCREEN_END_LINE              = 0<br>*   IR_SALV_LIST_ADAPTER           =<br>*   IT_EXCEPT_QINFO                =<br>*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE<br>* IMPORTING<br>*   E_EXIT_CAUSED_BY_CALLER        =<br>*   ES_EXIT_CAUSED_BY_USER         =<br>  TABLES<br>    t_outtab    = lt_final<br>* EXCEPTIONS<br>*   PROGRAM_ERROR                  = 1<br>*   OTHERS      = 2<br>  .<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.</pre><h3>Conclusion</h3><p>In this tutorial, we learned how to implement automatic sorting in an ALV report using ABAP. By utilizing the ID_SORT parameter in the grid display function module, we can ensure that the data is presented in the desired order without requiring user interaction.</p><p>Customers often request this functionality to enhance the usability of their reports. In our next video, we will explore additional functionalities to improve our ALV reports further.</p><p>Thank you for joining me today! If you have any questions or need further clarification, feel free to ask. Happy coding, and see you in the next session!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86966fe6a9a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hierarchical ALV Using REUSE_ALV_HIERSEQ_LIST_DISPLAY: Part 2 #13]]></title>
            <link>https://medium.com/@fahimaljadid/hierarchical-alv-using-reuse-alv-hierseq-list-display-part-2-13-39c94c387573?source=rss-261d1b1638db------2</link>
            <guid isPermaLink="false">https://medium.com/p/39c94c387573</guid>
            <category><![CDATA[sap-training]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[abap-training]]></category>
            <category><![CDATA[abap]]></category>
            <dc:creator><![CDATA[Fahim Al Jadid]]></dc:creator>
            <pubDate>Sun, 29 Dec 2024 06:46:56 GMT</pubDate>
            <atom:updated>2024-12-29T06:46:56.119Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be0I7D8I26CCCPK0uqy8EQ.png" /></figure><p>Hello everyone! Welcome back to our series on Hierarchical ALV. In the previous part, we set the groundwork by fetching data from the header table (VBAK) and the item table (VBAP). Today, we will focus on manually generating a field catalog that will allow us to display this data in a hierarchical format.</p><h3>What is a Field Catalog?</h3><p>A field catalog is a data structure that defines the properties of the columns to be displayed in the ALV output. It specifies details such as the column name, label, position, and data type. In our case, we will create a field catalog that includes columns from both the header and item tables.</p><h3>Understanding the Field Catalog Structure</h3><p>SAP provides a predefined table type for the field catalog, which can be found using the function module REUSE_ALV_FIELDCATALOG_MERGE. You can explore this in transaction SE37 by entering the function module name and checking the changing parameters. This will give you insight into the structure and fields available for the field catalog.</p><h3>Step-by-Step Guide to Creating the Field Catalog</h3><h3>Step 1: Declare the Field Catalog Internal Table</h3><p>In our program, we will declare an internal table for the field catalog and a work area to hold the individual entries as we build the catalog.</p><p>You will find the structure for the field catalog in the function module REUSE_ALV_FIELDCATALOG_MERGE.</p><pre>DATA : lt_fieldcat TYPE slis_t_fieldcat_alv. &quot; Internal Table for field catalog<br>DATA : ls_fieldcat TYPE slis_fieldcat_alv. &quot; Work area for field catalog</pre><h3>Step 2: Manually Generate the Field Catalog</h3><p>Now, we will manually create the field catalog by specifying the properties for each column. We will include five columns from the header table (VBAK) and three columns from the item table (VBAP).</p><h4>Adding Header Columns</h4><ol><li><strong>Sales Document Number:</strong></li></ol><pre>ls_fieldcat-col_pos = 1. &quot; First column position<br>ls_fieldcat-fieldname = &#39;VBELN&#39;. &quot; Field name for Sales Document Number<br>ls_fieldcat-tabname = &#39;LT_VBAK&#39;. &quot; Internal table name<br>ls_fieldcat-seltext_l = &#39;Sales Document Number&#39;. &quot; Long label<br>APPEND ls_fieldcat TO lt_fieldcat. &quot; Append to field catalog<br>CLEAR ls_fieldcat. &quot; Clear work area for next entry</pre><p>2. <strong>Creation Date:</strong></p><pre>ls_fieldcat-col_pos = 2.<br>ls_fieldcat-fieldname = &#39;ERDAT&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAK&#39;.<br>ls_fieldcat-seltext_l = &#39;Creation Date&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.</pre><p>3. <strong>Creation Time:</strong></p><pre>ls_fieldcat-col_pos = 3.<br>ls_fieldcat-fieldname = &#39;ERZET&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAK&#39;.<br>ls_fieldcat-seltext_l = &#39;Time&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.</pre><p>4. <strong>User :</strong></p><pre>ls_fieldcat-col_pos = 4.<br>ls_fieldcat-fieldname = &#39;ERNAM&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAK&#39;.<br>ls_fieldcat-seltext_l = &#39;User&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.</pre><p>5. <strong>Category:</strong></p><pre>ls_fieldcat-col_pos = 5.<br>ls_fieldcat-fieldname = &#39;VBTYP&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAK&#39;.<br>ls_fieldcat-seltext_l = &#39;Category&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.</pre><h4>Adding Item Columns</h4><p>Next, we will add the columns from the item table (VBAP):</p><ol><li><strong>Item Number:</strong></li></ol><pre>ls_fieldcat-col_pos = 1.<br>ls_fieldcat-fieldname = &#39;POSNR&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAP&#39;.<br>ls_fieldcat-seltext_l = &#39;Item Number&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.</pre><p>2. <strong>Material Number:</strong></p><pre>ls_fieldcat-col_pos = 2.<br>ls_fieldcat-fieldname = &#39;MATNR&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAP&#39;.<br>ls_fieldcat-seltext_l = &#39;Material Number&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.</pre><h3>Step 3: Binding Data with the Field Catalog</h3><p>Now that we have created our field catalog, the next step is to bind our data to this catalog and display it using the hierarchical ALV function module. This will allow us to visualize the relationship between the sales orders and their respective items.</p><h3>Step 4: Displaying the Hierarchical ALV</h3><p>To display our data using the hierarchical ALV function module, we will call REUSE_ALV_HIERSEQ_LIST_DISPLAY. Here’s how to do it:</p><ol><li>Call the Function Module: In your program, you will call the function module and pass the necessary parameters.</li></ol><p><strong>Here’s how to call the function module:</strong></p><pre>CALL FUNCTION &#39;REUSE_ALV_HIERSEQ_LIST_DISPLAY&#39;<br>  EXPORTING<br>*   I_INTERFACE_CHECK              = &#39; &#39;<br>*   I_CALLBACK_PROGRAM             =<br>*   I_CALLBACK_PF_STATUS_SET       = &#39; &#39;<br>*   I_CALLBACK_USER_COMMAND        = &#39; &#39;<br>*   IS_LAYOUT                      =<br>   IT_FIELDCAT                    = lt_fieldcat<br>*   IT_EXCLUDING                   =<br>*   IT_SPECIAL_GROUPS              =<br>*   IT_SORT                        =<br>*   IT_FILTER                      =<br>*   IS_SEL_HIDE                    =<br>*   I_SCREEN_START_COLUMN          = 0<br>*   I_SCREEN_START_LINE            = 0<br>*   I_SCREEN_END_COLUMN            = 0<br>*   I_SCREEN_END_LINE              = 0<br>*   I_DEFAULT                      = &#39;X&#39;<br>*   I_SAVE                         = &#39; &#39;<br>*   IS_VARIANT                     =<br>*   IT_EVENTS                      =<br>*   IT_EVENT_EXIT                  =<br>    i_tabname_header               = &#39;LT_VBAK&#39;<br>    i_tabname_item                 = &#39;LT_VBAP&#39;<br>*   I_STRUCTURE_NAME_HEADER        =<br>*   I_STRUCTURE_NAME_ITEM          =<br>    is_keyinfo                     = ls_keyinfo<br>*   IS_PRINT                       =<br>*   IS_REPREP_ID                   =<br>*   I_BYPASSING_BUFFER             =<br>*   I_BUFFER_ACTIVE                =<br>*   IR_SALV_HIERSEQ_ADAPTER        =<br>*   IT_EXCEPT_QINFO                =<br>*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE<br>* IMPORTING<br>*   E_EXIT_CAUSED_BY_CALLER        =<br>*   ES_EXIT_CAUSED_BY_USER         =<br>  TABLES<br>    t_outtab_header                = lt_vbak<br>    t_outtab_item                  = lt_vbap<br>* EXCEPTIONS<br>*   PROGRAM_ERROR                  = 1<br>*   OTHERS                         = 2<br>          .<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.</pre><h3>Important Parameters</h3><ul><li>it_fieldcat: This is the field catalog we created earlier.</li><li>it_outtab: This is the internal table containing the header data (VBAK).</li><li>it_outtab_item: This is the internal table containing the item data (VBAP).</li><li>is_key_info: This structure is crucial as it defines the common key between the header and item tables.</li></ul><h3>Step 5: Defining the Key Info Structure</h3><p>The is_key_info structure is used to specify the common column between the header and item tables. In our case, the common column is VBELN (Sales Document Number).</p><ol><li>Declare the Key Info Structure:</li></ol><pre>DATA : ls_keyinfo type SLIS_KEYINFO_ALV.</pre><p>2. Assign the Common Column:</p><pre><br>ls_keyinfo-header01 = &#39;VBELN&#39;.<br>ls_keyinfo-item01 = &#39;VBELN&#39;.</pre><p>This tells the function module that VBELN is the key that links the header and item data.</p><h3>Final Code:</h3><pre>*&amp;---------------------------------------------------------------------*<br>*&amp; Report ZPRG_ALV<br>*&amp;---------------------------------------------------------------------*<br>*&amp;<br>*&amp;---------------------------------------------------------------------*<br>REPORT zprg_alv.<br><br>&quot; Structure for VBAK<br>TYPES : BEGIN OF lty_vbak,<br>          vbeln TYPE vbeln_va,<br>          erdat TYPE erdat,<br>          erzet TYPE erzet,<br>          ernam TYPE ernam,<br>          vbtyp TYPE vbtyp,<br>        END OF lty_vbak.<br><br>DATA : lt_vbak TYPE TABLE OF lty_vbak. &quot; Internal Table for VBAK<br>DATA : ls_vbak TYPE lty_vbak. &quot; Work Area for VBAK<br><br>&quot; Structure for VBAP<br>TYPES : BEGIN OF lty_vbap,<br>          vbeln TYPE vbeln_va,<br>          posnr TYPE posnr_va,<br>          matnr TYPE matnr,<br>        END OF lty_vbap.<br><br>DATA : lt_vbap     TYPE TABLE OF lty_vbap. &quot; Internal Table for VBAP<br>DATA : ls_vbap     TYPE lty_vbap. &quot; Work Area for VBAP<br><br>DATA : lt_fieldcat TYPE slis_t_fieldcat_alv. &quot; Internal Table<br>DATA : ls_fieldcat TYPE slis_fieldcat_alv. &quot; Work area for field catalog<br><br>DATA : ls_keyinfo type SLIS_KEYINFO_ALV.<br><br>DATA : lv_vbln TYPE vbeln_va.<br><br>SELECT-OPTIONS : s_vbln FOR lv_vbln.<br><br>SELECT vbeln erdat erzet ernam vbtyp<br>  FROM vbak<br>  INTO TABLE lt_vbak<br>  WHERE vbeln IN s_vbln.<br><br>IF lt_vbak IS NOT INITIAL.<br>  SELECT vbeln posnr matnr<br>  FROM vbap<br>  INTO TABLE lt_vbap<br>  FOR ALL ENTRIES IN lt_vbak<br>    WHERE vbeln = lt_vbak-vbeln.<br>ENDIF.<br><br>&quot; Manual Catalog<br>ls_fieldcat-col_pos = 1. &quot; First column position<br>ls_fieldcat-fieldname = &#39;VBELN&#39;. &quot; Field name for Sales Document Number<br>ls_fieldcat-tabname = &#39;LT_VBAK&#39;. &quot; Internal table name<br>ls_fieldcat-seltext_l = &#39;Sales Document Number&#39;. &quot; Long label<br>APPEND ls_fieldcat TO lt_fieldcat. &quot; Append to field catalog<br>CLEAR ls_fieldcat. &quot; Clear work area for next entry<br><br>ls_fieldcat-col_pos = 2.<br>ls_fieldcat-fieldname = &#39;ERDAT&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAK&#39;.<br>ls_fieldcat-seltext_l = &#39;Creation Date&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 3.<br>ls_fieldcat-fieldname = &#39;ERZET&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAK&#39;.<br>ls_fieldcat-seltext_l = &#39;Time&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 4.<br>ls_fieldcat-fieldname = &#39;ERNAM&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAK&#39;.<br>ls_fieldcat-seltext_l = &#39;User&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 5.<br>ls_fieldcat-fieldname = &#39;VBTYP&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAK&#39;.<br>ls_fieldcat-seltext_l = &#39;Category&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 1.<br>ls_fieldcat-fieldname = &#39;POSNR&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAP&#39;.<br>ls_fieldcat-seltext_l = &#39;Item Number&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 2.<br>ls_fieldcat-fieldname = &#39;MATNR&#39;.<br>ls_fieldcat-tabname = &#39;LT_VBAP&#39;.<br>ls_fieldcat-seltext_l = &#39;Material Number&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_keyinfo-header01 = &#39;VBELN&#39;.<br>ls_keyinfo-item01 = &#39;VBELN&#39;.<br><br>CALL FUNCTION &#39;REUSE_ALV_HIERSEQ_LIST_DISPLAY&#39;<br>  EXPORTING<br>*   I_INTERFACE_CHECK              = &#39; &#39;<br>*   I_CALLBACK_PROGRAM             =<br>*   I_CALLBACK_PF_STATUS_SET       = &#39; &#39;<br>*   I_CALLBACK_USER_COMMAND        = &#39; &#39;<br>*   IS_LAYOUT                      =<br>   IT_FIELDCAT                    = lt_fieldcat<br>*   IT_EXCLUDING                   =<br>*   IT_SPECIAL_GROUPS              =<br>*   IT_SORT                        =<br>*   IT_FILTER                      =<br>*   IS_SEL_HIDE                    =<br>*   I_SCREEN_START_COLUMN          = 0<br>*   I_SCREEN_START_LINE            = 0<br>*   I_SCREEN_END_COLUMN            = 0<br>*   I_SCREEN_END_LINE              = 0<br>*   I_DEFAULT                      = &#39;X&#39;<br>*   I_SAVE                         = &#39; &#39;<br>*   IS_VARIANT                     =<br>*   IT_EVENTS                      =<br>*   IT_EVENT_EXIT                  =<br>    i_tabname_header               = &#39;LT_VBAK&#39;<br>    i_tabname_item                 = &#39;LT_VBAP&#39;<br>*   I_STRUCTURE_NAME_HEADER        =<br>*   I_STRUCTURE_NAME_ITEM          =<br>    is_keyinfo                     = ls_keyinfo<br>*   IS_PRINT                       =<br>*   IS_REPREP_ID                   =<br>*   I_BYPASSING_BUFFER             =<br>*   I_BUFFER_ACTIVE                =<br>*   IR_SALV_HIERSEQ_ADAPTER        =<br>*   IT_EXCEPT_QINFO                =<br>*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE<br>* IMPORTING<br>*   E_EXIT_CAUSED_BY_CALLER        =<br>*   ES_EXIT_CAUSED_BY_USER         =<br>  TABLES<br>    t_outtab_header                = lt_vbak<br>    t_outtab_item                  = lt_vbap<br>* EXCEPTIONS<br>*   PROGRAM_ERROR                  = 1<br>*   OTHERS                         = 2<br>          .<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.</pre><h3>Step 6: Debugging and Execution</h3><p>Before executing the program, it’s a good practice to check for any syntax errors and activate the program. You can also set breakpoints to debug and see how the data flows through your program.</p><ol><li><strong>Set Breakpoints:</strong> Place breakpoints at key points in your code to observe the values of your internal tables and the field catalog.</li><li><strong>Run the Program:</strong> Execute the program and input the sales order numbers you want to display.</li></ol><h3>Step 7: Viewing the Output</h3><p>Once you run the program, you should see the output displayed in a hierarchical format. The output will show:</p><ul><li><strong>Header Data:</strong> Five columns from the VBAK table.</li><li><strong>Item Data:</strong> Three columns from the VBAP table.</li></ul><p><strong>For example, you might see:</strong></p><p><strong>Sales Order 1000001</strong></p><ul><li>Creation Date: 2023–01–01</li><li>Creation Time: 10:00 AM</li><li>User: John Doe</li><li>Category: Standard</li></ul><p><strong>Items:</strong></p><ul><li>Item 10: Material A</li><li>Item 20: Material B</li></ul><p>This hierarchical display allows users to easily understand the relationship between sales orders and their associated items.</p><h3>Step 8: Conclusion</h3><p>In this part of our tutorial, we successfully created a field catalog for our hierarchical ALV display and bound our data to it. We learned how to specify the properties of each column and how to use the function module to display our data in a structured format.</p><p>we also successfully used the REUSE_ALV_HIERSEQ_LIST_DISPLAY function module to display our data in a hierarchical format. We defined the necessary parameters, specified the common key between the header and item tables, and executed the program to see the output.</p><p>Thank you for following along in this series on Hierarchical ALV! If you have any questions or need further clarification, feel free to ask. Happy coding, and see you in the next session!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39c94c387573" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hierarchical ALV Using REUSE_ALV_HIERSEQ_LIST_DISPLAY: Part 1 #12]]></title>
            <link>https://medium.com/@fahimaljadid/hierarchical-alv-using-reuse-alv-hierseq-list-display-part-1-12-cadc0fe5eb5f?source=rss-261d1b1638db------2</link>
            <guid isPermaLink="false">https://medium.com/p/cadc0fe5eb5f</guid>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[abap]]></category>
            <dc:creator><![CDATA[Fahim Al Jadid]]></dc:creator>
            <pubDate>Sat, 21 Dec 2024 21:08:38 GMT</pubDate>
            <atom:updated>2024-12-21T21:08:38.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be0I7D8I26CCCPK0uqy8EQ.png" /></figure><p>Hello everyone! Welcome back to our series on the Application List Viewer (ALV). In our previous sessions, we covered how to create a field catalog, bind data, and display the output using list and grid displays. Today, we will explore a new and exciting topic: Hierarchical ALV using the function module REUSE_ALV_HIERSEQ_LIST_DISPLAY.</p><h3>What is Hierarchical ALV?</h3><p>Hierarchical ALV allows us to display data in a parent-child relationship format. This means that we can show related data together in a structured way, making it easier for users to understand the relationships between different data points. For example, in a sales order scenario, we can display header information (like the sales order number) alongside its associated item details (like item numbers and material numbers).</p><h3>Understanding Hierarchical Output</h3><p>To illustrate the concept of hierarchical output, let’s consider a sample program. When we run this program, we will see an output that displays header data followed by item data in a structured format. For instance, you might see:</p><ul><li><strong>Header Data:</strong> Sales Document Number, Creation Date, Time, Name, and Category.</li><li><strong>Item Data:</strong> Sales Document Number, Item Number, Material Number.</li></ul><p>This format allows users to see the relationship between the sales order (header) and its items in a clear and organized manner.</p><h3>Real-World Example</h3><p>Imagine you are managing a project with multiple tasks. Each task has a parent project, and you want to display the project details alongside its associated tasks. In a hierarchical display, you would see:</p><p><strong>Project A</strong></p><ul><li><em>Task 1.1</em></li><li><em>Task 1.2</em></li></ul><p><strong>Project B</strong></p><ul><li><em>Task 2.1</em></li><li><em>Task 2.2</em></li><li><em>Task 2.3</em></li></ul><p>This format allows users to see the relationship between the projects and their tasks clearly.</p><h3>SAP Example</h3><p>In the context of SAP, consider a sales order scenario. You might want to display the sales order header information (like the sales order number and customer name) alongside its associated item details (like item numbers and material descriptions). The hierarchical display would look something like this:</p><p><strong>Sales Order 1000001</strong></p><ul><li><em>Item 10: Material A</em></li><li><em>Item 20: Material B</em></li></ul><p><strong>Sales Order 1000002</strong></p><ul><li><em>Item 10: Material C</em></li><li><em>Item 20: Material D</em></li><li><em>Item 30: Material E</em></li></ul><p>This structure helps users quickly understand which items belong to which sales order.</p><h3>Setting Up the Hierarchical ALV Program</h3><p>Now, let’s get started with creating our own hierarchical ALV report. We will use the manual method to generate a field catalog and then display the output using the hierarchical ALV function module.</p><h3>Step 1: Create a New Program</h3><ol><li><strong>Open Transaction SE38:</strong> This is where we will create our new executable program.</li><li><strong>Create a New Program:</strong> Click on the “Create” button and provide a name for your program, such as Z_HIERARCHICAL_ALV.</li><li><strong>Set the Title:</strong> Give your program a title, like “Hierarchical Display of Order Details”.</li><li><strong>Set the Type:</strong> Choose “Executable Program” and save it as a local object.</li></ol><h3>Step 2: Create a Variable &amp; Define the Selection Options</h3><p>Next, we will create a variable and define a selection option for the sales order number:</p><pre>DATA : lv_vbln TYPE vbeln_va.<br><br>SELECT-OPTIONS : s_vbln FOR lv_vbln.</pre><p>This allows users to input a range of sales order numbers when they run the program.</p><h3>Step 3: Declare Structures and Internal Tables</h3><p>We will create structures to hold data from the header table (VBAK) and the item table (VBAP):</p><pre>&quot; Structure for VBAK<br>TYPES : BEGIN OF lty_vbak,<br>          vbeln TYPE vbeln_va,<br>          erdat TYPE erdat,<br>          erzet TYPE erzet,<br>          ernam TYPE ernam,<br>          vbtyp TYPE vbtyp,<br>        END OF lty_vbak.<br><br>DATA : lt_vbak TYPE TABLE OF lty_vbak. &quot; Internal Table for VBAK<br>DATA : ls_vbak TYPE lty_vbak. &quot; Work Area for VBAK</pre><p>Similarly, we will create a structure for the item data:</p><pre>&quot; Structure for VBAP<br>TYPES : BEGIN OF lty_vbap,<br>          vbeln TYPE vbeln_va,<br>          posnr TYPE posnr_va,<br>          matnr TYPE matnr,<br>        END OF lty_vbap.<br><br>DATA : lt_vbap     TYPE TABLE OF lty_vbap. &quot; Internal Table for VBAP<br>DATA : ls_vbap     TYPE lty_vbap. &quot; Work Area for VBAP</pre><h3>Step 4: Fetch Data from the Database</h3><p>Now, we will fetch data from both the header and item tables. First, we will select data from the header table (VBAK):</p><pre>SELECT vbeln erdat erzet ernam vbtyp<br>  FROM vbak<br>  INTO TABLE lt_vbak<br>  WHERE vbeln IN s_vbln.</pre><p>Next, we will fetch data from the item table (VBAP) using the first internal table as a reference:</p><pre>IF lt_vbak IS NOT INITIAL.<br>  SELECT vbeln posnr matnr<br>  FROM vbap<br>  INTO TABLE lt_vbap<br>  FOR ALL ENTRIES IN lt_vbak<br>    WHERE vbeln = lt_vbak-vbeln.<br>ENDIF.</pre><h3>Step 5: Prepare for Hierarchical ALV Display</h3><p>In the next part of our tutorial, we will focus on creating the field catalog and displaying the hierarchical ALV output using the function module REUSE_ALV_HIERSEQ_LIST_DISPLAY.</p><h3>Conclusion</h3><p>In this first part of our exploration into Hierarchical ALV, we have set up the groundwork by creating a new program, defining selection options, declaring structures, and fetching data from the database. In the next lecture, we will continue by creating the field catalog and displaying the hierarchical output.</p><p>Thank you for joining me today! If you have any questions or need further clarification, feel free to ask. Happy coding, and see you in the next part of our Hierarchical ALV series!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cadc0fe5eb5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Combining the ALV Creation Steps in SAP ABAP #11]]></title>
            <link>https://medium.com/@fahimaljadid/combining-the-alv-creation-steps-in-sap-abap-11-6bf095c6dedd?source=rss-261d1b1638db------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bf095c6dedd</guid>
            <category><![CDATA[alv]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[sap-training]]></category>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[abap-training]]></category>
            <dc:creator><![CDATA[Fahim Al Jadid]]></dc:creator>
            <pubDate>Sat, 21 Dec 2024 21:07:57 GMT</pubDate>
            <atom:updated>2024-12-21T21:07:57.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be0I7D8I26CCCPK0uqy8EQ.png" /></figure><p>Hello everyone! Welcome back to our series on the Application List Viewer (ALV). In our previous sessions, we explored various methods for creating field catalogs, displaying ALV outputs, and modifying field catalogs generated by SAP function modules. Today, we will discuss an important topic: Can we combine the steps of creating a field catalog and binding data into a single step?</p><h3>Recap of Previous Sessions</h3><p>So far, we have learned that:</p><ul><li>We can create a field catalog manually or using SAP function modules.</li><li>We can display the ALV output using either REUSE_ALV_GRID_DISPLAY or REUSE_ALV_LIST_DISPLAY.</li><li>If we use the SAP function module to generate the field catalog, we can still modify it later if needed.</li></ul><p>Now, let’s dive into the question of combining the steps.</p><h3>Combining Field Catalog Creation and Data Binding</h3><p>The traditional approach to creating an ALV report involves two distinct steps:</p><ol><li><strong>Creating the Field Catalog:</strong> This step involves defining the structure and properties of the columns in the ALV output.</li><li><strong>Binding Data to the Field Catalog:</strong> This step involves linking the actual data to the field catalog for display.</li></ol><h3>Can We Combine These Steps?</h3><p>Yes, combining these two steps into one by using a single-function module is possible. For example, you can pass the structure name directly to the function module, which will generate the field catalog and bind the data in one go.</p><p>Here’s how you can do it:</p><ul><li>Instead of creating the field catalog separately, you can comment out the field catalog creation logic and use the function module to handle both tasks.</li><li>By passing the structure name to the function module, SAP will generate the field catalog and bind the data simultaneously.</li></ul><pre>*&amp;---------------------------------------------------------------------*<br>*&amp; Report ZPRG_ALV<br>*&amp;---------------------------------------------------------------------*<br>*&amp;<br>*&amp;---------------------------------------------------------------------*<br>REPORT zprg_alv.<br><br>&quot; Structure for VBAK<br>TYPES : BEGIN OF lty_vbak,<br>          vbeln TYPE vbeln_va,<br>          erdat TYPE erdat,<br>          erzet TYPE erzet,<br>          ernam TYPE ernam,<br>          vbtyp TYPE vbtyp,<br>        END OF lty_vbak.<br><br>DATA : lt_vbak TYPE TABLE OF lty_vbak.<br>DATA : ls_vbak TYPE lty_vbak.<br><br>&quot; Structure for VBAP<br>TYPES : BEGIN OF lty_vbap,<br>          vbeln TYPE vbeln_va,<br>          posnr TYPE posnr_va,<br>          matnr TYPE matnr,<br>        END OF lty_vbap.<br><br>DATA : lt_vbap     TYPE TABLE OF lty_vbap.<br>DATA : ls_vbap     TYPE lty_vbap.<br><br>DATA : lt_fieldcat TYPE slis_t_fieldcat_alv. &quot; Internal Table<br>DATA : ls_fieldcat TYPE slis_fieldcat_alv. &quot; Work area for field catalog<br><br>DATA : lt_final    TYPE TABLE OF zstr_sales.<br>DATA : ls_final    TYPE zstr_sales.<br><br>DATA : lv_vbln TYPE vbeln_va.<br><br>SELECT-OPTIONS : s_vbln FOR lv_vbln. &quot; character<br><br>SELECT vbeln erdat erzet ernam vbtyp<br>  FROM vbak<br>  INTO TABLE lt_vbak<br>  WHERE vbeln IN s_vbln.<br><br>IF lt_vbak IS NOT INITIAL.<br>  SELECT vbeln posnr matnr<br>  FROM vbap<br>  INTO TABLE lt_vbap<br>  FOR ALL ENTRIES IN lt_vbak<br>    WHERE vbeln = lt_vbak-vbeln.<br>ENDIF.<br><br>LOOP AT lt_vbak INTO ls_vbak.<br>  LOOP AT lt_vbap INTO ls_vbap WHERE vbeln = ls_vbak-vbeln.<br>    ls_final-vbeln = ls_vbak-vbeln.<br>    ls_final-erdat = ls_vbak-erdat.<br>    ls_final-erzet = ls_vbak-erzet.<br>    ls_final-ernam = ls_vbak-ernam.<br>    ls_final-vbtyp = ls_vbak-vbtyp.<br>    ls_final-posnr = ls_vbap-posnr.<br>    ls_final-matnr = ls_vbap-matnr.<br>    APPEND ls_final TO lt_final.<br>    CLEAR : ls_final.<br>  ENDLOOP.<br>ENDLOOP.<br><br>*&quot; Manual Catalog<br>*ls_fieldcat-col_pos = 1. &quot; First column position<br>*ls_fieldcat-fieldname = &#39;VBELN&#39;. &quot; Field name for Sales Document Number<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;. &quot; Internal table name<br>*ls_fieldcat-seltext_l = &#39;Sales Document Number&#39;. &quot; Long label<br>*APPEND ls_fieldcat TO lt_fieldcat. &quot; Append to field catalog<br>*CLEAR ls_fieldcat. &quot; Clear work area for next entry<br>*<br>*ls_fieldcat-col_pos = 2.<br>*ls_fieldcat-fieldname = &#39;ERDAT&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Creation Date&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br>*<br>*ls_fieldcat-col_pos = 3.<br>*ls_fieldcat-fieldname = &#39;ERZET&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Time&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br>*<br>*ls_fieldcat-col_pos = 4.<br>*ls_fieldcat-fieldname = &#39;ERNAM&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Name&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br>*<br>*ls_fieldcat-col_pos = 5.<br>*ls_fieldcat-fieldname = &#39;VBTYP&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Document Category&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br>*<br>*ls_fieldcat-col_pos = 6.<br>*ls_fieldcat-fieldname = &#39;POSNR&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Document Item&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br>*<br>*ls_fieldcat-col_pos = 7.<br>*ls_fieldcat-fieldname = &#39;MATNR&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Material Number&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br><br>*CALL FUNCTION &#39;REUSE_ALV_FIELDCATALOG_MERGE&#39;<br>*  EXPORTING<br>**   I_PROGRAM_NAME         =<br>**   I_INTERNAL_TABNAME     =<br>*    i_structure_name       = &#39;ZSTR_SALES&#39;<br>**   I_CLIENT_NEVER_DISPLAY = &#39;X&#39;<br>**   I_INCLNAME             =<br>**   I_BYPASSING_BUFFER     =<br>**   I_BUFFER_ACTIVE        =<br>*  CHANGING<br>*    ct_fieldcat            = lt_fieldcat<br>*  EXCEPTIONS<br>*    inconsistent_interface = 1<br>*    program_error          = 2<br>*    OTHERS                 = 3.<br>*IF sy-subrc &lt;&gt; 0.<br>** Implement suitable error handling here<br>*ENDIF.<br>*<br>*&quot; Modification Logic<br>*LOOP AT lt_fieldcat INTO ls_fieldcat.<br>*  IF ls_fieldcat-fieldname = &#39;VBELN&#39;.<br>*    ls_fieldcat-seltext_l = &#39;Document Number&#39;.<br>*    MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING seltext_l.<br>*  ENDIF.<br>*<br>*  IF ls_fieldcat-fieldname = &#39;ERDAT&#39;.<br>*    ls_fieldcat-col_pos = 3.<br>*    MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING col_pos.<br>*  ENDIF.<br>*<br>*  IF ls_fieldcat-fieldname = &#39;ERZET&#39;.<br>*    ls_fieldcat-col_pos = 2.<br>*    MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING col_pos.<br>*  ENDIF.<br>*<br>*ENDLOOP.<br><br>CALL FUNCTION &#39;REUSE_ALV_GRID_DISPLAY&#39;<br>  EXPORTING<br>*   I_INTERFACE_CHECK              = &#39; &#39;<br>*   I_BYPASSING_BUFFER             =<br>*   I_BUFFER_ACTIVE                = &#39; &#39;<br>*   I_CALLBACK_PROGRAM             = &#39; &#39;<br>*   I_CALLBACK_PF_STATUS_SET       = &#39; &#39;<br>*   I_CALLBACK_USER_COMMAND        = &#39; &#39;<br>   I_STRUCTURE_NAME               = &#39;ZSTR_SALES&#39;<br>*   IS_LAYOUT   =<br>*    it_fieldcat = lt_fieldcat<br>*   IT_EXCLUDING                   =<br>*   IT_SPECIAL_GROUPS              =<br>*   IT_SORT     =<br>*   IT_FILTER   =<br>*   IS_SEL_HIDE =<br>*   I_DEFAULT   = &#39;X&#39;<br>*   I_SAVE      = &#39; &#39;<br>*   IS_VARIANT  =<br>*   IT_EVENTS   =<br>*   IT_EVENT_EXIT                  =<br>*   IS_PRINT    =<br>*   IS_REPREP_ID                   =<br>*   I_SCREEN_START_COLUMN          = 0<br>*   I_SCREEN_START_LINE            = 0<br>*   I_SCREEN_END_COLUMN            = 0<br>*   I_SCREEN_END_LINE              = 0<br>*   IR_SALV_LIST_ADAPTER           =<br>*   IT_EXCEPT_QINFO                =<br>*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE<br>* IMPORTING<br>*   E_EXIT_CAUSED_BY_CALLER        =<br>*   ES_EXIT_CAUSED_BY_USER         =<br>  TABLES<br>    t_outtab    = lt_final<br>* EXCEPTIONS<br>*   PROGRAM_ERROR                  = 1<br>*   OTHERS      = 2<br>  .<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.</pre><h3>Advantages and Disadvantages</h3><p>While combining these steps may seem convenient, there are significant drawbacks to consider:</p><ol><li><strong>Loss of Flexibility:</strong> If you combine the steps, you lose the ability to modify the field catalog later. For instance, if a customer later requests changes such as:</li></ol><ul><li>Changing the position of columns.</li><li>Modifying labels.</li><li>Making certain columns editable or adding checkboxes.</li></ul><p>2. If you have combined the steps, you will find it challenging to accommodate these changes without backtracking to create a separate field catalog.</p><p>3. <strong>Future Requirements:</strong> If you anticipate that the requirements may change in the future, it is advisable to keep the steps separate. This way, you can easily adjust the field catalog without needing to rewrite significant portions of your code.</p><h3>When to Combine Steps</h3><p>If you are certain that the scope of the program is fixed and no further changes will be required, you might consider combining the steps. However, this is rarely the case in real-world scenarios, where requirements often evolve.</p><h3>Best Practice</h3><p>The best practice is to always create the field catalog as a separate step. This approach allows for maximum flexibility and adaptability to future changes. By keeping the steps distinct, you can easily modify the field catalog as needed without having to rewrite your entire logic.</p><h3>Conclusion</h3><p>In summary, while it is technically possible to combine the steps of creating a field catalog and binding data into a single step, it is generally not advisable due to the loss of flexibility and potential complications with future requirements. Always opt for a separate step for the field catalog to ensure you can accommodate any changes.</p><p>Thank you for joining me today! If you have any questions or need further clarification, feel free to ask. Happy coding, and see you in the next part of our ALV series!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bf095c6dedd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating ALV Reports in SAP ABAP Using REUSE_ALV_GRID_DISPLAY: Part 2 — Manual Catalog #07]]></title>
            <link>https://medium.com/@fahimaljadid/creating-alv-reports-in-sap-abap-using-reuse-alv-grid-display-part-2-manual-catalog-07-6949c23e78d4?source=rss-261d1b1638db------2</link>
            <guid isPermaLink="false">https://medium.com/p/6949c23e78d4</guid>
            <category><![CDATA[alv]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[sap-training]]></category>
            <category><![CDATA[abap-training]]></category>
            <dc:creator><![CDATA[Fahim Al Jadid]]></dc:creator>
            <pubDate>Sat, 21 Dec 2024 21:05:57 GMT</pubDate>
            <atom:updated>2024-12-21T21:05:57.007Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating ALV Reports in SAP ABAP Using REUSE_ALV_GRID_DISPLAY: Part 2 — Manual Catalog #07</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be0I7D8I26CCCPK0uqy8EQ.png" /></figure><p>Hello everyone! Welcome back to our series on the Application List Viewer (ALV). In our previous articles, we learned how to create a field catalog and bind data to it using SAP function modules. Today, we will take a different approach: we will learn how to manually create a field catalog using ABAP coding. This method gives us more control over the process and helps us understand the underlying mechanics of ALV better.</p><h3>Why Create a Field Catalog Manually?</h3><p>Previously, we relied on SAP function modules to generate the field catalog automatically by passing a structure. While this method is efficient, manually creating a field catalog allows us to customize it to our specific needs. By writing the code ourselves, we can ensure that every detail is tailored to our requirements.</p><h3>Step 1: Copy the Existing Program</h3><p>To start, we will create a copy of our existing program where we used the function module to generate the field catalog. This way, we can compare the two approaches easily.</p><ol><li>Create a Copy: In the ABAP editor, select your existing program and make a copy.</li><li>Rename the Program: Give the new program a descriptive name to differentiate it from the original.</li><li>Activate the New Program: Save and activate the new program.</li></ol><h3>Step 2: Comment Out the Function Module or Remove</h3><p>In the new program, we will comment out the line that calls the SAP function module for generating the field catalog. Instead, we will write our own code to fill the field catalog manually.</p><pre>*&amp;---------------------------------------------------------------------*<br>*&amp; Report ZPRG_ALV<br>*&amp;---------------------------------------------------------------------*<br>*&amp;<br>*&amp;---------------------------------------------------------------------*<br>REPORT zprg_alv.<br><br>&quot; Structure for VBAK<br>TYPES : BEGIN OF lty_vbak,<br>          vbeln TYPE vbeln_va,<br>          erdat TYPE erdat,<br>          erzet TYPE erzet,<br>          ernam TYPE ernam,<br>          vbtyp TYPE vbtyp,<br>        END OF lty_vbak.<br><br>DATA : lt_vbak TYPE TABLE OF lty_vbak.<br>DATA : ls_vbak TYPE lty_vbak.<br><br>&quot; Structure for VBAP<br>TYPES : BEGIN OF lty_vbap,<br>          vbeln TYPE vbeln_va,<br>          posnr TYPE posnr_va,<br>          matnr TYPE matnr,<br>        END OF lty_vbap.<br><br>DATA : lt_vbap     TYPE TABLE OF lty_vbap.<br>DATA : ls_vbap     TYPE lty_vbap.<br>DATA : lt_fieldcat TYPE slis_t_fieldcat_alv.<br>DATA : lt_final    TYPE TABLE OF zstr_sales.<br>DATA : ls_final    TYPE zstr_sales.<br><br>DATA : lv_vbln TYPE vbeln_va.<br><br>SELECT-OPTIONS : s_vbln FOR lv_vbln. &quot; character<br><br>SELECT vbeln erdat erzet ernam vbtyp<br>  FROM vbak<br>  INTO TABLE lt_vbak<br>  WHERE vbeln IN s_vbln.<br><br>IF lt_vbak IS NOT INITIAL.<br>  SELECT vbeln posnr matnr<br>  FROM vbap<br>  INTO TABLE lt_vbap<br>  FOR ALL ENTRIES IN lt_vbak<br>    WHERE vbeln = lt_vbak-vbeln.<br>ENDIF.<br><br>LOOP AT lt_vbak INTO ls_vbak.<br>  LOOP AT lt_vbap INTO ls_vbap WHERE vbeln = ls_vbak-vbeln.<br>    ls_final-vbeln = ls_vbak-vbeln.<br>    ls_final-erdat = ls_vbak-erdat.<br>    ls_final-erzet = ls_vbak-erzet.<br>    ls_final-ernam = ls_vbak-ernam.<br>    ls_final-vbtyp = ls_vbak-vbtyp.<br>    ls_final-posnr = ls_vbap-posnr.<br>    ls_final-matnr = ls_vbap-matnr.<br>    APPEND ls_final TO lt_final.<br>    CLEAR : ls_final.<br>  ENDLOOP.<br>ENDLOOP.<br><br>&quot; Creating field catalog manually<br><br>CALL FUNCTION &#39;REUSE_ALV_LIST_DISPLAY&#39;<br>  EXPORTING<br>*   I_INTERFACE_CHECK              = &#39; &#39;<br>*   I_BYPASSING_BUFFER             =<br>*   I_BUFFER_ACTIVE                = &#39; &#39;<br>*   I_CALLBACK_PROGRAM             = &#39; &#39;<br>*   I_CALLBACK_PF_STATUS_SET       = &#39; &#39;<br>*   I_CALLBACK_USER_COMMAND        = &#39; &#39;<br>*   I_STRUCTURE_NAME               =<br>*   IS_LAYOUT   =<br>    it_fieldcat = lt_fieldcat<br>*   IT_EXCLUDING                   =<br>*   IT_SPECIAL_GROUPS              =<br>*   IT_SORT     =<br>*   IT_FILTER   =<br>*   IS_SEL_HIDE =<br>*   I_DEFAULT   = &#39;X&#39;<br>*   I_SAVE      = &#39; &#39;<br>*   IS_VARIANT  =<br>*   IT_EVENTS   =<br>*   IT_EVENT_EXIT                  =<br>*   IS_PRINT    =<br>*   IS_REPREP_ID                   =<br>*   I_SCREEN_START_COLUMN          = 0<br>*   I_SCREEN_START_LINE            = 0<br>*   I_SCREEN_END_COLUMN            = 0<br>*   I_SCREEN_END_LINE              = 0<br>*   IR_SALV_LIST_ADAPTER           =<br>*   IT_EXCEPT_QINFO                =<br>*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE<br>* IMPORTING<br>*   E_EXIT_CAUSED_BY_CALLER        =<br>*   ES_EXIT_CAUSED_BY_USER         =<br>  TABLES<br>    t_outtab    = lt_final<br>* EXCEPTIONS<br>*   PROGRAM_ERROR                  = 1<br>*   OTHERS      = 2<br>  .<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.</pre><h3>Step 3: Understand the Field Catalog Structure</h3><p>Before we start coding, let’s take a closer look at the structure of the field catalog. The field catalog is essentially a table that contains several properties for each column we want to display.</p><ol><li>Field Catalog Table Type: The field catalog is defined as a specific table type in SAP. If you double-click on this type, you will see that it refers to a structure containing various fields such as:</li></ol><ul><li>Column Position</li><li>Row Position</li><li>Field Name</li><li>Tab Name</li><li>Long Text</li><li>Medium Text</li><li>Short Text</li></ul><p>These fields will be used to manually populate our field catalog.</p><h3>Step 4: Declare a Work Area for the Field Catalog</h3><p>Next, we will declare a work area that will hold the values for each column in our field catalog. Get the structure from the “slis_t_fieldcat_alv” type.</p><pre>DATA : lt_fieldcat TYPE slis_t_fieldcat_alv.<br>DATA : ls_fieldcat TYPE slis_fieldcat_alv.</pre><h3>Step 5: Manually Fill the Field Catalog</h3><p>Now, let’s start filling the field catalog manually. We will set the properties for each column one by one.</p><ol><li>Column Position: This indicates the order of the column in the output.</li><li>Field Name: This is the name of the field in the internal table.</li><li>Tab Name: This is the name of the internal table that contains the data.</li><li>Long Text: This is the label that will be displayed in the ALV output.</li></ol><p>Here’s how we can fill in the details for the first column:</p><pre>ls_fieldcat-col_pos = 1. &quot; First column position<br>ls_fieldcat-fieldname = &#39;VBELN&#39;. &quot; Field name for Sales Document Number<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;. &quot; Internal table name<br>ls_fieldcat-seltext_l = &#39;Sales Document Number&#39;. &quot; Long label<br>APPEND ls_fieldcat TO lt_fieldcat. &quot; Append to field catalog<br>CLEAR ls_fieldcat. &quot; Clear work area for next entry</pre><h3>Step 6: Repeat for Remaining Columns</h3><p>We will repeat the above steps for the remaining columns. Here’s a quick overview of the columns we will add:</p><ul><li>Creation Date: ERDAT</li><li>Creation Time: ERZET</li><li>Created By: ERNAM</li><li>Document Category: VBTYPE</li><li>Item Number: POSNR</li><li>Material Number: MATNR</li></ul><p>For each column, set the column_pos, fieldname, tabname, and long_text properties accordingly, and append each entry to the field catalog.</p><pre>ls_fieldcat-col_pos = 2.<br>ls_fieldcat-fieldname = &#39;ERDAT&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Creation Date&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 3.<br>ls_fieldcat-fieldname = &#39;ERZET&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Time&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 4.<br>ls_fieldcat-fieldname = &#39;ERNAM&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Name&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 5.<br>ls_fieldcat-fieldname = &#39;VBTYP&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Document Category&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 6.<br>ls_fieldcat-fieldname = &#39;POSNR&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Document Item&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 7.<br>ls_fieldcat-fieldname = &#39;MATNR&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Material Number&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.</pre><h3>Step 7: Check Syntax and Activate</h3><p>Once you have filled in all the columns, check the syntax of your program and activate it. This will ensure that everything is set up correctly.</p><h3>Final Code</h3><pre>*&amp;---------------------------------------------------------------------*<br>*&amp; Report ZPRG_ALV<br>*&amp;---------------------------------------------------------------------*<br>*&amp;<br>*&amp;---------------------------------------------------------------------*<br>REPORT zprg_alv.<br><br>&quot; Structure for VBAK<br>TYPES : BEGIN OF lty_vbak,<br>          vbeln TYPE vbeln_va,<br>          erdat TYPE erdat,<br>          erzet TYPE erzet,<br>          ernam TYPE ernam,<br>          vbtyp TYPE vbtyp,<br>        END OF lty_vbak.<br><br>DATA : lt_vbak TYPE TABLE OF lty_vbak.<br>DATA : ls_vbak TYPE lty_vbak.<br><br>&quot; Structure for VBAP<br>TYPES : BEGIN OF lty_vbap,<br>          vbeln TYPE vbeln_va,<br>          posnr TYPE posnr_va,<br>          matnr TYPE matnr,<br>        END OF lty_vbap.<br><br>DATA : lt_vbap     TYPE TABLE OF lty_vbap.<br>DATA : ls_vbap     TYPE lty_vbap.<br><br>DATA : lt_fieldcat TYPE slis_t_fieldcat_alv.<br>DATA : ls_fieldcat TYPE slis_fieldcat_alv.<br><br>DATA : lt_final    TYPE TABLE OF zstr_sales.<br>DATA : ls_final    TYPE zstr_sales.<br><br>DATA : lv_vbln TYPE vbeln_va.<br><br>SELECT-OPTIONS : s_vbln FOR lv_vbln. &quot; character<br><br>SELECT vbeln erdat erzet ernam vbtyp<br>  FROM vbak<br>  INTO TABLE lt_vbak<br>  WHERE vbeln IN s_vbln.<br><br>IF lt_vbak IS NOT INITIAL.<br>  SELECT vbeln posnr matnr<br>  FROM vbap<br>  INTO TABLE lt_vbap<br>  FOR ALL ENTRIES IN lt_vbak<br>    WHERE vbeln = lt_vbak-vbeln.<br>ENDIF.<br><br>LOOP AT lt_vbak INTO ls_vbak.<br>  LOOP AT lt_vbap INTO ls_vbap WHERE vbeln = ls_vbak-vbeln.<br>    ls_final-vbeln = ls_vbak-vbeln.<br>    ls_final-erdat = ls_vbak-erdat.<br>    ls_final-erzet = ls_vbak-erzet.<br>    ls_final-ernam = ls_vbak-ernam.<br>    ls_final-vbtyp = ls_vbak-vbtyp.<br>    ls_final-posnr = ls_vbap-posnr.<br>    ls_final-matnr = ls_vbap-matnr.<br>    APPEND ls_final TO lt_final.<br>    CLEAR : ls_final.<br>  ENDLOOP.<br>ENDLOOP.<br><br>&quot; Manual Catalog<br>ls_fieldcat-col_pos = 1. &quot; First column position<br>ls_fieldcat-fieldname = &#39;VBELN&#39;. &quot; Field name for Sales Document Number<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;. &quot; Internal table name<br>ls_fieldcat-seltext_l = &#39;Sales Document Number&#39;. &quot; Long label<br>APPEND ls_fieldcat TO lt_fieldcat. &quot; Append to field catalog<br>CLEAR ls_fieldcat. &quot; Clear work area for next entry<br><br>ls_fieldcat-col_pos = 2.<br>ls_fieldcat-fieldname = &#39;ERDAT&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Creation Date&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 3.<br>ls_fieldcat-fieldname = &#39;ERZET&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Time&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 4.<br>ls_fieldcat-fieldname = &#39;ERNAM&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Name&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 5.<br>ls_fieldcat-fieldname = &#39;VBTYP&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Document Category&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 6.<br>ls_fieldcat-fieldname = &#39;POSNR&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Document Item&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>ls_fieldcat-col_pos = 7.<br>ls_fieldcat-fieldname = &#39;MATNR&#39;.<br>ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>ls_fieldcat-seltext_l = &#39;Material Number&#39;.<br>APPEND ls_fieldcat TO lt_fieldcat.<br>CLEAR ls_fieldcat.<br><br>*CALL FUNCTION &#39;REUSE_ALV_FIELDCATALOG_MERGE&#39;<br>*  EXPORTING<br>**   I_PROGRAM_NAME         =<br>**   I_INTERNAL_TABNAME     =<br>*    i_structure_name       = &#39;ZSTR_SALES&#39;<br>**   I_CLIENT_NEVER_DISPLAY = &#39;X&#39;<br>**   I_INCLNAME             =<br>**   I_BYPASSING_BUFFER     =<br>**   I_BUFFER_ACTIVE        =<br>*  CHANGING<br>*    ct_fieldcat            = lt_fieldcat<br>*  EXCEPTIONS<br>*    inconsistent_interface = 1<br>*    program_error          = 2<br>*    OTHERS                 = 3.<br>*IF sy-subrc &lt;&gt; 0.<br>** Implement suitable error handling here<br>*ENDIF.<br><br><br>CALL FUNCTION &#39;REUSE_ALV_LIST_DISPLAY&#39;<br>  EXPORTING<br>*   I_INTERFACE_CHECK              = &#39; &#39;<br>*   I_BYPASSING_BUFFER             =<br>*   I_BUFFER_ACTIVE                = &#39; &#39;<br>*   I_CALLBACK_PROGRAM             = &#39; &#39;<br>*   I_CALLBACK_PF_STATUS_SET       = &#39; &#39;<br>*   I_CALLBACK_USER_COMMAND        = &#39; &#39;<br>*   I_STRUCTURE_NAME               =<br>*   IS_LAYOUT   =<br>    it_fieldcat = lt_fieldcat<br>*   IT_EXCLUDING                   =<br>*   IT_SPECIAL_GROUPS              =<br>*   IT_SORT     =<br>*   IT_FILTER   =<br>*   IS_SEL_HIDE =<br>*   I_DEFAULT   = &#39;X&#39;<br>*   I_SAVE      = &#39; &#39;<br>*   IS_VARIANT  =<br>*   IT_EVENTS   =<br>*   IT_EVENT_EXIT                  =<br>*   IS_PRINT    =<br>*   IS_REPREP_ID                   =<br>*   I_SCREEN_START_COLUMN          = 0<br>*   I_SCREEN_START_LINE            = 0<br>*   I_SCREEN_END_COLUMN            = 0<br>*   I_SCREEN_END_LINE              = 0<br>*   IR_SALV_LIST_ADAPTER           =<br>*   IT_EXCEPT_QINFO                =<br>*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE<br>* IMPORTING<br>*   E_EXIT_CAUSED_BY_CALLER        =<br>*   ES_EXIT_CAUSED_BY_USER         =<br>  TABLES<br>    t_outtab    = lt_final<br>* EXCEPTIONS<br>*   PROGRAM_ERROR                  = 1<br>*   OTHERS      = 2<br>  .<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.</pre><p>Before we dive into debugging, let’s quickly recap what we’ve done so far:</p><ol><li>Automatic Method: We used the SAP function module to generate a field catalog by simply passing a structure. SAP handled all the details for us.</li><li>Manual Method: We wrote the code ourselves to create a field catalog, giving us full control over the properties of each column.</li></ol><p>Now, let’s see both methods in action through debugging.</p><h3>Step 8: Setting Up Debugging</h3><p>To compare the two methods effectively, we will set breakpoints in both programs:</p><ol><li>Breakpoint in the Automatic Method: Set a breakpoint at the line where the SAP function module generates the field catalog.</li><li>Breakpoint in the Manual Method: Set a breakpoint at the start of the logic where we manually fill the field catalog.</li></ol><h3>Step 9: Running the Programs</h3><ol><li>Input Data: When prompted, provide the same input data for both programs. This ensures that we are comparing apples to apples.</li><li>Run the Automatic Method: Start with the program that uses the SAP function module. As the program runs, you will see how SAP generates the field catalog automatically.</li></ol><h3>Step 10: Observing the Automatic Field Catalog Generation</h3><p>As you step through the debugging process, pay attention to the following:</p><ul><li>Field Catalog Structure: You will see that SAP generates the field catalog with properties such as column position, field name, and long text.</li><li>Output: The generated field catalog will have the same fields as we defined in our manual method.</li></ul><h3>Step 11: Running the Manual Method</h3><p>Next, run the program where we manually create the field catalog.</p><ol><li>Step Through the Code: As you step through the code, observe how each record is added to the field catalog internal table one by one.</li><li>Count of Records: You will see the count of records in the field catalog increasing as each column is filled.</li></ol><h3>Step 5: Comparing Outputs</h3><p>Now that you have run both programs, let’s compare the outputs:</p><ul><li>Field Names and Positions: You will notice that the field names and their positions in both methods are identical. For example, VBELN, ERDAT, ERZET, and so on will appear in the same order.</li><li>Labels: In the manual method, we provided the long text labels for each field. In the automatic method, SAP also generates these labels, but we have the flexibility to customize them in our manual approach.</li></ul><h3>Advantages of Manual Field Catalog Creation</h3><ol><li>Full Control: When you create the field catalog manually, you have complete control over every aspect, including the order of columns, labels, and additional properties like medium and short text.</li><li>Customization: You can easily customize the field catalog to meet specific requirements without relying on SAP’s predefined structures.</li><li>Understanding: Writing the code yourself helps you understand how the field catalog works, which is beneficial for troubleshooting and future enhancements.</li></ol><h3>Conclusion</h3><p>In this session, we learned how to manually create a field catalog for our ALV report. By writing the code ourselves, we gained a deeper understanding of how the field catalog works and how to customize it to our needs. By using debugging, we were able to see that both methods yield the same results, but the manual method offers greater flexibility and control.</p><p>In our next article, we will continue to explore more advanced features of ALV reporting, including sorting, filtering, and enhancing user interaction. Thank you for joining me today! If you have any questions or need further clarification, feel free to ask. Happy coding, and see you in the next part of our ALV series!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6949c23e78d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modifying the Field Catalog Provided by REUSE_ALV_FIELDCATALOG_MERGE: Part 3 #10]]></title>
            <link>https://medium.com/@fahimaljadid/modifying-the-field-catalog-provided-by-reuse-alv-fieldcatalog-merge-part-3-10-042b9202989f?source=rss-261d1b1638db------2</link>
            <guid isPermaLink="false">https://medium.com/p/042b9202989f</guid>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[sap-training]]></category>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[abap-training]]></category>
            <category><![CDATA[alv]]></category>
            <dc:creator><![CDATA[Fahim Al Jadid]]></dc:creator>
            <pubDate>Fri, 20 Dec 2024 01:01:03 GMT</pubDate>
            <atom:updated>2024-12-20T01:01:03.749Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be0I7D8I26CCCPK0uqy8EQ.png" /></figure><p>Hello everyone! Welcome back to our series on the Application List Viewer (ALV). In our previous sessions, we discussed how to modify the field catalog generated by the SAP function module REUSE_ALV_FIELDCATALOG_MERGE. Today, we will continue our exploration by diving into debugging mode to see how our modifications take effect in real time.</p><h3>Recap of the Previous Sessions</h3><p>In the last lecture, we wrote logic to modify the field catalog based on specific requirements, such as changing the positions of the date and time columns and updating the label for the sales document. We emphasized that there is no need to replace the entire logic with a manual field catalog; instead, you can modify the internal table provided by SAP.</p><h3>Understanding the Debugging Process</h3><p>To solidify our understanding, we will use debugging mode to observe how our modifications are applied to the field catalog. This hands-on approach will help clarify the process and ensure we grasp the modifications&#39; logic.</p><h3>Step 1: Setting Up Debugging</h3><ol><li><strong>Run the Program:</strong> Start by executing the program that generates the field catalog.</li><li>S<strong>et Breakpoints: </strong>Place a breakpoint after the field catalog has been generated. This is where we will implement our modification logic.</li></ol><h3>Step 2: Analyzing the Internal Table</h3><p>Once the program hits the breakpoint, you can inspect the internal table that contains the field catalog. This table should have seven records, each representing a column in the ALV output.</p><h3>Step 3: Step Through the Logic</h3><p>As you step through the logic using the F6 key, observe how each record is processed:</p><ol><li><strong>First Iteration:</strong> The first record corresponds to the “Sales Document” column. The logic checks if the field name is VBELN. Since it is, the label is changed to &quot;Document Number&quot;. However, this change is only in the work area at this point.</li><li><strong>Modify Statement:</strong> When the MODIFY Statement is executed, the changes from the work area are applied to the internal table. You will see that the label in the internal table is now updated to &quot;Document Number&quot;.</li><li><strong>Subsequent Iterations:</strong> The program checks each record against the specified conditions as you continue stepping through the loop. For the “Time” column (ERZET), the position is updated to 2, and for the &quot;Date&quot; column (ERDAT), the position is updated to 3. Again, these changes are reflected in the internal table after the MODIFY statement is executed.</li><li><strong>Final Records:</strong> For the remaining records, the conditions do not match, so no changes are made. The loop continues until all records have been processed.</li></ol><h3>Step 4: Verifying the Output</h3><p>After the loop is complete, you will pass the modified internal table to the REUSE_ALV_GRID_DISPLAY function module. When you execute this, you should see the updated field catalog in the ALV output:</p><ul><li>The “Sales Document” column will now display “Document Number”.</li><li>The “Time” column will be in the second position, and the “Date” column will be in the third position.</li></ul><h3>Conclusion</h3><p>In this session, we successfully modified the field catalog generated by the SAP function module REUSE_ALV_FIELDCATALOG_MERGE using debugging mode. We observed how the modifications were applied to the internal table and verified the output in the ALV display.</p><p>Remember, while modifying the field catalog is a powerful feature when using the SAP function module, if you are developing an ALV from scratch, using a manual field catalog can provide you with greater flexibility and ease of use.</p><p>Thank you for joining me today! If you have any questions or need further clarification, feel free to ask. Happy coding, and see you in the next part of our ALV series!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=042b9202989f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modifying the Field Catalog Provided by REUSE_ALV_FIELDCATALOG_MERGE: Part 2 #09]]></title>
            <link>https://medium.com/@fahimaljadid/modifying-the-field-catalog-provided-by-reuse-alv-fieldcatalog-merge-part-2-09-67c54fee237b?source=rss-261d1b1638db------2</link>
            <guid isPermaLink="false">https://medium.com/p/67c54fee237b</guid>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[abap-training]]></category>
            <category><![CDATA[alv]]></category>
            <category><![CDATA[sap-training]]></category>
            <category><![CDATA[abap]]></category>
            <dc:creator><![CDATA[Fahim Al Jadid]]></dc:creator>
            <pubDate>Fri, 20 Dec 2024 00:59:07 GMT</pubDate>
            <atom:updated>2024-12-20T00:59:07.594Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be0I7D8I26CCCPK0uqy8EQ.png" /></figure><p>Hello everyone! Welcome back to our series on the Application List Viewer (ALV). In our previous session, we discussed how to modify the field catalog generated by the SAP function module REUSE_ALV_FIELDCATALOG_MERGE. Today, we will take a practical approach by implementing a specific requirement and writing the logic to modify the field catalog in debugging mode.</p><h3>Setting Up the Requirement</h3><p>To illustrate how to modify the field catalog, we will take a specific requirement:</p><p><strong>Change the Position of Columns:</strong></p><ul><li>Move the “Time” column to the second position.</li><li>Move the “Date” column to the third position.</li></ul><p><strong>Change the Label:</strong></p><ul><li>Change the label for the “Sales Document” column to “Document Number”.</li></ul><h3>Debugging and Writing Logic</h3><p>We will use debugging mode and write our logic to implement this requirement. This approach is beneficial for those who may struggle with coding, as it allows you to see how the program behaves in real time.</p><h3>Step 1: Open Debugging Mode</h3><ol><li>Run the Program: Start by running the program that generates the field catalog.</li><li>Set Breakpoints: Set a breakpoint after SAP has generated the field catalog. This is where we will write our modification logic.</li></ol><h3>Step 2: Analyze the Field Catalog</h3><p>Once the program hits the breakpoint, double-click on the field catalog internal table to inspect its contents. You should see the seven records that SAP generated, including the column positions and labels.</p><h3>Step 3: Writing the Modification Logic</h3><p>Now, let’s write the logic to modify the field catalog. Here’s how we can do it:</p><ol><li>Declare a Work Area: We need a work area to hold the values as we loop through the internal table.</li></ol><pre>DATA : ls_fieldcat TYPE slis_fieldcat_alv. &quot; Work area for field catalog</pre><p>2. Loop Through the Internal Table: We will loop through the field catalog internal table to find the records we want to modify.</p><pre>LOOP AT lt_fieldcat INTO ls_fieldcat.<br>  &quot; Modification Logic<br>ENDLOOP.</pre><p>3. Modify the Required Records: Inside the loop, we will check for the specific field names and make the necessary changes.</p><pre>  IF ls_fieldcat-fieldname = &#39;VBELN&#39;.<br>    ls_fieldcat-seltext_l = &#39;Document Number&#39;.<br>  ENDIF.<br><br>  IF ls_fieldcat-fieldname = &#39;ERDAT&#39;.<br>    ls_fieldcat-col_pos = 3.<br>  ENDIF.<br><br>  IF ls_fieldcat-fieldname = &#39;ERZET&#39;.<br>    ls_fieldcat-col_pos = 2.<br>  ENDIF.</pre><p>4. Modify the Internal Table: After making changes in the work area, we need to update the internal table. Always use the MODIFY statement with the TRANSPORTING option to ensure that only the specified fields are updated.</p><pre>MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING seltext_l.<br>MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING col_pos.<br>MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING col_pos.</pre><h3>Step 4: Finalize the Logic</h3><p>After writing the logic, ensure that you check the syntax and activate the program. This will allow you to see if the modifications are correctly applied.</p><h3>Final Code:</h3><pre>*&amp;---------------------------------------------------------------------*<br>*&amp; Report ZPRG_ALV<br>*&amp;---------------------------------------------------------------------*<br>*&amp;<br>*&amp;---------------------------------------------------------------------*<br>REPORT zprg_alv.<br><br>&quot; Structure for VBAK<br>TYPES : BEGIN OF lty_vbak,<br>          vbeln TYPE vbeln_va,<br>          erdat TYPE erdat,<br>          erzet TYPE erzet,<br>          ernam TYPE ernam,<br>          vbtyp TYPE vbtyp,<br>        END OF lty_vbak.<br><br>DATA : lt_vbak TYPE TABLE OF lty_vbak.<br>DATA : ls_vbak TYPE lty_vbak.<br><br>&quot; Structure for VBAP<br>TYPES : BEGIN OF lty_vbap,<br>          vbeln TYPE vbeln_va,<br>          posnr TYPE posnr_va,<br>          matnr TYPE matnr,<br>        END OF lty_vbap.<br><br>DATA : lt_vbap     TYPE TABLE OF lty_vbap.<br>DATA : ls_vbap     TYPE lty_vbap.<br><br>DATA : lt_fieldcat TYPE slis_t_fieldcat_alv. &quot; Internal Table<br>DATA : ls_fieldcat TYPE slis_fieldcat_alv. &quot; Work area for field catalog<br><br>DATA : lt_final    TYPE TABLE OF zstr_sales.<br>DATA : ls_final    TYPE zstr_sales.<br><br>DATA : lv_vbln TYPE vbeln_va.<br><br>SELECT-OPTIONS : s_vbln FOR lv_vbln. &quot; character<br><br>SELECT vbeln erdat erzet ernam vbtyp<br>  FROM vbak<br>  INTO TABLE lt_vbak<br>  WHERE vbeln IN s_vbln.<br><br>IF lt_vbak IS NOT INITIAL.<br>  SELECT vbeln posnr matnr<br>  FROM vbap<br>  INTO TABLE lt_vbap<br>  FOR ALL ENTRIES IN lt_vbak<br>    WHERE vbeln = lt_vbak-vbeln.<br>ENDIF.<br><br>LOOP AT lt_vbak INTO ls_vbak.<br>  LOOP AT lt_vbap INTO ls_vbap WHERE vbeln = ls_vbak-vbeln.<br>    ls_final-vbeln = ls_vbak-vbeln.<br>    ls_final-erdat = ls_vbak-erdat.<br>    ls_final-erzet = ls_vbak-erzet.<br>    ls_final-ernam = ls_vbak-ernam.<br>    ls_final-vbtyp = ls_vbak-vbtyp.<br>    ls_final-posnr = ls_vbap-posnr.<br>    ls_final-matnr = ls_vbap-matnr.<br>    APPEND ls_final TO lt_final.<br>    CLEAR : ls_final.<br>  ENDLOOP.<br>ENDLOOP.<br><br>*&quot; Manual Catalog<br>*ls_fieldcat-col_pos = 1. &quot; First column position<br>*ls_fieldcat-fieldname = &#39;VBELN&#39;. &quot; Field name for Sales Document Number<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;. &quot; Internal table name<br>*ls_fieldcat-seltext_l = &#39;Sales Document Number&#39;. &quot; Long label<br>*APPEND ls_fieldcat TO lt_fieldcat. &quot; Append to field catalog<br>*CLEAR ls_fieldcat. &quot; Clear work area for next entry<br>*<br>*ls_fieldcat-col_pos = 2.<br>*ls_fieldcat-fieldname = &#39;ERDAT&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Creation Date&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br>*<br>*ls_fieldcat-col_pos = 3.<br>*ls_fieldcat-fieldname = &#39;ERZET&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Time&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br>*<br>*ls_fieldcat-col_pos = 4.<br>*ls_fieldcat-fieldname = &#39;ERNAM&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Name&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br>*<br>*ls_fieldcat-col_pos = 5.<br>*ls_fieldcat-fieldname = &#39;VBTYP&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Document Category&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br>*<br>*ls_fieldcat-col_pos = 6.<br>*ls_fieldcat-fieldname = &#39;POSNR&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Document Item&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br>*<br>*ls_fieldcat-col_pos = 7.<br>*ls_fieldcat-fieldname = &#39;MATNR&#39;.<br>*ls_fieldcat-tabname = &#39;LT_FINAL&#39;.<br>*ls_fieldcat-seltext_l = &#39;Material Number&#39;.<br>*APPEND ls_fieldcat TO lt_fieldcat.<br>*CLEAR ls_fieldcat.<br><br>CALL FUNCTION &#39;REUSE_ALV_FIELDCATALOG_MERGE&#39;<br>  EXPORTING<br>*   I_PROGRAM_NAME         =<br>*   I_INTERNAL_TABNAME     =<br>    i_structure_name       = &#39;ZSTR_SALES&#39;<br>*   I_CLIENT_NEVER_DISPLAY = &#39;X&#39;<br>*   I_INCLNAME             =<br>*   I_BYPASSING_BUFFER     =<br>*   I_BUFFER_ACTIVE        =<br>  CHANGING<br>    ct_fieldcat            = lt_fieldcat<br>  EXCEPTIONS<br>    inconsistent_interface = 1<br>    program_error          = 2<br>    OTHERS                 = 3.<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.<br><br>&quot; Modification Logic<br>LOOP AT lt_fieldcat INTO ls_fieldcat.<br>  IF ls_fieldcat-fieldname = &#39;VBELN&#39;.<br>    ls_fieldcat-seltext_l = &#39;Document Number&#39;.<br>    MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING seltext_l.<br>  ENDIF.<br><br>  IF ls_fieldcat-fieldname = &#39;ERDAT&#39;.<br>    ls_fieldcat-col_pos = 3.<br>    MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING col_pos.<br>  ENDIF.<br><br>  IF ls_fieldcat-fieldname = &#39;ERZET&#39;.<br>    ls_fieldcat-col_pos = 2.<br>    MODIFY lt_fieldcat FROM ls_fieldcat TRANSPORTING col_pos.<br>  ENDIF.<br><br>ENDLOOP.<br><br>CALL FUNCTION &#39;REUSE_ALV_GRID_DISPLAY&#39;<br>  EXPORTING<br>*   I_INTERFACE_CHECK              = &#39; &#39;<br>*   I_BYPASSING_BUFFER             =<br>*   I_BUFFER_ACTIVE                = &#39; &#39;<br>*   I_CALLBACK_PROGRAM             = &#39; &#39;<br>*   I_CALLBACK_PF_STATUS_SET       = &#39; &#39;<br>*   I_CALLBACK_USER_COMMAND        = &#39; &#39;<br>*   I_STRUCTURE_NAME               =<br>*   IS_LAYOUT   =<br>    it_fieldcat = lt_fieldcat<br>*   IT_EXCLUDING                   =<br>*   IT_SPECIAL_GROUPS              =<br>*   IT_SORT     =<br>*   IT_FILTER   =<br>*   IS_SEL_HIDE =<br>*   I_DEFAULT   = &#39;X&#39;<br>*   I_SAVE      = &#39; &#39;<br>*   IS_VARIANT  =<br>*   IT_EVENTS   =<br>*   IT_EVENT_EXIT                  =<br>*   IS_PRINT    =<br>*   IS_REPREP_ID                   =<br>*   I_SCREEN_START_COLUMN          = 0<br>*   I_SCREEN_START_LINE            = 0<br>*   I_SCREEN_END_COLUMN            = 0<br>*   I_SCREEN_END_LINE              = 0<br>*   IR_SALV_LIST_ADAPTER           =<br>*   IT_EXCEPT_QINFO                =<br>*   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE<br>* IMPORTING<br>*   E_EXIT_CAUSED_BY_CALLER        =<br>*   ES_EXIT_CAUSED_BY_USER         =<br>  TABLES<br>    t_outtab    = lt_final<br>* EXCEPTIONS<br>*   PROGRAM_ERROR                  = 1<br>*   OTHERS      = 2<br>  .<br>IF sy-subrc &lt;&gt; 0.<br>* Implement suitable error handling here<br>ENDIF.</pre><h3>Summary</h3><p>In this session, we wrote the logic to modify the field catalog internal table based on specific requirements. We changed the column positions for the date and time fields and updated the label for the sales document.</p><p>Using debugging mode helped us understand how the field catalog is structured and how to effectively implement our changes. Remember, when modifying the internal table, always use the MODIFY statement with the TRANSPORTING option to ensure that only the specified fields are updated.</p><p>In our next article, we will continue to explore this logic in debugging mode to verify that we are getting the expected output. Thank you for joining me today! If you have any questions or need further clarification, feel free to ask. Happy coding, and see you in the next part of our ALV series!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67c54fee237b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modifying the Field Catalog Provided by REUSE_ALV_FIELDCATALOG_MERGE: Part 1 #08]]></title>
            <link>https://medium.com/@fahimaljadid/modifying-the-field-catalog-provided-by-reuse-alv-fieldcatalog-merge-part-1-08-7878be305c8c?source=rss-261d1b1638db------2</link>
            <guid isPermaLink="false">https://medium.com/p/7878be305c8c</guid>
            <category><![CDATA[sap]]></category>
            <category><![CDATA[sap-training]]></category>
            <category><![CDATA[abap-training]]></category>
            <category><![CDATA[abap]]></category>
            <category><![CDATA[alv]]></category>
            <dc:creator><![CDATA[Fahim Al Jadid]]></dc:creator>
            <pubDate>Fri, 20 Dec 2024 00:52:55 GMT</pubDate>
            <atom:updated>2024-12-20T00:52:55.948Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*be0I7D8I26CCCPK0uqy8EQ.png" /></figure><p>Hello everyone! Welcome back to our series on the Application List Viewer (ALV). In our previous sessions, we developed three programs demonstrating different methods of generating and displaying field catalogs. Today, we will focus on an important topic: how to modify the field catalog that is generated by the SAP function module REUSE_ALV_FIELDCATALOG_MERGE.</p><h3>Recap of Previous Programs</h3><ol><li>First Program: We used the SAP function module to generate the field catalog and displayed the output using REUSE_ALV_LIST_DISPLAY.</li><li>Second Program: We again used the SAP function module to generate the field catalog, but this time we displayed the output using REUSE_ALV_GRID_DISPLAY.</li><li>Third Program: Instead of using the SAP function module, we manually created the field catalog and displayed the output using the grid display function module.</li></ol><p>While the manual method of generating a field catalog offers flexibility, many developers prefer to use the SAP function module for its simplicity. However, this raises a common question: What if we want to modify the field catalog generated by the SAP function module?</p><h3>Understanding the Need for Modification</h3><p>The field catalog is generated based on the structure you provide when using the SAP function module. This means that the column positions and labels are determined by the data elements in that structure. However, customers often have specific requirements, such as:</p><ul><li>Changing the position of certain columns (e.g., moving the date column to the third position).</li><li>Modifying labels (e.g., changing “Sales Document” to “Document Number”).</li></ul><p>Many developers wonder if they need to replace the entire logic with a manual field catalog to accommodate these changes. The good news is that you do not need to replace the entire logic! Instead, you can modify the field catalog internal table after it has been generated.</p><h3>Modifying the Field Catalog Internal Table</h3><p>Here’s how you can modify the field catalog internal table generated by the SAP function module:</p><ol><li>Retain the Generated Field Catalog: After the SAP function module generates the field catalog, you can keep it as is.</li><li>Modify the Internal Table: You can change the column positions and labels directly in the internal table without affecting the original structure or other programs that use it.</li></ol><h3>Why This Approach is Beneficial</h3><ul><li>Local Changes: By modifying the internal table in your program, you ensure that the changes are local to that program only. This means you won’t inadvertently impact other programs that rely on the same structure.</li><li>Flexibility: You still have the flexibility to adjust the field catalog according to customer requirements without the overhead of creating a manual field catalog from scratch.</li></ul><h3>Example Scenario</h3><p>Let’s say you have a requirement to change the position of the date and time fields in your ALV output. Instead of altering the structure itself, you can simply modify the field catalog after it has been generated. For instance:</p><ul><li>Change the position of the time field to 2.</li><li>Change the position of the date field to 3.</li><li>Update the label for the sales document to “Document Number”.</li></ul><h3>Summary</h3><p>In this article, we discussed how to modify the field catalog internal table generated by the SAP function module REUSE_ALV_FIELDCATALOG_MERGE. We emphasized that you do not need to replace the entire logic with a manual field catalog. Instead, you can make local modifications to the internal table to meet specific requirements.</p><p>In our next session, we will dive into debugging mode to see how to implement these modifications in practice. We will take a specific requirement and demonstrate how to adjust the field catalog accordingly. Thank you for joining me today! If you have any questions or need further clarification, feel free to ask. Happy coding, and see you in the next part of our ALV series!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7878be305c8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>