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

How to get header in the ALV report

Former Member
0 Kudos
925

Hi

I want to print header in the ALV report.But i am not getting that.Plz see my program it is getting error and also not printing header.If there is any error means plz give me the solution.In this program there is an error.

REPORT ZREPORT_ALV .

TYPE-POOLS : slis.

tables:vbak,vbap.

DATA: report_id LIKE sy-repid.

DATA: I_LAYOUT TYPE SLIS_LAYOUT_ALV.

data: heading TYPE slis_t_listheader,

wa_header TYPE slis_listheader,

events TYPE slis_t_event.

data: l_string type c.

data: ivariant(1) type c,

itvariant like disvariant,

w_variant like disvariant.

initialization.

REPORT_ID = SY-REPID.

PERFORM pgm. "F1000_LAYOUT_INIT. "using I_LAYOUT.

ivariant = 'A'.

*PERFORM init.

itvariant = w_variant.

select-options:so_vbeln for vbap-vbeln.

data:itab like vbak occurs 0 with header line.

data:itab1 like vbap occurs 0 with header line.

start-of-selection.

select * from vbak into table itab where vbeln in so_vbeln.

if not itab[] is initial.

select * from vbap into table itab1

for all entries in itab

where vbeln = itab-vbeln.

endif.

data:ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat1 TYPE slis_t_fieldcat_alv.

****For alv display

IF NOT itab1[] IS INITIAL.

DEFINE ls_fieldcat.

add 1 to ls_fieldcat-col_pos.

ls_fieldcat-fieldname = &1.

ls_fieldcat-outputlen = &2.

ls_fieldcat-seltext_l = &3.

  • ls_fieldcat-emphasize = &4.

append ls_fieldcat to lt_fieldcat1.

clear ls_fieldcat.

END-OF-DEFINITION.

ls_fieldcat 'VBELN' '10' 'Sales Order Number'.

ls_fieldcat 'POSNR' '6' 'SO Item'.

ls_fieldcat 'MATNR' '13' 'Material No'.

  • m_fieldcat1 'NETWR' '13' 'Amount'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = sy-repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = I_LAYOUT

IT_FIELDCAT = lt_fieldcat1

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

IS_VARIANT = ITVARIANT

  • IT_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 = itab1

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

endif.

CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'

EXPORTING

I_SAVE = ivariant

CHANGING

CS_VARIANT = itvariant

  • EXCEPTIONS

  • WRONG_INPUT = 1

  • NOT_FOUND = 2

  • PROGRAM_ERROR = 3

  • OTHERS = 4

.

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 pgm. "F1000_LAYOUT_INIT. "USING I_LAYOUT TYPE SLIS_LAYOUT_ALV.

CLEAR I_LAYOUT.

i_layout-colwidth_optimize = 'X'.

  • I_LAYOUT-key_hotspot = u2018Xu2019.

  • I_LAYOUT-hotspot_fieldname = MATNR.

ENDFORM.

*regarding logo and header,,,,

*

*first store the logo in T-code OAOR, then call that in your report.....

*..

*data: heading TYPE slis_t_listheader,

  • wa_header TYPE slis_listheader,

  • events TYPE slis_t_event.

*

    • To display TOP_OF_PAGE.

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

FORM top_of_page.

DATA : text(40),txtdt(40).

CLEAR l_string.

l_string = 'JCB India Limited'(hd2).

wa_header-typ = 'H'.

wa_header-info = l_string.

APPEND wa_header TO heading. " index 1.

CLEAR l_string.

WRITE :'Number of records:' TO text,'dbcnt' TO text+20 LEFT-JUSTIFIED.

wa_header-typ = 'S'.

wa_header-info = text.

APPEND wa_header TO heading.

  • CLEAR l_string.

  • wa_header-typ = 'S'.

  • WRITE : 'Report Run Date :' TO txtdt,sy-datum TO txtdt+20 DD/MM/YY.

  • WRITE sy-datum TO dat DD/MM/YY.

  • wa_header-info = txtdt.

  • APPEND wa_header TO heading.

*

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

  • i_logo = 'ENJOYSAP_LOGO'

it_list_commentary = heading.

CLEAR heading.

ENDFORM. "top_of_page

*to execute top-of-page you have to create events.

*for ex......

FORM create_event USING p_events TYPE slis_t_event.

DATA: ls_event TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = p_events.

READ TABLE p_events WITH KEY name = slis_ev_top_of_page

INTO ls_event.

IF sy-subrc = 0.

MOVE formname_top_of_page TO ls_event-form.

APPEND ls_event TO p_events.

ENDIF.

ENDFORM. " create_event

7 REPLIES 7
Read only

Former Member
0 Kudos
693

you are not passing the events information or the TOP_OF_PAGE form name. then how it will show the TOP_OF_PAGE. check it once. Refer the standard program BALVST02_GRID

Read only

Former Member
0 Kudos
693

Hi Neeraja,

You haven't pass internal table for events p_events in your FM REUSE_ALV_GRID_DISPLAY.

Pass it in IT_EVENTS parameter.

Hope this will help.

Regards,

Nitin.

Read only

0 Kudos
693

I am getting error like this.Where i have to define this.How i have to define.Plz tell me

Statement "FORMNAME_TOP_OF_PAGE" is not defined. Check your spelling .

Read only

Former Member
0 Kudos
693

Hi,

Find below code for your question, you may get some idea,,

&----


*& Report ZACTIONGRIDPRACTICE

*&

&----


*&

*&

&----


REPORT ZACTIONGRIDPRACTICE.

*data declarations.....

TYPE-POOLS SLIS.

TABLES : T529T ,PA0000.

data : gd_repid type sy-repid.

DATA : LD_COLOR(10) TYPE N.

DATA : GD_TAB_GROUP TYPE SLIS_T_SP_GROUP_ALV.

Data: is_fieldcat TYPE slis_fieldcat_alv.

DATA : GD_LAYOUT TYPE SLIS_LAYOUT_ALV.

DATA : GD_DATUM TYPE DATUM.

DATA : BEGIN OF WA_TABLE,

MASSN TYPE T529T-MASSN,

MNTXT TYPE T529T-MNTXT,

userg type userg,

TOTAL TYPE I ,

begda type begda,

endda type endda,

april type i,

SLNO TYPE I,

LINE_COLOR(4) TYPE C,

END OF WA_TABLE,

IT_TABLE LIKE TABLE OF WA_TABLE.

data : april type i.

DATA : TEMP TYPE C.

data : LT_PA0000 TYPE TABLE OF PA0000,

LT_PA0000_T typE TABLE OF PA0000 with header line.

DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,

WA_FCAT LIKE LINE OF IT_FCAT.

DATA : IT_EVENTS TYPE SLIS_T_EVENT,

WA_EVENTS LIKE LINE OF IT_EVENTS.

wa_events-form = 'HEADER'.

WA_EVENTS-NAME = 'TOP_OF_PAGE'.

APPEND WA_EVENTS TO IT_EVENTS.

PERFORM HEADER.

DATA : SLNO TYPE I.

DATA : lv_output TYPE dats.

CALL FUNCTION 'ZHR_RE_BE_CALC_START_DATE'

EXPORTING

id_daberi = sy-datum

IMPORTING

ed_date_cor = lv_output.

  • select-options...

selection-screen BEGIN OF BLOCK B WITH FRAME TITLE TEXT-003.

select-options : s_date for sy-datum OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B.

lv_output = sy-datum - 27.

INITIALIZATION.

S_DATE-LOW = lv_output.

S_DATE-HIGH = SY-DATUM.

S_DATE-SIGN = 'I'.

S_DATE-OPTION = 'BT'.

APPEND s_date.

*

*AT SELECTION-SCREEN ON S_DATE.

*SELECT MASSN INTO TABLE IT_TABLE FROM PA0000 WHERE BEGDA IN S_DATE.

*SELECT STATEMENTS....

start-of-selection.

SELECT t529t~MASSN t529t~MNTXT INTO TABLE IT_table FROM T529T where SPRSL EQ 'E' and t529t~massn in ('10','13','16','20','28','30','45','01','03') .

  • DATUM IN S_DATE.

PERFORM LAYOUT.

loop at it_table into wa_table.

LD_COLOR = 2.

LD_COLOR = LD_COLOR + 1.

if LD_COLOR = 8.

LD_COLOR = 1.

endif.

concatenate 'C' '1' '11' into wa_table-LINE_COLOR . "='C410'.

modify it_table from wa_table.

*

endloop.

LOOP AT IT_TABLE INTO WA_TABLE." = 'C410'.

select massn from pa0000 into table lt_pa0000 where begda in s_date and massn = wa_table-massn.

*write : / sy-dbcnt. gt s_date-low and endda lt s_date-high

*DESCRIBE TABLE LT_PA0000_t LINES LV_LINES.

move sy-dbcnt to wa_table-total.

  • READ TABLE lt_pa0000 INTO LT_PA0000_T WITH KEY MASSN = wa_TABLE-MASSN BINARY SEARCH.

  • DESCRIBE TABLE LT_PA0000_t LINES LV_LINES.

  • MOVE LV_LINES to wa_TABLE-TOTAL.

MODIFY IT_TABLE FROM WA_TABLE.

MOVE SY-TABIX TO WA_TABLE-SLNO.

MODIFY IT_TABLE FROM WA_TABLE.

  • REFRESH : LT_PA0000_t.

  • CLEAR : LV_LINES.

ENDLOOP.

  • loop at it_table into wa_table.

*

  • SELECT MASSN FROM PA0000 INTO TABLE lt_pa0000 where begda between '01.02.2008' and '20.02.2008'.

  • MOVE SY-DBCNT TO WA_TABLE-APRIL.

  • MODIFY IT_TABLE FROM WA_TABLE.

*endloop.

*PERFORM STATEMENTS...

  • PERFORM FCAT USING '1' 'MASSN' 'ACTIONCODE'.

  • PERFORM FCAT USING '2' 'MNTXT' 'ACTION TYPE'.

  • PERFORM fcat USING '3' 'TOTAL' 'TOTAL'.

DEFINE m_fieldcat.

is_fieldcat-fieldname = &1.

is_fieldcat-hotspot = &2.

is_fieldcat-seltext_m = &3.

is_fieldcat-col_pos = &4.

is_fieldcat-outputlen = &5.

is_fieldcat-hotspot = &6.

append is_fieldcat to it_fcat.

clear is_fieldcat.

END-OF-DEFINITION.

m_fieldcat 'SLNO' '' Text-012 '1' '17' ''.

m_fieldcat 'MASSN' '' Text-010 '2' '40' ''.

m_fieldcat 'MNTXT' '' Text-009 '3' '50' '' .

m_fieldcat 'TOTAL' '' Text-011 '4' '10' 'X'.

  • m_fieldcat 'april' '' Text-013 '5' '10' 'X'.

*FOR DISPLAYING THE RECORDS...

gd_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = gd_repid

  • IS_LAYOUT = GD_LAYOUT

  • I_CALLBACK_USER_COMMAND = ' '

I_GRID_TITLE = 'REPORT'

IS_LAYOUT = gd_LAYOUT

IT_FIELDCAT = IT_FCAT

I_SAVE = 'X'

IT_EVENTS = IT_EVENTS

TABLES

T_OUTTAB = IT_TABLE.

*&----


**& Form FCAT

*&----


*FORM FCAT USING FP_COL_POS

  • FP_FIELDNAME

  • FP_SELTEXT_M.

  • WA_FCAT-COL_POS = FP_COL_POS.

  • WA_FCAT-FIELDNAME = FP_FIELDNAME.

  • wa_fcat-seltext_m = fp_seltext_m.

  • APPEND WA_FCAT TO IT_FCAT.

  • ENDFORM.

&----


*& Form HEADER

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form header .

DATA : IT_HEADER TYPE SLIS_T_LISTHEADER,

WA_HEADER LIKE LINE OF it_header.

WA_HEADER-TYP = 'H'.

WA_HEADER-INFO = 'ACTION TYPE REPORT'.

APPEND WA_HEADER TO IT_HEADER.

wa_header-typ = 'S'.

wa_header-key = Text-022.

CONCATENATE s_date-low+6(2) '.'

s_date-low+4(2) '.'

s_date-low(4)

temp

'. TO .'

s_date-high+6(2) '.'

s_date-high+4(2) '.'

s_date-high(4)

INTO wa_header-info SEPARATED BY space.

APPEND wa_header TO it_header.

CLEAR wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = IT_HEADER

I_LOGO = 'HRRU_51050061'.

*select single bstkd into CORRESPONDING FIELDS OF gt_vbkd

*from vbkd where vbeln = rt_outtab-vgbel

*and posnr = '000000'.

*rt_outtab-bstkd = gt_vbkd-bstkd.

ENDFORM. " HEADER

&----


*& Form LAYOUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM LAYOUT .

GD_LAYOUT-NO_INPUT = ''.

gd_layout-colwidth_optimize = ''.

gd_layout-totals_text = 'TOTALS'(201).

gd_layout-info_fieldname = 'LINE_COLOR'.

ENDFORM. " LAYOUT

Read only

Former Member
0 Kudos
693

Try to incorporate the following changes..

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = sy-repid

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE ' "use this..

IS_LAYOUT = I_LAYOUT

IT_FIELDCAT = lt_fieldcat1

IS_VARIANT = ITVARIANT

comment the below code or call the perform create_event before the function call..

FORM create_event USING p_events TYPE slis_t_event.
DATA: ls_event TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = p_events.
READ TABLE p_events WITH KEY name = slis_ev_top_of_page
INTO ls_event.
IF sy-subrc = 0.
MOVE 'TOP_OF_PAGE' TO ls_event-form.  "correct this code
APPEND ls_event TO p_events.
ENDIF.
ENDFORM. " create_event

Read only

Former Member
0 Kudos
693

Thankyou

Read only

Former Member
0 Kudos
693

Hi,,

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_INTERFACE_CHECK = ' '

I_BYPASSING_BUFFER = ' '

I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = sy-repid

I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = ' '

I_CALLBACK_TOP_OF_PAGE = ' '

I_CALLBACK_HTML_TOP_OF_PAGE = ' '

I_CALLBACK_HTML_END_OF_LIST = ' '

In this Fun module u hav to pass ur TOp-Of-page form name i.e

I_CALLBACK_TOP_OF_PAGE = ' UR TOP-OF PAGE FORM NAME'

Try this.....