Skip to Content

Overview

In this document I give a quick’n’dirty ABAP solution for storing the HR organizational structure in a string variable.

Coding

The coding is pretty straight forward and it should be easy to change or enhance it further. In the example I’m using the IDES organizational structure.

data lt_postree_objec    type table of objec.
data ls_postree_objec    type objec.
data lt_postree_struc    type table of struc.
data ls_postree_struc    type struc.
data lv_tot_str          type string.
data lv_tmp_str          type string.
data lv_tmp_str2         type string.
data lv_level            type i.
data lv_char60           type c length 60.

call function 'RH_STRUC_GET'
  exporting
    act_otype    = 'O'
    act_objid    = '00000300'          " org. unit IDES US
    act_wegid    = 'O-S-P'
  tables
    result_objec = lt_postree_objec
    result_struc = lt_postree_struc.

clear lv_tot_str.
clear lv_char60.

lv_char60 = 'Object'.

concatenate lv_char60
            'Object ID'
            cl_abap_char_utilities=>cr_lf
    into lv_tot_str
    separated by cl_abap_char_utilities=>horizontal_tab
    respecting blanks.

concatenate lv_tot_str
            cl_abap_char_utilities=>cr_lf
    into lv_tot_str.

loop at lt_postree_struc into ls_postree_struc.
  clear ls_postree_objec.

  read table lt_postree_objec into ls_postree_objec
                              with key otype = ls_postree_struc-otype
                                       objid = ls_postree_struc-objid.
  clear: lv_tmp_str,
         lv_tmp_str2.

  if ls_postree_struc-level gt 1.
    lv_level = 1.

    while lv_level lt ls_postree_struc-level.
      concatenate lv_tmp_str '   ' into lv_tmp_str respecting blanks.
      add 1 to lv_level.
    endwhile.

    concatenate lv_tmp_str '`--' into lv_tmp_str respecting blanks.
    concatenate '(' ls_postree_objec-otype ')' into lv_tmp_str2.
    concatenate lv_tmp_str lv_tmp_str2 ls_postree_objec-stext
                  into lv_tmp_str separated by space.
  else.
    concatenate '(' ls_postree_objec-otype ')' into lv_tmp_str2.
    concatenate lv_tmp_str2 ls_postree_objec-stext
                  into lv_tmp_str separated by space.
  endif.

  clear lv_char60.
  lv_char60 = lv_tmp_str.

  concatenate lv_char60
              ls_postree_struc-objid
              cl_abap_char_utilities=>cr_lf
         into lv_tmp_str
 separated by cl_abap_char_utilities=>horizontal_tab
              respecting blanks.
  concatenate lv_tot_str lv_tmp_str into lv_tot_str.
endloop.

At the end of execution lv_tot_str string variable will contain the whole organizational structure.

Screenshot

And this is how it will look if exported to text file, at the left the view in PPOSE.

/wp-content/uploads/2012/04/ppose_and_flat_file_94968.png

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply