Skip to content

Latest commit

 

History

History
124 lines (104 loc) · 5.62 KB

ValueStatementRule.md

File metadata and controls

124 lines (104 loc) · 5.62 KB

<-- previous rule | overview | next rule -->

Shorten VALUE statements

Shortens VALUE statements for internal tables by factoring out assignments that are identical in all lines.

Options

  • Move assignments with integer literals
  • Move assignments with '...' numeric literals
  • Move assignments with string literals
  • Move assignments with identifiers / constants
  • Move assignments with complex expressions
  • Move assignments with method calls (WARNING: could change behavior if methods with side effects are called!)
  • Skip expressions that contain commented-out table rows

Examples

  METHOD shorten_value_statements.
    lts_data = VALUE #( ( a = 2  b = 3  c = 6 )
                        ( a = 2  b = 4  c = 8 ) 
                        ( a = 2  b = 5  c = 10 )  ).

    lts_data_exp = VALUE #( ( item_key       = '20220010000101'
                              item_type      = lt_item[ 1 ]->item_data-item_type
                              contract_id    = lt_item[ 1 ]->get_contract_id( )
                              contract_type  = 'ABCD'
                              category       = 'AB'
                              flag           = if_any_interface=>co_any_flag
                              is_defined     = 'Y'
                              gjahr          = 2022
                              poper          = '001'
                              amount         = 6000
                              currency       = if_any_interface=>co_any_currency
                              account        = '12345'
                              guid           = '1')
                            ( item_key       = '20220010000101'
                              item_type      = lt_item[ 1 ]->item_data-item_type
                              contract_id    = lt_item[ 1 ]->get_contract_id( )
                              contract_type  = 'ABCD'
                              category       = 'CD'
                              flag           = if_any_interface=>co_other_flag
                              is_optional    = abap_true
                              is_defined     = 'Y'
                              gjahr          = 2022
                              poper          = '001'
                              amount         = -6000
                              currency       = if_any_interface=>co_any_currency
                              account        = '67890'
                              guid           = '2' ) ).

    " statements in which entire table rows ( ... ) are commented-out should be skipped,
    " because the commented-out content can not be considered
    lts_data = VALUE #( ( a = 2  b = 3  c = 6 )
*                        ( a = 1  b = 4  c = 8 ) 
                        ( a = 2  b = 5  c = 10 )  ).

    " by contrast, statements with commented-out assignments can be processed,
    " because the parameters in those assignments will never be moved to the top:
    lts_data = VALUE #( ( a = 2
*                          b = 3
                          c = 6 )
                        ( a = 2
                          b = 3
                          c = 8 ) ).
  ENDMETHOD.

Resulting code:

  METHOD shorten_value_statements.
    lts_data = VALUE #( a = 2
                        ( b = 3  c = 6 )
                        ( b = 4  c = 8 )
                        ( b = 5  c = 10 )  ).

    lts_data_exp = VALUE #( item_key       = '20220010000101'
                            item_type      = lt_item[ 1 ]->item_data-item_type
                            contract_type  = 'ABCD'
                            is_defined     = 'Y'
                            gjahr          = 2022
                            poper          = '001'
                            currency       = if_any_interface=>co_any_currency
                            ( contract_id    = lt_item[ 1 ]->get_contract_id( )
                              category       = 'AB'
                              flag           = if_any_interface=>co_any_flag
                              amount         = 6000
                              account        = '12345'
                              guid           = '1')
                            ( contract_id    = lt_item[ 1 ]->get_contract_id( )
                              category       = 'CD'
                              flag           = if_any_interface=>co_other_flag
                              is_optional    = abap_true
                              amount         = -6000
                              account        = '67890'
                              guid           = '2' ) ).

    " statements in which entire table rows ( ... ) are commented-out should be skipped,
    " because the commented-out content can not be considered
    lts_data = VALUE #( ( a = 2  b = 3  c = 6 )
*                        ( a = 1  b = 4  c = 8 ) 
                        ( a = 2  b = 5  c = 10 )  ).

    " by contrast, statements with commented-out assignments can be processed,
    " because the parameters in those assignments will never be moved to the top:
    lts_data = VALUE #( a = 2
                        (
*                          b = 3
                          c = 6 )
                        ( b = 3
                          c = 8 ) ).
  ENDMETHOD.

Related code