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: 

Error - Create chemical using program

Former Member
0 Kudos

Hi All,

I am trying to create a chemical using BO EHFND_CHEMICAL using program. Referring the sample code listed in 'Navigating to BOPF' blog series.

I have passed ROOT node and BI_CHEMICAL nodes. But I am getting error 'Mandatory node ROLE is missing'.

When I tried to add ROLE node , in the code its giving errors like 'Mandatory node ROLE is missing' OR can not create, source object does not exist'.

I went through the node structure for the BO. In it we have Root - > Revision -> Role.

So my query is how to pass information for ROLE node? We need to add REVISION node also?

If anybody can guide, will be really helpful.

1 ACCEPTED SOLUTION

0 Kudos

Hi Shubhada,

The problem is that determinations are creating instances of some of the nodes.  A determination is creating an instance of the REVISION node, but without the ROLE subnode instance—despite that the cardinality is 1:1…n.  This results in the error Mandatory node ROLE missing

The problem can be resolved by making two calls to the MODIFY method of the service manager.  Create only the ROOT node instance with the first call, and the determinations will create additional node instances, including the REVISION node instance.  Next get the key of the REVISION node instance, and use it to create an instance of the ROLE subnode by calling the MODIFY method again. Finally, commit the transaction by invoking the SAVE method of the transaction manager.  Following is a code sample:

         "Create the ROOT


         CREATE DATA lr_s_root.

         lr_s_root->key        = /bobf/cl_frw_factory=>get_new_key( ).

         lr_s_root->chm_nature = 'M'.

         APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.

         <ls_mod>-node         = if_ehfnd_chm_c=>sc_node-root.

         <ls_mod>-change_mode  = /bobf/if_frw_c=>sc_modify_create.

         <ls_mod>-key          = lr_s_root->key.

         <ls_mod>-data         = lr_s_root.

         CALL METHOD me->mo_chm_bo->mo_svc_mngr->modify

           EXPORTING

             it_modification = lt_mod

           IMPORTING

             eo_change       = lo_change

             eo_message      = lo_message.

         FREE lt_mod.

         "The REVISION node instance was created via a

         "determination. Get its key; it's needed to

         "create the ROLE node instance.

         lt_change = lo_change->get_changes( ).

         READ TABLE lt_change ASSIGNING <ls_change> INDEX 1.

         <ls_change>-change_object->get_changes( IMPORTING et_change = lt_node_change ).

         READ TABLE lt_node_change

           WITH KEY key1 COMPONENTS node_key = if_ehfnd_chm_c=>sc_node-revision

           ASSIGNING <ls_node_change>.

         lv_rev_key = <ls_node_change>-key.

         "Create the ROLE node instance; it's mandatory but was

         "not created in a determination

         CREATE DATA lr_s_role.

         lr_s_role->key       = /bobf/cl_frw_factory=>get_new_key( ).

         lr_s_role->chemical_role = '1'.

         APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.

         <ls_mod>-node        = if_ehfnd_chm_c=>sc_node-role.

         <ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_create.

         <ls_mod>-source_node = if_ehfnd_chm_c=>sc_node-revision.

         <ls_mod>-association =

           if_ehfnd_chm_c=>sc_association-revision-role.

         <ls_mod>-source_key  = lv_rev_key.

         <ls_mod>-key         = lr_s_role->key.

         <ls_mod>-data        = lr_s_role.

         CALL METHOD me->mo_chm_bo->mo_svc_mngr->modify

           EXPORTING

             it_modification = lt_mod

           IMPORTING

             eo_change       = lo_change

             eo_message      = lo_message.

         "Commit the transaction


         CALL METHOD me->mo_chm_bo->mo_txn_mngr->save

           IMPORTING

             eo_message  = lo_message

             ev_rejected = lv_rejected.

9 REPLIES 9

Former Member
0 Kudos

Hi Shubhada,

It would be better if you can attach the screenshot of the code you have written to create the chemical.

Looking at your BO, it is necessary to create REVISION node, as it is the parent node for the ROLE node.

Hope this helps you.

Regards,
Sanket.

0 Kudos

Hi Sanket,

Adding the code here.

*"Build the Rivision node:

      CREATE DATA lr_s_revision.

      lr_s_revision->key      = /bobf/cl_frw_factory=>get_new_key( ).

      APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.

      <ls_mod>-node        = IF_EHFND_CHM_C=>sc_node-revision.

      <ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_create.

      <ls_mod>-source_node = IF_EHFND_CHM_C=>sc_node-root.

      <ls_mod>-association =

        IF_EHFND_CHM_C=>sc_association-root-revision.

      <ls_mod>-source_key  = lr_s_root->key.

      <ls_mod>-key         = lr_s_revision->key.

      <ls_mod>-data        = lr_s_revision.

*        "Build the ROLE node:

        CREATE DATA lr_s_role.

        lr_s_role->key      = /bobf/cl_frw_factory=>get_new_key( ).

        lr_s_role->chemical_role    = '1'.

        APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.

        <ls_mod>-node        = if_ehfnd_chm_c=>sc_node-role.

        <ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_create.

        <ls_mod>-source_node = if_ehfnd_chm_c=>sc_node-revision.

        <ls_mod>-association =

          if_ehfnd_chm_c=>sc_association-revision-role.

        <ls_mod>-source_key  = lr_s_revision->key.

        <ls_mod>-root_key  = lr_s_root->key.

        <ls_mod>-key         = lr_s_role->key.

        <ls_mod>-data        = lr_s_role.

I think the source node or association I am entering here is incorrect.

But not able to figure it out.

0 Kudos

For me it looks like you forgot to add the parent key (the key of your revision instance) for the role.

0 Kudos

Hi Martin,

Thank you for the reply.

I have added parent key for the ROLE  but still getting error 'Mandatory node ROLE missing'.

*"Build the Revision node:

      CREATE DATA lr_s_revision.

      lr_s_revision->key      = /bobf/cl_frw_factory=>get_new_key( ).

      lr_s_revision->root_KEY = lr_s_root->key.

      APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.

      <ls_mod>-node        = IF_EHFND_CHM_C=>sc_node-revision.

      <ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_create.

      <ls_mod>-source_node = IF_EHFND_CHM_C=>sc_node-root.

      <ls_mod>-association =

        IF_EHFND_CHM_C=>sc_association-root-revision.

      <ls_mod>-source_key  = lr_s_root->key.

      <ls_mod>-key         = lr_s_revision->key.

      <ls_mod>-data        = lr_s_revision.

*        "Build the ROLE node:

        CREATE DATA lr_s_role.

        lr_s_role->key      = /bobf/cl_frw_factory=>get_new_key( ).

        lr_s_role->PARENT_KEY = lr_s_revision->key.

        lr_s_role->ROOT_KEY = lr_s_root->key.

        lr_s_role->chemical_role    = '1'.

        APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.

        <ls_mod>-node        = if_ehfnd_chm_c=>sc_node-role.

        <ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_create.

        <ls_mod>-source_node = if_ehfnd_chm_c=>sc_node-revision.

        <ls_mod>-association =

          if_ehfnd_chm_c=>sc_association-revision-role.

        <ls_mod>-source_key  = lr_s_revision->key.

        <ls_mod>-root_key  = lr_s_root->key.

        <ls_mod>-key         = lr_s_role->key.

        <ls_mod>-data        = lr_s_role.

Can you guide me please?

0 Kudos

The coding looks good for me. So maybe there is a role which needs to be created if you create a new revision. Check your model, maybe there is a validation on the revision node which validates that a certain role is created when you create a new revision instance.

0 Kudos

Hi Shubhada,

Your code looks good, but not confident about the REVISION Node.

For the REVISION Node the parent key is missing. Try filling that. Still if doesn't work then call service managers separately for each of the node creation.

And even check the association cardinality, if it is 1:1 then you need not create the ROLE node, you will have to just change the created ROLE node.

Regards,
Sanket.

0 Kudos

Hi Shubhada,

The problem is that determinations are creating instances of some of the nodes.  A determination is creating an instance of the REVISION node, but without the ROLE subnode instance—despite that the cardinality is 1:1…n.  This results in the error Mandatory node ROLE missing

The problem can be resolved by making two calls to the MODIFY method of the service manager.  Create only the ROOT node instance with the first call, and the determinations will create additional node instances, including the REVISION node instance.  Next get the key of the REVISION node instance, and use it to create an instance of the ROLE subnode by calling the MODIFY method again. Finally, commit the transaction by invoking the SAVE method of the transaction manager.  Following is a code sample:

         "Create the ROOT


         CREATE DATA lr_s_root.

         lr_s_root->key        = /bobf/cl_frw_factory=>get_new_key( ).

         lr_s_root->chm_nature = 'M'.

         APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.

         <ls_mod>-node         = if_ehfnd_chm_c=>sc_node-root.

         <ls_mod>-change_mode  = /bobf/if_frw_c=>sc_modify_create.

         <ls_mod>-key          = lr_s_root->key.

         <ls_mod>-data         = lr_s_root.

         CALL METHOD me->mo_chm_bo->mo_svc_mngr->modify

           EXPORTING

             it_modification = lt_mod

           IMPORTING

             eo_change       = lo_change

             eo_message      = lo_message.

         FREE lt_mod.

         "The REVISION node instance was created via a

         "determination. Get its key; it's needed to

         "create the ROLE node instance.

         lt_change = lo_change->get_changes( ).

         READ TABLE lt_change ASSIGNING <ls_change> INDEX 1.

         <ls_change>-change_object->get_changes( IMPORTING et_change = lt_node_change ).

         READ TABLE lt_node_change

           WITH KEY key1 COMPONENTS node_key = if_ehfnd_chm_c=>sc_node-revision

           ASSIGNING <ls_node_change>.

         lv_rev_key = <ls_node_change>-key.

         "Create the ROLE node instance; it's mandatory but was

         "not created in a determination

         CREATE DATA lr_s_role.

         lr_s_role->key       = /bobf/cl_frw_factory=>get_new_key( ).

         lr_s_role->chemical_role = '1'.

         APPEND INITIAL LINE TO lt_mod ASSIGNING <ls_mod>.

         <ls_mod>-node        = if_ehfnd_chm_c=>sc_node-role.

         <ls_mod>-change_mode = /bobf/if_frw_c=>sc_modify_create.

         <ls_mod>-source_node = if_ehfnd_chm_c=>sc_node-revision.

         <ls_mod>-association =

           if_ehfnd_chm_c=>sc_association-revision-role.

         <ls_mod>-source_key  = lv_rev_key.

         <ls_mod>-key         = lr_s_role->key.

         <ls_mod>-data        = lr_s_role.

         CALL METHOD me->mo_chm_bo->mo_svc_mngr->modify

           EXPORTING

             it_modification = lt_mod

           IMPORTING

             eo_change       = lo_change

             eo_message      = lo_message.

         "Commit the transaction


         CALL METHOD me->mo_chm_bo->mo_txn_mngr->save

           IMPORTING

             eo_message  = lo_message

             ev_rejected = lv_rejected.

0 Kudos

A huge thank you to you Kelly

Your explanation and code is correct. I could create a chemical. Thank you.

I was wondering how do we know the role of determinations? I was not able to get relation between the revision and role. If you have any good documentation/links please share.

Former Member
0 Kudos

Hi Gurus,

I need to create a subnode instance from the root through a determination.

I assume that the above code is only applicable when you want to create a subnode of a root in an external program. (I've tried it, but it is not succesful.)

Can anyone give me an idea to realise this?

Thank you.

Regards.