Skip to main content

Chapter 2: ALV Grid Presentation

In the previous chapter, we learned how to create an "order form" for our users to request the exact data they need. We packaged their request and sent it off to the database. Now, the data has arrived! But what do we do with it?

A raw block of data is like a pile of car parts. It's not very useful to the average driver. We need to assemble those parts into a finished car and present it in a showroom. This chapter is all about being the showroom designer for our data. We'll take the raw data and display it in a clean, interactive, and user-friendly grid.

The Showroom: ABAP List Viewer (ALV)

In the world of SAP, the ultimate showroom for data is the ABAP List Viewer, or ALV. It's a powerful, built-in framework that can turn a simple internal table of data into a professional-looking, interactive report grid with features like sorting, filtering, and exporting to Excel, all with minimal effort.

Our job is to give the ALV framework two things:

  1. The Blueprint: A set of instructions on how the grid should look. Which columns should appear? What should their headers be? This is called a Field Catalog.
  2. The Product: The actual data we retrieved from the database.

Let's see how our report program handles these two steps.

Step 1: Creating the Blueprint (The Field Catalog)

Before we can display anything, we need a plan. The field catalog is our blueprint. It's a special table that defines every single column in our output grid. For each column, we can specify:

  • fieldname: The technical field name from our data table (e.g., BUKRS).
  • coltext: The user-friendly text for the column header (e.g., 'Company Code').
  • outputlen: How wide the column should be.
  • ...and many other properties!

In our program, a subroutine named get_fcat is responsible for building this blueprint. Let's look at a simplified example of how it defines one column.

" A temporary structure to hold the definition for one column
DATA ls_fcat TYPE slis_fieldcat_alv.

" Define the 'Company Code' column
CLEAR ls_fcat.
ls_fcat-fieldname = 'BUKRS'.
ls_fcat-coltext = 'Company Code'.
APPEND ls_fcat TO gt_fcat.

This code snippet creates a single entry in our blueprint. It says, "Find the field named BUKRS in my data, create a column for it, and label that column 'Company Code'." The program repeats this for every field we want to show the user, building up a complete field catalog table called gt_fcat.

Step 2: Assembling the Grid (Displaying the Data)

With our blueprint (gt_fcat) and our final data table (gt_final) ready, we can finally call the ALV framework to build the visual grid. This is done in another subroutine, disp_data.

This routine makes a call to a standard SAP function module, REUSE_ALV_GRID_DISPLAY. Think of this function as the master builder. We hand it our blueprint and our data, and it does all the hard work of rendering the interactive grid for the user.

FORM disp_data.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = gt_fcat " <-- Our blueprint
TABLES
t_outtab = gt_final " <-- Our data
EXCEPTIONS
program_error = 1
OTHERS = 2.

ENDFORM.

The two most important lines are:

  • it_fieldcat = gt_fcat: We pass our blueprint (the field catalog) to the builder.
  • t_outtab = gt_final: We pass our final, processed data to the builder.

When this code runs, the user sees the final report—a beautiful, interactive grid where they can sort, filter, and analyze the VAT data they requested.

Under the Hood: The Presentation Flow

Let's visualize the entire process from having the data to showing the grid.

This flow neatly separates the "what" from the "how." We first define what the columns should look like (get_fcat), and then we tell the system how to display them using the data (disp_data). This makes the code clean and easy to understand. The data itself is prepared by other parts of our application, such as the HANA Database Data Retrieval (AMDP) and Data Transformation and Enrichment processes.

Conclusion

In this chapter, we played the role of a showroom designer. We learned that presenting data is just as important as retrieving it. We saw how the ALV Grid Presentation layer uses a two-step process:

  1. Create a blueprint (Field Catalog) to define the columns and their headers.
  2. Call the ALV framework to build the interactive grid using the blueprint and the final data.

This abstraction ensures that our report's output is always professional, interactive, and clear for the end-user.

But where does the data table (gt_final) that we just displayed actually come from? And what does its structure look like? Before we can fetch or display data, we must first define its structure. That is the topic of our next chapter.

Next: Chapter 3: Report Data Model


Generated by AI Codebase Knowledge Builder