Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Steps to create ALV grid

former_member130219
Participant
0 Likes
1,589

Hi All

I tried created ALV grid control,but facing error in the declaration of the data variables.

Please help ..where do we declare data for internal table and reference variables for

container and grid in the program.Acc. to its in the TOP include part.But its giving error

that data not accessible.

Thanks in advance..

Abhinandan Kumar

Hi All

I tried created ALV grid control,but facing error in the declaration of the data variables.

Please help ..where do we declare data for internal table and reference variables for

container and grid in the program.Acc. to its in the TOP include part.But its giving error

that data not accessible.

Thanks in advance..

Abhinandan Kumar

2 REPLIES 2
Read only

Former Member
0 Likes
745

Hi,

Find the code below.

REPORT ZTESTQ.

TABLES: t001.

*INTERNAL TABLE

DATA: gt_001 TYPE STANDARD TABLE OF t001.

*NAME OF CUSTOM CONTAINER ADDED ON SCREEN

DATA : gd_container_alv TYPE scrfname VALUE 'ALV_CON'.

*ALV GRID CONTAINER INSTANCE

DATA : go_cus_alv_container TYPE REF TO cl_gui_custom_container.

DATA : go_grid TYPE REF TO cl_gui_alv_grid.

*FIELD CATALOG

DATA : gt_fieldcat TYPE lvc_t_fcat,

gs_fieldcat TYPE lvc_s_fcat.

*LAYOUT

DATA : gs_layout TYPE lvc_s_layo.

*Class Definition

CLASS gcl_alv DEFINITION.

PUBLIC SECTION.

METHODS populate_tab.

METHODS create_field_catalog.

METHODS create_layout.

METHODS display_alv.

METHODS refresh_alv.

PRIVATE SECTION.

  • DATA : bukrs TYPE t001-bukrs.

ENDCLASS.

*Class implementation

CLASS gcl_alv IMPLEMENTATION.

METHOD populate_tab.

SELECT * FROM t001

INTO TABLE gt_001.

ENDMETHOD.

METHOD create_field_catalog.

gs_fieldcat-col_pos = '1'.

gs_fieldcat-fieldname = 'BUKRS'.

gs_fieldcat-tabname = 'gt_001'.

gs_fieldcat-coltext = 'Company Code'.

APPEND gs_fieldcat TO gt_fieldcat.

gs_fieldcat-col_pos = '2'.

gs_fieldcat-fieldname = 'BUTXT'.

gs_fieldcat-tabname = 'gt_001'.

gs_fieldcat-coltext = 'CC Text'.

APPEND gs_fieldcat TO gt_fieldcat.

ENDMETHOD.

METHOD create_layout.

gs_layout-grid_title = 'Company Code Report'.

gs_layout-zebra = 'X'.

ENDMETHOD.

METHOD display_alv.

CALL METHOD GO_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

I_DEFAULT = 'X'

IS_LAYOUT = gs_layout

CHANGING

IT_OUTTAB = gt_001

IT_FIELDCATALOG = gt_fieldcat

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

others = 3.

ENDMETHOD.

METHOD refresh_alv.

REFRESH gt_001.

SELECT * FROM t001

INTO TABLE gt_001.

CALL METHOD GO_GRID->REFRESH_TABLE_DISPLAY.

ENDMETHOD.

ENDCLASS.

DATA : go_alv TYPE REF TO gcl_alv.

START-OF-SELECTION.

CREATE OBJECT go_alv.

CALL METHOD go_alv->populate_tab.

CALL SCREEN 0100.

&----


*& Module PBO_100 OUTPUT

&----


  • text

----


MODULE PBO_100 OUTPUT.

*Set the GUI status

SET PF-STATUS '0100'.

*Create the container to be placed in the screen

CREATE OBJECT GO_CUS_ALV_CONTAINER

EXPORTING

CONTAINER_NAME = gd_container_alv.

*Create the ALV Grid Container within the parent container

CREATE OBJECT GO_GRID

EXPORTING

I_PARENT = go_cus_alv_container.

CALL METHOD go_alv->create_field_catalog.

CALL METHOD go_alv->create_layout.

CALL METHOD go_alv->display_alv.

ENDMODULE. " PBO_100 OUTPUT

&----


*& Module PAI_100 INPUT

&----


  • text

----


MODULE PAI_100 INPUT.

CASE sy-ucomm.

WHEN 'REFRESH'.

CALL METHOD go_alv->refresh_alv.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'EXIT'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " PAI_100 INPUT

Read only

former_member212005
Active Contributor
0 Likes
745

I believe that you are trying to create an ALV Grid using OOP

The basic steps are..

1) Create a custom container for the ALV Grid using the transaction SE51...

2) Declare a variable gv_custom_container TYPE REF TO cl_gui_custom_container...

3) Declare a variale gv_grid_control TYPE REF TO cl_gui_alv_grid,

4) Create an object for the custom container using CREATE OBJECT statement (gv_custom_container)

5) Create an object for the grid control using CREATE OBJECT statement (gv_grid_control)

6) Fill the Field Catalog for all the fields of the internal table which you want to display in ALV Grid...

gt_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat

7) Create the layout...

😎 Call the method gv_grid_control->set_table_for_first_display...passing the internal table which holds data and the fieldcatalog (GT_FIELDCAT)

If you are not using OOALV...then use..the FM REUSE_ALV_GRID_DISPLAY