‎2006 Dec 06 3:47 AM
‎2006 Dec 06 3:52 AM
Hi,
Check this code: Also goto se38, search for <b>BCALV</b>, you will get plenty of SAP Sample ALV Programs
include zalv_adv_top . "
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_0100 input.
copy_ok_code = ok_code.
clear ok_code.
case copy_ok_code.
when 'BACK' .
leave program.
endcase.
endmodule. " USER_COMMAND_0100 INPUT
module status_0100 output.
set pf-status 'SCREEN_0100'.
endmodule. " STATUS_0100 OUTPUT
module init_control_processing output.
if ref_container is initial.
* create container object
create object ref_container
exporting
extension = 2500.
* create alv grid object and link to container
create object ref_alv
exporting
i_parent = ref_container.
* send basic list to alv grid control
call method ref_alv->set_table_for_first_display
exporting
i_structure_name = 'SPFLI'
changing
it_outtab = it_spfli.
* event handling --> only ABAP Objects part,
set handler:lcl_event_handler=>on_double_click for ref_alv.
endif.
endmodule. " init_control_processing OUTPUT
*---------------------------
*&---------------------------------------------------------------------*
*& Include ZALV_ADV_TOP *
*& *
*&---------------------------------------------------------------------*
program zalv_adv .
data: ok_code type sy-ucomm.
types: begin of ty_sflight.
include structure sflight.
types: percentage type i,
sign type c,
end of ty_sflight.
data: copy_ok_code like ok_code,
* control specific: object references
ref_container type ref to cl_gui_docking_container,
ref_alv type ref to cl_gui_alv_grid,
box_container type ref to cl_gui_dialogbox_container,
box_alv type ref to cl_gui_alv_grid,
* internal tables
it_spfli type table of spfli,
it_sflight type table of ty_sflight,
it_popup type table of ty_sflight,
* work areas
wa_spfli like line of it_spfli,
wa_sflight like line of it_sflight.
select-options:so_carr for wa_spfli-carrid no-extension no intervals.
select * from spfli into table it_spfli where carrid in so_carr
order by carrid connid.
call screen '0100'.
* event handler class
*------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*------------------------------------------------------------------*
class lcl_event_handler definition.
public section.
class-methods:
on_double_click for event double_click of cl_gui_alv_grid
importing e_row,
* -------------------------------------------------------------
on_close for event close of cl_gui_dialogbox_container
importing sender.
endclass.
*-----------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*-----------------------------------------------------------------*
class lcl_event_handler implementation.
method on_double_click.
* local data
data: wa_popup like line of it_popup.
* find out selected line (double click)
read table it_spfli into wa_spfli index e_row-index.
* copy corresponding flight data to it_popup
clear it_popup.
loop at it_sflight into wa_sflight
where carrid = wa_spfli-carrid
and connid = wa_spfli-connid.
insert wa_sflight into table it_popup.
endloop.
if sy-subrc ne 0.
select * from sflight into wa_sflight
where carrid = wa_spfli-carrid
and connid = wa_spfli-connid.
insert wa_sflight into table: it_sflight,
it_popup.
endselect.
endif.
if box_container is initial.
* create dialog box container
create object box_container
exporting width = 800 height = 200 top = 120 left = 120.
* set event handler for dialogbox container: --> close
*
set handler on_close for box_container.
endif.
if box_alv is initial.
* create avl grid object and link to dialogbox container
create object box_alv
exporting i_parent = box_container.
* send popup data to new alv object
call method box_alv->set_table_for_first_display
exporting i_structure_name = 'SFLIGHT'
changing it_outtab = it_popup.
if sy-subrc <> 0.
message a012(bc412).
endif.
else. " do only refresh alv contents
call method box_alv->refresh_table_display.
endif.
endmethod.
* -----------------------------------------------------------------
method on_close.
call method sender->free.
free: box_container, box_alv.
endmethod.
endclass.
Message was edited by:
Raja T
Message was edited by:
Raja T
‎2006 Dec 06 3:54 AM
HI,
TYPE-POOLS : slis.
*----
Data
DATA : BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE t001.
DATA : flag tyPE c,
END OF itab.
DATA : alvfc TYPE slis_t_fieldcat_alv.
DATA : alvly TYPE slis_layout_alv.
*----
Select Data
SELECT * FROM t001 INTO TABLE itab.
*------- Field Catalogue
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'ITAB'
i_inclname = sy-repid
CHANGING
ct_fieldcat = alvfc
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
*----
Display
alvly-box_fieldname = 'FLAG'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = alvfc
i_callback_program = sy-repid "<-------Important
i_callback_user_command = 'ITAB_USER_COMMAND' "<------ Important
is_layout = alvly
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
*----
CALL BACK FORM
*----
FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE
slis_selfield.
*----
IMPORTANT.
data : m(100) type c.
m = whatrow-tabindex.
condense m.
concatenate 'Row Number is ' m into m separated by space.
*concatenate m ' : Field Clicked is ' whatrow-fieldname into m separated
by space.
message m type 'I'.
*----
Display
alvly-box_fieldname = 'FLAG'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = alvfc
i_callback_program = sy-repid "<-------Important
i_callback_user_command = 'ITAB_USER_COMMAND' "<------ Important
is_layout = alvly
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. "ITAB_user_command
http://www.sapgenie.com/abap/index.htm
RGDS,
SHAN
‎2006 Dec 06 3:54 AM
Have a look at below link which gives you a source code to generate secondary list in ALV.
<a href="http://www.sap-img.com/abap/an-interactive-alv-report.htm">Interactive ALV</a>
I hope it helps.
Best Regards,
Vibha
*Please mark all the helpful answers