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

ALV Report Using Classes

Former Member
0 Likes
1,545

This is my ALV Report using OOPS(class).

I am not able to display anything. The grid is not getting displayed. i am attaching the code here. Can anyone tell me whats wrong in the code?

types: begin of typ_mara,

matnr type matnr,

prdha type prodh_d,

end of typ_mara.

data: it_fieldcat type LVC_T_FCAT,

is_fieldcat type LVC_S_FCAT,

it_mara type standard table of typ_mara,

i_grid_title type lvc_title value 'Test Report'.

data: o_container type ref to cl_gui_custom_container,

o_grid type ref to cl_gui_alv_grid.

if o_container is initial.

CREATE OBJECT o_container

EXPORTING

container_name = 'MYTEST'

EXCEPTIONS

CNTL_ERROR = 1

CNTL_SYSTEM_ERROR = 2

CREATE_ERROR = 3

LIFETIME_ERROR = 4

LIFETIME_DYNPRO_DYNPRO_LINK = 5

others = 6 .

CREATE OBJECT o_grid

EXPORTING

i_parent = o_container

EXCEPTIONS

ERROR_CNTL_CREATE = 1

ERROR_CNTL_INIT = 2

ERROR_CNTL_LINK = 3

ERROR_DP_CREATE = 4

others = 5 .

select matnr prdha from mara into corresponding fields of

table it_mara.

perform build_field_catalog.

CALL METHOD o_grid->set_frontend_fieldcatalog

EXPORTING

it_fieldcatalog = it_fieldcat .

CALL METHOD o_grid->set_gridtitle

EXPORTING

i_gridtitle = i_grid_title .

CALL METHOD o_grid->set_table_for_first_display

CHANGING

it_outtab = it_mara[]

IT_FIELDCATALOG = it_fieldcat[]

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

TOO_MANY_LINES = 3

others = 4 .

IF sy-subrc <> 0.

MESSAGE ID 'ZZ' TYPE 'I' NUMBER SY-MSGNO

WITH SY-SUBRC.

ENDIF.

*&----


*& Form build_field_catalog

*&----


  • Build Field Catalogue table for alv grid display

*----


form build_field_catalog .

is_fieldcat-col_pos = 1.

is_fieldcat-fieldname = 'MATNR'.

is_fieldcat-lzero = 'X'.

is_fieldcat-SELTEXT = 'Material Number'.

append is_fieldcat to it_fieldcat.

is_fieldcat-col_pos = 2.

is_fieldcat-fieldname = 'PRHDA'.

  • is_fieldcat-lzero = 'X'.

is_fieldcat-SELTEXT = 'Product Hierarchy'.

append is_fieldcat to it_fieldcat.

endform. " build_field_catalog

thnx in advance

Balaji

4 REPLIES 4
Read only

Former Member
0 Likes
903

Hi Balaji,

The method needs also informations concerning how to be displayed.

It will be store in type: lvc_s_layo.

I allways use a DDIC-Structure, so all the HeaderLines will be shown in the standard way.

Therefore usually I use the FM: 'LVC_FIELDCATALOG_MERGE'

to create the Fieldcat.

But anyway; it works also with internal tables.

For example:

DATA: gf_layout TYPE lvc_s_layo.

*:--- GRID EIGENSCHAFTEN ÜBER FELDLEISTE

gf_layout-grid_title =

'Kontrolle inaktiver Bestände nach Wert'(t00).

gf_layout-zebra = 'X'.

gf_layout-edit = 'X'. " Nicht eingabebereit

gf_layout-edit_mode = 'X'. " Editmode

gf_layout-sel_mode = 'A'.

gf_layout-no_keyfix = ' '. " Keyspalten nicht fixieren

gf_layout-cwidth_opt = ' '. " optimale Breite

gf_layout-totals_bef = ' '. " Summenanzeige

gf_layout-no_rowmark = ' '. " Keine Zeilenmarkierung

gf_layout-no_toolbar = ' '. " keine Toolbar

gf_layout-info_fname = c_fldfarb. " FARBE = Zeilenfärbung

  • gf_layout-NUMC_TOTAL = 'X'. " Summen zulassen bei Numc

gf_layout-detailtitl = 'Detailanzeige'(t05).

gf_layout-detailinit = 'X'.

gf_layout-ctab_fname = 'X'.

call the method in this way:

CALL METHOD hnd_grid_01->set_table_for_first_display

EXPORTING i_structure_name = c_struc " Name of the DDIC-Structure if used

i_save = 'A'

i_default = 'X'

is_layout = gf_layout

it_toolbar_excluding = gt_xclude " to delete Buttons in the Toolbar

CHANGING it_outtab = gt_output[]

it_fieldcatalog = gt_fldcat[].

*:--- Only if you add extra Buttons etc..

SET HANDLER lcl_event_receiver=>hnd_user_command

lcl_event_receiver=>hnd_toolbar FOR ALL INSTANCES.

*:--- TOOLBAR

CALL METHOD hnd_grid_01->set_toolbar_interactive.

*:--- Table-control Markierungen setzen

CALL METHOD hnd_grid_01->set_ready_for_input

EXPORTING

i_ready_for_input = 0. " means no edit 1 means edit

*:--- Control anzeigen

CALL METHOD cl_gui_control=>set_focus

EXPORTING control = hnd_grid_01.

*:--- An example for excluding Buttons:

Data: gs_func TYPE ui_func.

gs_func = cl_gui_alv_grid=>mc_fc_loc_append_row.

APPEND gs_func TO gt_xclude.

gs_func = cl_gui_alv_grid=>mc_fc_loc_copy.

APPEND gs_func TO gt_xclude.

gs_func = cl_gui_alv_grid=>mc_fc_loc_copy_row.

APPEND gs_func TO gt_xclude.

Hope i could help you

BR Michael

Read only

Former Member
0 Likes
903

Hello again,

A question:

Did You add a coding similar to this to define the class?

*:--- OOP-Definitionen

DATA: cnt_name_01 TYPE scrfname VALUE 'CNTRL_KOBE',

hnd_grid_01 TYPE REF TO cl_gui_alv_grid,

hnd_cont_01 TYPE REF TO cl_gui_custom_container.

*******************************************************************

CLASS lcl_event_receiver DEFINITION DEFERRED.

****************************************************************

*:--- LOCAL CLASSES: Definition

****************************************************************

*:--- Definition der Grid-Klasse

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

*:--- Methoden

CLASS-METHODS:

*:--- Toolbar (Standard buttons)

hnd_toolbar

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object e_interactive,

*:--- Rückgabecodes (Funktion)

hnd_user_command

FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING e_ucomm.

*:--- Private Vereinbarungen

PRIVATE SECTION.

ENDCLASS.

*:--- Toolbar

METHOD hnd_toolbar.

LOOP AT gt_toolbar INTO gf_toolbar.

APPEND gf_toolbar TO e_object->mt_toolbar.

ENDLOOP.

ENDMETHOD.

*:--- User Command only if You have defined some

*********************************************

METHOD hnd_user_command.

CLEAR: gt_selline.

CLEAR: gt_seltab.

*:--- Selectierte Zeilen werden über Index zurückgeliefert

CALL METHOD hnd_grid_01->get_selected_rows

IMPORTING et_index_rows = gt_selline.

CALL METHOD cl_gui_cfw=>flush.

IF sy-subrc NE 0.

*:--- add your handling, for example

CALL FUNCTION 'POPUP_TO_INFORM'

EXPORTING

titel = gs_repid

txt2 = sy-subrc

txt1 = 'Error in Flush'(500).

ENDIF.

*:--- Hier die ButtonMenüs prozessieren

CASE e_ucomm.

WHEN 'DO IT'

PERFORM doit.

ENDCASE.

CALL METHOD hnd_grid_01->refresh_table_display.

ENDMETHOD. "hnd_user_command

ENDCLASS.

Read only

Former Member
0 Likes
903

Hai balaji,

Write select statement and call screen statement after declarations and check it out.

Read only

Former Member
0 Likes
903

I try to explain steps the create basic ALV without fieldcatalog.

Steps to create basic ALV:

1. Declare internal table and work area from any structure or table.

2. fetch all the data from the database table into internal table using select query.

3. using CALL SCREEN n statement to create the screen,inside the screen use custom container       screen element,give some name for that like ÇUST.

4. In the program write  DATA : OBJ TYPE REF TO CL_GUI_CIUSTOM_CONTAINER

                                       DATA : OBJ1 TYPE REF TO CL_GUI_ALV_GRID.

(CL_GUI_CUSTOM_CONTAINER is a class,just a container for ALV grid)

5. Now u need to create object for CL_GUI_CIUSTOM_CONTAINER

    CREATE OBJECT o_container

    EXPORTING

       container_name              = 'ÇUST'.

6.  Now u need to create object for CL_GUI_ALV_GRID

      CREATE OBJECT o_grid

       EXPORTING

       i_parent          = OBJ.

7.   After create the object call method SET_TABLE_FOR_FIRST_DISPLAY From the class                           CL_GUI_ALV_GIRD.

     

     CALL METHOD o_grid->set_table_for_first_display

      STRUCTURE             = 'VBAK'

      CHANGING

      it_outtab                     = IT_ITAB.

This is basic in ALV,from this u can build to any level.

Hope u got my explanation.

Regards

RV Karthikeyan.