Application Development 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: 

Object oriented ALV in executable report

Former Member
0 Kudos

Hello Friends,

I am having requirement of ALV objects to display report in ALV format.

I have created executable program in se38, in that I am having one internal table , I want to display that

table in ALV grid format by using ALV OOPS concept. I also have to show some of the data in header part.

This is not a modulle pool report.

so please suggest, or send me some sample code for ALV OOPS without module pool.

Thanks

5 REPLIES 5

Former Member
0 Kudos

Use:CL_SALV* classes here you dont have to use Module pool.

[CL_SALV|https://wiki.sdn.sap.com/wiki/display/Snippets/displayinghotspotinalvwithclasscl_salv_table]

[CL_SALV FOR HEADER AND FOOTER|https://wiki.sdn.sap.com/wiki/display/Snippets/TOPOFPAGEANDENDOFPAGEINCLASS+cl_salv_table]

Or,

Use: FM--> REUSE_ALV_GRID_DISPLAY_LVC

This function module internally uses classes.

Regards,

Gurpreet

former_member376453
Contributor
0 Kudos

There are many standard demo program in SAP. Check into the system :

BCALV_GRID_01

BCALV_GRID_02

BCALV_GRID_03

BCALV_GRID_04 ...... many more..

Kuntal

Former Member
0 Kudos

Hi Vinod,

Below is the executable report u can paste it in editor and see the output ...

REPORT z_ALV_OOPS.

tables: MARA.

data: begin of it_tab occurs 0,

matnr like mara-matnr,

ersda like mara-ersda, "creation date

ernam like mara-ernam, "person created

pstat like mara-pstat, "maint stat

lvorm like mara-lvorm, "flg for deletion

mtart like mara-mtart, "mat type

meins like mara-meins, "uom

end of it_tab.

data: wa_it_tab like line of it_tab.

CLASS lcl_events_d0100 DEFINITION DEFERRED.

DATA: event_receiver1 TYPE REF TO lcl_events_d0100.

----


  • CLASS lcl_events_d0100 DEFINITION

----


CLASS lcl_events_d0100 DEFINITION.

PUBLIC SECTION.

  • METHODS:

*

*double_click FOR EVENT double_click

  • OF cl_gui_alv_grid

  • IMPORTING e_row

  • e_column.

*

METHODS

handle_hotspot_click

FOR EVENT hotspot_click OF cl_gui_alv_grid

IMPORTING

e_row_id

e_column_id

es_row_no

sender.

*---code addition for ALV pushbuttons

*--for placing buttons

METHODS handle_toolbar_set

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING

e_object

e_interactive.

*---user command on clicking a button

METHODS handle_user_command

FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING

e_ucomm.

ENDCLASS. "lcl_events_d0100 DEFINITION

TYPE-POOLS cndp.

----


  • LOCAL VARIABLE

----


DATA ok_code TYPE sy-ucomm.

----


  • FOR VARIANT

----


DATA st_var TYPE disvariant .

DATA save TYPE c.

st_var-report = 'YKC_ALV_OOPS'.

save = 'A'.

----


  • FOR LAYOUT

----


DATA loyo TYPE lvc_s_layo.

loyo-zebra = 'X'.

loyo-detailinit = 'X'.

loyo-info_fname = 'RED'.

----


  • FOR FIELD CATALOG

----


DATA fcat TYPE lvc_t_fcat.

DATA wa_fcat LIKE LINE OF fcat.

*--Declaration for toolbar buttons

DATA : ty_toolbar TYPE stb_button.

DATA : e_object TYPE REF TO cl_alv_event_toolbar_set,

io_alv_toolbar TYPE REF TO cl_alv_event_toolbar_set.

*---custom container

DATA container TYPE REF TO cl_gui_custom_container.

DATA ref_grid TYPE REF TO cl_gui_alv_grid.

CREATE OBJECT container

EXPORTING

container_name = 'CONTAINER'."name of container in module pool

CREATE OBJECT ref_grid

EXPORTING

i_parent = container.

----


  • CLASS lcl_events_d0100 IMPLEMENTATION

----


CLASS lcl_events_d0100 IMPLEMENTATION.

----


  • METHOD double_click *

----


  • ........ *

----


  • METHOD double_click.

*

    • PERFORM d0100_event_double_click USING e_row

    • e_column .

**---remember when using double click hotspot will not work

*

  • ENDMETHOD. "double_click

*

*---method for hotspot

METHOD handle_hotspot_click.

DATA:ls_col_id TYPE lvc_s_col.

READ TABLE it_tab INTO wa_it_tab

INDEX e_row_id-index.

IF sy-subrc = 0.

CHECK ( wa_it_tab-matnr IS NOT INITIAL ).

CASE e_column_id-fieldname.

WHEN 'MATNR'.

leave program.

WHEN OTHERS.

  • do nothing

ENDCASE.

CALL METHOD ref_grid->set_current_cell_via_id

EXPORTING

is_row_id = e_row_id

is_column_id = ls_col_id.

ENDIF.

ENDMETHOD. "handle_hotspot_click

*

**---method for handling toolbar

METHOD handle_toolbar_set.

CLEAR ty_toolbar.

ty_toolbar-function = 'LEAVE'. "name of btn to catch click

ty_toolbar-butn_type = 0.

ty_toolbar-text = 'LEAVE'.

APPEND ty_toolbar TO e_object->mt_toolbar.

ENDMETHOD. "handle_toolbar_set

*

METHOD handle_user_command.

DATA: wr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

DATA: lt_rows TYPE lvc_t_row,

lt_index TYPE lvc_s_row-index.

CASE e_ucomm.

WHEN 'LEAVE'.

leave program.

ENDCASE.

ENDMETHOD. "handle_user_command

ENDCLASS. "lcl_events_d0100 IMPLEMENTATION

START-OF-SELECTION.

PERFORM get_data.

PERFORM field_catalog.

&----


*& Form get_data

&----


  • text : getting data into internal table

----


  • --> p1 text

  • <-- p2 text

----


form get_data .

*select matnr ersda ernam pstat lvorm mtart meins

  • into table it_tab

  • from mara

  • where lvorm = 'X'.

it_tab-matnr = '000000000000000001'.

it_tab-ersda = 'asd' .

it_tab-ernam = 'asd'.

it_tab-pstat = 'sd'.

  • it_tab-lvorm = fdf'.

it_tab-mtart = 'we'.

it_tab-meins = 'lb'.

append it_tab.

clear it_tab.

it_tab-matnr = '99999'.

it_tab-ersda = 'asd' .

it_tab-ernam = 'asd'.

it_tab-pstat = 'sd'.

  • it_tab-lvorm = fdf'.

it_tab-mtart = 'we'.

it_tab-meins = 'lb'.

append it_tab.

clear it_tab.

it_tab-matnr = '77777'.

it_tab-ersda = 'asd' .

it_tab-ernam = 'asd'.

it_tab-pstat = 'sd'.

  • it_tab-lvorm = fdf'.

it_tab-mtart = 'we'.

it_tab-meins = 'lb'.

append it_tab.

clear it_tab.

endform. " get_data

&----


*& Form field_catalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form field_catalog .

REFRESH fcat.

DATA: lv_pos TYPE i.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'MATNR'.

wa_fcat-coltext = 'Material No'.

wa_fcat-col_pos = lv_pos.

wa_fcat-hotspot = 'X'.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'ERSDA'.

wa_fcat-coltext = 'Creation Date'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'ERNAM'.

wa_fcat-coltext = 'Person Created'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'PSTAT'.

wa_fcat-coltext = 'Maint Stat'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'LVORM'.

wa_fcat-coltext = 'Flag For Deletion'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'MTART'.

wa_fcat-coltext = 'Material Type'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'MEINS'.

wa_fcat-coltext = 'UOM'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

  • CREATE OBJECT gr_events_d0100.

  • SET HANDLER gr_events_d0100->double_click FOR ref_grid.

CREATE OBJECT event_receiver1.

*---setting event handlers

SET HANDLER event_receiver1->handle_toolbar_set FOR ref_grid.

SET HANDLER event_receiver1->handle_user_command FOR ref_grid.

SET HANDLER event_receiver1->handle_hotspot_click FOR ref_grid.

----


  • ALV GRID DISPLAY

----


CALL METHOD ref_grid->set_table_for_first_display

EXPORTING

is_variant = st_var

i_save = save

is_layout = loyo

CHANGING

it_outtab = it_tab[]

it_fieldcatalog = fcat.

CALL SCREEN 100.

endform. " field_catalog

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


module STATUS_0100 output.

  • CREATE OBJECT gr_events_d0100.

*

  • SET HANDLER gr_events_d0100->double_click

*

  • FOR ref_grid.

SET PF-STATUS 'S100'.

SET TITLEBAR 'XXX'.

    • create the custom container

  • CREATE OBJECT container

  • EXPORTING

  • container_name = 'CONTAINER'. "'CUSTOM'.

*CALL METHOD cl_gui_cfw=>flush

  • EXCEPTIONS

  • cntl_system_error = 1

  • cntl_error = 2.

  • IF sy-subrc <> 0.

    • error handling

  • ENDIF.

endmodule. " STATUS_0100 OUTPUT

&----


*& Module exit INPUT

&----


  • text

----


module exit input.

CASE ok_code.

WHEN 'EXI' .

CLEAR ok_code.

LEAVE PROGRAM.

ENDCASE.

endmodule. " exit INPUT

Thanks & Regards,

Ruchi Tiwari

Former Member
0 Kudos

Hi,

Try this code.Hope it Helps!!!!!!!!!

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

  • internal tables

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

TYPES : BEGIN OF t_output,

matnr TYPE mara-matnr,

meins TYPE mara-meins,

END OF t_output.

DATA: i_output TYPE STANDARD TABLE OF t_output,

wa_output LIKE LINE OF i_output.

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

  • internal data fields

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

DATA: grid_layout TYPE lvc_s_layo,

i_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,

wa_fieldcat LIKE LINE OF i_fieldcat,

grid1 TYPE REF TO cl_gui_alv_grid ,

g_custom_container TYPE REF TO cl_gui_custom_container,

g_variant TYPE disvariant.

CONSTANTS : c_container_name TYPE scrfname " Container name

VALUE 'ALV_CONTROL'.

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

START-OF-SELECTION.

PERFORM get_data.

PERFORM build_catalogue.

PERFORM display_data.

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

&----


*& Form GET_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data .

  • Get the data from the tables and prepare an output table which you want to display

wa_output-matnr = '0020100300'.

wa_output-meins = 'PC'.

APPEND wa_output TO i_output.

ENDFORM. " GET_DATA

&----


*& Form BUILD_CATALOGUE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_catalogue .

  • Build catologue

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MATNR'. "(Pass the name of the database field that you want to display)

wa_fieldcat-tabname = 'I_OUTPUT'.

wa_fieldcat-coltext = 'Material'.

wa_fieldcat-fix_column = 'X'.

wa_fieldcat-edit = 'X'.

wa_fieldcat-col_pos = '1'.

APPEND wa_fieldcat TO i_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MEINS'."(Pass the name of the database field that you want to display)

wa_fieldcat-tabname = 'I_OUTPUT'.

wa_fieldcat-coltext = 'Unit'.

wa_fieldcat-fix_column = 'X'.

wa_fieldcat-edit = 'X'.

wa_fieldcat-col_pos = '2'.

APPEND wa_fieldcat TO i_fieldcat.

ENDFORM. " BUILD_CATALOGUE

&----


*& Form DISPLAY_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data .

CALL SCREEN 30.

*Click on the '30', it will prompt you to create a screen, give appropriate name to the screen,

*Click on the LAYOUT tab and create a container on the screen (Use Custom Control).

*Give appropriate name to the container it should be same as declared by the constant

*c_container_name TYPE scrfname.In this code it is named as ALV_CONTROL

*Once screen is created and activated double click on it it will take you to PBO and PAI modules.

*create these modules.

ENDFORM. " DISPLAY_DATA

&----


*& Module STATUS_0030 OUTPUT

&----


  • text

----


MODULE status_0030 OUTPUT.

SET PF-STATUS '030'. "(Create PF status by double clicking on that

SET TITLEBAR '030'.

*Standard toolbar options like BACK, SAVE , CANCEL can be added in toolbar using PF-STATUS

  • You need to add these buttons in function keys

IF g_custom_container IS INITIAL .

CREATE OBJECT g_custom_container

EXPORTING

container_name = c_container_name.

CREATE OBJECT grid1

EXPORTING

i_parent = g_custom_container.

ELSE.

CALL METHOD grid1->free.

CALL METHOD g_custom_container->free.

CREATE OBJECT g_custom_container

EXPORTING

container_name = c_container_name.

CREATE OBJECT grid1

EXPORTING

i_parent = g_custom_container.

ENDIF.

g_variant = sy-repid.

CALL METHOD grid1->set_table_for_first_display

EXPORTING

is_layout = grid_layout

is_variant = g_variant

i_save = 'A'

CHANGING

it_outtab = i_output[] "pass output table here

it_fieldcatalog = i_fieldcat.

ENDMODULE. " STATUS_0030 OUTPUT

&----


*& Module USER_COMMAND_0030 INPUT

&----


  • text

----


MODULE user_command_0030 INPUT.

  • The code that needs to be handled after output is displayed needs to be written

CASE sy-ucomm.

WHEN 'BACK' OR 'CANCEL'.

CALL METHOD g_custom_container->free.

CALL METHOD cl_gui_cfw=>flush.

SET SCREEN 0.

LEAVE SCREEN.

ENDCASE.

ENDMODULE. " USER_COMMAND_0030 INPUT

By Tejaswini Khante

former_member203501
Active Contributor
0 Kudos

hi look at the programs------->

BCALV* -


> for object oriented programs

SALV* -


> for new object OO model