Skip to content

Instantly share code, notes, and snippets.

@njames
Created December 13, 2013 05:25
Show Gist options
  • Save njames/7940126 to your computer and use it in GitHub Desktop.
Save njames/7940126 to your computer and use it in GitHub Desktop.
copy from one structure to another copy of the same structure and only overwrite the new items
METHOD copy_structure .
* parameters
* i_new type any
* i_old type any
* final - changing type any
* copy by component only if the new value is populated else take
* the existing component
DATA: _componentno TYPE i VALUE 0
.
FIELD-SYMBOLS: <field_new> TYPE ANY
, <field_old> TYPE ANY
.
final = i_old.
DO.
_componentno = _componentno + 1.
ASSIGN COMPONENT _componentno OF STRUCTURE final TO <field_old>.
ASSIGN COMPONENT _componentno OF STRUCTURE i_new TO <field_new>.
IF sy-subrc <> 0.
EXIT.
ELSE.
IF <field_old> IS ASSIGNED
AND <field_new> IS ASSIGNED
AND <field_new> IS NOT INITIAL.
<field_old> = <field_new>.
ENDIF.
ENDIF.
ENDDO.
ENDMETHOD.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment