2009 Aug 24 8:09 AM
HI ,
i build instance method with attributes and i want to fill this attributes with data and move it during the process to all the method that a
participate in the process
for example if i have method for create user and the public method get in the parameters
user i move it to the attributes mv_user like
mv_userid = is_user_data-userid .
and all the method know this field .
my question if i should use this like i do or to use set and get for it .
i have lot of attributes in my class .
Thanks
Nina
2009 Aug 24 8:47 AM
Hi Nina,
I guess this is in relevance to Joy's post
As for the question:
- use GET method when you want to receive exactly one result
"i.e method which returns user data
methods: get_user IMPORTING name TYPE ...
RETURNING VALUE(user_data) TYPE ....
...
method get_user.
"read here data for particular user and return to USER_DATA
user_data = is_user_data.
endmethod.
"now method could be called like
data: user type ...
user = lcl->get_user( 'MARCINP' ). "now USER will receive data stored in class for MARCINP
Here you should note that, no EXPORTING parameters are allowed together with RETURNING value. RETURNING means that this method is purerly for retrieving some data from class and expose them outside the class. And only this data we are interested in.
- SET method you could use similary. i.e you want to set some active user (from couple which are stored in class).
methods: set_user IMPORTING name TYPE...
method set_user.
"here you get approriate data for user and set attributes
mv_userid = is_user_data-userid . "now attibute MV_USERID stores data for active user, so all the methods can work directly with this user
endmethod.
It really depends on if you want entire class instance for one user only, or for several users.
The method CREATE_USER which you mention can also be applied if i.e you store different users in table within class. So every time you want new user to appear in class table you simply call your method adding new user. Here active user would be the one which you get with SET_USER, so you read data for one user and set attributes. Then you work with this user data. If in some moemnt you want to switch to other user, you simply SET another user active, and now you work with his/her data as class attributes.
If you still have some doubts let us know.
Regards
Marcin
HI ,
i build instance method with attributes and i want to fill this attributes with data and move it during the process to all the method that a
participate in the process
for example if i have method for create user and the public method get in the parameters
user i move it to the attributes mv_user like
mv_userid = is_user_data-userid .
and all the method know this field .
my question if i should use this like i do or to use set and get for it .
i have lot of attributes in my class .
Thanks
Nina
2009 Aug 24 8:47 AM
Hi Nina,
I guess this is in relevance to Joy's post
As for the question:
- use GET method when you want to receive exactly one result
"i.e method which returns user data
methods: get_user IMPORTING name TYPE ...
RETURNING VALUE(user_data) TYPE ....
...
method get_user.
"read here data for particular user and return to USER_DATA
user_data = is_user_data.
endmethod.
"now method could be called like
data: user type ...
user = lcl->get_user( 'MARCINP' ). "now USER will receive data stored in class for MARCINP
Here you should note that, no EXPORTING parameters are allowed together with RETURNING value. RETURNING means that this method is purerly for retrieving some data from class and expose them outside the class. And only this data we are interested in.
- SET method you could use similary. i.e you want to set some active user (from couple which are stored in class).
methods: set_user IMPORTING name TYPE...
method set_user.
"here you get approriate data for user and set attributes
mv_userid = is_user_data-userid . "now attibute MV_USERID stores data for active user, so all the methods can work directly with this user
endmethod.
It really depends on if you want entire class instance for one user only, or for several users.
The method CREATE_USER which you mention can also be applied if i.e you store different users in table within class. So every time you want new user to appear in class table you simply call your method adding new user. Here active user would be the one which you get with SET_USER, so you read data for one user and set attributes. Then you work with this user data. If in some moemnt you want to switch to other user, you simply SET another user active, and now you work with his/her data as class attributes.
If you still have some doubts let us know.
Regards
Marcin
2009 Aug 24 8:50 AM
some theorists would say that you must only use set/get methods (public of course) and define only private attributes. But it may cost a lot in abap because you spend time to create set/get methods (there are currently no automatic code generator). So it's up to you. I just recommend you not to bother too much with all this stuff. Read internet discussions about object oriented programming.