cancel
Showing results for 
Search instead for 
Did you mean: 

Attribut Componentcontroller

0 Kudos

Hi,

i want to reference to a attribut of the componentcontroller:

data: lv_value TYPE bukrs.

lv_value = wd_this->bukrs

thats the normal way. now i have only the litera 'bukrs' and i want to have the value of the attribute. How can i dynamically reference to the attribute.

data: lv_value TYPE bukrs

lv_attr TYPE string.

lv_attr = 'BUKRS'.

lv_value = wd_this->lv_attr ?????

Is there a way to do this?

Thanx

Accepted Solutions (0)

Answers (2)

Answers (2)

saravanan_narayanan
Active Contributor
0 Kudos

Hello Lars,

you dynamically access the member variable like this


field-symbols <fv> type bukrs.

assign wd_this->('BUKRS') to <fv>. "here 'BUKRS' is name of the member variable that is defined in the Attributes tab of the component controller and it should be in upper case

BR, Saravanan

Former Member
0 Kudos

Hi,

>

> i want to reference to a attribut of the componentcontroller:

>

> data: lv_value TYPE bukrs.

> lv_value = wd_this->bukrs

>

> thats the normal way. now i have only the litera 'bukrs' and i want to have the value of the attribute. How can i dynamically reference to the attribute.

>

> data: lv_value TYPE bukrs

> lv_attr TYPE string.

>

> lv_attr = 'BUKRS'.

> lv_value = wd_this->lv_attr ?????

>

> Is there a way to do this?

>

> Thanx

I am not sure if i understand you.

Say for example if you have a attribute (burks of type string defined in component controller as public ).

You want to assign the value of "burks" from component controller to the local variable in a view.

in that case the following statement would be appropriate.

data lv_value type string.

lv_value = wd_comp_controller->burks.

0 Kudos

Hi,

no you don't understand me. I do not know if there is an attribute called bukrs during the runtime. The attribut would be created dynamically. I have the literal "BUKRS" and i want to check is there an attribut called BUKRS, if yes give me the value.

So how can i reference to an component_controller alttribute with a literal? Typecast , assign etc.

Thanx

Edited by: Lars Schmittgen on Aug 20, 2011 11:45 AM

former_member450736
Active Participant
0 Kudos

Hi,

In addition to what sarvanan explained, you use below code to find out what is the type of varible and then get the value.

DATA: typedescr TYPE REF TO cl_abap_typedescr,
        header    TYPE x030l,
        lv_bukrs  TYPE bukrs.

  FIELD-SYMBOLS: <fs_bukrs> TYPE ANY,
                 <ls_bukrs> TYPE bukrs.

  CONSTANTS: c_bukrs TYPE bukrs VALUE '0100'.

* variable cretaion at runtime using type BUKRS
  CREATE DATA wd_this->generic TYPE ('BUKRS').

  ASSIGN wd_this->generic->* TO <fs_bukrs>.
  <fs_bukrs> = c_bukrs.

  ASSIGN wd_this->('TEST') TO <ls_bukrs>.
  <ls_bukrs> = '0002'.

  typedescr ?= cl_abap_datadescr=>describe_by_data( <ls_bukrs> ).

  header = typedescr->get_ddic_header( ).

* check if type of controller attribute at runtime is BUKRS
  IF header-tabname = 'BUKRS'.
*    ASSIGN wd_this->generic->* TO <ls_bukrs>.
*    lv_bukrs = <ls_bukrs>.
    
  ENDIF.

here wd_this->generic is of type 'DATA' and 'TEST' is of type 'BUKRS'.

What i do not understood here is if we are aware that type of 'TEST' is bukrs what is point of checking it again to get value??

unless controller attribute is generic type and we are creating the data dynamically.

or else, there should be someway to create controller attribute dynamically using WD API. i am not sure if this option is there in WD ABAP api.

Thanks,

Kranthi.