cancel
Showing results for 
Search instead for 
Did you mean: 

How to set a value to Object attribute?

Former Member
0 Kudos

I programmed as like that.

BEGIN_METHOD SET_ATTRIBUTE CHANGING CONTAINER.

...

OBJECT-UNAME = sy-uname.

SWC_REFRESH_OBJECT SELF.

END_METHOD.

Why does not the object 'UNAME' attribute set a current user?

I wonder how to set the object attribute?

Plz Help.

Accepted Solutions (0)

Answers (1)

Answers (1)

KKilhavn
Active Contributor
0 Kudos

First of all: import and export is via the container. Since this is a method, you should (from a "nice design" perspective) have exporting parameters.

So you need to update the container to get your data out. The value is read from the container, not from the object's (internal, private) data structure. Although this example is a bit special, normally you try to avoid difficult calculations by doing something along the following lines.

begin_method set_attribute CHANGING container.
IF object-uname IS INITIAL.
  object-uname = sy-uname.
ENDIF.

swc_set_element container 'UserName' object-uname.
end_method.

<i>Message was edited by Kjetil Kilhavn:</i>

If you have a virtual attribute you will in your code always need to update the container, even if you have done it in your method as in the example. The template code SAP offers to generate will have the necessary statements to update the container for a virtual attribute.