📜  reuse_alv_grid_display 示例 (1)

📅  最后修改于: 2023-12-03 15:19:49.066000             🧑  作者: Mango

ALV Grid Display with Reuse ALV Function Module

In SAP ABAP programming, ALV (Abap List Viewer) is a powerful and flexible tool to display data in a tabular form. There are several ways to create an ALV display, but one easy and efficient method is by using the Reuse ALV Function Module.

Introduction

The Reuse ALV Function Module (REUSE_ALV_GRID_DISPLAY) is a function module that creates an ALV grid display. It takes several input parameters and returns a handle to the grid control object.

The parameters define the data to be displayed on the grid and properties such as column headers, filtering options, and sorting criteria. Once the grid is created, it can be customized and enhanced by adding different features, such as toolbar buttons, context menus or event handlers.

Example

In this example, we will create an ALV grid display using the REUSE_ALV_GRID_DISPLAY function module to display a simple list of employees in a company. The employee data is stored in a table called ZEMPLOYEE. The following is the sample code:

REPORT ZEXAMPLE_ALV_GRID_DISPLAY.

TYPES: BEGIN OF ty_employee,
         emp_id TYPE i,
         emp_name TYPE string,
         emp_dept TYPE string,
       END OF ty_employee.

DATA: it_employee TYPE STANDARD TABLE OF ty_employee WITH HEADER LINE.

* Populate the employee data
SELECT emp_id emp_name emp_dept
  INTO CORRESPONDING FIELDS OF TABLE it_employee
  FROM zemployee.

* Create the ALV grid display
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_structure_name = 'TY_EMPLOYEE'
  TABLES
    t_outtab        = it_employee.
Explanation

The above code creates an ALV Grid Display using the REUSE_ALV_GRID_DISPLAY function module. The function module takes the following input parameters:

  • I_STRUCTURE_NAME: The name of the structure containing the data to be displayed.
  • T_OUTTAB: The internal table containing the data to be displayed in the grid.

In our example, we provided the name of the structure TY_EMPLOYEE, which we defined as a local type at the beginning of the program. We also provided the internal table IT_EMPLOYEE which we populated with the employee data from the database table.

Once the function module is called, it creates the grid display with default settings, which includes sorting and filtering options, and adds standard toolbar buttons.

ALV Grid with Employees data

At this point, we have a basic grid display, but we can enhance it further by adding different features, such as custom toolbar buttons or context menus, by using the appropriate function module parameters and event handlers.

Conclusion

The REUSE_ALV_GRID_DISPLAY function module is an easy and efficient way to create an ALV grid display in SAP ABAP programming. It provides a wide range of features and customization options, allowing developers to enhance the grid's functionality and user experience.