09-20-2007 4:43 AM
Hi,
HI Guru, This is very urgent, But no want give complete answer ,
I want to insert Header and Logo in OOPS Alv , Please give me code
Or Consern site name.
Thanks in Advance.
Points will reward.
Thanks&Regards
Durgesh
09-20-2007 2:02 PM
09-20-2007 2:06 PM
Hi,
Please take a look at the following code:
*&---------------------------------------------------------------------*
*& Report ZTEST_PRG4
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ztest_prg4 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.
*---------------------------------------------------------------------
* 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.
* 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.
09-21-2007 4:16 AM