Escolar Documentos
Profissional Documentos
Cultura Documentos
Scenario
Below is the PRINT PREVIEW of my report output.
Partial Solution:
Page break can be forced if there is any change in the value of a sorted column. For example, to force a page break for every change in PERNR, fill IT_SORT table in the FM ALV_GRID_DISPLAY as below.
====================================================
FORM LSORT USING l_FIELD l_TABLE l_UP l_group. ADD 1 TO L_POS. w_SORT-SPOS = l_POS. w_SORT-FIELDNAME = l_FIELD. w_SORT-TABNAME = l_TABLE. w_SORT-UP = l_UP. w_sort-group = l_group. APPEND w_sort to IT_SORT. ENDFORM. * Display the data in ALV format CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program i_callback_top_of_page I_CALLBACK_HTML_TOP_OF_PAGE IS_LAYOUT it_fieldcat IT_SORT it_events TABLES t_outtab = = = = = = = sy-repid 'TOP_OF_PAGE' 'HTML_TOP_OF_PAGE' ws_layout t_fieldcat it_sort it_events
= t_final.
=========================================== * in w_sort-group will force a page break, while UL will force an under line. Our aim is to get a Page Break for every 15 rows. How to do this? Here it is.
Full Solution:
Add a new field pagebrk in the ALV internal table definition. i.e. in T_FINAL for the above scenario. Modify the field catalog to include this field. (Else you will encounter a short dump) Here is the field catalog for the field pagebrk
line_fieldcat-fieldname = 'PAGEBRK'. line_fieldcat-tabname = 'T_FINAL'. line_fieldcat-no_out = 'X'. APPEND line_fieldcat TO t_fieldcat. line_fieldcat-no_out = ''.
line_fieldcat-no_out makes sure that the field is not shown in the report. Modify the IT_SORT as below. PERFORM LSORT USING 'PERNR' 'T_FINAL' '' ''.
PERFORM LSORT USING 'PAGEBRK' 'T_FINAL' '' '*'. Use the above mentioned form LSORT. Now, before you call the display ALV FM, T_FINAL need to be updated with pagebrk column as below.
SORT t_final by pernr. DESCRIBE TABLE t_final LINES l_tot. l_lin = 15. Initial page record length. l_pag = 1. LOOP AT t_final INTO w_final. IF sy-tabix LE l_tot. IF sy-tabix LE l_lin. w_final-pagebrk = l_pag. MODIFY t_final FROM w_final INDEX sytabix TRANSPORTING pagebrk. ELSE. l_lin = l_lin + 15. Break after 15 records. l_pag = l_pag + 1. w_final-pagebrk = l_pag. MODIFY t_final FROM w_final INDEX sytabix TRANSPORTING pagebrk. ENDIF. ENDIF. ENDLOOP
Below is the output thus obtained