It's pretty basic code but I do it often so I might as well be able to reuse it.
-
Creating a new anonymous data object of the same type of an existing variable:
data(new_ref) = new zcl_anonymous_data_object( i_like = existing_var )->ref( ).
-
Creating a new anonymous data object with a specified type:
data(new_ref) = new zcl_anonymous_data_object( i_type = some_var_type )->ref( ).
-
Copying an existing variable (both type and value) to a new anonymous data object:
data(copied_var) = new zcl_data_object_copy( existing_var )->ref( ).