From d7036829cef736f2d628410f7eff449e5535ed7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20P=C4=99giel?= Date: Tue, 19 Mar 2024 07:50:55 +0100 Subject: [PATCH] Quick Fix and Pragma for check 103 (#1136) Co-authored-by: abaplint[bot] <24845621+abaplint[bot]@users.noreply.github.com> Co-authored-by: Lars Hvam --- abaplint.json | 3 +- src/checks/zcl_aoc_check_103.clas.abap | 103 ++++++++- .../zcl_aoc_check_103.clas.locals_imp.abap | 218 ++++++++++++++++++ src/checks/zcl_aoc_check_103.clas.xml | 150 ++++++++++++ 4 files changed, 463 insertions(+), 11 deletions(-) create mode 100644 src/checks/zcl_aoc_check_103.clas.locals_imp.abap diff --git a/abaplint.json b/abaplint.json index 7f87dfde..97abcd22 100644 --- a/abaplint.json +++ b/abaplint.json @@ -232,7 +232,8 @@ "checkForms": true, "ignoreTestClasses": false, "exclude": [ - "zcl_aoc_check_69" + "zcl_aoc_check_69", + "zcl_aoc_check_103" ] }, "method_parameter_names": { diff --git a/src/checks/zcl_aoc_check_103.clas.abap b/src/checks/zcl_aoc_check_103.clas.abap index aa734007..0992c0d7 100644 --- a/src/checks/zcl_aoc_check_103.clas.abap +++ b/src/checks/zcl_aoc_check_103.clas.abap @@ -4,30 +4,55 @@ CLASS zcl_aoc_check_103 DEFINITION CREATE PUBLIC. PUBLIC SECTION. + CONSTANTS: BEGIN OF gc_code, - table_has_replacement_object TYPE sci_errc VALUE '001', + table_has_replacement_object TYPE sci_errc VALUE '001', + table_has_replacement_proposal TYPE sci_errc VALUE '002', END OF gc_code. - + CONSTANTS gc_pseudo_comment TYPE sci_pcom VALUE 'AOC_103_SELECT_OK' ##NO_TEXT. + TYPES: BEGIN OF ty_replace_proposal, + from TYPE tabname, + sequence TYPE n LENGTH 1, + to TYPE tabname, + oss_note TYPE c LENGTH 10, + END OF ty_replace_proposal, + tty_proposals TYPE SORTED TABLE OF ty_replace_proposal WITH UNIQUE KEY from sequence. + TYPES: BEGIN OF ty_message_detail, + tabname TYPE tabname, + replacement_object TYPE tabname, + proposed_table TYPE tabname, + message_code TYPE sci_errc, + oss_note TYPE c LENGTH 10, + END OF ty_message_detail. + CLASS-DATA gt_replace_proposalst TYPE tty_proposals READ-ONLY. METHODS constructor. METHODS check REDEFINITION. + CLASS-METHODS class_constructor. PRIVATE SECTION. - CLASS-DATA gt_proxy_objects TYPE HASHED TABLE OF dd02v WITH UNIQUE KEY tabname. + CLASS-DATA gt_proxy_objects TYPE HASHED TABLE OF dd02v WITH UNIQUE KEY tabname. METHODS get_tokens_for_statement IMPORTING is_statement TYPE sstmnt it_tokens TYPE stokesx_tab RETURNING VALUE(rt_tokens) TYPE stokesx_tab. METHODS get_table_info - IMPORTING iv_tabname TYPE tabname + IMPORTING iv_tabname TYPE tabname RETURNING VALUE(rs_table_info) TYPE dd02v. + METHODS get_message_detail + IMPORTING + iv_tabname TYPE tabname + iv_replacement_object TYPE dd02v-viewref + RETURNING + VALUE(rs_message_detail) TYPE ty_message_detail. ENDCLASS. CLASS zcl_aoc_check_103 IMPLEMENTATION. METHOD constructor. + DATA: lv_message_text TYPE zcl_aoc_super=>ty_scimessage_text. super->constructor( ). version = '001'. @@ -39,8 +64,17 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION. enable_rfc( ). + + insert_scimessage( iv_code = gc_code-table_has_replacement_object - iv_text = 'Table/View &1 has replacement object &2'(m01) ). + iv_text = 'Table/View &1 has replacement object &2'(m01) + iv_pcom = gc_pseudo_comment ). + + insert_scimessage( iv_code = gc_code-table_has_replacement_proposal + iv_text = 'Table/View &1 has replacement object &2. Consider using &3 instead. OSS Note &4'(m02) + iv_pcom = gc_pseudo_comment ). + + ENDMETHOD. METHOD check. @@ -49,11 +83,16 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION. DATA lt_statement_tokens TYPE stokesx_tab. DATA ls_next LIKE LINE OF lt_statement_tokens. DATA ls_table_info TYPE dd02v. + DATA lv_position TYPE int4. + DATA lv_detail TYPE xstring. + DATA lv_message_detail TYPE ty_message_detail. + DATA lt_source TYPE string_table. FIELD-SYMBOLS LIKE LINE OF io_scan->statements. FIELD-SYMBOLS LIKE LINE OF io_scan->tokens. + FIELD-SYMBOLS TYPE slevel. LOOP AT io_scan->statements ASSIGNING . - + lv_position = sy-tabix. READ TABLE io_scan->tokens ASSIGNING INDEX -from. IF sy-subrc <> 0. CONTINUE. @@ -74,20 +113,42 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION. IF sy-subrc <> 0. CONTINUE. ENDIF. - lv_tabname = ls_next-str. + lv_tabname = ls_next-str. ls_table_info = get_table_info( lv_tabname ). + + IF ls_table_info-viewref IS NOT INITIAL AND ls_table_info-viewref <> space. lv_include = io_scan->get_include( -level ). + + READ TABLE io_scan->levels ASSIGNING WITH KEY name = lv_include. + IF sy-subrc = 0. + lt_source = get_source( ). + ENDIF. + + lv_detail = lcl_quickfix=>get_quick_fixes( iv_current_tab_name = lv_tabname + iv_new_tab_name = ls_table_info-viewref + iv_include = lv_include + iv_col = ls_next-col + iv_source = lt_source + iv_line = ls_next-row ). + + lv_message_detail = get_message_detail( iv_tabname = lv_tabname + iv_replacement_object = ls_table_info-viewref ). inform( p_sub_obj_name = lv_include p_line = -row p_column = -col + p_position = lv_position p_kind = mv_errty p_test = myname - p_param_1 = lv_tabname - p_param_2 = ls_table_info-viewref - p_code = gc_code-table_has_replacement_object ). + p_param_1 = lv_message_detail-tabname + p_param_2 = lv_message_detail-replacement_object + p_param_3 = lv_message_detail-proposed_table + p_param_4 = lv_message_detail-oss_note + p_code = lv_message_detail-message_code + p_suppress = gc_pseudo_comment + p_detail = lv_detail ). ENDIF. @@ -128,4 +189,26 @@ CLASS zcl_aoc_check_103 IMPLEMENTATION. ENDIF. INSERT rs_table_info INTO TABLE gt_proxy_objects. ENDMETHOD. + + METHOD class_constructor. + gt_replace_proposalst = lcl_quickfix=>build_proposals_list( ). + ENDMETHOD. + + + METHOD get_message_detail. + DATA lv_proposals TYPE ty_replace_proposal. + + READ TABLE gt_replace_proposalst INTO lv_proposals WITH KEY from = iv_tabname sequence = 1. + IF sy-subrc = 0. + rs_message_detail-message_code = gc_code-table_has_replacement_proposal. + rs_message_detail-proposed_table = lv_proposals-to. + rs_message_detail-oss_note = lv_proposals-oss_note. + ELSE. + rs_message_detail-message_code = gc_code-table_has_replacement_object. + ENDIF. + rs_message_detail-tabname = iv_tabname. + rs_message_detail-replacement_object = iv_replacement_object. + + ENDMETHOD. + ENDCLASS. diff --git a/src/checks/zcl_aoc_check_103.clas.locals_imp.abap b/src/checks/zcl_aoc_check_103.clas.locals_imp.abap new file mode 100644 index 00000000..4ca9dfe8 --- /dev/null +++ b/src/checks/zcl_aoc_check_103.clas.locals_imp.abap @@ -0,0 +1,218 @@ +*"* use this source file for the definition and implementation of +*"* local helper classes, interface definitions and type +*"* declarations + +DEFINE add_replacement_proposal. + CLEAR lv_proposal. + lv_proposal-from = &1. + lv_proposal-sequence = &2. + lv_proposal-to = &3. + lv_proposal-oss_note = &4. + INSERT lv_proposal INTO TABLE rt_proposals. +END-OF-DEFINITION. + +CLASS lcl_quickfix DEFINITION FINAL. + + PUBLIC SECTION. + CLASS-METHODS get_quick_fixes + IMPORTING + iv_current_tab_name TYPE tabname + iv_new_tab_name TYPE tabname + iv_include TYPE program + iv_source TYPE string_table + iv_line TYPE i + iv_col TYPE token_col + RETURNING + VALUE(rv_qf_xstring) TYPE xstring. + + CLASS-METHODS build_proposals_list RETURNING VALUE(rt_proposals) TYPE zcl_aoc_check_103=>tty_proposals. + PROTECTED SECTION. + + PRIVATE SECTION. + CLASS-METHODS add_new_quickfix + IMPORTING + iv_current_tab_name TYPE tabname + iv_quickfixes TYPE REF TO object + iv_context TYPE any + iv_proposal TYPE zcl_aoc_check_103=>ty_replace_proposal. + +ENDCLASS. + +CLASS lcl_quickfix IMPLEMENTATION. + + + METHOD get_quick_fixes. + DATA: lv_quickfixes TYPE REF TO object. + DATA: lo_context TYPE REF TO object. + DATA: lo_context_interface TYPE REF TO data. + DATA: lv_quickfix TYPE REF TO object. + DATA: lv_quickfix_pragma TYPE REF TO object. + DATA: lv_column TYPE i. + FIELD-SYMBOLS: TYPE any. + FIELD-SYMBOLS: TYPE zcl_aoc_check_103=>ty_replace_proposal. + + CALL METHOD ('CL_CI_QUICKFIX_CREATION')=>('CREATE_QUICKFIX_ALTERNATIVES') + RECEIVING + p_quickfix_alternatives = lv_quickfixes. + + + lv_column = iv_col. + CALL METHOD ('CL_CI_QUICKFIX_ABAP_CONTEXT')=>('CREATE_FROM_INCLUDE') + EXPORTING + p_include = iv_include + p_source = iv_source + p_line = iv_line + p_col = lv_column + RECEIVING + p_context = lo_context. + + CREATE DATA lo_context_interface TYPE REF TO ('IF_CI_QUICKFIX_ABAP_CONTEXT'). + ASSIGN lo_context_interface->* TO . + ?= lo_context. + + LOOP AT zcl_aoc_check_103=>gt_replace_proposalst ASSIGNING WHERE from = iv_current_tab_name. + add_new_quickfix( iv_current_tab_name = iv_current_tab_name + iv_quickfixes = lv_quickfixes + iv_context = + iv_proposal = ). + ENDLOOP. + CALL METHOD lv_quickfixes->('CREATE_QUICKFIX') + RECEIVING + p_quickfix = lv_quickfix_pragma. + + CALL METHOD lv_quickfix_pragma->('IF_CI_QUICKFIX_ABAP_ACTIONS~ADD_PSEUDO_COMMENT') + EXPORTING + p_pseudo_comment = zcl_aoc_check_103=>gc_pseudo_comment + p_context = . + + TRY. + CALL METHOD lv_quickfixes->('EXPORT_TO_XSTRING') + RECEIVING + p_detail = rv_qf_xstring. + CATCH cx_root. + RETURN. + ENDTRY. + ENDMETHOD. + + METHOD add_new_quickfix. + + DATA lv_quickfix TYPE REF TO object. + DATA lv_quickfix_code TYPE c LENGTH 10. + DATA lv_current_tab_for_msg TYPE sy-msgv1. + DATA lv_new_tab_for_msg TYPE sy-msgv2. + + + "Each quick-fix should have a unique code + CONCATENATE '001_' iv_proposal-sequence INTO lv_quickfix_code. + + CALL METHOD iv_quickfixes->('CREATE_QUICKFIX') + EXPORTING + p_quickfix_code = lv_quickfix_code + RECEIVING + p_quickfix = lv_quickfix. + CALL METHOD lv_quickfix->('IF_CI_QUICKFIX_ABAP_ACTIONS~REPLACE_BY') + EXPORTING + p_new_code = iv_proposal-to + p_context = iv_context. + + CALL METHOD lv_quickfix->('IF_CI_QUICKFIX_SINGLE~ENABLE_AUTOMATIC_EXECUTION'). + CONCATENATE ' ' iv_current_tab_name INTO lv_current_tab_for_msg RESPECTING BLANKS. + CONCATENATE ' ' iv_proposal-to INTO lv_new_tab_for_msg RESPECTING BLANKS. + CALL METHOD lv_quickfix->('IF_CI_QUICKFIX_SINGLE~ADD_DOCU_FROM_MSGCLASS') + EXPORTING + p_msg_class = '00' + p_msg_number = '001' + p_msg_parameter1 = 'Replace'(m03) + p_msg_parameter2 = lv_current_tab_for_msg + p_msg_parameter3 = ' with'(m04) + p_msg_parameter4 = lv_new_tab_for_msg. + + ENDMETHOD. + + + + METHOD build_proposals_list. + DATA: lv_proposal TYPE zcl_aoc_check_103=>ty_replace_proposal. + add_replacement_proposal 'MARC' 1 'V_MARC_MD' '2206980'. + add_replacement_proposal 'MARC' 2 'NSDM_MIG_MARC' '2206980'. + add_replacement_proposal 'MARD' 1 'V_MARD_MD' '2206980'. + add_replacement_proposal 'MARD' 2 'NSDM_MIG_MARD' '2206980'. + add_replacement_proposal 'MKPF' 1 'NSDM_MIG_MKPF' '2206980'. + add_replacement_proposal 'MSEG' 1 'NSDM_MIG_MSEG' '2206980'. + add_replacement_proposal 'MCHB' 1 'V_MCHB_MD' '2206980'. + add_replacement_proposal 'MCHB' 2 'NSDM_MIG_MCHB' '2206980'. + add_replacement_proposal 'MKOL' 1 'V_MKOL_MD' '2206980'. + add_replacement_proposal 'MKOL' 2 'NSDM_MIG_MKOL' '2206980'. + add_replacement_proposal 'MSLB' 1 'V_MSLB_MD' '2206980'. + add_replacement_proposal 'MSLB' 2 'NSDM_MIG_MSLB' '2206980'. + add_replacement_proposal 'MSKA' 1 'V_MSKA_MD' '2206980'. + add_replacement_proposal 'MSKA' 2 'NSDM_MIG_MSKA' '2206980'. + add_replacement_proposal 'MSSA' 1 'NSDM_MIG_MSSA' '2206980'. + add_replacement_proposal 'MSPR' 1 'V_MSPR_MD' '2206980'. + add_replacement_proposal 'MSPR' 2 'NSDM_MIG_MSPR' '2206980'. + add_replacement_proposal 'MSSL' 1 'NSDM_MIG_MSSL' '2206980'. + add_replacement_proposal 'MSSQ' 1 'NSDM_MIG_MSSQ' '2206980'. + add_replacement_proposal 'MSKU' 1 'V_MSKU_MD' '2206980'. + add_replacement_proposal 'MSKU' 2 'NSDM_MIG_MSKU' '2206980'. + add_replacement_proposal 'MSTB' 1 'NSDM_MIG_MSTB' '2206980'. + add_replacement_proposal 'MSTE' 1 'NSDM_MIG_MSTE' '2206980'. + add_replacement_proposal 'MSTQ' 1 'NSDM_MIG_MSTQ' '2206980'. + add_replacement_proposal 'MCSD' 1 'MCSD_MD' '2206980'. + add_replacement_proposal 'MCSD' 2 'NSDM_MIG_MCSD' '2206980'. + add_replacement_proposal 'MCSS' 1 'MCSS_MD' '2206980'. + add_replacement_proposal 'MCSS' 2 'NSDM_MIG_MCSS' '2206980'. + add_replacement_proposal 'MSCD' 1 'MSCD_MD' '2206980'. + add_replacement_proposal 'MSCD' 2 'NSDM_MIG_MSCD' '2206980'. + add_replacement_proposal 'MSCS' 1 'MSCS_MD' '2206980'. + add_replacement_proposal 'MSCS' 2 'NSDM_MIG_MSCS' '2206980'. + add_replacement_proposal 'MSFD' 1 'MSFD_MD' '2206980'. + add_replacement_proposal 'MSFD' 2 'NSDM_MIG_MSFD' '2206980'. + add_replacement_proposal 'MSFS' 1 'MSFS_MD' '2206980'. + add_replacement_proposal 'MSFS' 2 'NSDM_MIG_MSFS' '2206980'. + add_replacement_proposal 'MSID' 1 'MSID_MD' '2206980'. + add_replacement_proposal 'MSID' 2 'NSDM_MIG_MSID' '2206980'. + add_replacement_proposal 'MSIS' 1 'MSIS_MD' '2206980'. + add_replacement_proposal 'MSIS' 2 'NSDM_MIG_MSIS' '2206980'. + add_replacement_proposal 'MSRD' 1 'MSRD_MD' '2206980'. + add_replacement_proposal 'MSRD' 2 'NSDM_MIG_MSRD' '2206980'. + add_replacement_proposal 'MSRS' 1 'MSRS_MD' '2206980'. + add_replacement_proposal 'MSRS' 2 'NSDM_MIG_MSRS' '2206980'. + add_replacement_proposal 'MARCH' 1 'NSDM_MIG_MARCH' '2206980'. + add_replacement_proposal 'MARDH' 1 'NSDM_MIG_MARDH' '2206980'. + add_replacement_proposal 'MCHBH' 1 'NSDM_MIG_MCHBH' '2206980'. + add_replacement_proposal 'MKOLH' 1 'NSDM_MIG_MKOLH' '2206980'. + add_replacement_proposal 'MSLBH' 1 'NSDM_MIG_MSLBH' '2206980'. + add_replacement_proposal 'MSKAH' 1 'NSDM_MIG_MSKAH' '2206980'. + add_replacement_proposal 'MSSAH' 1 'NSDM_MIG_MSSAH' '2206980'. + add_replacement_proposal 'MSPRH' 1 'NSDM_MIG_MSPRH' '2206980'. + add_replacement_proposal 'MSSQH' 1 'NSDM_MIG_MSSQH' '2206980'. + add_replacement_proposal 'MSKUH' 1 'NSDM_MIG_MSKUH' '2206980'. + add_replacement_proposal 'MSTBH' 1 'NSDM_MIG_MSTBH' '2206980'. + add_replacement_proposal 'MSTEH' 1 'NSDM_MIG_MSTEH' '2206980'. + add_replacement_proposal 'MSTQH' 1 'NSDM_MIG_MSTQH' '2206980'. + add_replacement_proposal 'MCSDH' 1 'NSDM_MIG_MCSDH' '2206980'. + add_replacement_proposal 'MCSSH' 1 'NSDM_MIG_MCSSH' '2206980'. + add_replacement_proposal 'MSCDH' 1 'NSDM_MIG_MSCDH' '2206980'. + add_replacement_proposal 'MSFDH' 1 'NSDM_MIG_MSFDH' '2206980'. + add_replacement_proposal 'MSIDH' 1 'NSDM_MIG_MSIDH' '2206980'. + add_replacement_proposal 'MSRDH' 1 'NSDM_MIG_MSRDH' '2206980'. + add_replacement_proposal 'EBEW' 1 'V_EBEW_MD' '2217299'. + add_replacement_proposal 'EBEW' 2 'MBVEBEWOLD' '2217299'. + add_replacement_proposal 'EBEWH' 1 'V_EBEWH_MD' '2217299'. + add_replacement_proposal 'EBEWH' 2 'MBVEBEWHOLD' '2217299'. + add_replacement_proposal 'MBEW' 1 'V_MBEW_MD' '2217299'. + add_replacement_proposal 'MBEW' 2 'MBVMBEWOLD' '2217299'. + add_replacement_proposal 'MBEWH' 1 'V_MBEWH_MD' '2217299'. + add_replacement_proposal 'MBEWH' 2 'MBVMBEWHOLD' '2217299'. + add_replacement_proposal 'OBEW' 1 'V_OBEW_MD' '2217299'. + add_replacement_proposal 'OBEW' 2 'MBVOBEWOLD' '2217299'. + add_replacement_proposal 'OBEWH' 1 'V_OBEWH_MD' '2217299'. + add_replacement_proposal 'OBEWH' 2 'MBVOBEWHOLD' '2217299'. + add_replacement_proposal 'QBEW' 1 'V_QBEW_MD' '2217299'. + add_replacement_proposal 'QBEW' 2 'MBVQBEWOLD' '2217299'. + add_replacement_proposal 'QBEWH' 1 'V_QBEWH_MD' '2217299'. + add_replacement_proposal 'QBEWH' 2 'MBVQBEWHOLD' '2217299'. + + ENDMETHOD. + +ENDCLASS. diff --git a/src/checks/zcl_aoc_check_103.clas.xml b/src/checks/zcl_aoc_check_103.clas.xml index 8b87acfb..a3d23c71 100644 --- a/src/checks/zcl_aoc_check_103.clas.xml +++ b/src/checks/zcl_aoc_check_103.clas.xml @@ -19,7 +19,157 @@ Table/View &1 has replacement object &2 132 + + I + M02 + Table/View &1 has replacement object &2. Consider using &3 instead. OSS Note &4 + 132 + + + I + M03 + Replace + 30 + + + I + M04 + with + 10 + + + + U1 + &FUNCTIONALITY& + + + AS + abapOpenChecks https://github.com/larshp/abapOpenChecks MIT License In + + + S/4HANA many old DB tables have now replacement objects/proxy + + + objectswhich in many case decrease the performance of old SELECT + + + statements when the DB table is used in the OpenSQL. + + + AS + In many cases usage of dictionary views based on that tables is much + + + faster. But we have to make sure that the selected field is still stored + + + in the DB level. + + + U1 + &RELATIONS& + + + AS + + + U1 + &EXAMPLE& + + + AS + MARC table has now replacement object. If we replace it with V_MARC_MD + + + it will be much faster to select basic plant level information. Check + + + OSS Note: https://me.sap.com/notes/0002000002 + + + U1 + &HINTS& + + + AS + + + U1 + &FURTHER_SOURCES_OF_INF& + + + AS + + + + + + CA + ZCL_AOC_CHECK_103 0000 + E + E + 0001 + X + 00009 + R + + + DOKU + ZCL_AOC_CHECK_103 0000 + CA + E + S_DOCU_SHOW + S_DOCUS1 + 00001 + 072 + + + + U1 + &WHAT_FOR& + + + * + + + * + <ZH>103 - Select on Table with Replacement Object </> + + + * + abapOpenChecks + + + * + https://github.com/larshp/abapOpenChecks + + + * + MIT License + + + * + + + * + In S/4HANA many old DB tables have now replacement objects/proxy objects + + + which in many case decrease the performance of old SELECT statements + + + when the DB table is used in the OpenSQL. In many cases usage of + + + dictionary views based on that tables is much faster. But we have to + + + make sure that the selected field is still stored in the DB level. + + + +