Application Development and Automation 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: 
Read only

ALV report

Former Member
0 Likes
1,328

Hi,

I want to use top-of-page event in an alv report.I want to display the following text at the top of the page before the data gets displayed in the alv grid.

Title: purchased parts forecast report

Plant: 1002 US UPG Wichita

Currency: USD

Period: 01.10.2007 To 31.12.2007

Sys Date and Time: 24.10.2007 20:01:57

How can I do this in an alv report?

Hi,

I want to use top-of-page event in an alv report.I want to display the following text at the top of the page before the data gets displayed in the alv grid.

Title: purchased parts forecast report

Plant: 1002 US UPG Wichita

Currency: USD

Period: 01.10.2007 To 31.12.2007

Sys Date and Time: 24.10.2007 20:01:57

How can I do this in an alv report?

9 REPLIES 9
Read only

Former Member
0 Likes
1,245

Hi ,

You can use the TOP of PAGE parameter of Reuse function module to display ALV grid .

And add following code to your report.

FORM top_of_page_grid.

*DATA: ls_line TYPE slis_listheader.

DATA:info1(50).

REFRESH gt_list_top_of_page.

CLEAR ls_line.

ls_line-typ = 'H'.

  • ls_line-key = 'Purchase Register Report'.

WRITE 'Exception Report' TO ls_line-info.

APPEND ls_line TO gt_list_top_of_page.

CLEAR ls_line.

ls_line-typ = 'S'.

ls_line-key = 'Material No :'.

CONCATENATE s_matnr-low ' / ' s_matnr-high INTO info1.

WRITE info1 TO ls_line-info.

APPEND ls_line TO gt_list_top_of_page.

CLEAR ls_line.

ls_line-typ = 'S'.

ls_line-key = 'Plant:'.

WRITE s_werks-low TO ls_line-info.

APPEND ls_line TO gt_list_top_of_page.

  • CLEAR ls_line.

  • ls_line-typ = 'S'.

  • ls_line-key = 'Plant '.

  • DATA:info1(50).

  • CONCATENATE s_werks-low ' / ' s_budat-high INTO info1.

  • WRITE info1 TO ls_line-info.

  • APPEND ls_line TO gt_list_top_of_page.

  • CLEAR info1.

  • CLEAR ls_line.

  • ls_line-typ = 'S'.

  • ls_line-key = 'GL Acc No. '.

  • WRITE s_hkont-low TO ls_line-info.

    • WRITE info1 TO ls_line-info.

  • APPEND ls_line TO gt_list_top_of_page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

  • I_LOGO = 'ENJOYSAP_LOGO'

it_list_commentary = gt_list_top_of_page.

ENDFORM. "top_of_page_grid

Read only

Former Member
0 Likes
1,245

Use in this way

FORM zf_sub_comment_build USING i_top_of_page TYPE slis_t_listheader.

DATA: lw_line TYPE slis_listheader.

DATA: lv_date(40) TYPE c,

lv_pcent(45) TYPE c,

lv_dat1(10) TYPE c,

lv_dat2(10) TYPE c.

lw_line-typ = 'H'.

lw_line-info = 'Commission Report'. "#EC NOTEXT

APPEND lw_line TO i_top_of_page.

CLEAR: lw_line.

IF NOT s_fkdat IS INITIAL.

WRITE : s_fkdat-low TO lv_dat1 USING EDIT MASK '__/__/____'.

WRITE : s_fkdat-high TO lv_dat2 USING EDIT MASK '__/__/____'.

IF s_fkdat-low IS NOT INITIAL AND s_fkdat-high IS INITIAL.

lw_line-typ = 'S'.

lw_line-info = lv_dat1.

lw_line-key = 'Billing date :'. "#EC NOTEXT

APPEND lw_line TO i_top_of_page.

CLEAR: lw_line.

ELSEIF s_fkdat-low IS NOT INITIAL AND s_fkdat-high IS NOT INITIAL.

CONCATENATE 'From: ' lv_dat1 ' To ' lv_dat2 INTO lv_date SEPARATED

BY ''. "#EC NOTEXT

lw_line-typ = 'S'.

lw_line-info = lv_date.

lw_line-key = 'Billing date :'. "#EC NOTEXT

APPEND lw_line TO i_top_of_page.

CLEAR: lw_line.

ENDIF.

ENDIF.

IF s_vkbur-low IS NOT INITIAL AND s_vkbur-high IS INITIAL.

lw_line-typ = 'S'.

lw_line-info = s_vkbur-low.

lw_line-key = 'Sales Office :'. "#EC NOTEXT

APPEND lw_line TO i_top_of_page.

CLEAR: lw_line.

ELSEIF s_vkbur-low IS NOT INITIAL AND s_vkbur-high IS NOT INITIAL.

CONCATENATE 'From: ' s_vkbur-low ' To ' s_vkbur-high INTO lv_pcent

SEPARATED BY ''. "#EC NOTEXT

lw_line-typ = 'S'.

lw_line-info = lv_pcent.

lw_line-key = 'Sales Office :'. "#EC NOTEXT

APPEND lw_line TO i_top_of_page.

CLEAR: lw_line.

ENDIF.

Thanks

Read only

Former Member
0 Likes
1,245

HI Check the following code.

FORM top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = t_list_top_of_page.
ENDFORM.                    " main_title
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat        = it_fieldcat
      it_events          = it_events[]
      i_callback_program = sy-repid
      is_layout          = gs_layout
    TABLES
      t_outtab           = i_output[].
  IF sy-subrc <> 0.
  ENDIF.
*  ls_line-typ  = 'S'.
*  ls_line-info = 'For the Date  :'.
*  WRITE p_date TO lv_date.
*  CONCATENATE ls_line-info lv_date INTO ls_line-info.
  APPEND ls_line TO t_list_top_of_page.

  ls_line-typ  = 'S'.
  ls_line-info = 'Total Strength of Workman:'.
  lv_total = v_total.
  CONCATENATE ls_line-info lv_total INTO ls_line-info.
  APPEND ls_line TO t_list_top_of_page.
FORM get_events .
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = it_events[]
    EXCEPTIONS
      list_type_wrong = 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.

  READ TABLE it_events WITH KEY name = slis_ev_top_of_page
                                INTO it_events.
  IF sy-subrc = 0.
    MOVE t_formname_top_of_page TO it_events-form.
    APPEND it_events.
  ENDIF.

ENDFORM.                    " get_events
DATA: t_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.

Read only

Former Member
0 Likes
1,245

Hi ,

You can find many more links for this . Please go through the below code.

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.

Read only

former_member156446
Active Contributor
0 Likes
1,245

u will be needed to use REUSE_ALV_COMMENTARY_WRITE

Read only

Former Member
0 Likes
1,245

Hi,

Look following trial program.

REPORT ZTRIAL .

*report sy-repid.

type-pools : slis.

*ALV Formatting tables /structures

data: gt_fieldcat type slis_t_fieldcat_alv.

data: gt_events type slis_t_event.

data: gs_layout type slis_layout_alv.

data: gt_page type slis_t_listheader.

data: gs_page type slis_listheader.

data: v_repid like sy-repid.

*ALV Formatting work area

data: w_fieldcat type slis_fieldcat_alv.

data: w_events type slis_alv_event.

data: gt_bsid type table of bsid with header line.

initialization.

PERFORM BUILD_EVENTS CHANGING GT_EVENTS.

perform build_page_header.

start-of-selection.

*perform build_comment. "top_of_page - in initialization at present

select * from bsid into table gt_bsid up to 10 rows.

*perform populate_for_fm using '1' '3' 'BUKRS' '8' 'GT_BSID' 'Whee'.

*USING = Row, Column, Field name, display length, table name, heading

*OR

perform build_fieldcat.

gs_layout-zebra = 'X'.

*top of page event does not work without I_callback_program

v_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = v_repid

i_structure_name = 'BSID'

  • i_background_id = 'ALV_BACKGROUND'

i_grid_title = 'This is the grid title'

  • I_GRID_SETTINGS =

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

it_events = gt_events[]

tables

t_outtab = gt_bsid.

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

  • Form..............: populate_for_fm

  • Description.......: Populates fields for function module used in ALV

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

form populate_for_fm using p_row

p_col

p_fieldname

p_len

p_table

p_desc.

w_fieldcat-row_pos = p_row. "Row Position

w_fieldcat-col_pos = p_col. "Column Position

w_fieldcat-fieldname = p_fieldname. "Field name

w_fieldcat-outputlen = p_len. "Column Lenth

w_fieldcat-tabname = p_table. "Table name

w_fieldcat-reptext_ddic = p_desc. "Field Description

w_fieldcat-input = '1'.

append w_fieldcat to gt_fieldcat.

clear w_fieldcat.

endform. " populate_for_fm

&----


*& Form build_events

&----


FORM BUILD_EVENTS CHANGING GT_EVENTS TYPE SLIS_T_EVENT.

DATA: LINE_EVENT TYPE SLIS_ALV_EVENT.

CLEAR LINE_EVENT.

LINE_EVENT-NAME = 'TOP_OF_PAGE'.

LINE_EVENT-FORM = 'TOP_OF_PAGE'.

APPEND LINE_EVENT TO GT_EVENTS.

ENDFORM. "build_events

&----


*& Form USER_COMMAND

&----


  • When user command is called it uses 2 parameters. The itab

  • passed to the ALV is in whatever order it currently is on screen.

  • Therefore, you can read table itab index rs_selfield-tabindex to get

  • all data from the table. You can also check r_ucomm and code

  • accordingly.

&----


form user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

read table gt_bsid index rs_selfield-tabindex.

  • error checking etc.

set parameter id 'KUN' field gt_bsid-kunnr.

call transaction 'XD03' and skip first screen.

endform.

&----


*& Form top_of_page

&----


  • Your own company logo can go here if it has been saved (OAOR)

  • If the logo is larger than the size of the headings in gt_page,

  • the window will not show full logo and will have a scroll bar. Thus,

  • it is a good idea to have a standard ALV header if you are going to

  • use logos in your top of page.

&----


form top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = gt_page

i_logo = 'ENJOYSAP_LOGO'.

endform.

&----


*& Form build_fieldcat

&----


*Many and varied fields are available here. Have a look at documentation

*for FM REUSE_ALV_LIST_DISPLAY and REUSE_ALV_FIELDCATALOG_MERGE

----


form build_fieldcat.

w_fieldcat-fieldname = 'BUDAT'.

w_fieldcat-seltext_m = 'Dte pst'.

w_fieldcat-ddictxt(1) = 'M'.

  • Can change the position of fields if you do not want them in order

  • of the DDIC or itab

  • w_fieldcat-row_pos = '1'.

  • w_fieldcat-col_pos = '10'.

append w_fieldcat to gt_fieldcat.

clear w_fieldcat.

endform. " build_fieldcat

&----


*& Form build_page_header

&----


  • gt_page is used in top of page (ALV subroutine - NOT event)

  • *H = Header, S = Selection, A = Action

----


form build_page_header.

  • For Headers, Key is not printed and is irrelevant. Will not cause

  • a syntax error, but is not used.

gs_page-typ = 'H'.

gs_page-info = 'Header 1'.

append gs_page to gt_page.

gs_page-typ = 'H'.

gs_page-info = 'Header 2'.

append gs_page to gt_page.

  • For Selections, the Key is printed (bold). It can be anything up to 20

  • bytes. It gets printed in order of code here, not by key value.

gs_page-typ = 'S'.

gs_page-key = 'And the winner is:'.

gs_page-info = 'Selection 1'.

append gs_page to gt_page.

gs_page-typ = 'S'.

gs_page-key = 'Runner up:'.

gs_page-info = 'Selection 2'.

append gs_page to gt_page.

  • For Action, Key is also irrelevant.

gs_page-typ = 'A'.

gs_page-info = 'Action goes here'.

append gs_page to gt_page.

endform. " build_page_header

Reward pts if usefull.

Regards,

Dhan

Read only

Former Member
0 Likes
1,245

1)Write a subroutine as TOP_OF_PAGE

2)Cal the FM REUSE_ALV_COMMENTARY_WRITE in it

3)Populate heading table

4)Pass the name of the subroutine in REUSE_ALV_GRID_DISPLAY


*&---------------------------------------------------------------------*
*& Report  ZALV_REPORT_SFLIGHT
*&
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
REPORT  ZALV_REPORT_SFLIGHT.
TABLES : SFLIGHT.
TYPE-POOLS : SLIS.**INTERNAL TABLE DECLARTION
DATA : WA_SFLIGHT TYPE SFLIGHT,
       IT_SFLIGHT TYPE TABLE OF SFLIGHT.**DATA DECLARTION
DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
      GD_LAYOUT    TYPE SLIS_LAYOUT_ALV,
      GD_REPID     LIKE SY-REPID,
      G_SAVE TYPE C VALUE 'X',
      G_VARIANT TYPE DISVARIANT,
      GX_VARIANT TYPE DISVARIANT,
      G_EXIT TYPE C,
      ISPFLI TYPE TABLE OF SPFLI.* To understand the importance of the following parameter, click here.
**SELECTION SCREEN DETAILS
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002 .
PARAMETERS: VARIANT LIKE DISVARIANT-VARIANT.
SELECTION-SCREEN END OF BLOCK B1.
**GETTING DEFAULT VARIANT
INITIALIZATION.
  GX_VARIANT-REPORT =SY-REPID.
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      I_SAVE     = G_SAVE
    CHANGING
      CS_VARIANT = GX_VARIANT
    EXCEPTIONS
      NOT_FOUND  = 2.
  IF SY-SUBRC = 0.
    VARIANT = GX_VARIANT-VARIANT.
  ENDIF.**PERFORM DECLARATIONS
START-OF-SELECTION.
  PERFORM DATA_RETRIVEL.
  PERFORM BUILD_FIELDCATALOG.
  PERFORM DISPLAY_ALV_REPORT.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCATALOG .  FIELDCATALOG-FIELDNAME   = 'CARRID'.
  FIELDCATALOG-SELTEXT_M   = 'Airline Code'.
  FIELDCATALOG-COL_POS     = 0.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.
  FIELDCATALOG-FIELDNAME   = 'CONNID'.
  FIELDCATALOG-SELTEXT_M   = 'Flight Connection Number'.
  FIELDCATALOG-COL_POS     = 1.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.  FIELDCATALOG-FIELDNAME   = 'FLDATE'.
  FIELDCATALOG-SELTEXT_M   = 'Flight date'.
  FIELDCATALOG-COL_POS     = 2.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.  FIELDCATALOG-FIELDNAME   = 'PRICE'.
  FIELDCATALOG-SELTEXT_M   = 'Airfare'.
  FIELDCATALOG-COL_POS     = 3.
  FIELDCATALOG-OUTPUTLEN   = 20.
  APPEND FIELDCATALOG TO FIELDCATALOG.
  CLEAR  FIELDCATALOG.
ENDFORM.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
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'
      IT_FIELDCAT             = FIELDCATALOG[]
      I_SAVE                  = 'X'
      IS_VARIANT              = G_VARIANT
    TABLES
      T_OUTTAB                = IT_SFLIGHT
    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" DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIVEL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DATA_RETRIVEL .
  SELECT * FROM SFLIGHT INTO TABLE IT_SFLIGHT.
ENDFORM.                    " DATA_RETRIVEL*-------------------------------------------------------------------*
* 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 = 'SFLIGHT 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.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      IT_LIST_COMMENTARY = T_HEADER.
ENDFORM.                    "top-of-page

Read only

Former Member
0 Likes
1,245

hi,

check this link..

hope this helps you....

regards,

praveena.

Read only

Former Member
0 Likes
1,245

Hi,

TYPE-POOLS : slis.

DATA : BEGIN OF i_data OCCURS 0,

vbeln LIKE vbap-vbeln,

posnr LIKE vbap-posnr,

matnr LIKE vbap-matnr,

ws_row TYPE i,

ws_char(5) TYPE c,

chk,

END OF i_data.

DATA : report_id LIKE sy-repid,

ws_title TYPE lvc_title VALUE 'A simple ALV report',

i_layout TYPE slis_layout_alv,

i_fieldcat TYPE slis_t_fieldcat_alv,

i_header TYPE slis_t_listheader.

START-OF-SELECTION.

select vbeln

posnr

matnr

into table i_data

from vbap

where vbeln <= '10'.

loop at i_data.

i_data-ws_row = sy-tabix.

i_data-ws_char = 'AAAA'.

modify i_data.

endloop.

report_id = sy-repid.

perform layout_init changing i_layout.

perform fieldcat_init changing i_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = report_id

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

I_GRID_TITLE = ws_title

  • I_GRID_SETTINGS =

IS_LAYOUT = i_layout

IT_FIELDCAT = i_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

I_SAVE = 'A'

  • IS_VARIANT =

  • IT_EVENTS = i_events

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP = 0

  • I_HTML_HEIGHT_END = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • IR_SALV_FULLSCREEN_ADAPTER =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = i_data

  • 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.

&----


*& Form layout_init

&----


  • text

----


  • <--P_I_LAYOUT text

----


form layout_init changing i_layout type slis_layout_alv.

clear i_layout.

i_layout-colwidth_optimize = 'X'.

i_layout-edit = 'X'.

endform. " layout_init

&----


*& Form fieldcat_init

&----


  • text

----


  • <--P_I_FIELDCAT text

----


form fieldcat_init changing p_i_fieldcat.

data : line_fieldcat type slis_fieldcat_alv.

clear line_fieldcat.

line_fieldcat-fieldname = 'VBELN'.

line_fieldcat-tabname = 'IT_DATA'.

line_fieldcat-seltext_m = 'sales doc.'.

append line_fieldcat to i_fieldcat.

clear line_fieldcat.

line_fieldcat-fieldname = 'POSNR'.

line_fieldcat-tabname = 'IT_DATA'.

line_fieldcat-seltext_m = 'item'.

append line_fieldcat to i_fieldcat.

clear line_fieldcat.

line_fieldcat-fieldname = 'MATNR'.

line_fieldcat-tabname = 'IT_DATA'.

line_fieldcat-seltext_m = 'material no.'.

append line_fieldcat to i_fieldcat.

endform. " fieldcat_init

&----


*& Form build_header

&----


  • text

----


  • <--P_I_HEADER text

----


form TOP-OF-PAGE.

data : gs_line type slis_listheader.

clear gs_line.

gs_line-typ = 'H'.

gs_line-info = 'purchased parts forecast report'.

append gs_line to i_header.

clear gs_line.

gs_line-typ = 'S'.

gs_line-key = 'plant:'.

gs_line-info = '1002 US UPG Wichita'.

append gs_line to i_header.

gs_line-key = 'currency:'.

gs_line-info = 'USD'.

append gs_line to i_header.

gs_line-key = 'period:'.

gs_line-info = '01.10.2007 To 31.12.2007'.

append gs_line to i_header.

gs_line-key = 'sys date and time:'.

gs_line-info = '24.10.2007 20:01:57'.

append gs_line to i_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = i_header

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

endform. " TOP-OF-PAGE