Skip to end of metadata
Go to start of metadata

Author: Tamilselvan K
Submitted: 9TH MAY 2008
Related Links:

In webdynpro abap,I dont find a F4 help for the organization hierarchy in the tree structure,so i developed the custom one which i placed here for your reference further you can can use this component in some other webdynpro component using the option of 'FREELY PROGRAMMED INPUT HELP' provided in the webdynpro ABAP.

I used the tree element with the recursive node option to attain the organization hierarchy structure as shown below. the fig shows only the object id's and not the name of the organization(U can add a extra field in the view context to display the name also if needed)
 

The steps involved involved in developing the above application will be as follows

Step1:create a webdynpro component and in the layout of the main view of the component include the tree element as shown below with the node type and the item type
Step2 : Next goto the context of the view and create the context nodes(with the recursive node)  as shown below

  
step3 : create the events onaction and onloadchildren for the nodetype as displayed in the below figure
Step4 : create the methods create_node and create_unit_element for the purpose of dynamically creating the nodetype and item type as shown below
step5: Add the attached code in the corresponding methods as shown below

method ONACTIONLOAD .

  DATA : PKEY TYPE STRING.

data children_loaded type wdy_boolean.

* check that the children of the same node weren't loaded a second
* time
    context_element->get_attribute( exporting name = 'CHILDREN_LOADED'
   importing value = children_loaded ).
    check children_loaded = abap_false.
    context_element->set_attribute( name = 'CHILDREN_LOADED' value =
   abap_true ).

  context_element->get_attribute( EXPORTING name = 'TEXT'
                                 IMPORTING VALUE = PKEY ).
 
 CREATE_NODE( EXPORTING CUR_ELEM = context_element
                        PARENT_KEY = PKEY ).

endmethod.

method CREATE_NODE .

  DATA:
      lr_cur_node TYPE REF TO if_wd_context_node,
      folder_item TYPE ihttpnvp,
      file_item   TYPE ihttpnvp,
       ITEM TYPE ihttpnvp.

DATA : L_OBJEC TYPE TABLE OF OBJEC,
       L_SWHACTOR TYPE TABLE OF SWHACTOR,
       OBJ TYPE HRP1001-OBJID,
       WA TYPE SWHACTOR.

DATA :L_OBJEC_1 TYPE TABLE OF OBJEC,
       L_SWHACTOR_1 TYPE TABLE OF SWHACTOR.

OBJ = PARENT_KEY.
CALL FUNCTION 'RH_STRUC_GET'
  EXPORTING
    ACT_OTYPE              = 'O'
    ACT_OBJID              = OBJ
    ACT_WEGID              = 'ORGEH'
*   ACT_INT_FLAG           =
   ACT_PLVAR              = '01'
   ACT_TDEPTH             = 2
 TABLES
   RESULT_TAB             = L_SWHACTOR
   RESULT_OBJEC           = L_OBJEC
*   RESULT_STRUC           =
 EXCEPTIONS
   NO_PLVAR_FOUND         = 1
   NO_ENTRY_FOUND         = 2
   OTHERS                 = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT L_SWHACTOR INTO WA.

  CALL FUNCTION 'RH_STRUC_GET'
  EXPORTING
    ACT_OTYPE              = 'O'
    ACT_OBJID              = wa-objid
    ACT_WEGID              = 'ORGEH'
*   ACT_INT_FLAG           =
   ACT_PLVAR              = '01'
   ACT_TDEPTH             = 2
 TABLES
   RESULT_TAB             = L_SWHACTOR_1
   RESULT_OBJEC           = L_OBJEC_1
*   RESULT_STRUC           =
 EXCEPTIONS
   NO_PLVAR_FOUND         = 1
   NO_ENTRY_FOUND         = 2
   OTHERS                 = 3
          .
IF L_SWHACTOR_1 IS NOT INITIAL.
  lr_cur_node = cur_elem->get_child_node( 'UNIT_CONTENT' ).
  ITEM-NAME = WA-OBJID.
  ITEM-VALUE = PARENT_KEY.

wd_This->Create_Unit_Element(
   EXPORTING
    CUR_NODE =  lr_cur_node                        " Ref to if_Wd_Context_Node
    FILE_ITEM = item                        " Ihttpnvp
  ).

ELSE.

  lr_cur_node = cur_elem->get_child_node( 'UNIT_ITEM' ).

DATA: lr_cur_element TYPE REF TO if_wd_context_element.

  lr_cur_element = LR_CUR_node->create_element( ).
  lr_cur_element->set_attribute( name = 'TEXT_ITEM' value = WA-OBJID ).

  LR_cur_node->bind_element( new_item = lr_cur_element set_initial_elements
= abap_false ).

ENDIF.

CLEAR : L_SWHACTOR_1,L_OBJEC_1,WA.

ENDLOOP.

endmethod.

method CREATE_UNIT_ELEMENT .

  DATA: lr_cur_element TYPE REF TO if_wd_context_element.

  lr_cur_element = cur_node->create_element( ).
  lr_cur_element->set_attribute( name = 'TEXT' value = file_item-name ).

  cur_node->bind_element( new_item = lr_cur_element set_initial_elements
= abap_false ).
endmethod.

Step6 : Now the component is ready with that u can create the WD Application and check how it works, if you want to use this component as a F4 help then you can  use with the 'freely programmed inputhelp' concept

Thanks

Tamil Selvan K

3 Comments

  1. Unknown User (t36roy1)

    The article is very helpful. But can any one tell me where the data is being populated to the node. I thing supply method or some other method is missing.

  2. Great article.  I also had this probelm a year ago. My problems questions are:

     Is it possible to select more then one entry in the tree?

    What about selecting all childrens with one click.

    In my solution I inserted this tree, into a table and the table had a checkbox, row, so the user can check the required org units, (more then one) and there was a separate button, for "selection all childre"

  3. Former Member

    How to find the images for this wiki?