MOVE-CORRESPONDING только заполненных полей

Описанный ниже класс и макрос позволяет делать MOVE-CORRESPONDING только заполненных полей

  1. CLASS lcl_utilities DEFINITION FINAL CREATE PRIVATE.
  2. PUBLIC SECTION.
  3. move_corresponding_ignore_init
  4. IMPORTING
  5. i_str_source TYPE any
  6. CHANGING
  7. c_str_dest TYPE any.
  8.  
  9. CLASS lcl_utilities IMPLEMENTATION.
  10. METHOD move_corresponding_ignore_init.
  11. l_rcl_abap_structdescr TYPE REF TO cl_abap_structdescr.
  12. <fs_str_component> LIKE LINE OF l_rcl_abap_structdescr->components,
  13. <fs_source_field> TYPE any,
  14. <fs_dest_field> TYPE any.
  15.  
  16. l_rcl_abap_structdescr ?= cl_abap_typedescr=>describe_by_data( i_str_source ).
  17. LOOP AT l_rcl_abap_structdescr->components ASSIGNING <fs_str_component>.
  18. ASSIGN COMPONENT <fs_str_component>-name OF STRUCTURE c_str_dest TO <fs_dest_field>.
  19. IF sy-subrc = 0.
  20. ASSIGN COMPONENT <fs_str_component>-name OF STRUCTURE i_str_source TO <fs_source_field>.
  21. ASSERT sy-subrc = 0.
  22. IF <fs_source_field> IS NOT INITIAL.
  23. <fs_dest_field> = <fs_source_field>.
  24. ENDMETHOD. "move_corresponding_ignore_init
  25.  
  26. DEFINE move_corresponding_ignore_init.
  27. lcl_utilities=>move_corresponding_ignore_init(
  28. exporting
  29. i_str_source = &1
  30. changing
  31. c_str_dest = &2
  32. ).

Категория: