实现ALV的TOP_OF_PAGE的两种方法(二)

非HTML控制TOP_OF_PAGE的方法,这种方法稍微复杂一点,主要有以下几个步骤(1,2,3)
1、FORM frm_alv_output .
  PERFORM frm_build_fcat CHANGING it_fcat.
  CLEAR: is_layo.
  is_layo-zebra = 'X'.
  PERFORM frm_build_events CHANGING it_events.   “调用  frm_build_events  
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      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 = c_end_of_page
      is_layout_lvc               = is_layo
      it_fieldcat_lvc             = it_fcat
*     I_DEFAULT                   = 'X'
      i_save                      = 'X'
      it_events                   = it_events  ”方法中调用 it_events 
*     I_HTML_HEIGHT_TOP           =
*     I_HTML_HEIGHT_END           =
    TABLES
      t_outtab                    = it_result
    EXCEPTIONS
      program_error               = 1
      OTHERS                      = 2.
ENDFORM.                    " FRM_ALV_OUTPUT


2、FORM frm_build_events  CHANGING pt_events TYPE slis_t_event.
  DATA: ls_events TYPE slis_alv_event.


  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = pt_events
    EXCEPTIONS
      list_type_wrong = 1
      OTHERS          = 2.


* 为alv添加top_of_page
  CLEAR ls_events.
  READ TABLE pt_events INTO ls_events WITH KEY name = slis_ev_top_of_page.
  IF sy-subrc = 0.
    MOVE c_top_of_page TO ls_events-form.
    MODIFY pt_events FROM ls_events INDEX sy-tabix.
  ELSE.
    ls_events-form = c_top_of_page.
    ls_events-name = c_top_of_page.
    APPEND ls_events TO pt_events.
  ENDIF.


* 为alv添加end_of_page
  CLEAR ls_events.
  READ TABLE pt_events INTO ls_events WITH KEY name = slis_ev_end_of_list.
  IF sy-subrc = 0.
    MOVE c_end_of_page TO ls_events-form.
    MODIFY pt_events FROM ls_events INDEX sy-tabix.
  ELSE.
    ls_events-form = c_end_of_page.
    ls_events-name = c_end_of_page.
    APPEND ls_events TO pt_events.
  ENDIF.




ENDFORM.                    " FRM_BUILD_EVENTS
3、FORM frm_top_of_page.
  DATA: ls_header TYPE slis_listheader,
        lt_header TYPE slis_t_listheader.
  DATA: l_str TYPE string,
        l_bukr TYPE string.
  CLEAR: ls_header.
  REFRESH: lt_header.
*---处理屏幕数据,作为表头--------------


*----处理ALV表头期间输出
  CLEAR: l_str,l_bukr.


***公司名称
  SELECT SINGLE butxt INTO l_bukr
    FROM t001
    WHERE bukrs = p_rbukrs.


  CONCATENATE p_ryear
              '年度'
              p_monat
              '月'
              INTO l_str.


*---------------------------------------
  ls_header-typ = 'S'.
  ls_header-info = l_bukr.
  APPEND ls_header TO lt_header.
  CLEAR ls_header.
  ls_header-typ = 'S'.
  ls_header-info = '损益表'.
  APPEND ls_header TO lt_header.
  ls_header-typ = 'S'.
  ls_header-info = l_str.
  APPEND ls_header TO lt_header.
  ls_header-typ = 'S'.
  ls_header-info = '(除特别注明外,金额单位均为人民币元)'.
  APPEND ls_header TO lt_header.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = lt_header
*     I_LOGO             =
*     I_END_OF_LIST_GRID =
      i_alv_form         = 'X'.


ENDFORM.                    "frm_top_of_page
*&---------------------------------------------------------------------*
*&      Form  frm_end_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_end_of_page.
  DATA: ls_header TYPE slis_listheader,
        lt_header TYPE slis_t_listheader.
  DATA: l_str TYPE string.
  CLEAR: ls_header.
  REFRESH: lt_header.


  CONCATENATE '法定代表人____________'
              '   '
              '主管会计工作负责人____________'
              '   '
              '会计机构负责人___________'
              INTO l_str.


*---------------------------------------
  ls_header-typ = 'S'.
  ls_header-info = '后附财务报表附注为财务报表的组成部分'.
  APPEND ls_header TO lt_header.
  CLEAR ls_header.
  ls_header-typ = 'S'.
  ls_header-info = l_str.
  APPEND ls_header TO lt_header.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = lt_header
*     I_LOGO             =
*     I_END_OF_LIST_GRID =
      i_alv_form         = 'X'.
ENDFORM.                    "frm_end_of_page

你可能感兴趣的:(SAP&ALV)