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: 

top-of-page in oo ALV

Former Member
0 Kudos

I am trying to display top of page using ALV class but I could not get it, its not displaying anything.

any one's help is greatly appreciated.

Thanks

Giri

28 REPLIES 28

Former Member
0 Kudos

In OOPS world u have to use Event handler for class "cl_gui_alv_grid" and event name is "print_top_of_page".

see link

http://help.sap.com/saphelp_bw30b/helpdata/en/ee/c8e06bd52611d2b468006094192fe3/content.htm

sample code

BCALV_GRID_01 in se38

Former Member
0 Kudos

Hi giri,

U can give ur display text inside ur Top-of-page event.

Top-of-page.

write:/ 'hai'.

This displays ur text in the top of the page.

Hope tihs helps u,

Regards,

Nagarajan.

former_member188685
Active Contributor
0 Kudos

hi IN OO you should use COmentry write fm.

it should work.....

IN top of page event use that FM.

regards

vijay

Former Member
0 Kudos

hi,

Only when the first write statement is encountered the TOP OF PAGE is triggered.

If you donot have any write statements the the top of page will never be triggered.

Former Member
0 Kudos

HI,

I fonud this code somewhee in forum, which shows use f top of page.

plz reward point if it helps you.

you also can visit this links

Report ZDEMO_ALVGRID *

*& *

&----


*& *

*& Example of a simple ALV Grid Report *

*& ................................... *

*& *

*& The basic requirement for this demo is to display a number of *

*& fields from the EKKO table. *

&----


REPORT zdemo_alvgrid .

TABLES: ekko.

type-pools: slis. "ALV Declarations

*Data Declaration

*----


TYPES: BEGIN OF t_ekko,

ebeln TYPE ekpo-ebeln,

ebelp TYPE ekpo-ebelp,

statu TYPE ekpo-statu,

aedat TYPE ekpo-aedat,

matnr TYPE ekpo-matnr,

menge TYPE ekpo-menge,

meins TYPE ekpo-meins,

netpr TYPE ekpo-netpr,

peinh TYPE ekpo-peinh,

END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

wa_ekko TYPE t_ekko.

*ALV data declarations

data: fieldcatalog type slis_t_fieldcat_alv with header line,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type slis_layout_alv,

gd_repid like sy-repid,

gt_events type slis_t_event,

gd_prntparams type slis_print_alv.

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

*Start-of-selection.

START-OF-SELECTION.

perform data_retrieval.

perform build_fieldcatalog.

perform build_layout.

perform build_events.

perform build_print_params.

perform display_alv_report.

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


form build_fieldcatalog.

  • There are a number of ways to create a fieldcat.

  • For the purpose of this example i will build the fieldcatalog manualy

  • by populating the internal table fields individually and then

  • appending the rows. This method can be the most time consuming but can

  • also allow you more control of the final product.

  • Beware though, you need to ensure that all fields required are

  • populated. When using some of functionality available via ALV, such as

  • total. You may need to provide more information than if you were

  • simply displaying the result

  • I.e. Field type may be required in-order for

  • the 'TOTAL' function to work.

fieldcatalog-fieldname = 'EBELN'.

fieldcatalog-seltext_m = 'Purchase Order'.

fieldcatalog-col_pos = 0.

fieldcatalog-outputlen = 10.

fieldcatalog-emphasize = 'X'.

fieldcatalog-key = 'X'.

  • fieldcatalog-do_sum = 'X'.

  • fieldcatalog-no_zero = 'X'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'EBELP'.

fieldcatalog-seltext_m = 'PO Item'.

fieldcatalog-col_pos = 1.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'STATU'.

fieldcatalog-seltext_m = 'Status'.

fieldcatalog-col_pos = 2.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'AEDAT'.

fieldcatalog-seltext_m = 'Item change date'.

fieldcatalog-col_pos = 3.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-seltext_m = 'Material Number'.

fieldcatalog-col_pos = 4.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MENGE'.

fieldcatalog-seltext_m = 'PO quantity'.

fieldcatalog-col_pos = 5.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MEINS'.

fieldcatalog-seltext_m = 'Order Unit'.

fieldcatalog-col_pos = 6.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.

fieldcatalog-seltext_m = 'Net Price'.

fieldcatalog-col_pos = 7.

fieldcatalog-outputlen = 15.

fieldcatalog-datatype = 'CURR'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'PEINH'.

fieldcatalog-seltext_m = 'Price Unit'.

fieldcatalog-col_pos = 8.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

endform. " BUILD_FIELDCATALOG

&----


*& Form BUILD_LAYOUT

&----


  • Build layout for ALV grid report

----


form build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

  • gd_layout-totals_only = 'X'.

  • gd_layout-f2code = 'DISP'. "Sets fcode for when double

  • "click(press f2)

  • gd_layout-zebra = 'X'.

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

endform. " BUILD_LAYOUT

&----


*& Form DISPLAY_ALV_REPORT

&----


  • Display report using ALV grid

----


form display_alv_report.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM

i_callback_user_command = 'USER_COMMAND'

  • i_grid_title = outtext

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

  • it_special_groups = gd_tabgroup

it_events = gt_events

is_print = gd_prntparams

i_save = 'X'

  • is_variant = z_template

tables

t_outtab = it_ekko

exceptions

program_error = 1

others = 2.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " DISPLAY_ALV_REPORT

&----


*& Form DATA_RETRIEVAL

&----


  • Retrieve data form EKPO table and populate itab it_ekko

----


form data_retrieval.

select ebeln ebelp statu aedat matnr menge meins netpr peinh

up to 10 rows

from ekpo

into table it_ekko.

endform. " DATA_RETRIEVAL

----


  • Form TOP-OF-PAGE *

----


  • ALV Report Header *

----


Form top-of-page.

*ALV Header declarations

data: t_header type slis_t_listheader,

wa_header type slis_listheader,

t_line like wa_header-info,

ld_lines type i,

ld_linesc(10) type c.

  • Title

wa_header-typ = 'H'.

wa_header-info = 'EKKO Table Report'.

append wa_header to t_header.

clear wa_header.

  • Date

wa_header-typ = 'S'.

wa_header-key = 'Date: '.

CONCATENATE sy-datum+6(2) '.'

sy-datum+4(2) '.'

sy-datum(4) INTO wa_header-info. "todays date

append wa_header to t_header.

clear: wa_header.

  • Total No. of Records Selected

describe table it_ekko lines ld_lines.

ld_linesc = ld_lines.

concatenate 'Total No. of Records Selected: ' ld_linesc

into t_line separated by space.

wa_header-typ = 'A'.

wa_header-info = t_line.

append wa_header to t_header.

clear: wa_header, t_line.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = t_header.

  • i_logo = 'Z_LOGO'.

endform.

----


  • FORM USER_COMMAND *

----


  • --> R_UCOMM *

  • --> RS_SELFIELD *

----


FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

  • Check function code

CASE r_ucomm.

WHEN '&IC1'.

  • Check field clicked on within ALVgrid report

IF rs_selfield-fieldname = 'EBELN'.

  • Read data table, using index of row user clicked on

READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.

  • Set parameter ID for transaction screen field

SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.

  • Sxecute transaction ME23N, and skip initial data entry screen

CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.

ENDIF.

ENDCASE.

ENDFORM.

&----


*& Form BUILD_EVENTS

&----


  • Build events table

----


form build_events.

data: ls_event type slis_alv_event.

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = 0

importing

et_events = gt_events[].

read table gt_events with key name = slis_ev_end_of_page

into ls_event.

if sy-subrc = 0.

move 'END_OF_PAGE' to ls_event-form.

append ls_event to gt_events.

endif.

read table gt_events with key name = slis_ev_end_of_list

into ls_event.

if sy-subrc = 0.

move 'END_OF_LIST' to ls_event-form.

append ls_event to gt_events.

endif.

endform. " BUILD_EVENTS

&----


*& Form BUILD_PRINT_PARAMS

&----


  • Setup print parameters

----


form build_print_params.

gd_prntparams-reserve_lines = '3'. "Lines reserved for footer

gd_prntparams-no_coverpage = 'X'.

endform. " BUILD_PRINT_PARAMS

&----


*& Form END_OF_PAGE

&----


form END_OF_PAGE.

data: listwidth type i,

ld_pagepos(10) type c,

ld_page(10) type c.

write: sy-uline(50).

skip.

write:/40 'Page:', sy-pagno .

endform.

&----


*& Form END_OF_LIST

&----


form END_OF_LIST.

data: listwidth type i,

ld_pagepos(10) type c,

ld_page(10) type c.

skip.

write:/40 'Page:', sy-pagno .

endform.

former_member188685
Active Contributor
0 Kudos

Hi Giri,

Write Statements will not work, Use

REUSE_ALV_COMMENTARY_WRITE in top of page..

former_member188685
Active Contributor
0 Kudos

Hi There is an event <b>TOP_OF_PAGE</b> in cl_gui_alv_grid class . You need define and implement in local class and set the handler for the grid , then it trigger ..

But in that no write statements possible. you need to use reuse_alv_comnetry_write for that...

check it once..

vijay

0 Kudos

Thanks for your response but I tried something what vijay said.. see the code below but still doesn't show up top of page.

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_top_of_page

FOR EVENT top_of_page OF cl_gui_alv_grid

IMPORTING e_dyndoc_id,

ENDCLASS.

CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_top_of_page.

PERFORM alv_topof_page.

ENDMETHOD.

ENDCLASS.

CREATE OBJECT g_event_receiver.

SET HANDLER g_event_receiver->handle_top_of_page FOR grid.

0 Kudos

hi Giri,

What are you doing in that top of page ...

can you tell me..

vijay

0 Kudos

Hi Try to PASS these parameters

handle_top_of_page

FOR EVENT top_of_page OF cl_gui_alv_grid

importing

<b>E_DYNDOC_ID

TABLE_INDEX</b>

0 Kudos

if you can paa the info to E_DYNDOC_ID parameter

then it will be done..

vijay

0 Kudos

Hi I got a solution For you..

If you check the Program <b>BCALV_TEST_GRID_EVENTS</b>

properly there they Implemented all the events..

There they Mentioned the same...

check it for your implementation

check the Program , if you are unable to find the program..

please let me know..

0 Kudos

Just trying to display this

DATA: t_header TYPE slis_t_listheader,

wa_header TYPE slis_listheader.

  • Title

wa_header-typ = 'H'.

wa_header-info = 'EE Lien Report'.

APPEND wa_header TO t_header.

CLEAR wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_header.

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

0 Kudos

hi Use the logic which is mentioned in

<b>BCALV_TEST_GRID_EVENTS</b>

it will work...

0 Kudos

Hi If your Problem solves

please close the thread, and reward points for helful answers...

vijay

0 Kudos

after trying these still does not work.please help me on this

thx

0 Kudos

hi

what exactly you need to show..

I also tried it is not triggering that event.

0 Kudos

All I wanted to dispaly like

partner no:

name:

company:

date:

based on some condition i wanted to show/hide.

Please reply me

0 Kudos

Giri,

As ABDUL said try to see that program there it is mentioned very clearly..if you follow the program.

0 Kudos

Yes I knew that program but its only for printing not for display, meaning you can see top of page on print out.

Thx

former_member188685
Active Contributor
0 Kudos

Hi Giri,

Please Reward if my suggestion really helps you...

regards

vijay

abdul_hakim
Active Contributor
0 Kudos

Hi

Check this program BCALV_GRID_01

REgards,

Abdul

abdul_hakim
Active Contributor
0 Kudos

Hi

If you want to display any title on top of page then u can also use the sample logic below..

DATA LAYO TYPE LVC_S_LAYO.

LAYO-GRID_TITLE = 'HAI'.

REgards,

Abdul

0 Kudos

I want multiple lines to be displayed but I believe it is possible for only one line

Thx

0 Kudos

Hi Giri,

Try to follow Srilatha's logic, you need to Use Splitter Containers to Achieve that..see her code....

line by line..

Regards

vijay

Former Member
0 Kudos

Hi Giri,

Try standard Program : BCALV_TEST_FULLSCREEN

It's really helpful to u.

Regards,

Digesh Panchal

Please reward point if it solve ur problem.

0 Kudos

Hi Giri,

To display top-of-page in ALV grid using class.

I have done in my program like below, it is working

for me check this.

1)First we nee to create one loacl class to implemment

event receiver handler methods.


*----------------------------------------------------------------------*
*             A L V  D E C L A R A T I O N S
*----------------------------------------------------------------------*

DATA : dg_fieldcatalog   TYPE lvc_t_fcat, " Field Catalog
* Reference to custom container
       dg_custom_container  TYPE REF TO cl_gui_custom_container,
* Reference to Grid
       dg_grid1             TYPE REF TO cl_gui_alv_grid,
* Reference to Control container
       dg_mycontainer       TYPE scrfname VALUE 'CONTROL',
* Reference to event receiver
       dg_event_receiver    TYPE REF TO lcl_event_receiver,
* 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.

  *----------------------------------------------------------------------*
*           C L A S S  D E C L A R A T I O N S

****************************************************************
* LOCAL CLASSES: Definition
****************************************************************
*===============================================================

CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
* § 2. Define a method for each print event you need.
    METHODS:
    top_of_page FOR EVENT top_of_page
                         OF cl_gui_alv_grid
                         IMPORTING e_dyndoc_id,
    handle_top_of_page
        FOR EVENT print_top_of_page OF cl_gui_alv_grid,

    handle_end_of_list
        FOR EVENT print_end_of_list OF cl_gui_alv_grid.
  PRIVATE SECTION.
ENDCLASS.
*===============================================================
****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
*===============================================================
* class c_event_receiver (Implementation)
CLASS lcl_event_receiver IMPLEMENTATION.
*§ 3.Implement your event handler methods. Use WRITE to provide output
  METHOD handle_top_of_page.
*  Print Top-of-page
    PERFORM print_top_of_page.
  ENDMETHOD.                           "handle_top_of_page
*-------------------------------------------
  METHOD handle_end_of_list.
* Print End-of-list
    PERFORM print_end_of_list.
  ENDMETHOD.                            "handle_end_of_list
*-------------------------------------------
  METHOD top_of_page.
* Top-of-page event
    PERFORM event_top_of_page USING dg_dyndoc_id.
  ENDMETHOD.                            "top_of_page
*-----------------------------------------------------------------
ENDCLASS.
*&---------------------------------------------------------------------*
*&      Form  EVENT_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       Top-of-page event
*----------------------------------------------------------------------*
FORM event_top_of_page USING   dg_dyndoc_id TYPE REF TO cl_dd_document.

 DATA : dl_text(255) TYPE c,  "Text
         dl_background_id TYPE sdydo_key VALUE '/EMN/EASTMAN_LOGO',
         dl_type.
  DATA a_logo TYPE REF TO cl_dd_area.

* Create TOP-Document
  CREATE OBJECT dg_dyndoc_id
                   EXPORTING style = 'ALV_GRID'.
* Populating header to top-of-page
  CALL METHOD dg_dyndoc_id->add_text
         EXPORTING
            text      = 'Primary Contact Membership Lists'(036)
            sap_style =  cl_dd_area=>heading.
 CALL METHOD dg_dyndoc_id->new_line.

  CLEAR : dl_text.
* Add 'Primary Contact ID'
  dl_text = text-033.
  PERFORM add_text USING dl_text 'H'.

  CALL METHOD dg_dyndoc_id->add_gap
         EXPORTING width   = 3.

  CLEAR dl_text.
  CONCATENATE dg_contact dg_ename INTO dl_text
  SEPARATED BY space.

  PERFORM add_text USING dl_text 'S'.
* Add new-line
  CALL METHOD dg_dyndoc_id->new_line.

  CLEAR : dl_text,dt_protc.
  READ TABLE dt_protc WITH KEY pgroup = dg_protc.


* Add Protocol category
  dl_text = text-034.
  PERFORM add_text USING dl_text 'H'.
  CALL METHOD dg_dyndoc_id->add_gap
         EXPORTING width   = 4.

  CLEAR dl_text.
  CONCATENATE dg_protc dt_protc-pgroupnam INTO dl_text
  SEPARATED BY space.

  PERFORM add_text USING dl_text 'S'.


* Add new-line
  CALL METHOD dg_dyndoc_id->new_line.

  CLEAR : dl_text,dt_prot.
  READ TABLE dt_prot WITH KEY pnumber = dg_prot.

* Add Protocol Number
  dl_text = text-035.
  PERFORM add_text USING dl_text 'H'.
  CALL METHOD dg_dyndoc_id->add_gap
         EXPORTING width   = 5.

  CLEAR dl_text.

  CONCATENATE dg_prot  dt_prot-pname INTO dl_text
  SEPARATED BY space.

  PERFORM add_text USING dl_text 'S'.


  CALL METHOD dg_dyndoc_id->vertical_split
              EXPORTING split_area =  dg_dyndoc_id
                        split_width = '70%'
                 IMPORTING right_area = a_logo.

  CALL METHOD a_logo->add_picture
        EXPORTING picture_id = '/EMN/EASTMAN_LOGO'.

  CALL METHOD dg_dyndoc_id->merge_document.

  CALL METHOD  dg_dyndoc_id->display_document
      EXPORTING reuse_control = 'X'
                parent =  dg_parent_html
      EXCEPTIONS html_display_error = 1.

ENDFORM.                    " EVENT_TOP_OF_PAGE

  

2) In PBO do below : First you need to split the container to two containers one is to palce top-of-page and other to display grid.


  IF dg_custom_container IS INITIAL.
* Create fieldcatalog for structure dt_final
    PERFORM fieldcat_init  USING dg_fieldcatalog[].
    dt_final[] = dt_members[].
* Create a custom container control for our ALV Control
    CREATE OBJECT dg_custom_container
        EXPORTING
            container_name = dg_mycontainer
        EXCEPTIONS
            cntl_error = 1
            cntl_system_error = 2
            create_error = 3
            lifetime_error = 4
            lifetime_dynpro_dynpro_link = 5.
    IF sy-subrc <> 0.
      dg_repid = sy-repid.
* Add your handling, for example
      CALL FUNCTION 'POPUP_TO_INFORM'
           EXPORTING
                titel = dg_repid
                txt2  = sy-subrc
                txt1  = 'The control could not be created'.
    ENDIF.

* Create TOP-Document
    CREATE OBJECT dg_dyndoc_id
                     EXPORTING style = 'ALV_GRID'.
* Create Splitter for custom_container
    CREATE OBJECT dg_splitter
               EXPORTING parent  = dg_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

    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.


* Set height for g_parent_html
    CALL METHOD dg_splitter->set_row_height
      EXPORTING
        id     = 1
        height = 25.
* Create an instance of alv control
    CREATE OBJECT dg_grid1
          EXPORTING i_appl_events = c_x
                    i_parent = dg_parent_grid.
* Registering events
    CREATE OBJECT dg_event_receiver.
    SET HANDLER dg_event_receiver->top_of_page FOR dg_grid1.
    SET HANDLER dg_event_receiver->handle_top_of_page FOR dg_grid1.
    SET HANDLER dg_event_receiver->handle_end_of_list FOR dg_grid1.

* Grid display
    CALL METHOD dg_grid1->set_table_for_first_display
             EXPORTING
               i_structure_name = 'TP_FINAL'
               is_layout        = ds_layout
             CHANGING
                it_fieldcatalog  = dg_fieldcatalog[]
                it_outtab        = dt_final.

* Initializing document
    CALL METHOD dg_dyndoc_id->initialize_document.

* Processing events
    CALL METHOD dg_grid1->list_processing_events
                      EXPORTING i_event_name = 'TOP_OF_PAGE'
                                i_dyndoc_id  = dg_dyndoc_id.


  ENDIF.
* Setting focus for created grid control
  CALL METHOD cl_gui_control=>set_focus EXPORTING control = dg_grid1.

Hope this will help you.

Thanks & Regards,

Siri.

Kindly awrd points if it is helpful.

Message was edited by: Srilatha T

Clemenss
Active Contributor
0 Kudos

Using OO ALV means that the GRID Control is used. That means that on the screen you have a GUI control. This is completely different from the list in good old times. No WRITE statement is supported for the control areas. For TOP_OF_PAGE event is not triggered for the control! Only the printed output (print preview) will trigger TOP_OF_PAGE event.

For online screen output HTML_TOP_OF_PAGE is used. See above replies regarding the use. But keep in mind that this is separated from TOP_OF_PAGE used for print (preview). That means it is necessary to identify what you want online and what in printed TOP-OF-PAGE.

Just to make it clear!

Clemens