How to find the Customizing Path via IMG-Activity
Asked Answered
R

2

6

I want to read the customizing path of an IMG-Activity in SAP via Code (abap). I have the IMG-Activity from e071K, which stores objects within a transport job. Now I found the table TNODEIMG where the tree structure of SPRO is stored. This is perfect, because it holds what I need. But I can't find the connection to my IMG-Activity. The Unique-Id in TNODEIMG is in other format and seems to be a different Id. Someone got an idea how I can read this out?

UPDATE:

@vwegert: Thank you for you helpful answer. So far I get this list filled with Node-Id's: lt_eref_list, but don't get the parents. Do you see some missunderstood or failure here?

DATA: lt_iref_list TYPE STANDARD TABLE OF hier_ref,
          lt_eref_list TYPE STANDARD TABLE OF hier_ref,
          ls_ref TYPE hier_ref,
          lt_parent_list TYPE STANDARD TABLE OF hier_iface,
          lt_check_list TYPE STANDARD TABLE OF hier_iface.

    ls_ref-node_id = 'SIMG_CFMENUOLQSOQ46'.
    APPEND ls_ref TO lt_iref_list.

    CALL FUNCTION 'STREE_GET_NODES_FOR_GIVEN_REF'
      TABLES
        i_list_of_references = lt_iref_list
        e_list_of_references = lt_eref_list.

    LOOP AT lt_eref_list ASSIGNING FIELD-SYMBOL(<ls_ref>).

      CALL FUNCTION 'STREE_GET_PARENTS_OF_NODE'
        EXPORTING
          structure_id = <ls_ref>-node_id
*     IMPORTING
*         message      = ls_message
        TABLES
          check_nodes  = lt_check_list
          parent_nodes = lt_parent_list.

    ENDLOOP.

Thank you in advance.

Roily answered 1/8, 2017 at 14:41 Comment(4)
You are aware of the fact that an activity can (and very frequently does!) appear in multiple tree structures, and either directly or via inclusion even multiple times within the same tree?Creativity
@Creativity thanks you for this information, I wasn't aware of this. But my problem is still the same. How to find an IMG-Activity in the TNODESIMG Table. How is this linked? I can read multiple tree path as well, thats not the problem.Roily
What do you need it for - what is the actual problem you are trying to solve? If you are simply searching for the nodes, the existing Where-Used function of the activity might be sufficient...?Creativity
@Creativity I'm developing a report, which generates a documentation of transport jobs. If a the job is a customizing job, I have to print the whole tree/trees like they are shown in SPRO. I'm not aware about the Where-Used function, can you explain this? Thank you in advance.Roily
C
1

IMG activities are maintained using the rather unwieldy transaction S_CUS_IMG_ACTIVITY. That transaction supplies a where-used function:

where-used index

Tracing that function leads through the function modules S_CUS_IMG_ACTIVITY_XREF and S_CUS_IMG_ENTRY_VIA_ACTIVITY to a function module named STREE_GET_NODES_FOR_GIVEN_REF that identifies the nodes (for the preparation, check its caller). Reading these function modules gives you a lot of information about the structures and function modules to be used.

For your purposes, STREE_GET_NODES_FOR_GIVEN_REF might be interesting. In the list of references, specify the activity ID as NODE_ID with type COBJ. This will give you a list of nodes including their parent IDs that you can then feed to STREE_GET_PARENTS_OF_NODE (the structure ID is the tree ID from the result set). To get the node text, you would use STREE_NODE_READ.

Creativity answered 3/8, 2017 at 6:24 Comment(2)
can you please take a look at my update? Your answer is very helpful, but I'm struggeling...Roily
1. The structure ID is the tree ID, not the node ID. 2. You need to pass the node(s) you want to get the parents of into the parameter CHECK_NODES.Creativity
S
0

Here is another approach for finding the IMG path, table-based.

In e071k we have technical IDs of IMG activities. You can also enable them in SPRO via Additional Information –> Additional Information –> Display Key –> IMG Activity, so they will be showed like this:

enter image description here

But in TNODEIMG table we have GUID IDs, which are not the same as technical ones. The relation table you can use for linking them is TNODEIMGR, it contains both GUID and tech ID of each node. Joining parent node, node ID and node text from TNODEIMGR, TNODEIMG and TNODEIMGT tables, we can build full IMG path for each node:

REPORT z_img.

DATA: lv_final_path TYPE string,
      exit_root     TYPE abap_bool,
      out           TYPE string.

* picking random activity from requests
SELECT SINGLE *
  FROM e071k
  INTO @DATA(lv_e071k).

* finding correspondent GUID ID for tech ID
SELECT gr~node_id, ach~text, img~parent_id
  FROM tnodeimgr AS gr
  JOIN cus_imgact AS ach
    ON ach~activity = gr~ref_object
  JOIN tnodeimg AS img
    ON img~node_id = gr~node_id
   AND spras = @sy-langu
  INTO TABLE @DATA(lt_node)
 WHERE ref_object = @lv_e071k-activity.

LOOP AT lt_node ASSIGNING FIELD-SYMBOL(<fs_tnode>).
  CLEAR: lv_final_path.

* writing bottom node text
  lv_final_path = lv_final_path && <fs_tnode>-text.
  DATA(lv_node_id) = <fs_tnode>-parent_id.

  DO 15 TIMES.
* fetching parent node text
    SELECT SINGLE g~parent_id, text
      INTO @DATA(lv_node)
      FROM tnodeimg AS g
      LEFT JOIN tnodeimgt AS t
        ON t~tree_id = g~tree_id
       AND t~extension = g~extension
       AND t~node_id = g~node_id
       AND t~ext_key = g~ext_key
       AND t~spras = @sy-langu
     WHERE g~node_id = @lv_node_id.

* checking if parent exists
    IF sy-subrc <> 0.
      exit_root = abap_true.
      EXIT.
    ELSE.
      exit_root = abap_false.
    ENDIF.

    lv_final_path = |{ lv_final_path } \n { repeat( val = |\t| occ = sy-index + 1 ) } --> { lv_node-text }|.
    lv_node_id = lv_node-parent_id.

    IF lv_node-parent_id IS INITIAL.
      EXIT.
    ENDIF.

  ENDDO.

  CHECK exit_root = abap_false.
* building the path
  lv_final_path = | IMG  path no. { sy-tabix } is \n\n { lv_final_path } \n\n |.
  out = out && lv_final_path.

ENDLOOP.

cl_demo_output=>display( out ).

However, the very root IMG node is not accessible with this approach.

Subclavius answered 7/8, 2017 at 14:30 Comment(1)
I would rather use the existing infrastructure than access the tables directly.Creativity

© 2022 - 2024 — McMap. All rights reserved.