在项目中,在处理问题时,通常会有需要修改表数据,我们通常用断点,或者SE16的函数来修改表,这样修改时不太方便,最主要的是不能记录修改日志,不能记录修改数据的历史值,当我们后期发现问题时,不方便追溯问题,下面这个程序可以任意增、删、改自定义表(如需要也可修改标准表),并记录修改的日志,修改人,修改人使用的电脑名称,修改数据的历史值,新值,修改备注说明。
1.程序代码
主程序代码,为代码中的一部份
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
*&********************************************************************* *& PROGRAM NAME : *& Module Name : *& Apply Author : XXX *& Author : *& Started on : %DATE% *& Transaction : *& Program type : Report *& Program ID : *& Program Description : 功能描述。。。。。。 *&*&******************************************************************* *& REVISION LOG * *& * *& LOG# DATE AUTHOR DESCRIPTION * *& ---- ---- ------ ----------- * *& 0001 2017-06-16 XXX Initial Creation *&********************************************************************* REPORT zchange. INCLUDE ztr_alv_table_top. DATA: c_noconv TYPE c ."内部转换 DATA: no_dom TYPE c ."无固定值校验 DATA: gr_more TYPE c ."有更多输入条件 CONSTANTS:split_flg TYPE c VALUE '\'. DATA rowlinen TYPE string. DATA :BEGIN OF gt_table_old OCCURS 0, key TYPE string, conment TYPE string, END OF gt_table_old. DATA gt_table_new LIKE TABLE OF gt_table_old WITH HEADER LINE. FIELD-SYMBOLS <cond> TYPE rsds_where. r_field = 'X'. r_text = ''. c_noconv = 'X'. DATA: opcode_usr_attr(1) TYPE x VALUE 5, terminal TYPE usr41-terminal. CALL 'ThUsrInfo' ID 'OPCODE' FIELD opcode_usr_attr ID 'TERMINAL' FIELD terminal. *DATA:lv_pcname TYPE string. *CALL METHOD cl_gui_frontend_services=>get_computer_name *CHANGING * computer_name = lv_pcname. *CALL METHOD cl_gui_cfw=>update_view. CALL SCREEN 0001 . *&---------------------------------------------------------------------* *& Module STATUS_0001 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_0001 OUTPUT. SET PF-STATUS '0001'. SET TITLEBAR '0001'. PERFORM buildobject . PERFORM buildfiedcat . PERFORM biuldlayout . PERFORM dispalyalv . ENDMODULE. *&---------------------------------------------------------------------* *& Form BUILDOBJECT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM buildobject . IF container IS INITIAL . CREATE OBJECT container EXPORTING container_name = 'CONTAINER' . CREATE OBJECT g_grid EXPORTING i_parent = container . ENDIF . ENDFORM. *&---------------------------------------------------------------------* *& Form BUILDFIEDCAT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM buildfiedcat . IF tabname IS NOT INITIAL AND tab_c = 'X' . REFRESH gt_fieldcat . CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING i_structure_name = tabname CHANGING ct_fieldcat = gt_fieldcat. * IF r_field = 'X' . * LOOP AT gt_fieldcat INTO gs_fieldcat . * gs_fieldcat-coltext = gs_fieldcat-fieldname . * MODIFY gt_fieldcat FROM gs_fieldcat . * ENDLOOP . * ENDIF . DELETE gt_fieldcat WHERE fieldname = 'MANDT'. LOOP AT gt_fieldcat INTO gs_fieldcat. gs_fieldcat-edit = 'X' . IF r_field = 'X' . gs_fieldcat-coltext = gs_fieldcat-fieldname . ENDIF . IF no_dom = 'X'. CLEAR gs_fieldcat-domname. CLEAR gs_fieldcat-ref_table. ENDIF. gs_fieldcat-no_convext = c_noconv. MODIFY gt_fieldcat FROM gs_fieldcat . ENDLOOP . ENDIF . ENDFORM. *&---------------------------------------------------------------------* *& Form BIULDLAYOUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM biuldlayout . IF gs_layout IS INITIAL . gs_layout-sel_mode = 'A' . gs_layout-cwidth_opt = 'X' . * gs_layout-edit = 'X' . ENDIF . ENDFORM. *&---------------------------------------------------------------------* *& Form DISPALYALV *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM dispalyalv . IF <d_ref> IS ASSIGNED AND tab_c = 'X'. CALL METHOD g_grid->set_table_for_first_display EXPORTING * I_BUFFER_ACTIVE = * I_BYPASSING_BUFFER = * I_CONSISTENCY_CHECK = * I_STRUCTURE_NAME = * IS_VARIANT = * I_SAVE = * I_DEFAULT = 'X' is_layout = gs_layout * IS_PRINT = * it_special_groups = gt_sgrp * IT_TOOLBAR_EXCLUDING = * IT_HYPERLINK = * IT_ALV_GRAPHICS = * IT_EXCEPT_QINFO = * IR_SALV_ADAPTER = CHANGING it_outtab = <d_ref> it_fieldcatalog = gt_fieldcat it_sort = gt_sort * IT_FILTER = * EXCEPTIONS * INVALID_PARAMETER_COMBINATION = 1 * PROGRAM_ERROR = 2 * TOO_MANY_LINES = 3 * others = 4 . ENDIF . ENDFORM. *&---------------------------------------------------------------------* *& Module CANC INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE canc INPUT. LEAVE PROGRAM . ENDMODULE. *&---------------------------------------------------------------------* *& Module USER_COMMAND_0001 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0001 INPUT. CASE ok_code . WHEN 'SEARCH' . IF tabname(1) = 'Z' OR tabname(1) = 'Y'. SELECT SINGLE * FROM dd02l WHERE tabname = tabname . IF sy-subrc <> 0 . MESSAGE '表不存在!!' TYPE 'I' . tab_c = '' . EXIT . ELSE . PERFORM search. ENDIF . ELSE . MESSAGE '你不允许修改此表!' TYPE 'E' . ENDIF . WHEN 'TABNAME' . tab_c = '' . CALL FUNCTION 'F4_DD_TABLES' EXPORTING object = tabname IMPORTING result = tabname. WHEN 'COUNT' . tab_c = '' . SELECT SINGLE * FROM dd02l WHERE tabname = tabname . IF sy-subrc <> 0 . MESSAGE '表不存在!!' TYPE 'I' . EXIT . ELSE . CLEAR tbcount . SELECT COUNT( * ) INTO tbcount FROM (tabname) WHERE (where) . MESSAGE i888(sabapdocu) WITH '满足条件的记录有' tbcount '条' . ENDIF . WHEN 'SAVE' . CALL METHOD g_grid->fcode_bouncer . CALL METHOD g_grid->refresh_table_display. UNASSIGN: <d_ref1> . CREATE DATA d_ref1 TYPE TABLE OF (tabname). ASSIGN d_ref1->* TO <d_ref1>. "去除未更改的行 REFRESH gt_table_new. LOOP AT <d_ref> ASSIGNING <dr_line>. PERFORM frm_trans_asign_to_string USING <dr_line> CHANGING gt_table_new. READ TABLE gt_table_old WITH KEY key = gt_table_new-key conment = gt_table_new-conment. IF sy-subrc = 0. " DELETE TABLE gt_table_old FROM gt_table_old. ELSE. APPEND gt_table_new. APPEND <dr_line> TO <d_ref1>. ENDIF. ENDLOOP. CHECK <d_ref1> IS NOT INITIAL. MODIFY (tabname) FROM TABLE <d_ref1> . PERFORM log_action USING 'U'. COMMIT WORK . WHEN 'DEL' . CALL METHOD g_grid->fcode_bouncer . CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' EXPORTING textline1 = '您确定要删除此条数据吗?' titel = '请注意:' IMPORTING answer = answer. IF answer = 'J' . REFRESH: lt_rows,gt_table_new . CLEAR: ls_rows , tabix. CALL METHOD g_grid->get_selected_rows IMPORTING et_index_rows = lt_rows. UNASSIGN: <d_ref1>,<dr_line1>. IF NOT i_alv_cat[] IS INITIAL . CREATE DATA d_ref1 TYPE TABLE OF (tabname). ASSIGN d_ref1->* TO <d_ref1>. CREATE DATA dr_line1 LIKE LINE OF <d_ref1>. ASSIGN dr_line1->* TO <dr_line1>. LOOP AT <d_ref> ASSIGNING <dr_line> . tabix = sy-tabix. LOOP AT lt_rows INTO ls_rows. IF tabix = ls_rows-index . <dr_line1> = <dr_line> . APPEND <dr_line1> TO <d_ref1>. PERFORM frm_trans_asign_to_string USING <dr_line1> CHANGING gt_table_new. APPEND gt_table_new. CLEAR <dr_line1>. ELSE . CONTINUE . ENDIF . ENDLOOP . ENDLOOP . ENDIF . ENDIF . DELETE (tabname) FROM TABLE <d_ref1> . PERFORM log_action USING 'D'. COMMIT WORK . WHEN 'BACK' OR 'CANC' OR 'EXIT'. LEAVE PROGRAM . WHEN 'ZFILT'. WHEN 'ZCONV'. LOOP AT gt_fieldcat ASSIGNING FIELD-SYMBOL(<fs_gf>). <fs_gf>-no_convext = c_noconv. ENDLOOP. g_grid->set_frontend_fieldcatalog( it_fieldcatalog = gt_fieldcat ). CHECK <d_ref1> IS ASSIGNED. g_grid->refresh_table_display( ). WHEN 'ZRAID'. PERFORM buildfiedcat . g_grid->set_frontend_fieldcatalog( it_fieldcatalog = gt_fieldcat ). WHEN 'EXP'. * CALL SCREEN 0002 . DATA selid TYPE rsdynsel-selid. DATA field_tab TYPE TABLE OF rsdsfields. DATA table_tab TYPE TABLE OF rsdstabs. DATA cond_tab TYPE rsds_twhere. DATA dref TYPE REF TO data. CLEAR gr_more. CLEAR where. table_tab = VALUE #( ( prim_tab = tabname ) ). CALL FUNCTION 'FREE_SELECTIONS_INIT' EXPORTING kind = 'T' IMPORTING selection_id = selid TABLES tables_tab = table_tab EXCEPTIONS OTHERS = 4. IF sy-subrc <> 0. EXIT. ENDIF. CALL FUNCTION 'FREE_SELECTIONS_DIALOG' EXPORTING selection_id = selid title = '更多选择' as_window = 'X' IMPORTING where_clauses = cond_tab TABLES fields_tab = field_tab EXCEPTIONS OTHERS = 4. IF sy-subrc <> 0. " LEAVE TO SCREEN 0. EXIT. ENDIF. ASSIGN cond_tab[ tablename = tabname ] TO <cond>. IF sy-subrc <> 0. MESSAGE '未选择筛选条件' TYPE 'S' DISPLAY LIKE 'W'. "LEAVE TO SCREEN 0. EXIT. ELSE. gr_more = 'X'. ENDIF. CHECK gr_more = 'X'. IF tabname(1) = 'Z' OR tabname(1) = 'Y'. PERFORM search. ELSE . MESSAGE '你不允许修改此表!' TYPE 'E' . ENDIF . WHEN 'LOG'. IF tabname IS INITIAL . MESSAGE '请先输入表名' TYPE 'S' DISPLAY LIKE 'W'. EXIT. ENDIF. SELECT * FROM ztrvchange INTO TABLE @DATA(lt_clog) WHERE tabname = @tabname AND criteria = @where. SORT lt_clog . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_structure_name = 'ZTRVCHANGE' it_fieldcat_lvc = VALUE lvc_t_fcat( no_out = 'X' ( fieldname = 'TABNAME' ) ( fieldname = 'CRITERIA' ) ) i_grid_title = 'ZTRTCHANGE操作日志' i_screen_start_column = 1 i_screen_start_line = 10 i_screen_end_column = 120 i_screen_end_line = 30 is_layout_lvc = VALUE lvc_s_layo( cwidth_opt = 'X' ) TABLES t_outtab = lt_clog EXCEPTIONS program_error = 1 OTHERS = 2. ENDCASE . CLEAR ok_code . ENDMODULE. *&---------------------------------------------------------------------* *& Module SEARCH_HELP_VALUES_TABNAME INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE search_help_values_tabname INPUT. ok_code = 'TABNAME' . SUPPRESS DIALOG. ENDMODULE. MODULE search_help_values_where INPUT. DATA: dynpro_values TYPE TABLE OF dynpread, lt_return TYPE TABLE OF ddshretval, field_value LIKE LINE OF dynpro_values. DATA:BEGIN OF ty_tab, indx TYPE ztrt2005-zxh, tabname TYPE ztrtchange_log-tabname, criteria TYPE ztrtchange_log-criteria, act TYPE ztrtchange_log-act, erdat TYPE ztrtchange_log-erdat, erzet TYPE ztrtchange_log-erzet, ernam TYPE ztrtchange_log-ernam, reason TYPE ztrtchange_log-reason, terminal TYPE ztrtchange_log-terminal, times TYPE ztrtchange_log-times, END OF ty_tab, values_tab LIKE TABLE OF ty_tab. CLEAR: field_value, dynpro_values,lt_return. field_value-fieldname = 'TABNAME'. APPEND field_value TO dynpro_values. field_value-fieldname = 'WHERE'. APPEND field_value TO dynpro_values. CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING dyname = 'ZTRTCHANGE' dynumb = '0001' translate_to_upper = 'X' TABLES dynpfields = dynpro_values. field_value = dynpro_values[ 1 ]. where = dynpro_values[ 2 ]-fieldvalue. SELECT DISTINCT tabname ,criteria, act ,erdat ,erzet, ernam,reason,times,terminal FROM ztrtchange_log WHERE tabname = @field_value-fieldvalue AND criteria NE '' INTO CORRESPONDING FIELDS OF TABLE @values_tab . LOOP AT values_tab ASSIGNING FIELD-SYMBOL(<fs>). <fs>-indx = sy-tabix. ENDLOOP. CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = 'CRITERIA' dynprofield = 'WHERE' value_org = 'S' dynpprog = 'ZTRTCHANGE' dynpnr = '0001' TABLES value_tab = values_tab return_tab = lt_return. IF sy-subrc = 0 AND lt_return IS NOT INITIAL. READ TABLE values_tab INTO DATA(ls_tab) WITH KEY indx = lt_return[ 1 ]-fieldval. IF sy-subrc = 0. where = ls_tab-criteria. ENDIF. ENDIF. ENDMODULE. MODULE create_screen_0002 OUTPUT. ENDMODULE. FORM log_action USING p_act. DATA ls_log TYPE ztrtchange_log. DATA lt_log1 TYPE TABLE OF ztrtchange_log1. DATA ls_log1 TYPE ztrtchange_log1. DATA ls_difield TYPE string. GET TIME STAMP FIELD ls_log-times. ls_log-tabname = tabname. ls_log-criteria = where. ls_log-act = p_act. ls_log-erdat = sy-datum.. ls_log-erzet = sy-uzeit. ls_log-ernam = sy-uname. ls_log-terminal = terminal. LOOP AT gt_table_new . ls_log1-times = ls_log-times. ls_log1-table_key = gt_table_new-key. IF p_act = 'U'. READ TABLE gt_table_old WITH KEY key = gt_table_new-key. IF sy-subrc = 0. PERFORM old_new_compare CHANGING gt_table_old-conment gt_table_new-conment ls_difield . ls_log1-content = ls_difield. APPEND ls_log1 TO lt_log1. ls_log1-content = gt_table_old-conment. ls_log1-type = 'O'. APPEND ls_log1 TO lt_log1. ENDIF. ls_log1-content = gt_table_new-conment. ls_log1-type = 'N'. APPEND ls_log1 TO lt_log1. ELSE. * PERFORM old_new_compare CHANGING gt_table_old-conment gt_table_new-conment ls_difield . * ls_log1-content = ls_difield. * APPEND ls_log1 TO lt_log1. ls_log1-type = 'O'. ls_log1-content = gt_table_new-conment. APPEND ls_log1 TO lt_log1. ENDIF. CLEAR :ls_log1,gt_table_old,gt_table_new. ENDLOOP. DATA fields TYPE STANDARD TABLE OF sval. DATA returncode(1). fields = VALUE #( ( tabname = 'ZTRTCHANGE_LOG' fieldname = 'REASON' field_obl = 'X' fieldtext = '修改备注:') ). CALL FUNCTION 'POPUP_GET_VALUES' EXPORTING no_value_check = 'X' popup_title = '请备注修改原因' IMPORTING returncode = returncode TABLES fields = fields EXCEPTIONS error_in_fields = 1 OTHERS = 2. IF returncode = '' AND sy-subrc = 0. ls_log-reason = fields[ 1 ]-value. INSERT ztrtchange_log FROM ls_log. INSERT ztrtchange_log1 FROM TABLE lt_log1. IF p_act = 'U'. MESSAGE i022(bp). ELSE. MESSAGE i817(xc). ENDIF. ELSE. RETURN. ENDIF. COMMIT WORK. ENDFORM. INCLUDE ztr_alv_change_form. |
2.GUI 标题
3.GUI状态
两个GUI状态,0001,001,
4.完整代码
隐藏内容需要支付:¥1
任何问题请联系yan252@163.com
任何问题请联系yan252@163.com
ztrt2005和ztrtchange_log这两张表的资料没有?
RKSE16N_CD_DISPLAY 这个程序有变更日志