本来需求是ALV双击某个字段的时候,弹出一个新ALV显示对应的明细,
但是明细字段太多了,弹出来以后也挺难看的。
就想起来SE11进去,查看数据
点明细的时候
于是就debug了下这个按钮
大概扫了一下上下文,也就几行代码比较重要,copy下改改,然后写了个简单demo
REPORT ZLM_ALV_DETAIL .
DATA:ls_spfli TYPE spfli.
DATA:ct_fieldcat TYPE slis_t_fieldcat_alv.
DATA:cs_fieldcat LIKE LINE OF ct_fieldcat.
DATA:lt_fieldcat TYPE lvc_t_fcat.
DATA:is_layout TYPE lvc_s_layo.
DATA:lt_fcat TYPE lvc_t_fcat.
DATA:ls_fcat LIKE LINE OF lt_fcat.
DATA:lt_detail_tab TYPE lvc_t_deta,
ls_detail_tab TYPE lvc_s_deta.
DATA:lt_detail TYPE lvc_t_detm .
DATA:ls_detail LIKE LINE OF lt_detail .FIELD-SYMBOLS: <l_f1> TYPE any.
SELECT SINGLE * FROM spfli INTO ls_spfli.
CLEAR ls_fcat.
CLEAR lt_fcat[].
ls_fcat-fieldname = 'COLUMNTEXT'.
ls_fcat-ref_table = 'LVC_S_DETA'. "Y6DK043061
ls_fcat-key = 'X'.
ls_fcat-seltext = 'Spalte'(102).
ls_fcat-scrtext_s = 'Spalte'(102).
ls_fcat-outputlen = 30.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'VALUE'.
ls_fcat-ref_table = 'LVC_S_DETA'. "Y6DK043061
ls_fcat-seltext = 'Inhalt'(103).
ls_fcat-scrtext_s = 'Inhalt'(103).
ls_fcat-outputlen = 20.
APPEND ls_fcat TO lt_fcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SPFLI'
CHANGING
ct_fieldcat = ct_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
LOOP AT ct_fieldcat INTO cs_fieldcat.
MOVE-CORRESPONDING cs_fieldcat TO ls_fcat.
ls_fcat-seltext = cs_fieldcat-seltext_l.
APPEND ls_fcat TO lt_fieldcat.
ENDLOOP.
LOOP AT lt_fieldcat INTO ls_fcat.
* CHECK ls_fcat-tech = space.
MOVE ls_fcat-seltext TO ls_detail_tab-columntext.
ASSIGN COMPONENT ls_fcat-fieldname
OF STRUCTURE ls_spfli TO <l_f1>.
MOVE <l_f1> TO ls_detail_tab-value.
APPEND ls_detail_tab TO lt_detail_tab.
ENDLOOP.
ls_detail-blockindex = 1.
ls_detail-detailtab = lt_detail_tab[].
APPEND ls_detail to lt_detail.
CALL FUNCTION 'LVC_ITEM_DETAIL'
EXPORTING
* I_TITLE =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
it_fieldcatalog = lt_fcat
is_layout = is_layout
* IMPORTING
* E_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = lt_detail.
效果图:
觉得在ALV双击某行弹出新ALV明细的时候还算实用一些。