Pages

Thursday, September 9, 2010

Display Top of page in ALV Function Module

Display top of page in ALV Function module method using the same code as in ALV OOPs method:

Basically we need to use the HTML call back TOP OF PAGE for this. This form uses the CL_DD_DOCUMENT object to publish the top of page. So we just need to create this form and use the same logic we use for OOPs approach.

Usual Code for OOPS approach:

*******************CODE*********************************
*******************CODE*********************************
FORM f_event_top_of_page USING p_dyndoc_id TYPE REF TO cl_dd_document.

* Design the Layout
PERFORM f_design_top_new USING p_dyndoc_id.

* populating data to html control
PERFORM f_html_header USING p_dyndoc_id.


ENDFORM. " EVENT_TOP_OF_PAGE


FORM f_design_top_new USING p_dyndoc_id TYPE REF TO cl_dd_document.

* populating header to top-of-page
PERFORM f_date_to_external USING sy-datum
CHANGING l_ext_date.

* add gap
CALL METHOD p_dyndoc_id->add_gap
EXPORTING
width = 150.

MOVE ' '(001) TO l_text.
"Add Text to Header
CALL METHOD p_dyndoc_id->add_text
EXPORTING
text = l_text
sap_style = cl_dd_area=>heading.

CALL METHOD p_dyndoc_id->underline.

ENDFORM.

FORM f_html_header USING p_dyndoc_id TYPE REF TO cl_dd_document.

* creating html control
IF obj_html_cntrl IS INITIAL.
CREATE OBJECT obj_html_cntrl
EXPORTING
parent = obj_parent_html.
ENDIF.
* reuse_alv_grid_commentary_set
CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
EXPORTING
document = p_dyndoc_id
bottom = space.
* get top->htmobj_table ready
CALL METHOD p_dyndoc_id->merge_document.
* set wallpaper
CALL METHOD p_dyndoc_id->set_document_background
EXPORTING
picture_id = space.
* connect top document to html-control
p_dyndoc_id->html_control = obj_html_cntrl.
* display top document
CALL METHOD p_dyndoc_id->display_document
EXPORTING
reuse_control = c_x
parent = obj_parent_html
EXCEPTIONS
html_display_error = 1.
IF sy-subrc NE 0.
MESSAGE i000 WITH 'Error in displaying top-of-page'(035).
ENDIF.

ENDFORM. " F_HTML_HEADER

*******************CODE*********************************
*******************CODE*********************************


Simple ALV FM approach:

*******************CODE*********************************
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_prog_name
i_callback_user_command = lc_user_cmd
it_fieldcat = gt_fieldcat
i_default = lc_default
I_CALLBACK_HTML_TOP_OF_PAGE = 'TOP_OF_PAGE'
TABLES
t_outtab = gt_alvrpt
EXCEPTIONS
program_error = 1
OTHERS = 2.

*** Here I have used my own Utility class to create CL_DD_DOCUMENT object
*** The main intension is to develop this Object. It can be done in any way

FORM TOP_OF_PAGE USING p_dyndoc_id TYPE REF TO CL_DD_DOCUMENT.

DATA: obj_sel_opt TYPE REF TO zcl_alv_header_utility,
l_text1 TYPE string.

CREATE OBJECT obj_sel_opt
EXPORTING
p_dyndoc_obj = p_dyndoc_id.

CALL METHOD obj_sel_opt->read_selection_screen
EXPORTING
repid = sy-repid
.

CALL METHOD obj_sel_opt->set_grid_top
EXPORTING
title1 = 'Scheduling Agreement or Contract vs Receipt Tracking'
* title2 =
* title3 =
* title4 =
.
ENDFORM.

*******************CODE*********************************
*******************CODE*********************************

I found out that displaying TOPOFPAGE with ALV FM is much easier than OOPs method.
Like OOPS we need not create any SPLITTER container in FM nor do we need to design the CL_DD_DOCUMENT object and fit it to the top split container.

But as it is said, its always better to hone the latest technique of coding so that our jobs are never at stake; and here OOPs is what SAP will continue polishing as development goes forward.