본문 바로가기
ABAP

ALV Top-of-Page

by clode 2023. 2. 21.
728x90
반응형

DATA 선언

  DATA: g_alv TYPE REF TO cl_gui_alv_grid,
    go_splitter type ref to cl_gui_splitter_container,
        g_top type REF TO cl_gui_container,
        g_bottom type ref to cl_gui_container,
        g_dyndoc_id type ref to cl_dd_document.

CLASS 정의

CLASS lcl_event DEFINITION. "정의부
  PUBLIC SECTION.
    METHODS : top_of_page
      FOR EVENT top_of_page OF cl_gui_alv_grid
      IMPORTING e_dyndoc_id.
ENDCLASS.

CLASS lcl_event IMPLEMENTATION. "구현부
  METHOD top_of_page.
    PERFORM set_top_page USING g_dyndoc_id.
  ENDMETHOD.                    "top_of_page
ENDCLASS.          

컨테이너, 그리드 등록

 FORM create_obj .
  CREATE OBJECT g_docking_con
    EXPORTING
      repid     = sy-repid
      dynnr     = sy-dynnr
      extension = 2000.

  CREATE OBJECT g_dyndoc_id
    EXPORTING
      style = 'ALV_GRID'.

* Create Splitter for custom_container
  CREATE OBJECT go_splitter
    EXPORTING
      parent  = g_docking_con
      rows    = 2
      columns = 1.

*Assigning Part 1 for TOP_OF_PAGE
  CALL METHOD go_splitter->get_container
    EXPORTING
      row       = 1
      column    = 1
    RECEIVING
      container = g_top.

* Assigning the Part 2 to GRID
  CALL METHOD go_splitter->get_container
    EXPORTING
      row       = 2
      column    = 1
    RECEIVING
      container = g_bottom.
* Set height for Top of page
  CALL METHOD go_splitter->set_row_height
    EXPORTING
      id     = 1
      height = 20.

  CREATE OBJECT g_alv
    EXPORTING
      i_parent = g_bottom.

ENDFORM.

핸들러 등록

FORM set_handler .
  DATA : g_application  TYPE REF TO lcl_event.

  CREATE OBJECT g_application.
  SET HANDLER g_application->top_of_page FOR G_alv.
ENDFORM.  

ALV 출력

FORM display_alv .
  CALL METHOD g_alv->set_table_for_first_display
    EXPORTING
      is_layout       = gs_layo
    CHANGING
      it_outtab       = gt_tab
      it_fieldcatalog = gt_fcat
      it_sort         = gt_sort. 

  CALL METHOD g_dyndoc_id->initialize_document
    EXPORTING
      background_color = cl_dd_area=>col_textarea.

  CALL METHOD g_alv->list_processing_events
    EXPORTING
      i_event_name = 'TOP_OF_PAGE'
      i_dyndoc_id  = g_dyndoc_id.

ENDFORM.

REFRESH 시 TOP OF PAGE 퍼폼문 이전에 initialize_document 메소드 한번 더 호출해주면 된다.

TOP OF PAGE 이벤트

FORM set_top_page  USING  o_dyndoc_id TYPE REF TO cl_dd_document.
  DATA: dl_text(255) TYPE c.

  CALL METHOD o_dyndoc_id->new_line( ). "한줄바꿈
  CALL METHOD o_dyndoc_id->new_line( ). "한줄바꿈

  CALL METHOD g_dyndoc_id->add_gap
    EXPORTING
      width = 30.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = '영업조직 :'
      sap_style    = cl_dd_area=>key
      sap_fontsize = cl_dd_area=>large
      sap_color    = cl_dd_area=>list_normal. "list_heading_int 민트색.

  CLEAR: dl_text.
  dl_text = s_vkorg-low.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = dl_text
      sap_style    = cl_dd_area=>key
      sap_fontsize = cl_dd_area=>large
      sap_color    = cl_dd_area=>list_normal.


*-------------------------------------------
  CALL METHOD o_dyndoc_id->new_line( ).

  CALL METHOD g_dyndoc_id->add_gap
    EXPORTING
      width = 30.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = '고객 :'
      sap_style    = cl_dd_area=>key
      sap_fontsize = cl_dd_area=>large
      sap_color    = cl_dd_area=>list_normal.

  CLEAR: dl_text.
  dl_text = s_kunnr-low.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = dl_text
      sap_style    = cl_dd_area=>key
      sap_fontsize = cl_dd_area=>large
      sap_color    = cl_dd_area=>list_normal.

  IF s_kunnr-high IS NOT INITIAL.
    CALL METHOD o_dyndoc_id->add_text
      EXPORTING
        text         = '~'
        sap_style    = cl_dd_area=>key
        sap_fontsize = cl_dd_area=>large
        sap_color    = cl_dd_area=>list_normal.

    CLEAR: dl_text.

    dl_text = s_kunnr-high.

    CALL METHOD o_dyndoc_id->add_text
      EXPORTING
        text         = dl_text
        sap_style    = cl_dd_area=>key
        sap_fontsize = cl_dd_area=>large
        sap_color    = cl_dd_area=>list_normal.
  ENDIF.

* --------------------------------------------
* 이거 안해주면 안보임
  CALL METHOD g_dyndoc_id->display_document
    EXPORTING
      reuse_control = 'X'
      parent        = g_top.


ENDFORM.
728x90
반응형

'ABAP' 카테고리의 다른 글

ALV Drop down list  (0) 2023.02.21
Working day function  (0) 2023.02.21
ALV 특정 Cell EDIT  (0) 2023.02.21
ALV Data changed Event  (0) 2023.02.20
ALV 툴바 버튼 Add & Exclude  (0) 2023.02.20

댓글