在報表列印時,有時可能會因為加入 NEW-PAGE,或是因為輸出字串過長換行,造成報表總頁數無法透過 "總筆數 / 每頁可顯示行數" 來進行計算可能的頁數時,則可透過下面語法進行取得 Total Page.
主要的語法是透過 SYST Structure 中的 SY-PAGNO, SY-INDEX 以及 SY-LISEL 來達成,但這三種語法並不能計算出總頁數。
REPORT Z_ABAP_21_WRITE_TTL_PAGE NO STANDARD PAGE HEADING LINE-SIZE 40 LINE-COUNT 20.
TOP-OF-PAGE.
WRITE: 'PAGE: ', SY-PAGNO.
START-OF-SELECTION.
DO 100 TIMES.
WRITE: / SY-INDEX.
ENDDO.
END-OF-SELECTION.
REPORT Z_ABAP_21_WRITE_TTL_PAGE NO STANDARD PAGE HEADING LINE-SIZE 40 LINE-COUNT 20.
DATA:
G_LAST_PAGE LIKE SY-PAGNO,
G_LAST_PAGE_C(10) TYPE C.
TOP-OF-PAGE.
WRITE: 'PAGE: ', SY-PAGNO, '/ [#TOTAL_PAGE$]'.
G_LAST_PAGE = SY-PAGNO.
START-OF-SELECTION.
DO 100 TIMES.
WRITE: / SY-INDEX.
ENDDO.
DO G_LAST_PAGE TIMES.
READ LINE 1 OF PAGE SY-INDEX .
WRITE G_LAST_PAGE TO G_LAST_PAGE_C NO-GROUPING.
CONDENSE G_LAST_PAGE_C.
REPLACE '[#TOTAL_PAGE$]' WITH G_LAST_PAGE_C INTO SY-LISEL.
MODIFY CURRENT LINE.
ENDDO.
END-OF-SELECTION.
沒有留言:
張貼留言