Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to assign default value to attribute?

Former Member
0 Kudos
666

is it possible to assign a default value to a given attribute of a node instance upon creation?

e.g. when a new instance of a node is created, i always want an attribute to contain a certain default value...

cheers

--MIKE

10 REPLIES 10

cyclingfisch_
Active Contributor
0 Kudos
251

Hi Mike,

you can create a determination which is triggered on create. In this determination you can set values.

Cheers,

Martni

0 Kudos
251

Which release? We are on SAP_BW_FND 7.31 SP 4 and i cannot see the trigger "on create"...

0 Kudos
251

Hi Mike,

For Martins solution you need to set the request node on create and only on create:

And Then configure under node category assignement after modify (and also only after modify):

But for node default values there is a better approach provided: The node class

In the conf_ui you can configure a node class on node level:

There you can enter a class which implements the interface /BOBF/IF_FRW_NODE. This interface provides a method for setting node default values:

Kind Regards

Aiko

0 Kudos
251

any ideas, why this code is not working?

  data:
    root_records        type /sesi/t_mw_root,
    root_record         type ref to /sesi/s_mw_root.



  io_read->retrieve( exporting iv_node      = is_ctx-node_key
                               it_key       = it_key
                               iv_fill_data = abap_true
                     importing et_data      = root_records ).

  loop at root_records reference into root_record.
    root_record->state = 'A'.

    io_modify->update( iv_node = is_ctx-node_key
                       iv_key  = root_record->key
                       is_data = root_record ).
  endloop.

the node instance is created, but attribute STATE remains initial...

0 Kudos
251

yes, you have to declare which attributes you want to change.

Use the parameter IT_CHANGED_FIELDS of the update method for that.

0 Kudos
251

thanks martin. doesnt work ... sorry...

  data:
    root_records        type /sesi/t_mw_root,
    root_record         type ref to /sesi/s_mw_root,
    changed_field       type line of /bobf/t_frw_name,
    changed_fields      type /bobf/t_frw_name.


  io_read->retrieve( exporting iv_node      = is_ctx-node_key
                               it_key       = it_key
                               iv_fill_data = abap_true
                     importing et_data      = root_records ).


  changed_field = 'STATE'.
  insert changed_field into table changed_fields.


  loop at root_records reference into root_record.
    root_record->state = 'A'.

    io_modify->update( iv_node           = is_ctx-node_key
                       iv_key            = root_record->key
                       is_data           = root_record
                       it_changed_fields = changed_fields ).
  endloop.

0 Kudos
251

For me the code looks good at first sight.

But it is better to use the constants for the attribute names instead of a text literal.

There should be a generated constant interface for your business object and you can find the attributes there:

<constant interface of your BO>=>sc_node_attribute-root-state

0 Kudos
251

I use the constant now, but it does not work... any other suggestions?

0 Kudos
251

Which way did you choose? Via Determination or Node Class? Did you set a Break-Point in the code and checked, if he stopped there during creation of an instance?

0 Kudos
251

I implemented a Node class. I can see that all this is running successfully in debugger, but unfortunately, nothing is really changed in the newly created node instance...