cancel
Showing results for 
Search instead for 
Did you mean: 

Reading context using method chaining in 7.02

frank_stdle
Participant
0 Kudos

In 7.02, method chaining in ABAP is allowed, which means that we can write less code and use fewer temporary variables. In a web dynpro view method, is there a method for reading the contents of a context node into a structure using just one line of code? I tried this:

ls_old_material = wd_context->get_child_node( name = wd_this->wdctx_old_material )->get_static_attributes( )

This does not work because get_attributes() does not have a returning parameter.

So I have to do it this way:

lo_el_old_material = wd_context->get_child_node( name = wd_this->wdctx_old_material )->get_element( ).


lo_el_old_material->get_static_attributes( IMPORTING static_attributes = ls_old_material ).

Any tips on how to squeeze this into on line?

thanks!
Frank

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Yes, use GET_STATIC_ATTRIBUTES_REF instead:

data ls_selection_criteria type ref to wd_this->element_selection_criteria.
  ls_selection_criteria ?= wd_context->get_child_node(
    name = wd_this->wdctx_selection_criteria )->get_element( )->get_static_attributes_ref( ).


append ls_selection_criteria->* to it_name.

frank_stdle
Participant
0 Kudos

Thanks for the quick reply - I noticed that option, but I think perhaps having to derefence whenever I need the data will make the code a bit confusing to most people.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I don't know.  Personally once I got used to data references I really like them. Treating a field in a structure the same as an attribute of a class instance starts to make sense. I started using the data references for the content becuase of the method chaining, but now I find myself using them with the context whenever possible.

It can be more memory efficient as well. There is a lot of dynamic type creation involved with the other approach. The reference approach is much lighter since the original data reference can just be passed around.

frank_stdle
Participant
0 Kudos

Thomas, I just went ahead with your suggestion and I realized that I can reference a field in a structure using the -> just like an object. I did not know that was possible until now, but I have to say I like it. It makes sense to me to treat structures as objects with attributes and no methods. Im sold!

frank_stdle
Participant
0 Kudos

Is this also possible if the context node is a table, that 0..n cardinality? Can you get a reference to the context node as a table?

Answers (0)