*&----------------------------------------------------
*& SHOW SE16N LOG
*&----------------------------------------------------
REPORT ytest015.
*------------------------------------------------------------*
* TABLES
*------------------------------------------------------------*
TYPE-POOLS slis.
TABLES se16n_cd_key.
*------------------------------------------------------------*
* DESC: 表/ 结构 / 视图 / 变量的声明
*------------------------------------------------------------*
DATA :lv_line TYPE i,
lv_sline TYPE char10,
lv_title TYPE lvc_title.
"dynamic table
FIELD-SYMBOLS : <fs> TYPE ANY,
<ws> TYPE ANY,
<fld> TYPE ANY,
<tab> TYPE STANDARD TABLE.
FIELD-SYMBOLS: <value> TYPE x,
<input> TYPE x.
DATA: lt_newtable TYPE REF TO data,
ls_newline TYPE REF TO data,
lt_fldcat TYPE lvc_t_fcat,
wa_fldcat TYPE lvc_s_fcat.
*------------------------------------------------------------*
* DESC:定义所需要的内表
*------------------------------------------------------------*
DATA : lt_zc TYPE se16n_cd_data OCCURS 0 WITH HEADER LINE,
lt_zk TYPE se16n_cd_key OCCURS 0 WITH HEADER LINE.
"alv
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
wa_layout TYPE slis_layout_alv.
*----------------------------------------------------------------------*
* PARAMETERS *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS p_tab TYPE dd02l-tabname OBLIGATORY.
SELECT-OPTIONS: s_id FOR se16n_cd_key-id,
username FOR se16n_cd_key-uname,
date FOR se16n_cd_key-sdate.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON p_tab.
SELECT COUNT(*) FROM dd02l WHERE tabname = p_tab AND as4local = 'A'.
IF sy-subrc <> 0.
MESSAGE e001(zsd_01) WITH '表不存在'.
ELSE.
SELECT SINGLE ddtext INTO lv_title FROM dd02t WHERE tabname = p_tab AND ddlanguage = sy-langu AND as4local = 'A'.
ENDIF.
*----------------------------------------------------------------------*
* Start-of-selection/开始选择事件
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM frm_get_data.
PERFORM frm_process_data.
PERFORM frm_display.
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_get_data.
SELECT * INTO TABLE lt_zk FROM se16n_cd_key WHERE id IN s_id AND tab = p_tab AND uname IN username AND sdate IN date.
IF sy-subrc <> 0.
MESSAGE s001(00) WITH 'No data' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
CHECK sy-subrc = 0.
"get se16n log
SORT lt_zk BY id.
SELECT * INTO TABLE lt_zc FROM se16n_cd_data
FOR ALL ENTRIES IN lt_zk
WHERE id = lt_zk-id .
IF sy-subrc <> 0.
MESSAGE s001(00) WITH 'No data' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. "frm_get_data
*&---------------------------------------------------------------------*
*& Form frm_process_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_process_data.
"1, create dynamic table
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = p_tab "--表结构有变更时,由于显示的最新版本,可能出现数据无法正常显示
i_client_never_display = ''
CHANGING
ct_fieldcat = lt_fldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SE16N_CD_KEY'
i_client_never_display = 'X'
CHANGING
ct_fieldcat = lt_fldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
DELETE lt_fldcat WHERE fieldname = 'ID' OR fieldname = 'TAB' OR fieldname = 'SDATE' OR fieldname = 'STIME' OR fieldname = 'CLNTDEP'.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SE16N_CD_DATA'
i_client_never_display = 'X'
CHANGING
ct_fieldcat = lt_fldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
DELETE lt_fldcat WHERE fieldname = 'TAB' OR fieldname = 'LENGTH' OR fieldname = 'VALUE'.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fldcat
IMPORTING
ep_table = lt_newtable.
ASSIGN lt_newtable->* TO <tab>.
CREATE DATA ls_newline LIKE LINE OF <tab>.
ASSIGN ls_newline->* TO <ws>.
"fill to innertable
LOOP AT lt_zc.
"unicode conversion
CATCH SYSTEM-EXCEPTIONS assign_casting_illegal_cast = 1.
ASSIGN lt_zc-value TO <value> CASTING.
ENDCATCH.
IF sy-subrc = 0.
ASSIGN <ws> TO <input> CASTING.
<input> = <value>.
ENDIF.
CHECK <ws> IS ASSIGNED.
CHECK <ws> IS NOT INITIAL.
ASSIGN COMPONENT 'CHANGE_TYPE' OF STRUCTURE <ws> TO <fld>.
IF <fld> IS ASSIGNED.
<fld> = lt_zc-change_type.
ENDIF.
ASSIGN COMPONENT 'ID' OF STRUCTURE <ws> TO <fld>.
IF <fld> IS ASSIGNED.
<fld> = lt_zc-id.
ENDIF.
ASSIGN COMPONENT 'POS' OF STRUCTURE <ws> TO <fld>.
IF <fld> IS ASSIGNED.
<fld> = lt_zc-pos.
ENDIF.
READ TABLE lt_zk WITH KEY id = lt_zc-id.
ASSIGN COMPONENT 'UNAME' OF STRUCTURE <ws> TO <fld>.
IF <fld> IS ASSIGNED.
<fld> = lt_zk-uname.
ENDIF.
APPEND <ws> TO <tab>.
ENDLOOP.
ENDFORM. "frm_process_data
*&---------------------------------------------------------------------*
*& Form frm_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_display.
DESCRIBE TABLE <tab> LINES lv_line.
lv_sline = lv_line.
CONDENSE lv_sline.
CONCATENATE lv_title ' - (' lv_sline ')' INTO lv_title.
"show alv table
wa_layout-zebra = 'X'.
wa_layout-colwidth_optimize = 'X'. "优化列宽选项是否设置
"FIELD CAT
REFRESH it_fieldcat.
CALL FUNCTION 'LVC_TRANSFER_TO_SLIS'
EXPORTING
it_fieldcat_lvc = lt_fldcat
IMPORTING
et_fieldcat_alv = it_fieldcat
EXCEPTIONS
it_data_missing = 1
it_fieldcat_lvc_missing = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
DELETE it_fieldcat WHERE fieldname = 'MANDT'.
"ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_save = 'A'
i_grid_title = lv_title
it_fieldcat = it_fieldcat
is_layout = wa_layout
TABLES
t_outtab = <tab>
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. "frm_display
*--------------------------------------------------------------------*
*-- text
*DATE 开始日期
*P_TAB 表名
*S_ID 标识
*USERNAME 用户名
SE16N 修改日志查询
最新推荐文章于 2023-08-18 13:06:07 发布