ALV Reports
ABAP Developmentintermediate

ALV Reports Part 3: OO ALV with CL_GUI_ALV_GRID and a Custom Container

Key takeaway

Build the classic OO ALV used in most custom transactions: screen 100 with a custom control, CL GUI CUSTOM CONTAINER, CL GUI ALV GRID, LVC field catalog and layout, set table for first display, PBO/PAI modules and refresh table display.

Explanation

📌 KEY POINTS
✅ CL_GUI_ALV_GRID is a GUI control placed in a container on your own dynpro screen.

✅ Flow: CALL SCREEN 100 → PBO creates container + grid once → set_table_for_first_display → PAI handles OK codes.

✅ It uses LVC types (lvc_t_fcat, lvc_s_layo) — not the SLIS types of REUSE_ALV.

⚠️ Create container and grid only once (IF go_grid IS INITIAL); later use refresh_table_display.

━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE

Parts 1–2 were full-screen ALVs without own screens. CL_GUI_ALV_GRID gives full control — events (Part 6, 8), editing (Part 9), several grids on one screen.

━━━━━━━━━━━━━━━━━━━━
▶ 1. BUILDING BLOCKS

  • Screen 100 (SE51 or from SE80) with a Custom Control element named e.g. CC_ALV.
  • GUI status (SE41) with BACK/EXIT/CANCEL functions, set in PBO.
  • Container: CL_GUI_CUSTOM_CONTAINER EXPORTING container_name = 'CC_ALV'. (Alternative: CL_GUI_DOCKING_CONTAINER — no screen element needed.)
  • Grid: CL_GUI_ALV_GRID EXPORTING i_parent = go_container.

━━━━━━━━━━━━━━━━━━━━
▶ 2. FIELD CATALOG AND LAYOUT (LVC)

  • LVC_FIELDCATALOG_MERGE with i_structure_name builds lvc_t_fcat from DDIC; then adjust coltext, outputlen, do_sum.
  • lvc_s_layo: zebra, cwidth_opt, sel_mode ('A' for multi-row selection), grid_title.

━━━━━━━━━━━━━━━━━━━━
▶ 3. FIRST DISPLAY AND REFRESH

go_grid->set_table_for_first_display( EXPORTING is_layout = gs_layout CHANGING it_outtab = gt_out it_fieldcatalog = gt_fcat ).

  • Called once. After changing gt_out, call go_grid->refresh_table_display( ) — optionally with is_stable to keep scroll position.

━━━━━━━━━━━━━━━━━━━━
▶ 4. SCREEN FLOW

PBO: SET PF-STATUS, SET TITLEBAR, create ALV if initial.

PAI: CASE ok_code — BACK/EXIT → LEAVE TO SCREEN 0; free controls on exit (go_container->free( )).

━━━━━━━━━━━━━━━━━━━━
▶ 5. WHY STILL USE IT

Most custom Z transactions with ALV in ECC and S/4 on-premise use this pattern; you will maintain it in support projects.

━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP

  1. Create report ZALV_GRID_OO with screen 100 (custom control CC_ALV) and status STATUS_100 (BACK, EXIT, CANCEL).
  2. Paste the code example and activate everything.
  3. Add a REFRESH function in the status: re-select data and call refresh_table_display.

💡 Tip: CL_GUI_DOCKING_CONTAINER EXPORTING extension = 2000 lets you place an ALV on a selection screen or without a screen element.

✅ CHECKPOINT: you can build and maintain a screen-based ALV with CL_GUI_ALV_GRID.

Code example

ABAP Code
REPORT zalv_grid_oo. DATA: gt_out       TYPE STANDARD TABLE OF sflight,      go_container TYPE REF TO cl_gui_custom_container,      go_grid      TYPE REF TO cl_gui_alv_grid,      gt_fcat      TYPE lvc_t_fcat,      gs_layout    TYPE lvc_s_layo,      gv_ok_code   TYPE sy-ucomm.                " OK_CODE field of screen 100 PARAMETERS p_carr TYPE s_carr_id DEFAULT 'LH'. START-OF-SELECTION.  PERFORM get_data.  CALL SCREEN 100. *----------------------------------------------------------------------*FORM get_data.  SELECT * FROM sflight INTO TABLE gt_out WHERE carrid = p_carr.ENDFORM. *----------------------------------------------------------------------** Screen 100 flow logic:*   PROCESS BEFORE OUTPUT.*     MODULE status_0100.*     MODULE init_alv_0100.*   PROCESS AFTER INPUT.*     MODULE user_command_0100.*----------------------------------------------------------------------*MODULE status_0100 OUTPUT.  SET PF-STATUS 'STATUS_100'.  SET TITLEBAR 'TITLE_100'.ENDMODULE. MODULE init_alv_0100 OUTPUT.  IF go_grid IS INITIAL.                          " create only once*   Step 1: container on the custom control    CREATE OBJECT go_container      EXPORTING container_name = 'CC_ALV'.*   Step 2: grid inside the container    CREATE OBJECT go_grid      EXPORTING i_parent = go_container.*   Step 3: field catalog from DDIC, then adjust    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'      EXPORTING i_structure_name = 'SFLIGHT'      CHANGING  ct_fieldcat      = gt_fcat.    PERFORM adjust_fcat.*   Step 4: layout    gs_layout-zebra      = 'X'.    gs_layout-cwidth_opt = 'X'.    gs_layout-sel_mode   = 'A'.                   " multiple row selection    gs_layout-grid_title = 'Flights'.*   Step 5: first display    go_grid->set_table_for_first_display(      EXPORTING is_layout       = gs_layout      CHANGING  it_outtab       = gt_out                it_fieldcatalog = gt_fcat ).  ENDIF.ENDMODULE. MODULE user_command_0100 INPUT.  DATA ls_stable TYPE lvc_s_stbl.  CASE gv_ok_code.    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.      IF go_container IS BOUND.        go_container->free( ).                    " release the control      ENDIF.      LEAVE TO SCREEN 0.    WHEN 'REFRESH'.      PERFORM get_data.      ls_stable-row = 'X'.      ls_stable-col = 'X'.      go_grid->refresh_table_display( is_stable = ls_stable ).  " keep scroll position  ENDCASE.  CLEAR gv_ok_code.ENDMODULE. *----------------------------------------------------------------------*FORM adjust_fcat.  FIELD-SYMBOLS <ls_fcat> TYPE lvc_s_fcat.  LOOP AT gt_fcat ASSIGNING <ls_fcat>.    CASE <ls_fcat>-fieldname.      WHEN 'MANDT'.        <ls_fcat>-no_out = 'X'.                   " hide client      WHEN 'SEATSOCC' OR 'PAYMENTSUM'.        <ls_fcat>-do_sum = 'X'.      WHEN 'SEATSMAX'.        <ls_fcat>-coltext = 'Capacity'.    ENDCASE.  ENDLOOP.ENDFORM.

Real project scenario

A support ticket reported that a custom goods receipt transaction became slower each time the user pressed Refresh, and eventually the GUI froze. The PBO module created a new container and grid on every screen round trip, stacking dozens of controls.
The fix was the standard pattern: create container and grid only IF go_grid IS INITIAL, and use refresh_table_display with is_stable afterwards. The container was freed on BACK. Response time returned to normal.

Common mistakes

  • Creating container/grid in every PBO.
  • Custom control name in the screen not matching container_name.
  • Calling set_table_for_first_display again instead of refresh_table_display.
  • Output table declared locally (grid keeps a reference).
  • Not clearing the OK code or not freeing controls on exit.

Best practices

  • Create controls once, refresh afterwards with is_stable.
  • Build the LVC catalog from DDIC and adjust in a loop with field symbols.
  • Keep the output table global or as a class attribute.
  • Use a docking container when no screen layout is needed.
  • Encapsulate ALV handling in a local class for larger reports.

Interview angle

Questions: "How do you display an ALV with CL_GUI_ALV_GRID?", "Why check IS INITIAL in PBO?", "Custom vs docking container?"
Strong answer: screen with custom control, CL_GUI_CUSTOM_CONTAINER with container_name, CL_GUI_ALV_GRID with i_parent, LVC field catalog (LVC_FIELDCATALOG_MERGE) and layout, set_table_for_first_display once, refresh_table_display for updates; create objects only once in PBO; docking container needs no screen element.

Practice this lesson

Quick check

1. In PBO of a screen with CL_GUI_ALV_GRID, how should the grid be created?

2. Which container class is typically used to embed a CL_GUI_ALV_GRID control within a custom control area defined on a screen (dynpro)?

3. In CL_GUI_ALV_GRID, which method is called to refresh the displayed grid data after the bound internal table has been changed programmatically in ABAP?

Interview questions

1. How do you build a reusable ALV wrapper?

Answer it in your own words first, then compare.

2. In a custom transaction with CL_GUI_ALV_GRID, the screen becomes slower on every refresh and eventually hangs. What is the likely cause and fix?

Answer it in your own words first, then compare.

Practice more with Interview AI →

Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.

More lessons in this topic

Interview questions on this topic

Related SAP topics