Sort Employees As Positioned In OM Structure

How to sort employees same as they are positioned in the OM structure (transaction PPOME or PPOSE)?

Resolution:

Problem can be solved by using FM RH_PM_GET_STRUCTURE which gives you back all objects in the exact order like in OM (trans PPOME).

Add a key field to the structure and a loop to get the position between all objects.

*&---------------------------------------------------------------------*
*&      Form  GET_OM_OBJECTS_SORT
*&---------------------------------------------------------------------*
*       get sort in OM objects (same as transaction PPOME)
*----------------------------------------------------------------------*
form get_om_objects_sort .

  call function 'RH_PM_GET_STRUCTURE'
    exporting
      plvar                    = '01'
      otype                    = 'O'
      objid                    = p_toporg
      begda                    = pn-begda
      endda                    = pn-begda
*   STATUS                   = '1'
      wegid                    = 'O-S-P'
*   77AW_INT                 = ' '
*   AUTHY                    = 'X'
*   DEPTH                    = 0
*   CHECK_OBJECT             = ' '
*   PROGRESS_INDICATOR       = ' '
*   SVECT                    =
*   ACTIV                    = 'X'
*   BUFFER_MODE              =
    tables
      objec_tab                = gt_objec
*   STRUC_TAB                =
*   GDSTR_TAB                =
exceptions
   not_found                = 1
   ppway_not_found          = 2
   others                   = 3.
 

*&---------------------------------------------------------------------*
*&      Form  FILL_KEYS
*&---------------------------------------------------------------------*
*       fill key fields for sorting purposes
*----------------------------------------------------------------------*
form fill_keys .

  loop at gt_compensation into gs_compensation.

    loop at gt_objec into gs_objec
      where objid = gs_compensation-pernr.

      move sy-tabix to gs_compensation-key.

      modify gt_compensation from gs_compensation transporting key.

    endloop. " at gt_objec into gs_objec
  endloop. " at gt_compensation into gs_compensation.

  loop at gt_totals into gs_totals.

    loop at gt_objec into gs_objec
      where objid = gs_totals-orgeh.

      move sy-tabix to gs_totals-key.

      modify gt_totals from gs_totals transporting key.

    endloop. " at gt_objec into gs_objec
  endloop. " at gt_totals into gs_totals.

  sort gt_compensation by key.
  sort gt_totals       by key.

endform.                    " FILL_KEYS

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.