`
zjut_xiongfeng
  • 浏览: 287267 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Printing ALV along with Page numbers

阅读更多

By Joyjit Ghosh, IBM India

Expected Layout of the ALV report (when printing):

Step 1: Display each new document in a new page<?XML:NAMESPACE PREFIX = O />

To achieve this below routine is written to populate the IT_SORT table parameter of ALV function module REUSE_ALV_GRID_DISPLAY. And ALV will automatically insert page break whenever a new document is encountered.
CONSTANTS:     
c_spos        TYPE SLIS_SPOS   VALUE '01',     " Column position
c_up          TYPE SLIS_SOUP   VALUE 'X',      " Sorting order
c_table       TYPE tabname     VALUE 'I_FINAL'," Name of o/p table
c_group       TYPE SLIS_CTRLS  VALUE '*',      " Sorting group
c_fld2        TYPE fieldname   VALUE 'IDCNGA04-IDCN037'." Field name(Document no)
* Prepare sort table
  PERFORM prepare_sort_table CHANGING i_sort[].
FORM prepare_sort_table CHANGING pi_sort TYPE slis_t_sortinfo_alv.
  CLEAR st_sort.
  st_sort-spos      = c_spos.     " Sort sequence
  st_sort-fieldname = c_fld2.     " Document no
  st_sort-tabname   = c_table.    " Table name
  st_sort-up        = c_up.       " Ascending
  st_sort-group     = c_group.    " Group
* Populate sort table
  APPEND st_sort TO pi_sort.
ENDFORM.                    "prepare_sort_table

Step 2: Reset page number to 1 for each new document

From ALV function module we cannot control the page numbers as it will automatically increment the page counter whenever a new page is printed. So to achieve this we have written our custom code within the TOP_OF_PAGE routine.

Register TOP_OF_PAGE routine with the TOP_OF_PAGE event in IT_EVENTS table parameter of the ALV function module.
* Prepare event table
  PERFORM prepare_event_table.
FORM prepare_event_table .
* Populate top-of-page event
  st_event-name = slis_ev_top_of_page.
  st_event-form = slis_ev_top_of_page.
  APPEND st_event TO i_event.
  CLEAR st_event.
ENDFORM.                    " prepare_event_table

Custom code to control the page number in TOP_OF_PAGE routine

Code block marked in bold are used to control the page number. As in our case we are using ALV grid to display the report so during report display page number is not visible. It is only visible in print preview or at the time of printing.

FORM top_of_page.
* Local variable declaration
  STATICS: l_comm  TYPE syucomm.  " Store user command
* Declaration of local variables
  DATA: l_line_size  TYPE sylinsz,           " Line size
        l_line       TYPE slis_listheader,   " Hold list header
        l_currdoc    TYPE idcn037,           " Current doc.
        l_currtabix  TYPE sytabix.           " Current index
* Check for print or print preview
  IF ( sy-ucomm = c_prin OR
  sy-ucomm = c_rnt_prev OR
  sy-ucomm = c_rnt ).
    IF l_comm <> sy-ucomm.
      CLEAR : g_page_cnt.
    ENDIF. " l_comm <> sy-ucomm
*   Store current table index
    l_currtabix  = sy-tabix.
    CLEAR st_final.
*   If current index is 1 then start page numbering from 1
    IF l_currtabix = 1.
*     Read 1st record and store the document no
      READ TABLE i_final INDEX l_currtabix INTO st_final.
      g_prevdoc = st_final-idcnga04-idcn037.
*     Start page numbering from 1
      g_page_cnt =  1.
      g_prevtabix = 1.
    ELSE.
*     Read the table line
      READ TABLE i_final INDEX l_currtabix INTO st_final.
*     Store the current document
      l_currdoc = st_final-idcnga04-idcn037.
*     If the current doc. is same as previou doc.
*     increament the page no, otherwise start it from 1
      IF l_currdoc = g_prevdoc.
*       Increament the page no
        g_page_cnt = g_page_cnt + 1.
      ELSE.
*       Start page from 1
        g_page_cnt =  1.
*       Store current doc. as previous doc.
        g_prevdoc = l_currdoc.
      ENDIF. " l_currdoc = g_prevdoc
    ENDIF. " l_currtabix = 1
  ENDIF. " sy-ucomm = c_prin OR
  IF g_page_cnt = 1.
*   Store the user command
    l_comm = sy-ucomm.
  ENDIF. " g_page_cnt = 1
* Display page no
  IF g_page_cnt > 0 .
*  Store the report width
    l_line_size = sy-linsz.
*  Calculate position
    l_line_size = l_line_size - 10.
*  Display page no
    WRITE AT l_line_size 'Page no:'(021).
*  Calculate position
    l_line_size = l_line_size + 5.
    WRITE AT l_line_size g_page_cnt.
  ENDIF. " g_page_cnt > 0
  REFRESH st_list_top_of_page.
* Populate company name
  CLEAR l_line.
  l_line-typ  = c_typ.
  l_line-info = g_comp_name.
  APPEND l_line TO st_list_top_of_page.
* Populate heading
  CLEAR l_line.
  l_line-typ  = c_typ.
  l_line-info = text-020.
  APPEND l_line TO st_list_top_of_page.
* At the time of printing or print preview display additional info
* on 1st page
  IF g_page_cnt = 1 AND
    ( sy-ucomm = c_prin OR
      sy-ucomm = c_rnt_prev OR
      sy-ucomm = c_rnt ).
    CLEAR l_line.
    l_line-typ  = 'A'.
*   Populate Staff name
    CONCATENATE text-017
                st_final-idcnga04-idcn053
                INTO l_line-info
                SEPARATED BY ':'.
    APPEND l_line TO st_list_top_of_page.
    CLEAR l_line.
    l_line-typ  = 'A'.
*   Populate Accountant
    CONCATENATE text-018
                '______________________'
                INTO l_line-info
                SEPARATED BY ':'.
    APPEND l_line TO st_list_top_of_page.
    CLEAR l_line.
    l_line-typ  = 'A'.
*   Populate Book keeper
    CONCATENATE text-019
                '______________________'
                INTO l_line-info
                SEPARATED BY ':'.
    APPEND l_line TO st_list_top_of_page.
    l_line-typ  = 'A'.
    l_line-info = space.
    APPEND l_line TO st_list_top_of_page.
  ENDIF.
* Display list header
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      i_logo             = space
      it_list_commentary = st_list_top_of_page.
* No sy-subrc check is required
ENDFORM.                    " top_of_page

Step 3: Display report

Display the ALV report using 'REUSE_ALV_GRID_DISPLAY' function module.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = l_prog         " Call back progrm
      it_fieldcat             = i_fieldcat_msg " Field catalog
      is_layout               = st_layout      " Layout
      it_sort                 = i_sort[]       " Sort table
      i_save                  = c_save         " 'A'
      is_variant              = l_variant      " ALV variant
      it_events               = i_event        " ALV events
      is_print                = st_print       " Print parameters
    TABLES
      t_outtab                = i_final        " Output table
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.

Result:

Report is displayed in ALV grid. Note that no page number is displayed. Now press the print preview button

Report is displayed in print preview with page numbers.

Limitations:

  1. For positioning the page number in the report we have to calculate the position based on the list width. As in this case we are using the formula

Page number position = sy-linsz – 10. But if you want you can change it.

  1. In print preview only 1st page number is visible for every document i.e. if a document spreading multiple pages only the 1st page number will be visible. You can see all the page numbers at the time of actual printing.

<!-- google_ad_client = "pub-1086451200925480"; google_alternate_color = "0000FF"; google_ad_width = 336; google_ad_height = 280; google_ad_format = "336x280_as"; google_ad_type = "text"; //2007-04-05: 336 x 280 google_ad_channel = "5227776827"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "008000"; //-->window.google_render_ad();
分享到:
评论

相关推荐

    abap-ALV.rar_ABAP系统ALV_abap_abap开发alv

    描述中提到“ABAP ALV总结,ALV格式,REUSE_ALV_GRID_DISPLAY_LVC函数使用”,这表明我们将重点关注ALV的基本概念、数据格式以及如何通过REUSE_ALV_GRID_DISPLAY_LVC函数来实现ALV的显示。 ALV格式通常涉及如何组织...

    alv使用 alv使用

    data: i_fieldcat_alv type slis_t_fieldcat_alv with header line, i_layout type slis_layout_alv, i_fieldcat type slis_fieldcat_alv, w_repid like sy-repid. start-of-selection. perform getdata. ...

    ALV.rar_SAP_abaP ALV_abap_alv_sap alv

    在SAP系统中,ALV(Accelerated List Viewer)是一种用于数据展示的工具,它提供了标准的表格形式来显示数据库查询结果。ALV是ABAP编程的重要组成部分,它简化了复杂数据的可视化处理。本篇将深入探讨如何通过ABAP...

    [SAP ABAP开发技术总结]ALV详解(Fuction ALV 和OO ALV)

    [SAP ABAP开发技术总结]ALV详解(Fuction ALV 和OO ALV) 图文并茂,详细介绍了Fuction ALV 和OO ALV的相关开发 [SAP ABAP开发技术总结]ALV详解:Function ALV(一) [SAP ABAP开发技术总结]ALV详解:Function ALV...

    ABAP-ALV进阶

    "ABAP-ALV进阶知识点详解" ABAP-ALV进阶是指在SAP系统中使用ABAP语言开发的高级列表查看器(ALV)。ALV是SAP系统中心的列表标准,可以在ABAP程序中进行报表输出。下面是ABAP-ALV进阶的知识点详解: 一、ALV概要 ...

    ABAP OOALV学习文档

    DATA: gt_data TYPE STANDARD TABLE OF sflight WITH EMPTY KEY. ``` 在这个示例中,我们首先定义了容器 (`wcl_container`) 和 ALV 网格 (`wcl_alv`),接着创建了字段目录 (`gt_fieldcat`) 和布局结构 (`gs_layout`...

    SAP ALV总结 ALV总结

    - **定义变量**:在子FORM F_TOP_OF_PAGE中,定义存放表头信息的变量,如用户登录名和生成报表的日期。 - **输出表头数据**:根据定义的变量,使用适当的方式(如CALL METHOD)将表头信息输出到ALV报表的顶部。 3...

    [ABAP]Function实现ALV Table 二:ALV的弹出窗口形式

    在ABAP(Advanced Business Application Programming)中,ALV(ABAP List Viewer)是SAP提供的一种用于显示数据表的标准化接口。本篇我们将深入探讨如何使用Function来实现ALV Table的弹出窗口形式,这对于创建用户...

    SAP ABAP ALV 详解

    例如,使用 REUSE_ALV_COMMENTARY_WRITE 函数可以在 ALV 中输出表头,应在 ALV 的 TOP-OP-PAGE 事件中调用。 ALV 是 SAP 系统中的一个强大工具,提供了丰富的列表输出功能和交互功能,可以满足不同的业务需求。

    ALV For WebDynpro

    在SAP系统中,ALV(Accelerated List Viewer)是一种用于数据展示的强大工具,它能够以表格形式高效地显示大量数据。"ALV for Web Dynpro"是将ALV的功能集成到Web Dynpro应用程序中,使得在Web环境中也能实现丰富的...

    alv abap sap 总结

    在子 FORM(如 F_TOP_OF_PAGE)中,定义变量来存储表头信息,如用户登录名、制表日期等。然后在回调程序中,利用这些变量输出表头。 2. 输入参数的应用: - **排序**:在显示 ALV 的子 FORM 中,定义排序所需的...

    SAP ALV功能总结

    ### SAP ALV功能总结 #### 一、FUNCTION 'REUSE_ALV_GRID_DISPLAY'概述 在SAP系统中,ALV(Application List Viewer)是用于显示列表数据的强大工具,它不仅支持基本的数据展示,还提供了丰富的自定义选项。本文将...

    面向对象的alv 资料

    面向对象的ALV资料 面向对象的ALV资料是SAP List Viewer(ALV)的面向对象的应用,ALV Grid Control是一个灵活的工具,提供了基本功能的列表操作,也可以通过自定义来进行增强。 一、ALV介绍 ALV Grid Control...

    OO ALV 开发 实例 SAP

    面向对象的ALV开发在SAP ABAP环境中是一种先进的数据展示技术,相比于传统的函数模块`REUSE_ALV_GRID_DISPLAY`,面向对象的方式提供了更灵活、更可扩展的解决方案。通过利用`CL_SALV_TABLE`类,开发者可以构建更加...

    OOALV常用功能完整简例

    标题中提及的“OOALV常用功能完整简例”,描述中说明了该简例包含的内容:热键单击、双击、帮助、编辑和自定义工具条等。OOALV是指面向对象的ALV,它是在SAP系统中常用的报表输出组件,用于将数据以表格形式展示。在...

    SAP ALV Grid资料整理 (很全面)

    SAP ALV Grid 资料整理(很全面) SAP ALV Grid 是一种灵活的工具,用于显示列表,并提供了常见的列表操作通用函数,可以通过自定义选项来增强其功能。ALV Grid 控件可以创建非层次的友好交互式报表,是一个基于...

    sap alv 去掉多余按钮

    在SAP系统中,ALV(Application List Viewer)是一种用于展示和处理大量数据的强大工具,它不仅能够以列表形式展示数据,还提供了多种交互功能,如排序、筛选、分组等。然而,在某些应用场景下,ALV界面中预设的一些...

    SAP ABAP ALV分页显示

    ### SAP ABAP ALV 分页显示技术解析 #### 核心知识点:SAP ABAP ALV 分页显示 本篇文章将深入分析一个基于SAP ABAP的ALV(Application List Viewer)分页显示的实现方法。ALV是SAP GUI中用于展示表格数据的一种...

    ALV_GRID介绍

    ### ALV_GRID介绍 #### 一、ALV介绍 ALV Grid Control(ALV = SAP List Viewer)是一种灵活且强大的工具,主要用于展示列表数据。它不仅提供了基础的列表操作功能,还支持高度定制化,使得开发者能够根据需求对其...

    sap abap oo实现ALV

    ### SAP ABAP OO 实现 ALV 的方法与实践 #### 一、背景介绍 在SAP ABAP领域中,ALV(Application List Viewer)是一种常用的技术,用于展示表格形式的数据。传统的ALV实现方式通常采用面向过程的方法,通过调用标准...

Global site tag (gtag.js) - Google Analytics