Skip to Content
avatar image
Former Member

Attribut Componentcontroller

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Aug 19, 2011 at 02:40 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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.

  • avatar image
    Former Member
    Aug 20, 2011 at 09:53 AM

    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

    Add comment
    10|10000 characters needed characters exceeded