### Configuration Example for Data References Source: https://docs.abapopenchecks.org/checks/69 Illustrates how to configure multiple allowed values for data references using '|' separation within round brackets. ```abap (R|O) ``` -------------------------------- ### Example of Double Space in ABAP Source: https://docs.abapopenchecks.org/checks/49 This snippet shows an example of code containing a double space that needs to be condensed. It highlights the 'before' state. ```abap IF foo = bar. ``` -------------------------------- ### Allowed Prefixes for Data References Source: https://docs.abapopenchecks.org/checks/69 Example showing valid prefixes 'R' and 'O' for data references, allowing multiple values separated by '|'. ```abap lo_object lr_object ``` -------------------------------- ### Use REF expression for getting data reference Source: https://docs.abapopenchecks.org/checks/45 Replaces the GET REFERENCE OF statement for a more concise way to obtain a reference to a data object. ```ABAP GET REFERENCE OF i_data INTO lo_data. ``` ```ABAP lo_data = REF #( i_data ). ``` -------------------------------- ### String Template Concatenation Example Source: https://docs.abapopenchecks.org/checks/60 Demonstrates replacing older concatenation methods with the '|' operator for assembling text strings, as recommended by Clean ABAP styleguides. Use this pattern for cleaner string construction. ```ABAP lv_foo && |moo { lv_bar }| replaced with |{ lv_foo }moo { lv_bar }| ``` -------------------------------- ### Original Large WHEN Construct Source: https://docs.abapopenchecks.org/checks/34 This snippet shows a typical large WHEN construct within a CASE statement. It is difficult to maintain and get an overview of the code. ```ABAP CASE lv_foo. WHEN 'BAAR' ... code ... ENDCASE. ``` -------------------------------- ### Correct Definition Order in ABAP Routine Source: https://docs.abapopenchecks.org/checks/17 This example demonstrates the corrected version of the previous snippet, where the DATA declaration is moved to the top of the FORM routine, adhering to ABAP coding standards. ```abap FORM foo. DATA: lv_bar TYPE i. gv_moo = 2. .... ENDFORM. ``` -------------------------------- ### Use lines( ) expression for table row count Source: https://docs.abapopenchecks.org/checks/45 Replaces the DESCRIBE TABLE statement for a more concise way to get the number of rows in an internal table. ```ABAP DESCRIBE TABLE lt_table LINES lv_lines. ``` ```ABAP lv_lines = lines( lt_table ). ``` -------------------------------- ### Built-in Functions in ABAP Source: https://docs.abapopenchecks.org/checks/100 Shows examples of built-in functions for table operations. 'line_exists' checks for row existence, and 'line_index' returns the row number. ```ABAP line_exists( itab ) line_index( itab ) ``` -------------------------------- ### Chained ABAP Declarations Source: https://docs.abapopenchecks.org/checks/55 This snippet shows an example of chained ABAP declarations, where multiple variables are declared on a single line. Activating this check goes against the Clean ABAP recommendation: Do not chain up-front declarations. ```abap DATA: foo type c. DATA: bar type c. ``` ```abap DATA: foo type c, bar type c. ``` -------------------------------- ### Incorrect Definition Order in ABAP Routine Source: https://docs.abapopenchecks.org/checks/17 This example shows a common mistake where variable declarations appear after executable code within an ABAP FORM routine. It violates the guideline of placing all definitions at the top. ```abap FORM foo. gv_moo = 2. DATA: lv_bar TYPE i. .... ENDFORM. ``` -------------------------------- ### Incorrect READ TABLE statement with empty line Source: https://docs.abapopenchecks.org/checks/41 This example shows an incorrect READ TABLE statement where an empty line separates the table name from the INDEX clause. This can cause syntax errors. ```abap READ TABLE lt_table INDEX 1 INTO ls_table. ``` -------------------------------- ### Incorrect READ TABLE statement with comment line Source: https://docs.abapopenchecks.org/checks/41 This example demonstrates an incorrect READ TABLE statement containing a comment line between the table name and the INDEX clause. Such comments within a statement can lead to syntax errors. ```abap READ TABLE lt_table " read index 1 INDEX 1 INTO ls_table. ``` -------------------------------- ### Using SAPGUI_PROGRESS_INDICATOR Function Module Source: https://docs.abapopenchecks.org/checks/53 Demonstrates the traditional way to display a progress indicator using the SAPGUI_PROGRESS_INDICATOR function module. This method requires manual percentage calculation and text setting. ```ABAP CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' EXPORTING percentage = progress_percent text = progress_text. ``` -------------------------------- ### Using CL_PROGRESS_INDICATOR for Progress Indication with Text Placeholders Source: https://docs.abapopenchecks.org/checks/53 Shows how to use the CL_PROGRESS_INDICATOR class to display progress, utilizing text with placeholders for dynamic updates. This approach automates percentage calculation. ```ABAP cl_progress_indicator=>progress_indicate( i_text = 'Processed &1 % (&2 of &3 records)' i_processed = current_record i_total = total_records i_output_immediately = abap_true ). ``` -------------------------------- ### String Templates in ABAP Source: https://docs.abapopenchecks.org/checks/100 Demonstrates the use of string templates for easy string construction and concatenation. Useful for building dynamic strings. ```ABAP lv_string = | … | && | … ``` -------------------------------- ### Using CL_PROGRESS_INDICATOR for Progress Indication with Message Placeholders Source: https://docs.abapopenchecks.org/checks/53 Illustrates using the CL_PROGRESS_INDICATOR class with message IDs and numbers, allowing progress to be displayed via system messages with placeholders. This method also automates percentage calculation. ```ABAP cl_progress_indicator=>progress_indicate( i_msgid = 'ZMYMSG' i_msgno = '005' i_processed = current_record i_total = total_records i_output_immediately = abap_true ). ``` -------------------------------- ### Chained Statements in ABAP Source: https://docs.abapopenchecks.org/checks/100 Shows syntax for chained method calls in static and instance contexts. This allows for sequential method invocations. ```ABAP class=>method( )->method( ) class->method( )->method( ) ``` -------------------------------- ### Optimized SELECT using V_MARC_MD view Source: https://docs.abapopenchecks.org/checks/103 This snippet demonstrates replacing a slow SELECT on MARC with a faster SELECT on the V_MARC_MD view. Use this pattern when selecting basic plant-level information to leverage optimized dictionary views in S/4HANA. ```ABAP DATA: materials TYPE HASHED TABLE OF MARC WITH UNIQUE KEY MATNR. SELECT * FROM V_MARC_MD WHERE WERKS = '0001' INTO CORRESPONDING FIELDS OF TABLE materials. ``` -------------------------------- ### Constructor Operators in ABAP Source: https://docs.abapopenchecks.org/checks/100 Shows various constructor operators for creating and manipulating data objects. These operators provide concise ways to initialize complex data structures. ```ABAP NEW #( … ) VALUE #( … ) CAST #( … ) CONV #( … ) REF #( … ) CORRESPONDING #( … ) EXACT #( … ) REDUCE #( … ) FILTER #( … ) COND #( … ) SWITCH #( … ) ``` -------------------------------- ### Use NEW expression for object instantiation Source: https://docs.abapopenchecks.org/checks/45 Replaces the CREATE OBJECT statement for inline object creation, especially useful when the object is used immediately. ```ABAP DATA: lo_foo TYPE REF TO zcl_foobar. CREATE OBJECT lo_foo EXPORTING iv_moo = 'ABC'. ``` ```ABAP DATA(lo_moo) = NEW zcl_foobar( 'ABC' ). ``` -------------------------------- ### Iteration Expressions in ABAP Source: https://docs.abapopenchecks.org/checks/100 Illustrates iteration expressions for loops and table processing. Includes FOR loops with conditions and grouping for LOOP AT statements. ```ABAP ( FOR … UNTIL | WHILE … | … IN … … ) LOOP AT itab GROUP BY … ``` -------------------------------- ### Use replace( ) for string condensation without gaps Source: https://docs.abapopenchecks.org/checks/45 Provides an alternative to CONDENSE NO-GAPS by using the replace function to remove all space characters from a string. ```ABAP DATA(my_numbers) = ` 5566551 122 `. " with CONDENSE CONDENSE my_numbers NO-GAPS. " with replace( ) my_numbers = replace( val = my_numbers regex = ` ` with = `` occ = 0 ). " Result: my_numbers = `5566551122` ``` -------------------------------- ### Replace LOOP with DELETE WHERE Source: https://docs.abapopenchecks.org/checks/62 Use DELETE WHERE directly instead of looping and deleting individual entries. ```abap LOOP AT lt_tab ASSIGNING WHERE ... DELETE lt_tab FROM . ENDLOOP. ``` ```abap DELETE lt_tab WHERE ... ``` -------------------------------- ### Add EXCEPTIONS for RFC Call Error Handling Source: https://docs.abapopenchecks.org/checks/47 Include system_failure, communication_failure, and resource_failure exceptions with MESSAGE clauses to capture detailed error information during RFC calls. This aids in future debugging. ```ABAP EXCEPTIONS system_failure = 1 MESSAGE lv_msg communication_failure = 2 MESSAGE lv_msg resource_failure = 3. ``` -------------------------------- ### Inline Declarations in ABAP Source: https://docs.abapopenchecks.org/checks/100 Demonstrates inline declaration syntax for variables and field symbols. Use when declaring variables directly at their point of use. ```ABAP DATA(itab) FIELD-SYMBOL() ``` -------------------------------- ### Assignment Operators in ABAP Source: https://docs.abapopenchecks.org/checks/100 Demonstrates shorthand assignment operators for arithmetic and string concatenation. These operators modify a variable in place. ```ABAP lv_data += 1. lv_data -= 1. lv_data *= 1. lv_data /= 1. lv_data &&= ‘Hello’. ``` -------------------------------- ### Simplify RAISE EXCEPTION TYPE with MESSAGE Source: https://docs.abapopenchecks.org/checks/66 This snippet shows how to simplify a RAISE EXCEPTION TYPE statement by using a shorthand for message ID, type, and number. ```abap RAISE EXCEPTION TYPE zcx_foobar MESSAGE ID 'ZFOOBAR' TYPE 'E' NUMBER '012'. ``` ```abap RAISE EXCEPTION TYPE zcx_foobar MESSAGE e012(zfoobar). ``` -------------------------------- ### Incorrect LIKE Wildcard Usage Source: https://docs.abapopenchecks.org/checks/94 This snippet shows the incorrect use of '*' as a wildcard with the LIKE operator. Use '%' for string matching instead. ```abap SELECT ... WHERE xyz LIKE 'PATTERN*'. ``` ```abap SELECT ... WHERE xyz LIKE 'PATTERN%'. ``` -------------------------------- ### Prefer IS NOT to NOT IS Source: https://docs.abapopenchecks.org/checks/101 Use 'IS NOT' for clearer negation in ABAP. This is the recommended pattern for improved readability. ```abap IF variable IS NOT INITIAL. IF variable NP 'TODO*'. IF variable <> 42. ``` ```abap " anti-pattern IF NOT variable IS INITIAL. IF NOT variable CP 'TODO*'. IF NOT variable = 42. ``` -------------------------------- ### Prefer functional style over RECEIVING Source: https://docs.abapopenchecks.org/checks/07 Replace procedural method calls with RECEIVING parameters by assigning the result directly. This enhances code clarity and conciseness. ```abap zcl_foo=>bar( RECEIVING rv_moo = lv_boo ). ``` ```abap lv_boo = zcl_foo=>bar( ). ``` -------------------------------- ### ABAP Configuration for LTCL Naming Source: https://docs.abapopenchecks.org/checks/29 Adjust the default LTCL_* settings to match your project's naming requirements. This configuration is crucial for maintaining consistent naming conventions for local test classes. ```abap CODE ``` -------------------------------- ### Use string templates for string concatenation Source: https://docs.abapopenchecks.org/checks/45 Replaces the CONCATENATE statement with the `&&` operator or string templates for more readable string construction. ```ABAP CONCATENATE field1 field2 INTO field3. ``` ```ABAP field = field1 && field2. ``` -------------------------------- ### Table Expressions in ABAP Source: https://docs.abapopenchecks.org/checks/100 Illustrates table expressions for accessing rows in internal tables. Use this syntax for direct row referencing. ```ABAP itab[ … ] ``` -------------------------------- ### Original SELECT on MARC table Source: https://docs.abapopenchecks.org/checks/103 This snippet shows a typical SELECT statement on the MARC table, which may be slow in S/4HANA due to replacement objects. Use this pattern when direct table access is necessary and performance is not a critical concern or when the replacement object does not significantly impact performance for the specific query. ```ABAP DATA: materials TYPE HASHED TABLE OF MARC WITH UNIQUE KEY MATNR. SELECT * FROM MARC WHERE WERKS = '0001' INTO CORRESPONDING FIELDS OF TABLE materials. ``` -------------------------------- ### Using SELECT UP TO n ROWS with ENDSELECT Source: https://docs.abapopenchecks.org/checks/38 This is an exception where SELECT UP TO n ROWS with ENDSELECT might be used, though SELECT SINGLE is often preferred for clarity when fetching a single row. ```ABAP SELECT * FROM db1 UP TO 1 ROWS INTO struc1 WHERE key2 = value2. ENDSELECT. ``` -------------------------------- ### Replace Hardcoded Icon String with Constant Source: https://docs.abapopenchecks.org/checks/10 This snippet demonstrates replacing a hardcoded icon string literal with a predefined constant. Constants for icons can be found using the standard report RSTXICON. ```ABAP lv_icon = '@00@'. ``` ```ABAP lv_icon = icon_dummy. ``` -------------------------------- ### Refactoring for GUI Output Source: https://docs.abapopenchecks.org/checks/57 Refactor solutions to ensure classes are not directly responsible for GUI output. This promotes better separation of concerns and testability by decoupling business logic from presentation. ```abap CLASS lcl_data_processor DEFINITION. PUBLIC SECTION. METHODS: process_data IMPORTING iv_input TYPE string RETURNING VALUE(rv_output) TYPE string. ENDCLASS. CLASS lcl_data_processor IMPLEMENTATION. METHOD process_data. " Business logic to process data rv_output = |Processed: { iv_input }|. ENDMETHOD. ENDCLASS. " In a separate UI-related class or report: DATA(lo_processor) = NEW lcl_data_processor( ). DATA(lv_result) = lo_processor->process_data( iv_input = 'Sample Input' ). WRITE lv_result. ``` -------------------------------- ### Using Message-Based Class Exceptions Source: https://docs.abapopenchecks.org/checks/57 Implement message-based class exceptions for robust error handling in global classes. This approach centralizes error reporting through standard message mechanisms. ```abap CLASS lcl_my_class DEFINITION. PUBLIC SECTION. METHODS: constructor RAISING cx_static_check. ENDCLASS. CLASS lcl_my_class IMPLEMENTATION. METHOD constructor. " Example of raising a message-based exception RAISE EXCEPTION TYPE cx_static_check EXPORTING textid = cx_static_check=>default_text. ENDMETHOD. ENDCLASS. ``` -------------------------------- ### ABAP Constants Source: https://docs.abapopenchecks.org/checks/100 Lists predefined ABAP constants for boolean values and undefined states. These are commonly used in conditional logic and initializations. ```ABAP abap_bool abap_true abap_false abap_undefined ``` -------------------------------- ### Incorrect and Correct Logical Expression Parentheses Source: https://docs.abapopenchecks.org/checks/59 Demonstrates the correct and incorrect usage of parentheses in ABAP logical expressions. Avoid excessive or insufficient parentheses for clarity and correctness. ```ABAP * Bad, too many parentheses IF ( ( foo = bar ) AND ( moo = boo ) ). IF ( foo = bar AND moo = boo ). IF ( foo = bar ) AND ( moo = boo ). IF foo = bar AND ( moo = boo ). * Good IF foo = bar AND moo = boo. * Bad, too few parentheses IF foo = bar AND moo = boo OR laa = baa. * Good IF ( foo = bar AND moo = boo ) OR laa = baa. IF foo = bar AND ( moo = boo OR laa = baa ). ``` -------------------------------- ### Detect Identical WHEN Blocks in CASE Statement Source: https://docs.abapopenchecks.org/checks/42 This snippet demonstrates a CASE statement where the code within the WHEN 1 and WHEN 2 blocks is identical. The check identifies such redundancies. ```abap CASE lv_foo. WHEN 1. WRITE lv_bar. WHEN 2. WRITE lv_bar. " <- identical to WHEN 1 ENDCASE. ``` -------------------------------- ### Use line_exists( ) for checking row existence Source: https://docs.abapopenchecks.org/checks/45 Replaces the READ TABLE with TRANSPORTING NO FIELDS pattern for checking if a specific row exists in an internal table. Avoid using it solely to check existence before reading; consider assigning to a field symbol instead. ```ABAP READ TABLE itab INDEX 1 TRANSPORTING NO FIELDS. IF sy-subrc = 0. ... ENDIF. ``` ```ABAP IF line_exists( itab[ 1 ] ). ... ENDIF. ``` -------------------------------- ### Incorrect CP Wildcard Usage Source: https://docs.abapopenchecks.org/checks/94 This snippet demonstrates the incorrect use of '*' with the CP (Contains Pattern) operator. Use '%' for pattern matching. ```abap IF xyz CP 'PATTERN%'. ``` ```abap IF xyz CP 'PATTERN*'. ``` -------------------------------- ### Correct Work Area Declaration using LINE OF Source: https://docs.abapopenchecks.org/checks/19 This snippet demonstrates the recommended ABAP practice of using the LINE OF addition to declare a work area. This ensures the work area automatically adjusts if the table's structure is modified, preventing potential errors and improving maintainability. ```abap DATA: lt_table TYPE TABLE OF usr02, FIELD-SYMBOLS: LIKE LINE OF lt_table. LOOP AT lt_table ASSIGNING . ... ENDLOOP. ``` -------------------------------- ### ABAP MESSAGE using SY-MSGTY, SY-MSGNO Source: https://docs.abapopenchecks.org/checks/71 This snippet demonstrates the use of ABAP system variables for message handling. It's relevant when dealing with exceptions where standard or custom function modules might not always raise a message alongside the exception, potentially causing ST22 dumps. ```abap message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ``` -------------------------------- ### Reduce Nested ELSE IF Statements Source: https://docs.abapopenchecks.org/checks/01 This snippet demonstrates how to simplify nested ELSE IF structures. The reduced form using ELSEIF is more concise and easier to understand. ```abap ELSE. IF condition. ... ENDIF. ENDIF. ``` ```abap ELSEIF condition. ... ENDIF. ``` -------------------------------- ### ABAP: CLEAR as first use of variable Source: https://docs.abapopenchecks.org/checks/79 This ABAP code snippet demonstrates the correct usage of CLEAR for a local variable within a method of a global class. It ensures that the variable is explicitly cleared before its first use. ```abap METHOD foobar. DATA lv_index TYPE i. CLEAR lv_index. .. ENDMETHOD. .. ``` -------------------------------- ### Use CORRESPONDING #( ) expression for structure assignment Source: https://docs.abapopenchecks.org/checks/45 Replaces the MOVE-CORRESPONDING statement for assigning components of one structure to another. Use BASE addition for ABAP 740sp08+ to match MOVE-CORRESPONDING behavior. ```ABAP MOVE-CORRESPONDING struc1 TO struc2. ``` ```ABAP struc2 = CORRESPONDING #( struc1 ). ``` ```ABAP struc2 = CORRESPONDING #( BASE( struc2 ) struc1 ). ``` -------------------------------- ### Omit EXPORTING Keyword for Exporting Parameters Source: https://docs.abapopenchecks.org/checks/30 When calling methods and supplying only exporting parameters, the EXPORTING keyword can be omitted for a more concise syntax. This applies to RFC-enabled function modules and methods. ```ABAP lx_error->to_fpm_error( EXPORTING iv_ref_name = lv_field_name iv_ref_index = lv_row ). ``` ```ABAP lx_error->to_fpm_error( iv_ref_name = lv_field_name iv_ref_index = lv_row ). ``` -------------------------------- ### Refactor SELECT-ENDSELECT to SELECT INTO TABLE Source: https://docs.abapopenchecks.org/checks/38 Replace SELECT-ENDSELECT with SELECT INTO TABLE for better performance when retrieving multiple rows. ```ABAP SELECT * FROM db1 INTO struc1. ... ENDSELECT. ``` ```ABAP SELECT * FROM db1 INTO TABLE itab1. ``` -------------------------------- ### Optimize CONTINUE Statement Source: https://docs.abapopenchecks.org/checks/62 Remove CONTINUE statements from loops if the subsequent code is empty or can be implicitly handled by the loop's end. ```abap LOOP AT lt_tab ASSIGNING WHERE ... ... CONTINUE. ENDLOOP. ``` ```abap LOOP AT lt_tab ASSIGNING WHERE ... ... ``` -------------------------------- ### String Template Concatenation with WHERE Clause Source: https://docs.abapopenchecks.org/checks/60 Illustrates a specific use case for the '|' operator in constructing WHERE clauses, simplifying the assembly of dynamic filter strings. This adheres to Clean ABAP practices for string manipulation. ```ABAP | WHERE| && | { lv_filter } | replaced with | WHERE { lv_filter } | ``` -------------------------------- ### Equivalent IF statement Source: https://docs.abapopenchecks.org/checks/99 This snippet shows the refactored version of the previous CASE statement, using an IF statement when only a single condition is present. ```ABAP FORM foo. DATA lv_bar TYPE i. IF lv_bar = 1. WRITE: / 'hello world'. ENDIF. ENDFORM. ``` -------------------------------- ### Use concat_lines_of( ) for concatenating table lines Source: https://docs.abapopenchecks.org/checks/45 Replaces the CONCATENATE LINES OF statement for a more functional approach to joining lines from an internal table into a string. ```ABAP CONCATENATE LINES OF itab INTO field. ``` ```ABAP field = concat_lines_of( itab ). ``` -------------------------------- ### Corrected ABAP Code with Single Space Source: https://docs.abapopenchecks.org/checks/49 This snippet demonstrates the corrected version of the ABAP code after condensing the double space to a single space. It shows the 'after' state. ```abap IF foo = bar. ``` -------------------------------- ### Using get_text() with Message Exception Source: https://docs.abapopenchecks.org/checks/37 When using the get_text() method with a message exception, the message may not display correctly. This snippet shows the incorrect approach. ```abap MESSAGE lo_cx->get_text( ) TYPE 'S'. ``` -------------------------------- ### Reduce CALL METHOD to functional call Source: https://docs.abapopenchecks.org/checks/07 When a method call does not require explicit RECEIVING parameters, it can be simplified from a procedural CALL METHOD statement to a direct functional call. ```abap CALL METHOD lo_obj->method( ). ``` ```abap lo_obj->method( ). ``` -------------------------------- ### Directly Using Message Exception Source: https://docs.abapopenchecks.org/checks/37 To ensure message texts display properly when using message-based exceptions, use the exception object directly instead of calling get_text(). ```abap MESSAGE lo_cx TYPE 'S'. ``` -------------------------------- ### Reduced ABAP Code with Simplified Logic Source: https://docs.abapopenchecks.org/checks/22 This optimized version of the ABAP code moves the common assignment outside the conditional block, reducing redundancy and improving readability. ```ABAP lv_moo = abap_true. IF lv_foo = lv_bar. WRITE: / lv_moo. ENDIF. ``` -------------------------------- ### CASE statement with a single WHEN branch Source: https://docs.abapopenchecks.org/checks/99 This snippet demonstrates a CASE statement with only one WHEN branch, which can be refactored into an IF statement for improved clarity. ```ABAP FORM foo. DATA lv_bar TYPE i. CASE lv_bar. WHEN 1. WRITE: / 'hello world'. ENDCASE. ENDFORM. ``` -------------------------------- ### Omit Parameter Name in Single Parameter Call Source: https://docs.abapopenchecks.org/checks/43 Use this when calling a method with a single parameter to improve readability. This applies to functional style method calls. ```ABAP lo_column = lo_columns->get_column( columnname = 'FOOBAR' ). ``` ```ABAP lo_column = lo_columns->get_column( 'FOOBAR' ). ``` -------------------------------- ### Simplify TRY without CATCH Source: https://docs.abapopenchecks.org/checks/03 If a TRY block does not have a CATCH clause, it can often be removed entirely. This simplifies the code by eliminating unnecessary control structures. ```ABAP TRY. lo_obj->method( ). ENDTRY. ``` ```ABAP lo_obj->method( ). ``` -------------------------------- ### Reduce Nested IF Statements Source: https://docs.abapopenchecks.org/checks/01 This snippet shows a common pattern of nested IF statements that can be simplified. Use the reduced form to improve readability and maintainability. ```abap IF condition1. IF condition2. ... ENDIF. ENDIF. ``` ```abap IF ( condition1 ) AND ( condition2 ). ... ENDIF. ``` -------------------------------- ### Use condense( ) expression for string condensation Source: https://docs.abapopenchecks.org/checks/45 Replaces the CONDENSE statement for removing leading/trailing spaces and reducing internal spaces in a string. Note that the NO-GAPS option is not directly available. ```ABAP CONDENSE field. ``` ```ABAP field = condense( field ). ``` -------------------------------- ### Use to_upper( ) for converting string to uppercase Source: https://docs.abapopenchecks.org/checks/45 Replaces the TRANSLATE TO UPPER CASE statement for a functional approach to converting a string to uppercase. ```ABAP TRANSLATE field TO UPPER CASE. ``` ```ABAP field = to_upper( field ). ``` -------------------------------- ### Declare variable in LOOP statement Source: https://docs.abapopenchecks.org/checks/45 Allows inline declaration of the work area variable within the LOOP statement, reducing boilerplate code. ```ABAP DATA: ls_foo LIKE LINE OF lt_table. LOOP AT lt_table INTO ls_foo. ... ENDLOOP. ``` ```ABAP LOOP AT lt_table INTO DATA(ls_foo). ... ENDLOOP. ``` -------------------------------- ### Refactored CASE Statement with FORM Routine Source: https://docs.abapopenchecks.org/checks/34 This snippet demonstrates the refactored version where the code within the WHEN construct is extracted into a separate FORM routine, improving readability. ```ABAP CASE lv_foo. WHEN 'BAAR' PERFORM foobar. ENDCASE. FORM foobar. ... code ... ENDFORM. ``` -------------------------------- ### Reduce Nested CATCH Blocks Source: https://docs.abapopenchecks.org/checks/03 When multiple nested TRY-ENDTRY blocks contain identical CATCH clauses for the same exception, they can typically be consolidated into a single CATCH block. This reduces redundancy and improves readability. ```ABAP CATCH zcx_error. ENDTRY. CATCH zcx_error. ENDTRY. CATCH zcx_error. ENDTRY. ``` ```ABAP CATCH zcx_error. ENDTRY. ``` -------------------------------- ### Simplify Loop Condition Source: https://docs.abapopenchecks.org/checks/62 Remove explicit checks for table lines before looping if the loop itself handles the condition. ```abap IF lines( lt_tab ) > 0 LOOP AT lt_tab ASSIGNING WHERE ... ... ENDLOOP. ENDIF. ``` ```abap LOOP AT lt_tab ASSIGNING WHERE ... ... ENDLOOP. ``` -------------------------------- ### Detect Shadowed Variables and Field-Symbols Source: https://docs.abapopenchecks.org/checks/46 This ABAP code demonstrates how variables and field-symbols can shadow existing declarations. It returns an error for shadowed variables or field-symbols. Note: this check does not work if a data declaration shadows a variable defined with TABLES. ```ABAP REPORT zshadow. DATA: foo TYPE c. FIELD-SYMBOLS: TYPE c. START-OF-SELECTION. PERFORM foo. FORM foo. DATA: foo TYPE i. " shadowing FIELD-SYMBOLS: TYPE c. " shadowing WRITE: / 'sdf'. ENDFORM. CLASS foo DEFINITION. PUBLIC SECTION. DATA: foo TYPE c. METHODS: asdf. ENDCLASS. CLASS foo IMPLEMENTATION. METHOD asdf. DATA: foo TYPE c. " shadowing ENDMETHOD. ENDCLASS. ``` -------------------------------- ### Use shift_left( ) for left shifting string content Source: https://docs.abapopenchecks.org/checks/45 Replaces the SHIFT LEFT statement for a functional approach to shifting characters in a string to the left. ```ABAP SHIFT field LEFT. ``` ```ABAP field = shift_left( field ). ``` -------------------------------- ### Original ABAP Code with Redundant Assignments Source: https://docs.abapopenchecks.org/checks/22 This snippet shows an ABAP IF-ELSE block where the same variable is assigned a value in both branches. This can often be simplified. ```ABAP IF lv_foo = lv_bar. lv_moo = abap_true. WRITE: / lv_moo. ELSE. lv_moo = abap_true. ENDIF. ``` -------------------------------- ### Use translate( ) expression for character translation Source: https://docs.abapopenchecks.org/checks/45 Replaces the TRANSLATE statement with a functional expression for translating characters within a string based on specified mappings. ```ABAP TRANSLATE field USING mask ``` ```ABAP field = translate( val = field from = from to = to ) ``` -------------------------------- ### Remove Redundant CLEAR Statement Source: https://docs.abapopenchecks.org/checks/27 This snippet demonstrates a form where a CLEAR statement is the last executable statement. The check recommends its removal as it has no impact on the program's state at that point. ```ABAP ... DATA(bar) = `ABCD`. ... CLEAR bar. ENDFORM. ``` ```ABAP ... DATA(bar) = `ABCD`. ... ENDFORM. ``` -------------------------------- ### Remove Redundant RETURN Statement Source: https://docs.abapopenchecks.org/checks/27 This snippet shows a form where a RETURN statement is present. The check suggests removing it as it does not affect the program's execution flow when it's the last statement. ```ABAP ... IF p_subrut[] IS INITIAL. WRITE: / 'foobar'. RETURN. ENDIF. ENDFORM. ``` ```ABAP ... IF p_subrut[] IS INITIAL. WRITE: / 'foobar'. ENDIF. ENDFORM. ``` -------------------------------- ### Remove Unnecessary Space Before Period Source: https://docs.abapopenchecks.org/checks/28 This snippet shows the incorrect formatting with a space before a period. It is used to identify and correct instances where a space precedes a period, which is not standard in clean ABAP. ```ABAP lv_foo = lv_bar . ``` -------------------------------- ### Corrected Space Before Period Source: https://docs.abapopenchecks.org/checks/28 This snippet demonstrates the corrected ABAP code after removing the unnecessary space before the period. Adhering to this rule improves code clarity and follows clean ABAP conventions. ```ABAP lv_foo = lv_bar. ``` -------------------------------- ### Incorrect Work Area Declaration Source: https://docs.abapopenchecks.org/checks/19 This snippet shows an incorrect way to declare a work area for a table loop, which can lead to errors if the table structure changes. The work area is defined with a specific type instead of using LINE OF. ```abap DATA: lt_table TYPE TABLE OF usr02, FIELD-SYMBOLS: TYPE usr02. LOOP AT lt_table ASSIGNING . ... ENDLOOP. ``` -------------------------------- ### Remove EC CI_SUBRC when SUBRC is checked Source: https://docs.abapopenchecks.org/checks/78 This snippet demonstrates an ABAP SELECT statement where the SUBRC is checked afterwards. The pseudo comment "#EC CI_SUBRC" can be removed in this scenario. ```ABAP SELECT * FROM TADIR. "#EC CI_SUBRC <- can be removed, since SUBRC is checked afterwards IF sy-subrc = 0. .. ENDIF. ``` -------------------------------- ### Remove trailing period from method call Source: https://docs.abapopenchecks.org/checks/16 Corrects a method call by removing the standalone period at the end of the line. ```ABAP lo_object->method( p_werks ). ``` ```ABAP lo_object->method( p_werks ). ``` -------------------------------- ### Remove Redundant CHECK Statement Source: https://docs.abapopenchecks.org/checks/27 This snippet illustrates a form where a CHECK statement is the last executable statement. The check suggests removing it, as any condition failure would have already been handled or is irrelevant at this stage. ```ABAP ... DATA(foo) = `foo`. DATA(bar) = `bar`. CHECK foo = bar. ENDFORM. ``` ```ABAP ... DATA(foo) = `foo`. DATA(bar) = `bar`. ENDFORM. ``` -------------------------------- ### Remove trailing period from CALL FUNCTION Source: https://docs.abapopenchecks.org/checks/16 Corrects a CALL FUNCTION statement by removing the standalone period at the end of the line. ```ABAP CALL FUNCTION 'ZASDF' EXPORTING A_WERKS = p_werks . ``` ```ABAP CALL FUNCTION 'ZASDF' EXPORTING A_WERKS = p_werks. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.