Dec26

ABAP New Feature 01

1) Internal table lines

DATA(lv_lines) = LINES( some_itab ).

2) Create object with NEW

DATA(lo_obj) = NEW zcl_someobject( NAME = 'XYZ' ).

3) Fill table with VALUE

DATA(lo_obj) = NEW zcl_monster_model( )->retrieve_headers_by_attribute(
                       EXPORTING it_selections =
                       VALUE ztt_bc_coseltab(
                             ( field = 'EVILNESS' )
                             ( option = 'EQ' )
                             ( sign = 'I' )
                             ( low = 'EVIL' )   "Evil Monster (two lines)
                             ( low = 'VERY' ) ) "Very Evil Monster
                       IMPORTING et_monster_headers = DATA(monster_headers) ).

4) Fill internal table from other tables using FOR

SELECT *
  FROM ztmonster_header
  INTO TABLE @DATA(all_monsters).

DATA(neurotic_monsters) = VALUE ztt_monster_header(
      FOR monster_details IN all_monsters
    WHERE ( sanity_percentage < 20 )
     ( name = monster_details-name
       monster_number = monster_details-monster_number ) ).

5) Use LET as Short-Lived Variables

DO lines( all_monsters[] ) TIMES.
  DATA(arming_description) = CONV string(
       LET weapon_name  = iterator->get_next_weapon( )
           monster_name = all_monsters[ sy-index ]-name
           date_string  =
           |{ sy-datum+6(2) } / { sy-datum+4(2) } / { sy-datum(4) }|
        IN |Monster { monster_name } was issued a { weapon_name } on 
            { date_string }| ).
  MESSAGE arming_description TYPE 'I'.
ENDDO.

6) String Processing

DATA(lv_msg) = | Problem with Monster Number { monster_number ALPHA = OUT }|.
DATA(lv_date) = |{ lv_createdt DATE USER }|.
DATA(lv_time) = |{ lv_createtm TIME ISO }|.

7) Call function or method avoiding mismatch dumps

monster->get_ahead_get_a_hat(
  EXPORTING id_monster_number  = CONV #( monster_number )
  IMPORTING ed_number_of_heads = DATA(number_of_heads)
            ed_number_of_hats  = DATA(number_of_hats) ).

8) Function that Expect TYPE REF TO DATA

monster->log( REF #( value ) ).

9) Switch replaces CASE

DATA(bopf_edit_mode) =SWITCH /bobf/conf_edit_mode( id_edit_mode
               WHEN 'R' THEN /bobf/if_conf_c=>sc_edit_read_only "Read
               WHEN 'U' THEN /bobf/if_conf_c=>sc_edit_exclusive "Update
               ELSE THROW zcx_monster_exceptions( ) )."Unexpected

10) COND replace IF/ELSE

cs_monster_header-sanity_description =COND text30( 
  WHEN cs_monster_header-sanity_percentage = 5 THEN 'VERY SANE'
  WHEN cs_monster_header-sanity_percentage = 4 THEN 'SANE'
  WHEN cs_monster_header-sanity_percentage = 3 THEN 'SLIGHTLY MAD'
  WHEN cs_monster_header-sanity_percentage = 2 THEN 'VERY MAD'
  WHEN cs_monster_header-sanity_percentage = 1 THEN 'BONKERS'
  ELSE 'RENAMES SAP PRODUCTS' ).

11) Read from table avoid exception

zcl_bc_screen_message=>output( |{ monster_name }'s Monster Number is { VALUE #
  ( table_of_monsters[ monster_name ]-monster_number OPTIONAL ) }| ).
zcl_bc_screen_message=>output( |{ monster_name }’s Monster Number is { VALUE #
  ( table_of_monsters[ monster_name ]-monster_number DEFAULT '9999' ) }| ).

12) CORRESPONDING for internal tables

green_monsters = CORRESPONDING #( blue_monsters
  MAPPING people_scared = most_peasants_scared  "map field when name different
  EXCEPT  evilness ). "exculding fields

13) Move corresponding between internal tables

MOVE-CORRESPONDING lt_euro_results TO lt_us_results.

14) Move corresponding between internal tables Keeping target lines

 MOVE-CORRESPONDING KEEPING TARGET LINES is rather like 

 APPEND LINES OF table1 to table2 except structures are different.

本篇文章已有0条评论