✒️ABAP Los reportes ALV
ABAP Los reportes ALV
ALV Reports (ABAP List Viewer Reports)
The ABAP List Viewer (ALV) is an exclusive tool used for efficient, quick, and standardized report creation in ABAP.
Key advantages of ALV reports include:
- Simplified report development leading to reduced programming times.
- Provision of numerous standard functionalities for reports, such as sorting, total calculation, filtering, column sorting, hiding columns, and exporting results to Microsoft Excel, local files, CSV files, HTML format, among others.
- Consistent and uniform screen output.
The Evolution of ALV Reports
- ABAP List: The initial tool for on-screen data output was the ABAP List. It used the WRITE statement to display data lines on the screen. However, it required manual coding for each field, column, total, or subtotal, offering users a rigid report structure.
- ALV List: The ALV framework, first as ALV List, improved upon ABAP List functionality. ALV Lists featured aligned columns, an enhanced toolbar with sorting, filtering, and subtotal capabilities. Users could customize column visibility and order, saving preferences for future runs. Developers benefited from tools for data presentation without manual position calculations.
- ALV Grid: The next step in ALV evolution was ALV Grid, resembling a tabular format like Microsoft Excel. Early implementations utilized SAP function modules starting with REUSE_ALV.
- Hierarchical ALV: Used for displaying header and detail data.
- First Object-Oriented ALV Framework: Introduced object classes starting with CL_GUI_ALV, producing visually similar results to function module-based implementations but allowing ALV objects to link to custom containers on a screen.
- SALV Framework: Current implementation, available since SAP Netweaver 7.0, employs object classes starting with CL_SALV, supporting ALV table, ALV tree, and sequential hierarchical list formats.
- ALV with IDA: The latest, known as SAP List View with Integrated Data Access (ALV with IDA), leverages SAP HANA in-memory database functionality. Implementation uses the object class CL_SALV_TABLE_IDA.
Creating ALV Reports with Function Modules
Commonly used function modules are:
- Grids: REUSE_ALV_GRID_DISPLAY
- Lists: REUSE_ALV_LIST_DISPLAY
- Hierarchical: REUSE_ALV_HIERSEQ_LIST_DISPLAY
Grids and lists can be used in any report, while hierarchical ones are for cases involving header and detail data (e.g., invoice numbers and details, airline and flight data).
ALV Report Creation Steps
- Step 1: Declarations of ALV-specific types, structures, and internal tables. Within this step, we declare the type SLIS, which is essential for utilizing ALV reports. We also declare an internal table and a structure for the ALV catalog, both of type SLIS_T_FIELDCAT_ALV and SLIS_FIELDCAT_ALV, respectively. Another structure for output configuration, type SLIS_LAYOUT_ALV, is declared, along with a variable of type SY-REPID to store the program name.
* Internal table and structure for the catalog
DATA: it_catalog TYPE slis_t_fieldcat_alv,
wa_catalog TYPE slis_fieldcat_alv.
* Structure for output configuration
DATA: wa_layout TYPE slis_layout_alv.
* Variable with the program name
DATA: v_repid LIKE sy-repid.
- Step 2: Declaration of the ALV output internal table.
* Internal table and output structure for ALV
DATA: it_users TYPE STANDARD TABLE OF zuser_table_jega,
wa_users LIKE LINE OF it_users,
- Step 3: Data selection for ALV display. Within the START-OF-SELECTION event, create a subroutine to select data records from the database table to be displayed in the output list, storing them in the internal table.
START-OF-SELECTION.
PERFORM select_data.
FORM select_data.
REFRESH it_users.
SELECT * FROM zuser_table_jega INTO TABLE it_users.
ENDFORM.
- Step 4: Building the ALV catalog. Within the START-OF-SELECTION event, create a subroutine to build the ALV catalog with fields that will become columns in the report. Complete the fields for each column in the list, belonging to the internal catalog table.
START-OF-SELECTION.
PERFORM build_catalog.
FORM build_catalog.
REFRESH it_catalog.
CLEAR wa_catalog.
wa_catalog-fieldname = 'DNI'. "Field Name
wa_catalog-tabname = 'IT_USERS'. "Table Name
wa_catalog-seltext_s = 'DNI'. "Short Header Description
wa_catalog-seltext_m = 'DNI'. "Medium Header Description
wa_catalog-seltext_l = 'DNI'. "Long Header Description
wa_catalog-outputlen = 10. "Column Width
wa_catalog-just = 'R'. "Alignment
APPEND wa_catalog TO it_catalog.
CLEAR wa_catalog.
wa_catalog-fieldname = 'NAME'.
wa_catalog-tabname = 'IT_USERS'.
wa_catalog-seltext_s = 'Name and Surname'.
wa_catalog-seltext_m = 'Name and Surname'.
wa_catalog-seltext_l = 'Name and Surname'.
wa_catalog-outputlen = 25.
wa_catalog-just = 'R'.
APPEND wa_catalog TO it_catalog.
CLEAR wa_catalog.
wa_catalog-fieldname = 'STATUS'.
wa_catalog-tabname = 'IT_USERS'.
wa_catalog-seltext_s = 'User Status'.
wa_catalog-seltext_m = 'User Status'.
wa_catalog-seltext_l = 'User Status'.
wa_catalog-outputlen = 20.
wa_catalog-just = 'R'.
APPEND wa_catalog TO it_catalog.
CLEAR wa_catalog.
wa_catalog-fieldname = 'BIRTH_DATE'.
wa_catalog-tabname = 'IT_USERS'.
wa_catalog-seltext_s = 'Birth Date'.
wa_catalog-seltext_m = 'Birth Date'.
wa_catalog-seltext_l = 'Birth Date'.
wa_catalog-outputlen = 16.
wa_catalog-just = 'R'.
APPEND wa_catalog TO it_catalog.
ENDFORM.
- Step 5: Configuring the ALV output layout. Within the START-OF-SELECTION event, create a subroutine to configure certain aspects of the ALV output. There are many more options to configure in the layout of an ALV report. For additional information, double-click on the SLIS_LAYOUT_ALV type.
START-OF-SELECTION.
PERFORM configure_layout.
*&---------------------------------------------------------------------*
*& Form CONFIGURE_LAYOUT
*&---------------------------------------------------------------------*
* This form configures the layout settings for the ALV report.
* It sets the window titlebar to display "User Report."
*---------------------------------------------------------------------*
FORM configure_layout.
CLEAR wa_layout.
wa_layout-window_titlebar = TEXT-001. "User Report
ENDFORM.
- Step 6: Finally, execute the ALV function module. For a grid-type report, use the REUSE_ALV_GRID_DISPLAY function module. For a list-type report, use REUSE_ALV_LIST_DISPLAY. Both function modules are completed in the same manner.
START-OF-SELECTION.
PERFORM execute_alv.
*&---------------------------------------------------------------------*
*& Form EXECUTE_ALV
*&---------------------------------------------------------------------*
* This form executes the ALV display based on the specified parameters.
* If the display mode is 'Grid' (p_grid = c_x), it uses REUSE_ALV_GRID_DISPLAY.
* If the display mode is 'List' (p_list = c_x), it uses REUSE_ALV_LIST_DISPLAY.
*---------------------------------------------------------------------*
FORM execute_alv.
CLEAR v_repid.
v_repid = sy-repid.
IF p_grid EQ c_x.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
it_fieldcat = it_catalog[]
is_layout = wa_layout
TABLES
t_outtab = it_users.
ELSEIF p_list EQ c_x.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = v_repid
it_fieldcat = it_catalog[]
is_layout = wa_layout
TABLES
t_outtab = it_users.
ENDIF.
ENDFORM.
E.g
*&---------------------------------------------------------------------*
*& Report ZTEST_ABAP_JEGA_18
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ztest_abap_jega_18.
* Type-pool declaration for ALV
TYPE-POOLS: slis.
* Constants
CONSTANTS: c_x(1) TYPE c VALUE 'X'.
* Internal table and structure for user data
DATA: it_users TYPE STANDARD TABLE OF zuser_table_jega,
wa_users LIKE LINE OF it_users.
* Internal table and structure for ALV catalog
DATA: it_catalog TYPE slis_t_fieldcat_alv,
wa_catalog TYPE slis_fieldcat_alv.
* Structure for the configuration of the output
DATA: wa_layout TYPE slis_layout_alv.
* Variable with the name of the program
DATA: v_repid LIKE sy-repid.
*---------------------------------------------------------------------*
* Selection screen
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bloque WITH FRAME TITLE TEXT-001.
PARAMETERS: p_grid RADIOBUTTON GROUP bot2,
p_list RADIOBUTTON GROUP bot2.
SELECTION-SCREEN END OF BLOCK bloque.
*---------------------------------------------------------------------*
* Start of selection
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM select_data.
PERFORM build_catalog.
PERFORM configure_layout.
PERFORM execute_alv.
*---------------------------------------------------------------------*
* Form: SELECT_DATA
* Description: Selects data from the database table ZUSER_TABLE_JEGA.
*---------------------------------------------------------------------*
FORM select_data.
REFRESH it_users.
SELECT *
FROM zuser_table_jega
INTO TABLE it_users.
ENDFORM. " SELECT_DATA"
*---------------------------------------------------------------------*
* Form: BUILD_CATALOG
* Description: Builds the catalog for ALV display.
*---------------------------------------------------------------------*
FORM build_catalog.
CLEAR it_catalog.
" DNI Field
CLEAR wa_catalog.
wa_catalog-fieldname = 'DNI'.
wa_catalog-tabname = 'ZUSER_TABLE_JEGA'.
wa_catalog-seltext_s = 'DNI'.
wa_catalog-seltext_m = 'DNI'.
wa_catalog-seltext_l = 'DNI'.
wa_catalog-outputlen = 10.
wa_catalog-just = 'R'.
APPEND wa_catalog TO it_catalog.
" Name and Surname Field
CLEAR wa_catalog.
wa_catalog-fieldname = 'NOMBRE_APE'.
wa_catalog-tabname = 'ZUSER_TABLE_JEGA'.
wa_catalog-seltext_s = 'Name and Surname'.
wa_catalog-seltext_m = 'Name and Surname'.
wa_catalog-seltext_l = 'Name and Surname'.
wa_catalog-outputlen = 25.
wa_catalog-just = 'R'.
APPEND wa_catalog TO it_catalog.
" Status Field
CLEAR wa_catalog.
wa_catalog-fieldname = 'ESTADO'.
wa_catalog-tabname = 'ZUSER_TABLE_JEGA'.
wa_catalog-seltext_s = 'User Status'.
wa_catalog-seltext_m = 'User Status'.
wa_catalog-seltext_l = 'User Status'.
wa_catalog-outputlen = 20.
wa_catalog-just = 'R'.
APPEND wa_catalog TO it_catalog.
" Birthdate Field
CLEAR wa_catalog.
wa_catalog-fieldname = 'BIRTHDATE'.
wa_catalog-tabname = 'ZUSER_TABLE_JEGA'.
wa_catalog-seltext_s = 'Birth Date'.
wa_catalog-seltext_m = 'Birth Date'.
wa_catalog-seltext_l = 'Birth Date'.
wa_catalog-outputlen = 16.
wa_catalog-just = 'R'.
APPEND wa_catalog TO it_catalog.
ENDFORM. " BUILD_CATALOG"
*---------------------------------------------------------------------*
* Form: CONFIGURE_LAYOUT
* Description: Configures the layout settings for the ALV report.
*---------------------------------------------------------------------*
FORM configure_layout.
CLEAR wa_layout.
wa_layout-window_titlebar = 'User Report'.
ENDFORM. " CONFIGURE_LAYOUT"
*---------------------------------------------------------------------*
* Form: EXECUTE_ALV
* Description: Executes the ALV display based on the specified parameters.
* If the display mode is 'Grid' (p_grid = 'X'), it uses
* REUSE_ALV_GRID_DISPLAY. If the display mode is 'List'
* (p_list = 'X'), it uses REUSE_ALV_LIST_DISPLAY.
*---------------------------------------------------------------------*
FORM execute_alv.
CLEAR v_repid.
v_repid = sy-repid.
IF p_grid = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
it_fieldcat = it_catalog[]
is_layout = wa_layout
TABLES
t_outtab = it_users.
ELSEIF p_list = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = v_repid
it_fieldcat = it_catalog[]
is_layout = wa_layout
TABLES
t_outtab = it_users.
ENDIF.
ENDFORM. " EXECUTE_ALV"
 
 
 
Sobre el autor
Publicación académica de Jaime Eduardo Gomez Arango, en su ámbito de estudios para la Carrera Consultor ABAP.
Jaime Eduardo Gomez Arango
Profesión: Ingeniero de Sistemas y Computación - España - Legajo: SW34C
✒️Autor de: 149 Publicaciones Académicas
🎓Egresado de los módulos:
- Carrera Consultor en SAP Fiori
- Carrera Consultor ABAP Nivel Avanzado
- Carrera Consultor ABAP Nivel Inicial
Disponibilidad Laboral: FullTime
Presentación:
Ingeniero de sistemas y computación con 8 años de experiencia el desarrollo frontend & backend (react/node) y en cloud (aws), actualmente desarrollando habilidades en sap btp, ui5, abap y fiori.
Certificación Académica de Jaime Gomez