Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Legend

2021-08-XX v.1.16.0
------------------
* Magic Number: CASE SY-TABIX and CO NUMBERS (#480)
* Magic Number: Leading Zeros (#479)
* Prefer New to Create Object: Dynamic Type (#469)
* Magic Number: Table Index (#468)
Expand Down
12 changes: 7 additions & 5 deletions src/checks/y_check_magic_number.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CLASS y_check_magic_number DEFINITION PUBLIC INHERITING FROM y_check_base CREATE
METHODS is_magic_number RETURNING VALUE(result) TYPE abap_bool.
METHODS is_index RETURNING VALUE(result) TYPE abap_bool.
METHODS is_lines RETURNING VALUE(result) TYPE abap_bool.
METHODS is_sy_subrc_in_case RETURNING VALUE(result) TYPE abap_bool.
METHODS is_sy_in_case RETURNING VALUE(result) TYPE abap_bool.

ENDCLASS.

Expand Down Expand Up @@ -43,7 +43,7 @@ CLASS y_check_magic_number IMPLEMENTATION.
ENDIF.

IF keyword = if_kaizen_keywords_c=>gc_when
AND is_sy_subrc_in_case( ) = abap_true.
AND is_sy_in_case( ) = abap_true.
RETURN.
ELSEIF next1( 'SY-SUBRC' ) IS NOT INITIAL
OR next1( 'SY-TABIX' ) IS NOT INITIAL.
Expand Down Expand Up @@ -76,7 +76,8 @@ CLASS y_check_magic_number IMPLEMENTATION.
result = xsdbool( string IS NOT INITIAL
AND string CO '0123456789'
AND string CN '0'
AND string <> '1' ).
AND string <> '1'
AND string <> '0123456789' ).
ENDMETHOD.


Expand All @@ -95,15 +96,16 @@ CLASS y_check_magic_number IMPLEMENTATION.
ENDMETHOD.


METHOD is_sy_subrc_in_case.
METHOD is_sy_in_case.
DATA(when_statement) = statement_wa.
DATA(when_structure) = ref_scan->structures[ when_statement-struc ].

DATA(case_structure) = ref_scan->structures[ when_structure-back ].
DATA(case_statement) = ref_scan->statements[ case_structure-stmnt_from ].
DATA(case_target) = ref_scan->tokens[ case_statement-to ].

result = xsdbool( case_target-str = 'SY-SUBRC' ).
result = xsdbool( case_target-str = 'SY-SUBRC'
OR case_target-str = 'SY-TABIX' ).
ENDMETHOD.


Expand Down
33 changes: 31 additions & 2 deletions src/checks/y_check_magic_number.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ CLASS ltc_case IMPLEMENTATION.
ENDCLASS.


CLASS ltc_sy_subrc DEFINITION INHERITING FROM ltc_if FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
CLASS ltc_sy DEFINITION INHERITING FROM ltc_if FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_code_without_issue REDEFINITION.
ENDCLASS.

CLASS ltc_sy_subrc IMPLEMENTATION.
CLASS ltc_sy IMPLEMENTATION.

METHOD get_code_without_issue.
result = VALUE #(
Expand All @@ -265,6 +265,15 @@ CLASS ltc_sy_subrc IMPLEMENTATION.
( | WHEN 8. | )
( | WRITE 'other error'. | )
( | ENDCASE. | )

( | CASE sy-tabix. | )
( | WHEN 1. | )
( | WRITE 'first'. | )
( | WHEN 2. | )
( | WRITE 'second'. | )
( | WHEN 3. | )
( | WRITE 'other'. | )
( | ENDCASE. | )
).
ENDMETHOD.

Expand Down Expand Up @@ -356,3 +365,23 @@ CLASS ltc_leading_zeros IMPLEMENTATION.
ENDMETHOD.

ENDCLASS.


CLASS ltc_checking_numbers DEFINITION INHERITING FROM ltc_if FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PROTECTED SECTION.
METHODS get_code_without_issue REDEFINITION.
ENDCLASS.

CLASS ltc_checking_numbers IMPLEMENTATION.

METHOD get_code_without_issue.
result = VALUE #(
( ' REPORT ut_test.' )
( ' START-OF-SELECTION.' )
( | DATA char TYPE c LENGTH 6. | )
( | IF char CO '0123456789'. | )
( ' ENDIF. ' )
).
ENDMETHOD.

ENDCLASS.