Create an ALV with custom control

Create an ALV with custom control

You can check the SAP demo programs starting with BCALV_GRID_*

To create an ALV on screen, create a custom control.

On the TOP (global declaration) :


  DATA : go_custom_container TYPE REF TO cl_gui_custom_container,
         go_alv              TYPE REF TO cl_gui_alv_grid,
         gs_layout           TYPE lvc_s_layo.

Then on your PBO screen, declare a Module to display ALV :


PROCESS BEFORE OUTPUT.

  MODULE status_0200.
  MODULE initialisation.

  MODULE display_alv.

In this module :


MODULE display_alv OUTPUT.

  " No data declaration here, in module, all declarations are global
  " (better to do it in TOP include)

  IF go_custom_container IS INITIAL.

    " Create a custom container control for our ALV Control
    CREATE OBJECT go_custom_container
      EXPORTING
        container_name              = 'CUST_CTRL_ALV_GRID'
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5.
    IF sy-subrc NE 0.
      MESSAGE i000(zpp) WITH 'The custom control could not be created'.
      RETURN.
    ENDIF.

    " Create ALV
    CREATE OBJECT go_alv
      EXPORTING
        i_parent = go_custom_container.

    " Title on the ALV grid
    gs_layout-grid_title = 'My title'.

    " Allow to select multiple lines
    gs_layout-sel_mode = 'A'.


    " Configuration for first display.
    CALL METHOD go_alv->set_table_for_first_display
      EXPORTING
        i_structure_name = 'SFLIGHT'
        is_layout        = gs_layout
      CHANGING
        it_outtab        = gt_sflight.


  ENDIF.  " /* eo go_custom_container IS NOT BOUND. */

ENDMODULE.                 " DISPLAY_ALV  OUTPUT

To add a header, see :
https://archive.sap.com/discussions/thread/116555
or
https://archive.sap.com/discussions/thread/1054560

About the author

fjourneau administrator

Hi, I'm Florian Journeau, SAP ABAP R3 Freelance, based in Toulouse, France. You want to know more about me, have a look on my CV : cv.fjourneau.net.

2 Comments so far

vikasPosted on12:24 pm - Jan 21, 2022

i_structure_name = ‘SFLIGHT’

from where this structure name has taken please rly

Leave a Reply