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

INTERACTIVE ALV USING CLASSES

Former Member
0 Likes
2,700

Hi Experts

I want sample code for interactive ALV reports using classes

reply will be rewarded.

Thanx in advanced.

Puru

6 REPLIES 6
Read only

Former Member
0 Likes
1,278

Have a look at my post in the ABAP Objects Forum

Cheers

jimbo

Read only

mnicolai_77
Active Participant
0 Likes
1,278

hi,

try with se83 transaction.

regards

Marco

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,278

Check any program starting with BCALV_GRID* for internactive examples, specifically BCALV_GRID_02 for the hotspot(double click) functionality.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,278

hi,

try like this....

Method 1

&----


*& Report ZALV_OOP

*&

&----


*&

*&

&----


REPORT zalv_oop.

----


  • CLASS lcl_event_handler DEFINITION

----


*

----


CLASS lcl_event_handler DEFINITION .

PUBLIC SECTION .

METHODS:

*--Double-click control

handle_double_click

FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row e_column es_row_no.

PRIVATE SECTION.

ENDCLASS. "lcl_event_handler DEFINITION

----


  • CLASS lcl_event_handler IMPLEMENTATION

----


*

----


CLASS lcl_event_handler IMPLEMENTATION .

*--Handle Double Click

METHOD handle_double_click .

PERFORM handle_double_click USING e_row e_column es_row_no .

ENDMETHOD . "handle_double_click

ENDCLASS . "lcl_event_handler IMPLEMENTATION

TABLES : mseg.

DATA : BEGIN OF itab OCCURS 0,

mblnr LIKE mseg-mblnr,

matnr LIKE mseg-matnr,

menge LIKE mseg-menge,

END OF itab.

DATA : gr_alvgrid TYPE REF TO cl_gui_alv_grid,

gr_ccontainer TYPE REF TO cl_gui_custom_container,

gt_fcat TYPE lvc_t_fcat,

gs_layo TYPE lvc_s_layo.

DATA gr_event_handler TYPE REF TO lcl_event_handler .

DATA : ok_code LIKE sy-ucomm.

DATA : t_mat LIKE mara-matnr.

SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : s_mblnr FOR mseg-mblnr.

SELECTION-SCREEN : END OF BLOCK blk1.

START-OF-SELECTION.

SET SCREEN 100.

CREATE OBJECT gr_event_handler .

PERFORM get_data.

PERFORM dis_data.

&----


*& Form get_data

&----


  • text

----


FORM get_data.

SELECT mblnr matnr menge FROM mseg INTO CORRESPONDING FIELDS OF TABLE itab

WHERE mblnr IN s_mblnr.

ENDFORM. "get_data

&----


*& Form dis_data

&----


  • text

----


FORM dis_data.

IF gr_alvgrid IS INITIAL.

CREATE OBJECT gr_ccontainer

EXPORTING

container_name = 'CC_ALV'

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

OTHERS = 6.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CREATE OBJECT gr_alvgrid

EXPORTING

i_parent = gr_ccontainer

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

OTHERS = 5.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

PERFORM create_fcat CHANGING gt_fcat.

PERFORM create_layout CHANGING gs_layo.

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE = 'A'

  • I_DEFAULT = 'X'

is_layout = gs_layo

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

  • IR_SALV_ADAPTER =

CHANGING

it_outtab = itab[]

it_fieldcatalog = gt_fcat

  • IT_SORT =

  • IT_FILTER =

  • EXCEPTIONS

  • INVALID_PARAMETER_COMBINATION = 1

  • PROGRAM_ERROR = 2

  • TOO_MANY_LINES = 3

  • others = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .

ENDIF.

ENDFORM. "dis_data

&----


*& Form create_fcat

&----


  • text

----


  • <--P_GT_FCAT text

----


FORM create_fcat CHANGING pt_fcat TYPE lvc_t_fcat.

DATA : ls_fcat TYPE lvc_s_fcat.

ls_fcat-fieldname = 'MBLNR'.

ls_fcat-coltext = 'Material Doc.'.

APPEND ls_fcat TO pt_fcat.

ls_fcat-fieldname = 'MATNR'.

ls_fcat-coltext = 'Material'.

APPEND ls_fcat TO pt_fcat.

ls_fcat-fieldname = 'MENGE'.

ls_fcat-coltext = 'Quantity'.

APPEND ls_fcat TO pt_fcat.

ENDFORM. " create_fcat

&----


*& Form create_layout

&----


  • text

----


  • <--P_GS_LAYO text

----


FORM create_layout CHANGING ps_layo TYPE lvc_s_layo.

ps_layo-zebra = 'X'.

ENDFORM. " create_layout

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE status_0100 OUTPUT.

SET PF-STATUS 'ZALV_OOP'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE user_command_0100 INPUT.

ok_code = sy-ucomm.

CASE ok_code.

WHEN 'BACK' OR 'UP' OR 'CANC'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form handle_double_click

&----


  • text

----


  • -->I_ROW text

  • -->I_COLUMN text

  • -->IS_ROW_NO text

----


FORM handle_double_click USING i_row TYPE lvc_s_row

i_column TYPE lvc_s_col

is_row_no TYPE lvc_s_roid.

READ TABLE itab INDEX is_row_no-row_id .

IF sy-subrc = 0 .

IF i_column = 'MATNR'.

t_mat = itab-matnr.

SET PARAMETER ID 'MAT' FIELD t_mat.

CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.

SET PARAMETER ID 'MAT' FIELD space.

ELSEIF i_column = 'MBLNR'.

CALL TRANSACTION 'MIGO'.

ENDIF .

ENDIF.

ENDFORM . "handle_double_click

here i have created one screen 100. i took one custom control name CC_ALV....

Method 2

DATA: gt_outtab TYPE TABLE OF sflight.

DATA: toolbar TYPE REF TO cl_salv_functions_list .

DATA: gr_table TYPE REF TO cl_salv_table.

DATA: lr_aggregations TYPE REF TO cl_salv_aggregations.

DATA: lr_groups TYPE REF TO cl_salv_sorts .

SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_outtab.

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = gt_outtab.

lr_aggregations = gr_table->get_aggregations( ).

toolbar = gr_table->get_functions( ) .

toolbar->set_all( value = if_salv_c_bool_sap=>true ).

lr_aggregations->clear( ).

lr_groups = gr_table->get_sorts( ) .

lr_groups->clear( ).

TRY.

lr_groups->add_sort(

columnname = 'CARRID'

position = 8

subtotal = abap_true

sequence = if_salv_c_sort=>sort_up ).

CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing.

ENDTRY.

TRY.

lr_aggregations->add_aggregation( columnname = 'SEATSMAX' ).

CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing.

ENDTRY.

gr_table->display( ).

reward if useful...

Edited by: Dhwani shah on Jan 4, 2008 10:15 AM

Read only

Former Member
0 Likes
1,278
Read only

Former Member
0 Likes
1,278

&----


*& Report Z_ALV_SKELETON

*&

*& Author: Sheila Titchener

*& Date: December 2006

&----


*& ALV Grid control skeleton using OO Methods

*&

&----


REPORT Z_ALV_SKELETON .

&----


&----


  • internal tables

DATA: i_tab TYPE TABLE OF zchangereq,

w_tab TYPE zchangereq.

  • display field details

DATA: w_field_cat_wa TYPE lvc_s_fcat. " Field Catalog work area

*

&----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-020.

&----


PARAMETERS: p_outs RADIOBUTTON GROUP g1,

p_comp RADIOBUTTON GROUP g1.

SELECTION-SCREEN END OF BLOCK b1.

&----


*MACROS

&----


DEFINE add_field.

  • &1 = FIELDNAME &2 = HEADING &3 = Key field flag

clear w_field_cat_wa.

w_field_cat_wa-fieldname = &1.

  • lw_field_cat_wa-ref_table = p_ref_table.

  • lw_field_cat_wa-inttype = p_inttype.

  • lw_field_cat_wa-decimals = p_decimals.

  • lw_field_cat_wa-coltext = p_coltext.

  • lw_field_cat_wa-seltext = p_seltext.

  • lw_field_cat_wa-do_sum = p_do_sum.

  • lw_field_cat_wa-no_out = p_no_out.

  • lw_field_cat_wa-col_pos = p_col_pos.

  • lw_field_cat_wa-reptext = p_coltext.

  • lw_field_cat_wa-colddictxt = p_colddictxt.

w_field_cat_wa-scrtext_m = &2.

w_field_cat_wa-key = &3.

append w_field_cat_wa to i_field_cat.

END-OF-DEFINITION.

*----


  • ALV specific Declarations...........................................

*----


  • ALV specific Internal table declarations.............................

DATA: i_field_cat TYPE lvc_t_fcat, " Field catalogue

i_alv_sort TYPE lvc_t_sort. " Sort table

  • ALV variables........................................................

DATA: w_alv_layout TYPE lvc_s_layo, " ALV Layout

w_alv_save TYPE c, " ALV save

w_alv_variant TYPE disvariant. " ALV Variant

  • ALV Class definitions................................................

*----


CLASS lcl_event_handler DEFINITION.

*----


PUBLIC SECTION.

METHODS: handle_double_click

FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row e_column.

METHODS: handle_hotspot

FOR EVENT hotspot_click OF cl_gui_alv_grid

IMPORTING e_row_id e_column_id.

ENDCLASS. " CLASS LCL_EVENT_HANDLER DEF..

  • ALV Class implementation............................................

  • In the Event of a Double Click drill down to the corresponding CHANGE REQUEST

*----


CLASS lcl_event_handler IMPLEMENTATION.

*----


METHOD handle_double_click.

DATA: l_tab LIKE LINE OF i_tab.

CHECK e_row-rowtype(1) EQ space.

READ TABLE i_tab INDEX e_row-index INTO l_tab.

SET PARAMETER ID 'ZTY' FIELD l_tab-ztype.

SET PARAMETER ID 'ZCR' FIELD l_tab-zcref.

CALL TRANSACTION 'ZCRT' AND SKIP FIRST SCREEN.

ENDMETHOD. " HANDLE_DOUBLE_CLICK

  • not working yet - hotspot seems to stay in the gui!!

METHOD handle_hotspot.

DATA: l_tab LIKE LINE OF i_tab.

CHECK e_row_id-rowtype(1) EQ space.

READ TABLE i_tab INDEX e_row_id-index INTO l_tab.

SET PARAMETER ID 'ZTY' FIELD l_tab-ztype.

SET PARAMETER ID 'ZCR' FIELD l_tab-zcref.

CALL TRANSACTION 'ZCRT' AND SKIP FIRST SCREEN.

ENDMETHOD. " HANDLE_DOUBLE_CLICK

ENDCLASS. " CLASS LCL_EVENT_HANDLER IMPL...

  • ALV Grid Control definitions........................................

DATA:

  • ALV Grid Control itself

o_grid TYPE REF TO cl_gui_alv_grid,

  • Container to hold the ALV Grid Control

o_custom_container TYPE REF TO cl_gui_custom_container,

  • Event handler (defined in the class above)

o_event_handler TYPE REF TO lcl_event_handler.

&----


INITIALIZATION.

&----


PERFORM create_field_catalogue. " Create ALV Field Catalog

&----


START-OF-SELECTION.

&----


  • Outstanding requests

IF p_outs = 'X'.

SELECT * FROM zchangereq

INTO TABLE i_tab

WHERE zstatus < 99.

ELSE.

  • completed requests

SELECT * FROM zchangereq

INTO TABLE i_tab

WHERE zstatus = 99.

ENDIF.

&----


END-OF-SELECTION.

&----


PERFORM list_output_to_alv. " Perform ALV Output operations

----


  • FORM LIST_OUTPUT_TO_ALV *

----


  • This subroutine is used to call the screen for ALV Output. *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM list_output_to_alv.

CALL SCREEN 100.

*

ENDFORM. " LIST_OUTPUT_TO_ALV

----


  • Module STATUS_0100 OUTPUT *

----


  • This is the PBO module which will be processed befor displaying the *

  • ALV Output. *

----


MODULE status_0100 OUTPUT.

SET PF-STATUS '0100'. " PF Status for ALV Output Screen

IF p_outs = 'X'.

SET TITLEBAR 'STD'.

ELSE.

  • completed requests

SET TITLEBAR 'COMP'.

ENDIF.

CREATE OBJECT: o_custom_container

EXPORTING container_name = 'SC_GRID',

o_grid

EXPORTING i_parent = o_custom_container.

PERFORM define_alv_layout. " ALV Layout options definitions

PERFORM save_alv_layout_options. " save ALV layout options

PERFORM call_alv_grid. " Call ALV Grid Control

ENDMODULE. " STATUS_0100 OUTPUT

----


  • Module USER_COMMAND_0100 INPUT *

----


  • This is the PAI module which will be processed when the user performs*

  • any operation from the ALV output. *

----


MODULE user_command_0100 INPUT.

CASE sy-ucomm.

WHEN 'EXIT' OR 'BACK' OR 'CANC'.

  • may need to do this so display is refreshed if other report selected

CALL METHOD o_custom_container->free.

SET SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

----


  • FORM DEFINE_ALV_LAYOUT *

----


  • This subroutine is used to Define the ALV layout. *

----


FORM define_alv_layout .

w_alv_layout-numc_total = 'X'. " Numc total line

w_alv_layout-cwidth_opt = 'X'. " Optimal column width

w_alv_layout-detailinit = 'X'. " Show values that are initial in

" detail list.

w_alv_layout-sel_mode = 'A'. " Column selection mode

w_alv_layout-no_merging = 'X'. " No merging while sorting columns

w_alv_layout-keyhot = 'X'.

ENDFORM. " DEFINE_ALV_LAYOUT

----


  • FORM SAVE_ALV_LAYOUT_OPTIONS *

----


  • This subroutine is used to Save the ALV layout options. *

----


FORM save_alv_layout_options.

  • See the ALV grid control documentation for full list of options

w_alv_save = 'A'.

w_alv_variant-report = sy-repid.

ENDFORM. " SAVE_ALV_LAYOUT_OPTIONS

----


  • FORM CALL_ALV_GRID *

----


  • This subroutine is used to call ALV Grid control for processing. *

----


FORM call_alv_grid.

CALL METHOD o_grid->set_table_for_first_display

EXPORTING

is_layout = w_alv_layout

i_save = w_alv_save

is_variant = w_alv_variant

CHANGING

it_outtab = i_tab[]

it_sort = i_alv_sort

it_fieldcatalog = i_field_cat.

  • Link used Events and Event Handler Methods

CREATE OBJECT o_event_handler.

  • Set handler o_event_handler->handle_top_of_page for o_grid.

SET HANDLER o_event_handler->handle_double_click FOR o_grid.

ENDFORM. " CALL_ALV_GRID

&----


*& Form create_field_catalogue

&----


  • set up field catalogue

&----


FORM create_field_catalogue .

  • Fieldname Heading Key?

*eg add_field 'ZTYPE' 'Type' 'X'.

ENDFORM. " create_field_catalogue