You are on page 1of 9

report ztest1234_alv_top message-id zz .

data: g_grid type ref to cl_gui_alv_grid.


data: l_valid type c,
v_flag,
v_data_change,
v_row type lvc_s_row,
v_column type lvc_s_col,
v_row_num type lvc_s_roid.
"the below definitions must.....
data:
* reference to document
dg_dyndoc_id type ref to cl_dd_document,
* reference to split container
dg_splitter type ref to cl_gui_splitter_container,
* reference to grid container
dg_parent_grid type ref to cl_gui_container,
* reference to html container
dg_html_cntrl type ref to cl_gui_html_viewer,
* reference to html container
dg_parent_html type ref to cl_gui_container.
"up to here
*---------------------------------------------------------------------*
* class lcl_event_handler definition
*---------------------------------------------------------------------*
class lcl_event_handler definition .
public section .
methods:
**hot spot handler
handle_hotspot_click for event hotspot_click of cl_gui_alv_grid
importing e_row_id e_column_id es_row_no,
**double click handler
handle_double_click for event double_click of cl_gui_alv_grid
importing e_row e_column es_row_no,

top_of_page for event top_of_page "event handler


of cl_gui_alv_grid
importing e_dyndoc_id.

endclass. "lcl_event_handler definition


*---------------------------------------------------------------------*
* class lcl_event_handler implementation
*---------------------------------------------------------------------*
class lcl_event_handler implementation.
*handle hotspot click
method handle_hotspot_click .
clear: v_row,v_column,v_row_num.
v_row = e_row_id.
v_column = e_column_id.
v_row_num = es_row_no.
message i000 with v_row 'clicked'.
endmethod. "lcl_event_handler

*handle double click


method handle_double_click.

endmethod. "handle_double_click

method top_of_page. "implementation


* top-of-page event
perform event_top_of_page using dg_dyndoc_id.
endmethod. "top_of_page
endclass. "lcl_event_handler implementation

*&---------------------------------------------------------------------*
*& global definitions
*&---------------------------------------------------------------------*
data: g_custom_container type ref to cl_gui_custom_container,"container1
g_handler type ref to lcl_event_handler. "handler

data: ok_code like sy-ucomm,


save_ok like sy-ucomm,
g_container1 type scrfname value 'test',
gs_layout type lvc_s_layo.

*- fieldcatalog for first and second report


data: it_fieldcat type lvc_t_fcat,
x_fieldcat type lvc_s_fcat,
ls_vari type disvariant.
parameters: p_matnr like mara-matnr.
*---------------------------------------------------------------------
* start-of_selection
*---------------------------------------------------------------------
start-of-selection.
data:begin of itab occurs 0,
vbeln like likp-vbeln,
posnr like lips-posnr,
cellcolor type lvc_t_scol, "required for color
drop(10),
end of itab.
select vbeln
posnr
from lips
up to 20 rows
into corresponding fields of table itab.
end-of-selection.
if not itab[] is initial.
call screen 100.
else.
message i002 with 'no data for the selection'(004).
endif.
*&---------------------------------------------------------------------*
*& form create_and_init_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form create_and_init_alv .
data: lt_exclude type ui_functions.
"attention.....from here
"split your container here...into two parts

"create the container


create object g_custom_container
exporting container_name = g_container1.
"this is for top of page
* create top-document
create object dg_dyndoc_id
exporting style = 'alv_grid'.
* create splitter for custom_container
create object dg_splitter
exporting parent = g_custom_container
rows = 2
columns = 1.
* split the custom_container to two containers and move the reference
* to receiving containers g_parent_html and g_parent_grid
"i am allocating the space for grid and top of page
call method dg_splitter->get_container
exporting
row = 1
column = 1
receiving
container = dg_parent_html.
call method dg_splitter->get_container
exporting
row = 2
column = 1
receiving
container = dg_parent_grid.

"you can set the height of it


* set height for g_parent_html
call method dg_splitter->set_row_height
exporting
id = 1
height = 5.
"from here as usual..you need to specify parent as splitter part
"which we alloted for grid
create object g_grid
exporting i_parent = dg_parent_grid.
* set a titlebar for the grid control
clear gs_layout.
gs_layout-grid_title = text-003.
gs_layout-zebra = space.
gs_layout-cwidth_opt = 'x'.
gs_layout-no_rowmark = 'x'.
gs_layout-ctab_fname = 'cellcolor'.
call method g_grid->register_edit_event
exporting
i_event_id = cl_gui_alv_grid=>mc_evt_enter.

create object g_handler.


set handler g_handler->handle_double_click for g_grid.
set handler g_handler->handle_hotspot_click for g_grid.
set handler g_handler->top_of_page for g_grid.
data: ls_cellcolor type lvc_s_scol. "required for color
data: l_index type sy-tabix.
"here i am changing the color of line 1,5,10...
"so you can change the color of font conditionally
loop at itab.
l_index = sy-tabix.
if l_index = 1 or l_index = 5 or l_index = 10.
ls_cellcolor-fname = 'vbeln'.
ls_cellcolor-color-col = '6'.
ls_cellcolor-color-int = '0'.
ls_cellcolor-color-inv = '1'.
append ls_cellcolor to itab-cellcolor.
modify itab index l_index transporting cellcolor.
ls_cellcolor-fname = 'posnr'.
ls_cellcolor-color-col = '6'.
ls_cellcolor-color-int = '0'.
ls_cellcolor-color-inv = '1'.
append ls_cellcolor to itab-cellcolor.
modify itab index l_index transporting cellcolor.
endif.
endloop.

* setting focus for created grid control


call method cl_gui_control=>set_focus
exporting
control = g_grid.
* build fieldcat and set editable for date and reason code
* edit enabled. assign a handle for the dropdown listbox.
perform build_fieldcat.
perform set_drdn_table.
* optionally restrict generic functions to 'change only'.
* (the user shall not be able to add new lines).
perform exclude_tb_functions changing lt_exclude.
**vaiant to save the layout
ls_vari-report = sy-repid.
ls_vari-handle = space.
ls_vari-log_group = space.
ls_vari-username = space.
ls_vari-variant = space.
ls_vari-text = space.
ls_vari-dependvars = space.

**calling the method for alv output


call method g_grid->set_table_for_first_display
exporting
it_toolbar_excluding = lt_exclude
is_variant = ls_vari
is_layout = gs_layout
i_save = 'a'
changing
it_fieldcatalog = it_fieldcat
it_outtab = itab[].
"do these..{
* initializing document
call method dg_dyndoc_id->initialize_document.

* processing events
call method g_grid->list_processing_events
exporting
i_event_name = 'top_of_page'
i_dyndoc_id = dg_dyndoc_id.
"end }
* set editable cells to ready for input initially
call method g_grid->set_ready_for_input
exporting
i_ready_for_input = 1.

endform. "create_and_init_alv
*&---------------------------------------------------------------------*
*& form exclude_tb_functions
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->pt_exclude text
*----------------------------------------------------------------------*
form exclude_tb_functions changing pt_exclude type ui_functions.
* only allow to change data not to create new entries (exclude
* generic functions).
data ls_exclude type ui_func.

ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
append ls_exclude to pt_exclude.
endform. " exclude_tb_functions
*&---------------------------------------------------------------------*
*& form build_fieldcat
*&---------------------------------------------------------------------*
* fieldcatalog
*----------------------------------------------------------------------*
form build_fieldcat .
data: l_pos type i.
l_pos = l_pos + 1.

x_fieldcat-scrtext_m = 'delivery'(024).
x_fieldcat-fieldname = 'vbeln'.
x_fieldcat-tabname = 'it_final'.
x_fieldcat-col_pos = l_pos.
x_fieldcat-no_zero = 'x'.
x_fieldcat-outputlen = '10'.
x_fieldcat-hotspot = 'x'.

append x_fieldcat to it_fieldcat.


clear x_fieldcat.
l_pos = l_pos + 1.

x_fieldcat-scrtext_m = 'item'(025).
x_fieldcat-fieldname = 'posnr'.
x_fieldcat-tabname = 'it_final'.
x_fieldcat-col_pos = l_pos.
x_fieldcat-outputlen = '5'.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.
l_pos = l_pos + 1.

x_fieldcat-scrtext_m = 'drop'(025).
x_fieldcat-fieldname = 'drop'.
x_fieldcat-tabname = 'it_final'.
x_fieldcat-col_pos = l_pos.
x_fieldcat-outputlen = '5'.
x_fieldcat-edit = 'x'.
x_fieldcat-drdn_hndl = '1'.
x_fieldcat-drdn_alias = 'x'.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.

endform. " build_fieldcat


*&---------------------------------------------------------------------*
*& module status_0100 output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module status_0100 output.
set pf-status 'main100'.
set titlebar 'main100'.
if g_custom_container is initial.
**initializing the grid and calling the fm to display the o/p
perform create_and_init_alv.
endif.
endmodule. " status_0100 output
*&---------------------------------------------------------------------*
*& module user_command_0100 input
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module user_command_0100 input.
case sy-ucomm.
when 'back'.
leave to screen 0.
endcase.
endmodule. " user_command_0100 input

*&---------------------------------------------------------------------*
*& form set_drdn_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form set_drdn_table.

data:lt_dral type lvc_t_dral,


ls_dral type lvc_s_dral.
loop at itab .
* first listbox (handle '1').
if sy-index = 1.
ls_dral-handle = '1'.
ls_dral-value = ' '.
ls_dral-int_value = ' '.
else.
ls_dral-handle = '1'.
ls_dral-value = itab-posnr.
ls_dral-int_value = itab-posnr.
endif.
append ls_dral to lt_dral.
endloop.
**setting the drop down table for reason code
call method g_grid->set_drop_down_table
exporting
it_drop_down_alias = lt_dral.
endform. " set_drdn_table
*&---------------------------------------------------------------------*
*& form event_top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->dg_dyndoc_id text
*----------------------------------------------------------------------*
form event_top_of_page using dg_dyndoc_id type ref to cl_dd_document.
"this is more clear.....check it
"first add text, then pass it to comentry write fm
data : dl_text(255) type c. "text
* populating header to top-of-page
call method dg_dyndoc_id->add_text
exporting
text = 'test report'
sap_style = cl_dd_area=>heading.
* add new-line
call method dg_dyndoc_id->new_line.

clear : dl_text.
* move program id
concatenate 'program name :' sy-repid
into dl_text separated by space.
* add program name to document
perform add_text using dl_text.
* add new-line
call method dg_dyndoc_id->new_line.

clear : dl_text.

concatenate 'matnr :' p_matnr


into dl_text separated by space.
* add parameter to document
perform add_text using dl_text.
* add new-line
call method dg_dyndoc_id->new_line.

clear : dl_text.
* move user id
concatenate 'user id :' sy-uname into dl_text separated by space
.
* add user id to document
perform add_text using dl_text.
* add new-line
call method dg_dyndoc_id->new_line.
clear : dl_text.
* move client
concatenate 'client :' sy-mandt into dl_text separated by space.
* add client to document
perform add_text using dl_text.
* add new-line
call method dg_dyndoc_id->new_line.

clear : dl_text.
* move date
write sy-datum to dl_text.
concatenate 'date :' dl_text into dl_text separated by space.
* add date to document
perform add_text using dl_text.
* add new-line
call method dg_dyndoc_id->new_line.

clear : dl_text.
* move time
write sy-uzeit to dl_text.
concatenate 'time :' dl_text into dl_text separated by space.
* add time to document
perform add_text using dl_text.
* add new-line
call method dg_dyndoc_id->new_line.
* populating data to html control
perform html.

endform. " event_top_of_page


*&---------------------------------------------------------------------*
*& form add_text
*&---------------------------------------------------------------------*
* to add text
*----------------------------------------------------------------------*
form add_text using p_text type sdydo_text_element.
* adding text
call method dg_dyndoc_id->add_text
exporting
text = p_text
sap_emphasis = cl_dd_area=>heading.
endform. " add_text
*&---------------------------------------------------------------------*
*& form html
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form html.
data : dl_length type i, " length
dl_background_id type sdydo_key value space. " background_id
* creating html control
if dg_html_cntrl is initial.
create object dg_html_cntrl
exporting
parent = dg_parent_html.
endif.
* reuse_alv_grid_commentary_set
call function 'reuse_alv_grid_commentary_set'
exporting
document = dg_dyndoc_id
bottom = space
importing
length = dl_length.
* get top->html_table ready
call method dg_dyndoc_id->merge_document.
* set wallpaper
call method dg_dyndoc_id->set_document_background
exporting
picture_id = dl_background_id.
* connect top document to html-control
dg_dyndoc_id->html_control = dg_html_cntrl.
* display top document
call method dg_dyndoc_id->display_document
exporting
reuse_control = 'x'
parent = dg_parent_html
exceptions
html_display_error = 1.
if sy-subrc ne 0.
message i999 with 'error in displaying top-of-page'(036).
endif.

endform. " html

You might also like