cancel
Showing results for 
Search instead for 
Did you mean: 

xSteps: how to add nodes through ABAP

VXLozano
Active Contributor
0 Kudos

I need to add a xStep node in the tree of a process order. I'm trying to do it through the CMX_XS* classes' methods, but I'm stuck with the if_cmx_xs_root->edit method.

The problem is that method calls a CO_BT* function module that checks a in-memory internal table, where my order is NOT because I'm not changing the order through standard transactions. I think it must exist a way to say the system I'm changing that order, but I cannot find it.

Up to now, my code looks like:

DATA: myfac       TYPE REF TO if_cmx_xs_factory,

         mylib       TYPE REF TO if_cmx_xs_library,

         mychange    TYPE REF TO if_cmx_xs_change_object,

         myroot      TYPE REF TO if_cmx_xs_root,

         mynode      TYPE REF TO if_cmx_xs_node,

         mycopy      TYPE REF TO if_cmx_xs_node,

         myex        TYPE REF TO cx_cmx_xs_exception,

         myerr       TYPE string,

         t_children  TYPE cmx_xs_t_node.

   myfac = cl_cmx_xs_system=>get_factory( ).

   mylib = cl_cmx_xs_system=>get_library( ).

* Well, it seems we need another child, not the first one

   TRY.

       IF mychange IS INITIAL.

         mychange = myfac->create_change_object_nonhist( ).

       ENDIF.

       CALL METHOD mylib->get_root_by_nid

         EXPORTING

           nid           = <child>-parent_oid

           change_object = mychange

         RECEIVING

           root          = myroot.

     CATCH cx_cmx_xs_exception INTO myex.

       myerr =  myex->if_message~get_text( ).

   ENDTRY.

   IF myerr IS INITIAL.

     TRY.

         CALL METHOD myroot->get_children

           RECEIVING

             children = t_children.

       CATCH cx_cmx_xs_exception INTO myex.

         myerr =  myex->if_message~get_text( ).

     ENDTRY.

     IF myerr IS INITIAL.

       READ TABLE t_children INTO mynode INDEX 3.

       IF sy-subrc = 0.

         TRY.

             CALL METHOD mynode->get_copy

               RECEIVING

                 result = mycopy.

           CATCH cx_cmx_xs_exception INTO myex.

             myerr =  myex->if_message~get_text( ).

         ENDTRY.

         IF myerr IS INITIAL.

           TRY.

               myroot->edit( ).

               myroot->append_child( mycopy ).

             CATCH cx_cmx_xs_exception INTO myex.

               myerr =  myex->if_message~get_text( ).

           ENDTRY.

         ENDIF.

       ENDIF.

     ENDIF.

   ENDIF.

In the last TRY you can see the myroot->edit call, that triggers the excepcion message "Order xxxxx hass not been loaded."

I cannot get the message's information because it's not in the cx_cmx_xs_exception class (or I've not been able to find it yet).

Any hint would be appreciated. Thanks in advance,

Vic

Accepted Solutions (1)

Accepted Solutions (1)

VXLozano
Active Contributor
0 Kudos

I've received help from Herr Doctor Uwe Dittes, who pointed me to the SAP Note 1453716, the CMX_TOOLS package and the function module CMX_TOOLS_FM_CREATE_XS_TREE. It's a good point to start from.

Thank you, Uwe!

Answers (1)

Answers (1)

0 Kudos

When you add new nodes to the tree model, set the flag ITEMSINCOM to 'X'.
This informs the tree model that you want to load the items for that node on demand.

Hope that Helps.

Beyond that, try to call EXPAND_NODE after you added the items/nodes and see if that helps.

VXLozano
Active Contributor
0 Kudos

Hello Bharat and thanks for your answer.

I cannot find that flag nor that method (I guess is a method) you pointed me.

Let me try to explain better my needs:

I have a three levels order tree:

  • preparation
  • action
  • package

When the preparation team finishes, they must click a button to assign the action order to one or more action teams. Because not all action orders will be assigned to the same number of teams, I must create Process Instructions for each team. It means I must:

  1. enter into the action order xStep tree
  2. find the action reference node
  3. clone it as many times as needed

My current approach is to use the CMX_XS classes to find the reference node and clone it. My current trouble is the need to put the order in "Edit" mode, or the APPEND_CHILD method doesn't work.

But when I try to call the EDIT method, the system tries to find the order number in a memory table and crashes because the number is not there.

Any other approach available? I've been suggested to use Batch-Inputs through COR2, but it will hard as hell to code a batch-input with all those tree-nodes and context menuses