Unlocking the Power of ALV in ABAP: A Comprehensive Guide

 

ALV :-

  • Application List Viewer or ABAP List Viewer

When displaying data, ALV (ABAP List Viewer) offers a more organized and user-friendly method than utilizing write statements in ABAP. ALV is recommended for the following reasons:

  1. Flexibility: ALV provides a number of layout choices, including list, grid, and tree layouts. Users are able to alter the arrangement to suit their tastes.
  2. Sorting and Filtering: Without adding extra code, ALV enables users to quickly and simply sort and filter data. This improves the application's usability.
  3. Column Resizing and Rearranging: By using ALV, users can dynamically resize and rearrange columns to improve data readability.
  4. Exporting Data: The built-in functionality of ALV allows for the exportation of data to multiple formats, including Excel, PDF, and CSV. This feature is useful when creating reports.
  5. Interactive Features: To improve user experience, ALV offers interactive features including drill-down functionality and the ability to double-click on a row to navigate to detailed information.
  6. Performance Optimization: With performance optimizations built right in, ALV manages massive amounts of data with ease.
  7. Standardization: ALV adheres to accepted SAP design guidelines, ensuring uniformity throughout various SAP ecosystem apps.

Compared to write statements, ALV improves the functionality, streamlines the development process, and improves the user experience of ABAP programs.


Steps to Create ALV :-

  1. Create a Field Catalog:

    • The format of the ALV output is specified in the field catalog. It has details about the fields (columns) that will be shown, including field names, descriptions, data types, and formatting choices.

    • When it comes to making a field catalog, you have two choices:

      a) Utilizing the REUSE_ALV_FIELDCATALOG_MERGE SAP Function Module: The structure of the internal table that is supplied to this function module determines how a field catalog is automatically generated. It generates the relevant field catalog entries after analyzing the internal table's structure.

      b) Manually Define a Field Catalog: As an alternative, you can directly specify the fields and their attributes to manually define the field catalog.

  2. Bind Data with Field Catalog:

    • You must tie the field catalog with the real data that will be shown in the ALV after it has been created.

    For presenting ALV output, there are various function modules available, each with unique characteristics and functionalities:

    a) REUSE_ALV_LIST_DISPLAY: The ALV output is shown in a straightforward list manner by this function module. It works well for tabular data display.

    b) REUSE_ALV_GRID_DISPLAY: Compared to list display, this function module offers greater layout and navigation freedom by displaying the ALV output in a grid format.

    c) REUSE_ALV_HIERSEQ_LIST_DISPLAY: Hierarchical sequential lists are displayed using this function module. It is helpful for displaying master-detail connections or tree-like data since it enables you to display data in a hierarchical manner.

These steps are crucial for configuring an ALV in an ABAP program because they give the data binding and structure needed to produce the required output format.


Displaying data in Reuse ALV List Display :-

Requirement :-

  • Take few fields of VBAK and VBAP table.
  • Create a final structure to show this fields.
  • Use function module REUSE_ALV_FIELDCATALOG_MERGE to create field catalog manually.
  • Use function module REUSE_ALV_LIST_DISPLAY to display the data in form of ALV list.

Solution :-

  • Step 1 :- Go to ABAP Editor {SE38} and create a executable program.



  • Step 2 :- Create a type structure for both header and item table.



  • Step 3 :- Create the type structure for final table.



  • Step 4 :- Declare the internal table and work area for all the three type structure.



  • Step 5 :- Declare a select option to take data in range.



  • Step 6 :- Write the select queries to fetch data from VBAK and VBAP table.



  • Step 7 :- fill data in final internal table.



  • Step 8 :- Call the function module REUSE_ALV FEILDCATALOG_MERGE.



    • Create a global structure from SE11 to pass into the above function module.



    • Declare a internal table for field catalog.



  • Step 9 :- Call the function module REUSE_ALV_LIST_DISPLAY.




Code :-

*************************************************
*Start of Program
*Type Strcuture fo Both header and Item table
TYPES : BEGIN OF ty_vbak,
          vbeln TYPE vbeln_va,
          erdat TYPE erdat,
          erzet TYPE erzet,
          ernam TYPE ernam,
          vbtyp TYPE vbtypl,
        END OF ty_vbak.
TYPES : BEGIN OF ty_vbap,
          vbeln TYPE vbeln_va,
          posnr TYPE posnr_va,
          matnr TYPE matnr,
        END OF ty_vbap.

********************************************
*Type structure for final table.
TYPES : BEGIN OF ty_final,
          vbeln TYPE vbeln_va,
          erdat TYPE erdat,
          erzet TYPE erzet,
          ernam TYPE ernam,
          vbtyp TYPE vbtypl,
          posnr TYPE posnr_va,
          matnr TYPE matnr,
        END OF ty_final.

*************************************************
*Declaring the internal table and work area
DATA : lt_vbak type table of ty_vbak,
       ls_vbak  type ty_vbak,
       lt_vbap type table of ty_vbap,
       ls_vbap type ty_vbap,
       lt_final type table of ty_final,
       ls_final type ty_final,
       lv_vbeln type vbeln_va.

DATA : lt_fieldcat type table of slis_fieldcat_alv.

***************
*Declaring a select option.
SELECT-OPTIONS : s_vbeln for lv_vbeln.

START-OF-SELECTION.
SELECT vbeln erdat erzet ernam vbtyp
  from vbak into table lt_vbak
  where vbeln in s_vbeln.

  if lt_vbak is not INITIAL.
    select vbeln posnr matnr
      from vbap
      into table lt_vbap
      FOR ALL ENTRIES IN lt_vbak
      where vbeln = lt_vbak-vbeln.

      loop at lt_vbap into ls_vbap.
        ls_final-posnr = ls_vbap-posnr.
        ls_final-matnr = ls_vbap-matnr.

        Read table lt_vbak into ls_vbak with KEY vbeln = ls_vbap-vbeln.
        if sy-subrc eq 0.
          ls_final-vbeln = ls_vbak-vbeln.
          ls_final-erdat = ls_vbak-erdat.
          ls_final-erzet = ls_vbak-erzet.
          ls_final-ernam = ls_vbak-ernam.
          ls_final-vbtyp = ls_vbak-vbtyp.
        endif.

        append ls_final to lt_final.
        clear : ls_final, ls_vbak, ls_vbap.
      ENDLOOP.

***************************************
*Call REUSE ALV fieldcatalog merge
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
 EXPORTING
   I_STRUCTURE_NAME             = 'ZAR_ORDER_DETAILS'
  CHANGING
    ct_fieldcat                  = lt_fieldcat
 EXCEPTIONS
   INCONSISTENT_INTERFACE       = 1
   PROGRAM_ERROR                = 2
   OTHERS                       = 3
          .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
 EXPORTING
   IT_FIELDCAT                    = lt_fieldcat
  TABLES
    t_outtab                       = lt_final
 EXCEPTIONS
   PROGRAM_ERROR                  = 1
   OTHERS                         = 2
          .

  endif.

*****************
*End of Program
*****************************************************

Execute the Code :-



  • You can see the output as a list of values.

Comments

Popular posts from this blog

Understanding Different Types of SAP Function Modules: Normal, RFC, and Update

Mastering ABAP: A Step-by-Step Guide to Function Modules and Groups for Modularized Programming

Introduction to SAP