Skip to Content
avatar image
Former Member

How to set a value to Object attribute?

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.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Oct 09, 2007 at 09:17 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded