Application Development 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: 

Printing Header for the ALV Grid created with Objects

SimoneMilesi
Active Contributor
0 Kudos

Hi all,

I need to send to the printer my ALV grid created with methods and object.

I discovered that the header i can see in my alv list is not printed!

There is a solution to this problem?

Output on screen

Header with my paramters

-


Column1 Column2 Column3

Column1 Column2 Column3

Column1 Column2 Column3

Output on printer/spool

Column1 Column2 Column3

Column1 Column2 Column3

Column1 Column2 Column3

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

u have to handle print_top_of_page

refer this

***********************************************************************

Class definition :

***********************************************************************

-


CLASS v_lcl_event_receiver DEFINITION

-


CLASS v_lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_print_top_of_page FOR EVENT print_top_of_page OF

cl_gui_alv_grid,

handle_top_of_page FOR EVENT top_of_page OF

cl_gui_alv_grid.

ENDCLASS.

-


CLASS V_LCL_EVENT_RECEIVER IMPLEMENTATION

-


CLASS v_lcl_event_receiver IMPLEMENTATION.

METHOD handle_print_top_of_page.

IF sy-pagno = 1.

PERFORM top_of_page.

ENDIF.

ENDMETHOD.

METHOD handle_top_of_page.

PERFORM top_of_page.

ENDMETHOD.

ENDCLASS.

DATA: v_event_receiver TYPE REF TO v_lcl_event_receiver.

FORM top_of_page.

WRITE: text-020,

/

ENDFORM. " top_of_page

In PBo of the screen

DATA: v_split TYPE REF TO cl_gui_easy_splitter_container,

v_contnr_top TYPE REF TO cl_gui_container,

v_contnr_bot TYPE REF TO cl_gui_container,

v_grid_02 TYPE REF TO cl_gui_alv_grid,

v_html TYPE REF TO cl_dd_document,

v_text20(255) TYPE c,

v_text16(255) TYPE c,

FORM f9000_objects_create.

IF cl_gui_alv_grid=>offline( ) IS INITIAL.

Create a container

CREATE OBJECT o_dockingcontainer

EXPORTING

ratio = '95'

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

others = 6.

IF sy-subrc NE 0.

MESSAGE i000 WITH text-e01."Error in creating Docking container

LEAVE LIST-PROCESSING.

ENDIF.

CREATE OBJECT v_split

EXPORTING

parent = o_dockingcontainer

ORIENTATION = 0

sash_position = 25

with_border = 0

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

others = 3.

IF sy-subrc NE 0.

MESSAGE i000 WITH text-e01."Error in creating Docking container

LEAVE LIST-PROCESSING.

ENDIF.

Get the containers of the splitter control

v_contnr_top = v_split->top_left_container.

v_contnr_bot = v_split->bottom_right_container.

CREATE OBJECT o_alvgrid

EXPORTING

i_parent = o_dockingcontainer.

Create an instance of alv control

CREATE OBJECT o_alvgrid

EXPORTING i_parent = v_contnr_bot.

Object for display of selection parameters in HTML top container

CREATE OBJECT v_html

EXPORTING

style = 'ALV_GRID'.

Must be after the SET HANDLER for TOP_OF_PAGE and foreground only

CALL METHOD o_alvgrid->list_processing_events

EXPORTING i_event_name = 'TOP_OF_PAGE'

i_dyndoc_id = v_html.

v_text20 = text-020(summary Record counts)Any text.

CALL METHOD v_html->add_gap

EXPORTING

width = 120.

CALL METHOD v_html->add_text

EXPORTING

text = v_text20.

CALL METHOD v_html->new_line.

Display Text-016

v_text16 = text-016.

CALL METHOD v_html->add_gap

EXPORTING

width = 1.

CALL METHOD v_html->add_text

EXPORTING

text = v_text16.

v_text16 = v_sap_recon.

CALL METHOD v_html->add_gap

EXPORTING

width = 1.

CALL METHOD v_html->add_text

EXPORTING

text = v_text16.

CALL METHOD v_html->new_line.

Display the data

CALL METHOD v_html->display_document

EXPORTING

parent = v_contnr_top.

Handle the event

CALL METHOD o_alvgrid->list_processing_events

EXPORTING i_event_name = 'PRINT_TOP_OF_PAGE'.

IN PBO while populating in the output table

FORM f9004_display_data TABLES p_report_tab

p_fieldcat.

CALL METHOD o_alvgrid->set_table_for_first_display

EXPORTING

is_variant = w_variant

i_save = c_a

is_layout = w_layout

CHANGING

it_outtab = p_report_tab[]

it_fieldcatalog = p_fieldcat[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc 0.

MESSAGE i000 WITH text-e06."Error in ALV report display

LEAVE LIST-PROCESSING.

ENDIF.

Create object

IF v_event_receiver IS INITIAL.

CREATE OBJECT v_event_receiver.

ENDIF.

SET HANDLER v_event_receiver->handle_print_top_of_page FOR o_alvgrid.

SET HANDLER v_event_receiver->handle_top_of_page FOR o_alvgrid.

Regards

Vasu

6 REPLIES 6

Former Member
0 Kudos

Hi

u have to handle print_top_of_page

refer this

***********************************************************************

Class definition :

***********************************************************************

-


CLASS v_lcl_event_receiver DEFINITION

-


CLASS v_lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_print_top_of_page FOR EVENT print_top_of_page OF

cl_gui_alv_grid,

handle_top_of_page FOR EVENT top_of_page OF

cl_gui_alv_grid.

ENDCLASS.

-


CLASS V_LCL_EVENT_RECEIVER IMPLEMENTATION

-


CLASS v_lcl_event_receiver IMPLEMENTATION.

METHOD handle_print_top_of_page.

IF sy-pagno = 1.

PERFORM top_of_page.

ENDIF.

ENDMETHOD.

METHOD handle_top_of_page.

PERFORM top_of_page.

ENDMETHOD.

ENDCLASS.

DATA: v_event_receiver TYPE REF TO v_lcl_event_receiver.

FORM top_of_page.

WRITE: text-020,

/

ENDFORM. " top_of_page

In PBo of the screen

DATA: v_split TYPE REF TO cl_gui_easy_splitter_container,

v_contnr_top TYPE REF TO cl_gui_container,

v_contnr_bot TYPE REF TO cl_gui_container,

v_grid_02 TYPE REF TO cl_gui_alv_grid,

v_html TYPE REF TO cl_dd_document,

v_text20(255) TYPE c,

v_text16(255) TYPE c,

FORM f9000_objects_create.

IF cl_gui_alv_grid=>offline( ) IS INITIAL.

Create a container

CREATE OBJECT o_dockingcontainer

EXPORTING

ratio = '95'

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

others = 6.

IF sy-subrc NE 0.

MESSAGE i000 WITH text-e01."Error in creating Docking container

LEAVE LIST-PROCESSING.

ENDIF.

CREATE OBJECT v_split

EXPORTING

parent = o_dockingcontainer

ORIENTATION = 0

sash_position = 25

with_border = 0

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

others = 3.

IF sy-subrc NE 0.

MESSAGE i000 WITH text-e01."Error in creating Docking container

LEAVE LIST-PROCESSING.

ENDIF.

Get the containers of the splitter control

v_contnr_top = v_split->top_left_container.

v_contnr_bot = v_split->bottom_right_container.

CREATE OBJECT o_alvgrid

EXPORTING

i_parent = o_dockingcontainer.

Create an instance of alv control

CREATE OBJECT o_alvgrid

EXPORTING i_parent = v_contnr_bot.

Object for display of selection parameters in HTML top container

CREATE OBJECT v_html

EXPORTING

style = 'ALV_GRID'.

Must be after the SET HANDLER for TOP_OF_PAGE and foreground only

CALL METHOD o_alvgrid->list_processing_events

EXPORTING i_event_name = 'TOP_OF_PAGE'

i_dyndoc_id = v_html.

v_text20 = text-020(summary Record counts)Any text.

CALL METHOD v_html->add_gap

EXPORTING

width = 120.

CALL METHOD v_html->add_text

EXPORTING

text = v_text20.

CALL METHOD v_html->new_line.

Display Text-016

v_text16 = text-016.

CALL METHOD v_html->add_gap

EXPORTING

width = 1.

CALL METHOD v_html->add_text

EXPORTING

text = v_text16.

v_text16 = v_sap_recon.

CALL METHOD v_html->add_gap

EXPORTING

width = 1.

CALL METHOD v_html->add_text

EXPORTING

text = v_text16.

CALL METHOD v_html->new_line.

Display the data

CALL METHOD v_html->display_document

EXPORTING

parent = v_contnr_top.

Handle the event

CALL METHOD o_alvgrid->list_processing_events

EXPORTING i_event_name = 'PRINT_TOP_OF_PAGE'.

IN PBO while populating in the output table

FORM f9004_display_data TABLES p_report_tab

p_fieldcat.

CALL METHOD o_alvgrid->set_table_for_first_display

EXPORTING

is_variant = w_variant

i_save = c_a

is_layout = w_layout

CHANGING

it_outtab = p_report_tab[]

it_fieldcatalog = p_fieldcat[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc 0.

MESSAGE i000 WITH text-e06."Error in ALV report display

LEAVE LIST-PROCESSING.

ENDIF.

Create object

IF v_event_receiver IS INITIAL.

CREATE OBJECT v_event_receiver.

ENDIF.

SET HANDLER v_event_receiver->handle_print_top_of_page FOR o_alvgrid.

SET HANDLER v_event_receiver->handle_top_of_page FOR o_alvgrid.

Regards

Vasu

SimoneMilesi
Active Contributor
0 Kudos

I'm a little confused.

I got a code for PBO a bit different from your and i post it down.

This because you refer to cl_gui_easy_splitter_container while i use cl_gui_splitter_container .

There is a way to use cl_gui_splitter_container instead?

Thank you for your quick reply!

IF gr_alvgrid IS INITIAL.

IF sy-batch = 'X'.

*---- Creating ALV grid within a docking container

CREATE OBJECT gr_alvgrid

EXPORTING

i_parent = gr_docking_container.

ELSE.

*---- Creating Splitted Containers

CREATE OBJECT gr_splitter_container

EXPORTING

parent = cl_gui_container=>screen0

rows = 1

columns = 1.

CALL METHOD gr_splitter_container->set_border

EXPORTING

border = cl_gui_cfw=>false.

CALL METHOD gr_splitter_container->set_row_mode

EXPORTING

mode = gr_splitter_container->mode_relative.

gr_container =

gr_splitter_container->get_container( row = 1 column = 1 ).

*---- Creating ALV Grid instance

CREATE OBJECT gr_alvgrid

EXPORTING

i_parent = gr_container.

*---- Preparing document header

In this perform i create my header

PERFORM prepare_header.

ENDIF.

*-- Creating an instance for the event handler

CREATE OBJECT gr_event_handler.

*-- Registering handler methods to handle ALV Grid events

SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid.

SET HANDLER gr_event_handler->handle_hotspot_click FOR gr_alvgrid.

SET HANDLER gr_event_handler->handle_data_changed FOR gr_alvgrid.

SET HANDLER gr_event_handler->handle_data_changed_finished

FOR gr_alvgrid.

SET HANDLER gr_event_handler->handle_toolbar FOR gr_alvgrid.

SET HANDLER gr_event_handler->handle_user_command FOR gr_alvgrid.

*-- Preparing layout structure

PERFORM prepare_layout.

*-- Preparing print structure

PERFORM prepare_print.

*-- Preparing field catalog

PERFORM prepare_field_catalog.

*-- Preparing sort criteria table

PERFORM prepare_sort_criteria.

*-- Prepating filter criteria table

PERFORM prepare_filter_criteria.

*-- Preparing function codes to exclude from the toolbar

PERFORM prepare_toolbar_exclude.

*-- Preparing the output for the ALV grid list

*-- NOTE: set I_BUFFER_ACTIVE = 'X' to speed to the list display

*-- if the ALV grid uses statically always the same field catalog

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

  • i_buffer_active = 'X'

  • i_structure_name = 'GS_OUTTAB'

is_variant = gs_variant

i_save = 'A'

i_default = 'X'

is_layout = gs_layout

is_print = gs_print

  • IT_SPECIAL_GROUPS =

it_toolbar_excluding = gt_exclude[]

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

CHANGING

it_outtab = i_simula[]

it_fieldcatalog = gt_fieldcat[]

it_sort = gt_sort[]

it_filter = gt_filter[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

*-- Allows to edit the toolbar

  • NOTA: Asteriscare/disasteriscare se si desidera o meno aggiungere

  • nuovi tasta alla barra degli strumenti ALV.

CALL METHOD gr_alvgrid->set_toolbar_interactive.

ELSE.

CALL METHOD gr_alvgrid->refresh_table_display.

ENDIF.

And here the FORM Prepare header

FORM prepare_header .

data: field(255) TYPE c.

DATA: wa TYPE obj_range.

CREATE OBJECT gr_docking_container

EXPORTING

repid = g_repid

dynnr = '0100'

ratio = 25

side = gr_docking_container->dock_at_top.

CREATE OBJECT gr_document.

CALL METHOD gr_document->add_picture

EXPORTING

picture_id = 'ENJOYSAP_LOGO'.

CALL METHOD gr_document->add_gap

EXPORTING

width = 5.

CALL METHOD gr_document->add_text

EXPORTING

text = text-035

sap_fontsize = cl_dd_document=>large

sap_emphasis = cl_dd_document=>strong.

CALL METHOD gr_document->new_line.

MOVE 'User:' TO field.

CALL METHOD gr_document->new_line.

CALL METHOD gr_document->add_text

EXPORTING

text = field

sap_emphasis = cl_dd_document=>strong.

CLEAR field.

WRITE sy-uname TO field.

CALL METHOD gr_document->add_text

EXPORTING

text = field.

CLEAR field.

CALL METHOD gr_document->display_document

EXPORTING

parent = gr_docking_container.

ENDFORM. " prepare_header

Edited by: Simone Milesi on Apr 24, 2008 4:28 PM

Former Member
0 Kudos

Hi,

ALV reports:

ALV means ABAP List Viewer. Most convenient way to use it is through reuse library (cf. transaction se83) available from release 4.6 of SAP R/3.

ALV is available in two modes: list and grid. List mode is good old list processing with standard functionnalities, and grid mode is using a new OCX object displaying grids.

Classical reports needs more coding to set the horizontal and vertical lines.we need to adjust the lines manually.Even interactive also takes lot of code.

ALV reports reduces the code when compared to classical reports.we use function modules to generate the output.

that r REUSE_ALV_LIST_DISPLAY,REUSE_ALV_GRID_DISPLAY,REUSE_ALV_HIERSEQ_LIST_DISPLAY etc..

the following threads will give some examples of the functions which you are expecting

https://www.sdn.sap

Reprots

http://www.sapgenie.com/abap/reports.htm

http://www.allsaplinks.com/material.html

http://www.sapdevelopment.co.uk/reporting/reportinghome.htm

ALV

1. Please give me general info on ALV.

http://www.sapfans.com/forums/viewtopic.php?t=58286

http://www.sapfans.com/forums/viewtopic.php?t=76490

http://www.sapfans.com/forums/viewtopic.php?t=20591

http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.

2. How do I program double click in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=11601

http://www.sapfans.com/forums/viewtopic.php?t=23010

3. How do I add subtotals (I have problem to add them)...

http://www.sapfans.com/forums/viewtopic.php?t=20386

http://www.sapfans.com/forums/viewtopic.php?t=85191

http://www.sapfans.com/forums/viewtopic.php?t=88401

http://www.sapfans.com/forums/viewtopic.php?t=17335

4. How to add list heading like top-of-page in ABAP lists?

http://www.sapfans.com/forums/viewtopic.php?t=58775

http://www.sapfans.com/forums/viewtopic.php?t=60550

http://www.sapfans.com/forums/viewtopic.php?t=16629

5. How to print page number / total number of pages X/XX in ALV? http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)

6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.

http://www.sapfans.com/forums/viewtopic.php?t=64320

http://www.sapfans.com/forums/viewtopic.php?t=44477

7. How can I set the cell color in ALV? http://www.sapfans.com/forums/viewtopic.php?t=52107

8. How do I print a logo/graphics in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=81149

http://www.sapfans.com/forums/viewtopic.php?t=35498

http://www.sapfans.com/forums/viewtopic.php?t=5013

9. How do I create and use input-enabled fields in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=84933

http://www.sapfans.com/forums/viewtopic.php?t=69878

10. How can I use ALV for reports that are going to be run in background?

http://www.sapfans.com/forums/viewtopic.php?t=83243

http://www.sapfans.com/forums/viewtopic.php?t=19224

11. How can I display an icon in ALV? (Common requirement is traffic light icon).

http://www.sapfans.com/forums/viewtopic.php?t=79424

http://www.sapfans.com/forums/viewtopic.php?t=24512

12. How can I display a checkbox in ALV? http://www.sapfans.com/forums/viewtopic.php?t=88376

http://www.sapfans.com/forums/viewtopic.php?t=40968

http://www.sapfans.com/forums/viewtopic.php?t=6919

Check this for basic concepts of OOPS

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20...

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20...

Tabstrip

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20...

Editable ALV

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20...

Tree

http://www.sapdevelopment.co.uk/reporting/alv/alvtree/alvtree_usrint.htm

General Tutorial for OOPS

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/an%20ea...

http://www.sapdevelopment.co.uk/reporting/alvhome.htm

http://www.sap-img.com/abap/what-is-alv-programming.htm

http://www.sap-img.com/abap-function.htm

http://www.geocities.com/mpioud/Abap_programs.html

http://www.sapdevelopment.co.uk/reporting/alv/alvtree%5Calvtree_basic.htm

http://esnips.com/doc/ad20dca9-6182-4903-8d8f-96a66dc8590c/ALV.pdf

http://www.sap-img.com/abap-function.htm

SimoneMilesi
Active Contributor
0 Kudos

Thanks all!

After some tries with the code, i understand what Vasu means (sorry for the late) and now i got my nice header while printing the output.

Thanks all.

0 Kudos

Hi Simone,

I have also similar kind of requirement, i.e., using OO ALV Grid I need to display Header both online and in print. I have followed what Vasu suggested and the result is, though event TOP_OF_PAGE is triggered, no Header is getting displayed. Kindly guide me how you have fixed this issue.

Thanks in advance,

Avijit