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: 

ALV USING FM

Former Member
0 Kudos

I want to split report out in to "N" number of pages. Is it possible in ALV using FM.If so explain with example.

4 REPLIES 4

Former Member
0 Kudos

Hi,

See the following example and execute it.

**BLOCKED LIST DISPLAY FOR KNA1 AND MARA

&----


*& Report ZJE_ALV_BLOCKED1

*&

&----


*&

*&

&----


REPORT zje_alv_blocked1.

TABLES: kna1, vbak.

TYPE-POOLS: slis.

TYPES: BEGIN OF ty_kna1,

kunnr LIKE kna1-kunnr,

land1 LIKE kna1-land1,

name1 LIKE kna1-name1,

ort01 LIKE kna1-ort01,

END OF ty_kna1.

TYPES: BEGIN OF ty_mara,

matnr LIKE mara-matnr,

ersda LIKE mara-ersda,

ernam LIKE mara-ernam,

END OF ty_mara.

DATA: it_kna1 TYPE STANDARD TABLE OF ty_kna1,

wa_kna1 TYPE ty_kna1.

DATA: it_mara TYPE STANDARD TABLE OF ty_mara,

wa_mara TYPE ty_mara.

DATA: wa_layout TYPE slis_layout_alv,

it_fieldcat_kna1 TYPE slis_t_fieldcat_alv,

wa_fieldcat_kna1 TYPE slis_fieldcat_alv,

it_fieldcat_mara TYPE slis_t_fieldcat_alv,

wa_fieldcat_mara TYPE slis_fieldcat_alv,

it_event_kna1 TYPE slis_t_event,

wa_event_kna1 TYPE slis_alv_event,

  • it_event_kna2 TYPE slis_t_event,

  • wa_event_kna2 TYPE slis_alv_event,

*

it_event_mara TYPE slis_t_event,

wa_event_mara TYPE slis_alv_event.

  • wa_print TYPE slis_print_alv.

INITIALIZATION.

PERFORM layout.

PERFORM fieldcat_kna1.

PERFORM fieldcat_mara.

*PERFORM fieldcat_vbak.

START-OF-SELECTION.

SELECT kunnr land1 name1 ort01

FROM kna1

INTO TABLE it_kna1

UP TO 10 ROWS.

SELECT matnr ersda ernam

FROM mara

INTO TABLE it_mara

UP TO 20 ROWS.

PERFORM display.

&----


*& Form layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM layout .

wa_layout-zebra ='X'.

wa_layout-get_selinfos = 'X'.

ENDFORM. " layout

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

*FIELD CATALOUGE*******************************

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

&----


*& Form fieldcat_kna1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fieldcat_kna1 .

REFRESH it_fieldcat_kna1.

CLEAR wa_fieldcat_kna1.

wa_fieldcat_kna1-fieldname = 'KUNNR'.

wa_fieldcat_kna1-seltext_l = 'CUSTOMER NUMBER'.

wa_fieldcat_kna1-datatype = 'CHAR'.

wa_fieldcat_kna1-outputlen = 30.

wa_fieldcat_kna1-tabname = 'IT_KNA1'.

wa_fieldcat_kna1-key = 'X'.

wa_fieldcat_kna1-hotspot = 'X'.

wa_fieldcat_kna1-col_pos = 1.

wa_fieldcat_kna1-emphasize = 'C21'.

APPEND wa_fieldcat_kna1 TO it_fieldcat_kna1.

CLEAR wa_fieldcat_kna1.

wa_fieldcat_kna1-fieldname = 'LAND1'.

wa_fieldcat_kna1-seltext_l = 'COUNTRY CODE'.

wa_fieldcat_kna1-datatype = 'CHAR'.

wa_fieldcat_kna1-outputlen = 30.

wa_fieldcat_kna1-tabname = 'IT_KNA1'.

wa_fieldcat_kna1-hotspot = 'X'.

wa_fieldcat_kna1-col_pos = 2.

wa_fieldcat_kna1-emphasize = 'C31'.

APPEND wa_fieldcat_kna1 TO it_fieldcat_kna1.

CLEAR wa_fieldcat_kna1.

wa_fieldcat_kna1-fieldname = 'NAME1'.

wa_fieldcat_kna1-seltext_l = 'CUSTOMER NAME'.

wa_fieldcat_kna1-datatype = 'CHAR'.

wa_fieldcat_kna1-outputlen = 30.

wa_fieldcat_kna1-tabname = 'IT_KNA1'.

wa_fieldcat_kna1-hotspot = 'X'.

wa_fieldcat_kna1-col_pos = 3.

wa_fieldcat_kna1-emphasize = 'C71'.

APPEND wa_fieldcat_kna1 TO it_fieldcat_kna1.

CLEAR wa_fieldcat_kna1.

wa_fieldcat_kna1-fieldname = 'ORT01'.

wa_fieldcat_kna1-seltext_l = 'COUNTRY '.

wa_fieldcat_kna1-datatype = 'CHAR'.

wa_fieldcat_kna1-outputlen = 30.

wa_fieldcat_kna1-tabname = 'IT_KNA1'.

wa_fieldcat_kna1-hotspot = 'X'.

wa_fieldcat_kna1-col_pos = 4.

wa_fieldcat_kna1-emphasize = 'C51'.

APPEND wa_fieldcat_kna1 TO it_fieldcat_kna1.

CLEAR wa_fieldcat_kna1.

ENDFORM. " fieldcat_kna1

&----


*& Form fieldcat_kna2

&----


  • text

----


FORM fieldcat_mara .

wa_fieldcat_mara-fieldname = 'MATNR'.

wa_fieldcat_mara-seltext_l = 'MATERIAL NUMBER'.

wa_fieldcat_mara-datatype = 'CHAR'.

wa_fieldcat_mara-outputlen = 30.

wa_fieldcat_mara-tabname = 'IT_MARA'.

wa_fieldcat_mara-key = 'X'.

wa_fieldcat_mara-hotspot = 'X'.

wa_fieldcat_mara-col_pos = 1.

wa_fieldcat_mara-emphasize = 'C21'.

APPEND wa_fieldcat_mara TO it_fieldcat_mara.

CLEAR wa_fieldcat_mara.

wa_fieldcat_mara-fieldname = 'ERSDA'.

wa_fieldcat_mara-seltext_l = 'CREATED ON'.

wa_fieldcat_mara-datatype = 'CHAR'.

wa_fieldcat_mara-outputlen = 30.

wa_fieldcat_mara-tabname = 'IT_MARA'.

wa_fieldcat_mara-hotspot = 'X'.

wa_fieldcat_mara-col_pos = 2.

wa_fieldcat_mara-emphasize = 'C41'.

APPEND wa_fieldcat_mara TO it_fieldcat_mara.

CLEAR wa_fieldcat_mara.

wa_fieldcat_mara-fieldname = 'MATNR'.

wa_fieldcat_mara-seltext_l = 'MATERIAL NUMBER'.

wa_fieldcat_mara-datatype = 'CHAR'.

wa_fieldcat_mara-outputlen = 30.

wa_fieldcat_mara-tabname = 'IT_MARA'.

wa_fieldcat_mara-hotspot = 'X'.

wa_fieldcat_mara-col_pos = 3.

wa_fieldcat_mara-emphasize = 'C61'.

APPEND wa_fieldcat_mara TO it_fieldcat_mara.

CLEAR wa_fieldcat_mara.

ENDFORM. "fieldcat_kna2

&----


*& Form Display

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display .

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'

EXPORTING

i_callback_program = sy-repid.

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • IT_EXCLUDING =

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

is_layout = wa_layout

it_fieldcat = it_fieldcat_kna1

i_tabname = 'IT_KNA1'

it_events = it_event_kna1

  • IT_SORT =

  • I_TEXT = ' '

TABLES

t_outtab = it_kna1

EXCEPTIONS

program_error = 1

maximum_of_appends_reached = 2

OTHERS = 3

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'

EXPORTING

is_layout = wa_layout

it_fieldcat = it_fieldcat_mara

i_tabname = 'IT_VBAK'

it_events = it_event_mara

  • IT_SORT =

  • I_TEXT = ' '

TABLES

t_outtab = it_mara

EXCEPTIONS

program_error = 1

maximum_of_appends_reached = 2

OTHERS = 3

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'

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

former_member188685
Active Contributor
0 Kudos

In Display you can't see ...

But in print you can see the effect.

use sort table here you have option to trigger each page

if you give sort-group = '*'. then it will give new page.

assume you have n number of vbelns in your report

then you will have n number pages in your print.

sort-fieldname = 'VBELN'.

sort-group = '*'.

etc..

Former Member
0 Kudos

hi check this...it is given with page no and subtotals if u click on any button it will give you the data expanded

&----


*& Report ZVG_ALV_SLIST2 *

*& *

&----


report zvg_alv_slist2 .

  • ALV

type-pools: slis.

*----


  • G L O B A L I N T E R N A L T A B L E S

*----


data: gt_fieldcat type slis_t_fieldcat_alv,

gs_layout type slis_layout_alv,

gt_events type slis_t_event.

data: it_sort type slis_t_sortinfo_alv ,

wa_sort type slis_sortinfo_alv .

data: gs_print type slis_print_alv.

data: begin of it_sflight occurs 0,

carrid like sflight-carrid,

connid like sflight-connid,

fldate like sflight-fldate,

price like sflight-price,

planetype like sflight-planetype,

seatsmax like sflight-seatsmax,

seatsocc like sflight-seatsocc,

paymentsum like sflight-paymentsum,

end of it_sflight.

*DATA: GI_SFLIGHT LIKE STANDARD TABLE OF ST_SFLIGHT.

data: g_repid like sy-repid.

data: gt_list_top_of_page type slis_t_listheader.

data: v_total(5).

start-of-selection.

g_repid = sy-repid.

perform init_fieldcat using gt_fieldcat[].

perform build_eventtab using gt_events[].

perform build_comment using gt_list_top_of_page[].

perform get_data.

perform set_layout using gs_layout.

  • SORTING

clear wa_sort.

wa_sort-fieldname = 'CARRID'.

wa_sort-up = 'X'.

wa_sort-group = '*'.

wa_sort-subtot = 'X'.

append wa_sort to it_sort.

clear wa_sort.

wa_sort-fieldname = 'CONNID'.

wa_sort-up = 'X'.

wa_sort-group = 'UL'.

wa_sort-subtot = 'X'.

append wa_sort to it_sort.

  • DISPLAY LIST

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

i_interface_check = ' '

i_callback_program = g_repid

i_callback_user_command = 'USER_COMMAND'

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

it_sort = it_sort[]

it_events = gt_events

is_print = gs_print

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.

&----


*& Form INIT_FIELDCAT

&----


form init_fieldcat using p_gt_fieldcat type slis_t_fieldcat_alv.

data: ls_fieldcat type slis_fieldcat_alv,

l_index type sy-tabix.

data :rep like sy-repid.

rep = sy-repid.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = rep

i_internal_tabname = 'IT_SFLIGHT'

i_inclname = rep

changing

ct_fieldcat = gt_fieldcat

exceptions

inconsistent_interface = 1

program_error = 2

others = 3.

if sy-subrc <> 0.

message id sy-msgid type 'S' number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-subrc.

endif.

sort gt_fieldcat by col_pos.

loop at gt_fieldcat into ls_fieldcat.

l_index = sy-tabix.

if ls_fieldcat-fieldname = 'PRICE'.

ls_fieldcat-do_sum = 'X'.

ls_fieldcat-sp_group = 'X'.

modify gt_fieldcat from ls_fieldcat index l_index .

endif.

endloop.

endform. " INIT_FIELDCAT

&----


*& Form BUILD_EVENTTAB

&----


form build_eventtab using p_gt_events type slis_t_event.

data: ls_event type slis_alv_event.

clear ls_event.

ls_event-name = slis_ev_top_of_page.

ls_event-form = 'XTOP_OF_PAGE'.

append ls_event to p_gt_events.

clear ls_event.

ls_event-name = slis_ev_top_of_list.

ls_event-form = 'XTOP_OF_LIST'.

append ls_event to p_gt_events.

clear ls_event.

clear ls_event.

ls_event-name = slis_ev_end_of_page.

ls_event-form = 'XEND_OF_PAGE'.

append ls_event to p_gt_events.

ls_event-name = slis_ev_end_of_list.

ls_event-form = 'XEND_OF_LIST'.

append ls_event to p_gt_events.

clear ls_event.

endform. " BUILD_EVENTTAB

&----


*& Form BUILD_COMMENT

&----


form build_comment using p_gt_list_top_of_page type slis_t_listheader.

data: ls_line type slis_listheader.

ls_line-typ = 'H'." = Header, S = Selection, A = Action

ls_line-key = 'KEY'.

ls_line-info = 'INFO'.

append ls_line to p_gt_list_top_of_page.

endform. " BUILD_COMMENT

&----


*& Form SELECTION

&----


form get_data..

data: l_rows type i value 3.

  • Read data from table SFLIGHT

select carrid

connid

fldate

price

planetype

seatsmax

seatsocc

paymentsum

from sflight

into table it_sflight.

    • up to l_rows rows.

sort it_sflight.

endform. " SELECTION

&----


*& Form SET_LAYOUT

&----


form set_layout using p_gs_layout type slis_layout_alv.

  • * P_GS_LAYOUT-F2CODE = P_F2CODE.

p_gs_layout-zebra = 'X'.

p_gs_layout-colwidth_optimize = 'X'.

p_gs_layout-no_input = 'X'.

p_gs_layout-no_colhead = space.

p_gs_layout-totals_text = 'Total Price'.

p_gs_layout-subtotals_text = 'Sub Total'.

p_gs_layout-totals_only = 'X'.

p_gs_layout-key_hotspot = 'X'.

p_gs_layout-detail_popup = 'X'.

p_gs_layout-no_subtotals = space.

p_gs_layout-expand_all = 'X'.

p_gs_layout-group_buttons = 'X'."space.

endform. " SET_LAYOUT

----


  • FORM XTOP_OF_PAGE *

----


form xtop_of_page.

data : lv_page(5),

lv_text(20).

MOVE SY-PAGNO TO LV_PAGE.

write:/ 'X_TOP_OF_PAGE'.

.

endform. "xtop_of_page

----


  • FORM XTOP_OF_LIST *

----


form xtop_of_list.

write:/ 'X_TOP_OF_LIST'.

endform. "xtop_of_list

----


  • FORM XEND_OF_PAGE *

----


form xend_of_page.

write:/ 'X_END_OF_PAGE'.

endform. "xend_of_page

----


  • FORM XEND_OF_LIST *

----


form xend_of_list.

write:/ 'X_END_OF_LIST'.

data : lv_page(5),

lv_text(20).

data : l_lines type i,

l_line type i.

clear v_total.

write sy-pagno to v_total left-justified.

  • export v_total to memory id 'V_TOTAL'.

do sy-pagno times.

lv_page = sy-index.

concatenate 'Page' lv_page 'of' v_total

into lv_text separated by space.

if sy-index = 1.

read line 2 of page sy-index.

else.

read line 1 of page sy-index.

endif.

sy-lisel+60(20) = lv_text.

modify current line .

enddo.

endform. "xend_of_list

----


  • USER_COMMAND *

----


form user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

case r_ucomm.

when 'EXIT'.

leave to screen 0.

when '&IC1'.

data: text(256),text1(6),text2(5).

move rs_selfield-tabindex to text1.

move rs_selfield-sumindex to text2.

concatenate 'Double clicked on (field:'

rs_selfield-fieldname

'Value:'

rs_selfield-value

','

text1

','

text2

' ) '

into text

separated by space.

call function 'POPUP_TO_DISPLAY_TEXT'

exporting

textline1 = text.

endcase.

endform. "user_command

regards,

venkat.

Former Member
0 Kudos

Using FM: REUSE_ALV_GRID_DISPLAY you cannot print page footers..so you cannot get the page numbers with this FM...so try to use : REUSE_ALV_LIST_DISPLAY..with this you can do page footer like using the event END_OF_PAGE..within this you write the code for pages.

Reward if it useful.

Dara.