Dec26

ABAP New Feature 02

1) Dynamic MOVE-CORRESPONDING

* Local Variables
DATA: 
mapping_record TYPE cl_abap_corresponding=>mapping_info,
mapping_table  TYPE cl_abap_corresponding=>mapping_table.
mapping_record-level = 0.
mapping_record-kind  = cl_abap_corresponding=>mapping_component.
mapping_record-dstname = 'BEST_BRAIN_01'.
IF is_monster_header-hat_size > 5.
  mapping_record-srcname = 'BIGGEST_BRAIN'.
ELSE.
  mapping_record-srcname = 'SMALLEST_BRAIN'.
ENDIF.
APPEND mapping_record TO mapping_table.
mapping_record-dstname = 'BEST_BRAIN_02'.
IF id_monster_usage = 'MORTGAGE_SALESMAN'.
  mapping_record-srcname = 'EVILEST_BRAIN'.
ELSEIF id_monster_usage = 'MORRIS_DANCER'.
  mapping_record-srcname = 'WEIRDEST_BRAIN'.
ENDIF.
APPEND mapping_record TO mapping_table.

TRY.
  DATA(dynamic_mapper) = cl_abap_corresponding=>create(
    source = is_possible_brains
    destination = rs_best_brains
    mapping = mapping_table ).
  dynamic_mapper->execute(
    EXPORTING source = is_possible_brains
    CHANGING destination = rs_best_brains ).
  CATCH cx_corr_dyn_error.
  "Fatal Error
ENDTRY.


2) Build-in function LINE_INDEX and LINE_EXISTS

LOOP AT table_of_monsters FROM 
  line_index( table_of_monsters[ monster_number = monster_number ] )
  ASSIGNING FIELD-SYMBOL(<monster_details2>).
ENDLOOP.

DATA(start_row2) = line_index( table_of_monsters[ monster_number 
  = monster_number ] ).
LOOP AT table_of_monsters FROM start_row 
  ASSIGNING FIELD-SYMBOL(<monster_details>).
  "Do Something
ENDLOOP.


3) Internal Query with REDUCE

DATA lt_tab TYPE TABLE OF i WITH EMPTY KEY.
lt_tab = VALUE #( FOR j = 1 WHILE j <= 10 ( j ) ).
DATA(sum) = REDUCE i( INIT x = 0 FOR wa IN lt_tab NEXT x += wa ).


4) Filter internal table with FILTER

DATA lt_err = FILTER #( lt_result EXCEPT WHERE msgty = 'E' ).
DATA(averagely_mad_monsters2) =
  FILTER #( all_monsters USING KEY bonkers_ness
                         WHERE sanity < 75 ).


5) For all entries on Internal Table

SELECT *
  FROM ztmonster_pets
  INTO CORRESPONDING FIELDS OF TABLE monster_pets
  FOR ALL ENTRIES IN all_monsters
  WHERE owner = all_monsters-monster_number.
  
DATA(pets_of_our_monsters) =
  FILTER #( monster_pets IN all_monsters
            WHERE owner = monster_number ).


本篇文章已有0条评论