简介
有时候报表展示时需要有下钻功能,即双击ALV某行数据,展示出对应的明细数据,实现的方式大约如下:
(1). CALL SCREEN + 内嵌ALV
(2). SALV
(3). POPUP 功能的 ALV函数
(4). …
以上的实现方式,都固定了明细界面的大小。本文介绍了一种可以调整明细窗口大小的用例,代码如下
代码
*&---------------------------------------------------------------------*
*& Report YTESTZXH
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ytestzxh.
DATA lt_fieldcat_lvc TYPE lvc_t_fcat.
DATA ls_layout TYPE lvc_s_layo.
DATA item TYPE TABLE OF vbap.
TABLES:vbak.
SELECT-OPTIONS: s FOR vbak-vbeln.
CLASS lcl_event DEFINITION.
PUBLIC SECTION.
METHODS: handle_close
FOR EVENT close OF cl_gui_dialogbox_container
IMPORTING sender.
ENDCLASS.
CLASS lcl_event IMPLEMENTATION.
METHOD handle_close.
CALL METHOD sender->set_visible
EXPORTING
visible = space.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
SELECT vbeln,erdat FROM vbak INTO TABLE @DATA(lt_alv) UP TO 10 ROWS.
PERFORM frm_set_fieldcat:
USING 'VBELN' 12 '单号' '' CHANGING lt_fieldcat_lvc,
USING 'ERDAT' 12 '日期' '' CHANGING lt_fieldcat_lvc.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'FRM_PF_STATUS_ALV'
i_callback_user_command = 'FRM_USER_COMMAND'
is_layout_lvc = ls_layout
it_fieldcat_lvc = lt_fieldcat_lvc
i_save = 'A'
TABLES
t_outtab = lt_alv
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
FORM frm_pf_status_alv USING p_extab TYPE slis_t_extab.
SET PF-STATUS 'ZZZ'.
ENDFORM.
FORM frm_user_command USING iv_ucomm TYPE sy-ucomm
is_selfield TYPE slis_selfield.
DATA:
sub_grid TYPE REF TO cl_gui_alv_grid,
sub_box TYPE REF TO cl_gui_dialogbox_container.
CASE iv_ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN '&IC1'.
IF sub_grid IS INITIAL..
DATA lt_fieldcat_lvc TYPE lvc_t_fcat.
DATA(vbeln) = CONV vbeln( is_selfield-value ).
SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE @item WHERE vbeln = @vbeln.
PERFORM frm_set_fieldcat:
USING 'VBELN' 10 '单号' '' CHANGING lt_fieldcat_lvc,
USING 'POSNR' 10 '行项目' '' CHANGING lt_fieldcat_lvc,
USING 'MATNR' 10 '物料' '' CHANGING lt_fieldcat_lvc.
CREATE OBJECT sub_box
EXPORTING
top = 80
left = 100
lifetime = cntl_lifetime_dynpro
caption = '明细'
width = 80
height = 20.
sub_grid = NEW cl_gui_alv_grid( sub_box ).
DATA(gt_event_item) = NEW lcl_event( ).
SET HANDLER gt_event_item->handle_close FOR sub_box. "弹出窗口关闭
CALL METHOD sub_grid->set_table_for_first_display
EXPORTING
i_save = 'A'
CHANGING
it_outtab = item "==**此处需要设置全局变量 否则对明细表排序时 可能会导致DUMP**==
it_fieldcatalog = lt_fieldcat_lvc.
ENDIF.
ENDCASE.
ENDFORM.
FORM frm_set_fieldcat USING iv_fieldname TYPE c
iv_len TYPE i
iv_text TYPE c
iv_edit TYPE c
CHANGING et_fieldcat_lvc TYPE lvc_t_fcat.
DATA ls_fieldcat TYPE lvc_s_fcat.
ls_fieldcat-fieldname = iv_fieldname.
ls_fieldcat-outputlen = iv_len.
ls_fieldcat-reptext = iv_text.
ls_fieldcat-edit = iv_edit.
ls_fieldcat-f4availabl = 'X'.
APPEND ls_fieldcat TO et_fieldcat_lvc.
ENDFORM.
效果