• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8251
  • Last Modified:

Howto find the Direct Supervisor in SAP HR

Howto find the Direct Supervisor in SAP HR

I'm currently doing an IDM project that has SAP HR as the authoritative source. When I activesync from SAPHR I'm unable to fetch the Direct Supervisor value.

Can some one have a look at the enclosed ABAP code and let me know the field or attribute that I can query or map to fetch the Supervisor's value.

FUNCTION zesshfu_common_reportstruct_ad .
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(PERSNO) TYPE  ZESSHDT_MEDIFORM-PERNR OPTIONAL
*"  TABLES
*"      FT_DATA STRUCTURE  ZESSHST_RESTRUCT
*"----------------------------------------------------------------------

  DATA: BEGIN OF lt_pernr OCCURS 0,
          pernr LIKE p0001-pernr,
          stat2 LIKE p0000-stat2.
  DATA: END OF lt_pernr.
  DATA: BEGIN OF lt_pa0001 OCCURS 0.
          INCLUDE STRUCTURE pa0001.
  DATA: END OF lt_pa0001.
  DATA: BEGIN OF lt_pa0002 OCCURS 0,
          pernr LIKE p0002-pernr,
          cname LIKE p0002-cname.
  DATA: END OF lt_pa0002.
  DATA: BEGIN OF lt_pa0006 OCCURS 0,
          pernr LIKE p0006-pernr,
          num01 LIKE p0006-num01.
  DATA: END OF lt_pa0006.
  DATA: BEGIN OF lt_pa0105 OCCURS 0,
          pernr LIKE p0105-pernr,
          usrid_long LIKE p0105-usrid_long.
  DATA: END OF lt_pa0105.
  DATA: BEGIN OF lt_pa0032 OCCURS 0,
          pernr LIKE p0032-pernr,
          gebnr LIKE p0032-gebnr,
          zimnr LIKE p0032-zimnr,
          tel01 LIKE p0032-tel01,
          tel02 LIKE p0032-tel02.
  DATA: END OF lt_pa0032.
  DATA: lt_bukrs LIKE t001 OCCURS 0 WITH HEADER LINE,
        lt_werks LIKE t500p OCCURS 0 WITH HEADER LINE,
        lt_btrtl LIKE t001p OCCURS 0 WITH HEADER LINE,
        lt_kostl LIKE cskt OCCURS 0 WITH HEADER LINE,
        lt_orgeh LIKE t527x OCCURS 0 WITH HEADER LINE,
        lt_plans LIKE hrp1000 OCCURS 0 WITH HEADER LINE,
        lt_stell LIKE t513s OCCURS 0 WITH HEADER LINE,
        lt_persk LIKE t503t OCCURS 0 WITH HEADER LINE.
  DATA: ld_splan LIKE hrp1001-sobid,
        ld_spern LIKE hrp1001-sobid,
        ld_btrtl LIKE pa0001-btrtl,
        ld_flag_divis.

  IF NOT persno IS INITIAL.
    lt_pernr = persno.
    SELECT SINGLE stat2 FROM pa0000 INTO lt_pernr-stat2
                                   WHERE pernr = persno
                                     AND begda LE sy-datum
                                     AND endda GE sy-datum.
    APPEND lt_pernr. CLEAR lt_pernr.
  ELSE.
    SELECT pernr stat2 FROM pa0000 INTO TABLE lt_pernr
                                  WHERE begda LE sy-datum
                                    AND endda GE sy-datum.
    CHECK NOT lt_pernr[] IS INITIAL.
    SORT lt_pernr BY pernr.
    DELETE ADJACENT DUPLICATES FROM lt_pernr.
  ENDIF.

* Get organizational assignment data
  SELECT * FROM pa0001 INTO TABLE lt_pa0001
                       FOR ALL ENTRIES IN lt_pernr
                       WHERE pernr = lt_pernr-pernr
                         AND begda LE sy-datum
                         AND endda GE sy-datum.
* Get employee name
  SELECT pernr cname FROM pa0002 INTO TABLE lt_pa0002
                            FOR ALL ENTRIES IN lt_pernr
                            WHERE pernr = lt_pernr-pernr
                              AND begda LE sy-datum
                              AND endda GE sy-datum.

* Get office telephone number
  SELECT pernr num01 FROM pa0006 INTO TABLE lt_pa0006
                            FOR ALL ENTRIES IN lt_pernr
                            WHERE pernr = lt_pernr-pernr
                              AND anssa = '1'
                              AND begda LE sy-datum
                              AND endda GE sy-datum.

* Get email address
  SELECT pernr usrid_long FROM pa0105 INTO TABLE lt_pa0105
                                 FOR ALL ENTRIES IN lt_pernr
                                 WHERE pernr = lt_pernr-pernr
                                   AND subty = '0010'
                                   AND begda LE sy-datum
                                   AND endda GE sy-datum.

* Get location
  SELECT pernr gebnr zimnr tel01 tel02 FROM pa0032 INTO TABLE lt_pa0032
                                 FOR ALL ENTRIES IN lt_pernr
                                 WHERE pernr = lt_pernr-pernr
                                   AND begda LE sy-datum
                                   AND endda GE sy-datum.

* Get company code text
  SELECT * FROM t001 INTO TABLE lt_bukrs
                          WHERE land1 = 'ID'.

* Get personnel area text
  SELECT * FROM t500p INTO TABLE lt_werks
                           WHERE molga = '34'.

* Get personnel subarea text
  SELECT * FROM t001p INTO TABLE lt_btrtl
                           WHERE molga = '34'.

* Get cost center text
  SELECT * FROM cskt INTO TABLE lt_kostl
                          WHERE spras = 'E'.

* Get org. unit text
  SELECT * FROM t527x INTO TABLE lt_orgeh
                           WHERE sprsl = 'E'
                             AND begda LE sy-datum
                             AND endda GE sy-datum.

* Get position text
  SELECT * FROM hrp1000 INTO TABLE lt_plans
                             WHERE plvar = '01'
                               AND otype = 'S'
                               AND istat = '1'
                               AND langu = 'E'
                               AND begda LE sy-datum
                               AND endda GE sy-datum.

* Get job text
  SELECT * FROM t513s INTO TABLE lt_stell
                           WHERE sprsl = 'E'
                             AND begda LE sy-datum
                             AND endda GE sy-datum.

* Get employee subgroup
  SELECT * FROM t503t INTO TABLE lt_persk
                           WHERE sprsl = 'E'.

  LOOP AT lt_pernr.
    clear ld_btrtl.
    ft_data-lpern = lt_pernr-pernr.
*    CHANGE BY RSE 23.09.2002
*     IF lt_pernr-stat2 = '3'.
*       ft_data-aflag = 'A'.
*     ENDIF.
     CASE lt_pernr-stat2.
       WHEN '0'.
         ft_data-aflag = 'T'.
       WHEN '1'.
         ft_data-aflag = 'I'.
       WHEN '3'.
         ft_data-aflag = 'A'.
     ENDCASE.
*    END CHANGE BY RSE 23.09.2002
* Get Division
    CLEAR: hrp1001, ld_flag_divis.
    SELECT sobid FROM hrp1001
                        INTO hrp1001-sobid
                       WHERE otype = 'P'
                         AND objid = lt_pernr-pernr
                         AND plvar = '01'
                         AND rsign = 'B'
                         AND relat = '008'
                         AND istat = '1'
                         AND begda LE sy-datum
                         AND endda GE sy-datum
                         AND sclas = 'S'.
      IF ld_flag_divis = 'X'.
        EXIT.
      ENDIF.
      SELECT sobid FROM hrp1001
                          INTO hrp1001-sobid
                         WHERE otype = 'S'
                           AND objid = hrp1001-sobid
                           AND plvar = '01'
                           AND rsign = 'A'
                           AND relat = '003'
                           AND istat = '1'
                           AND begda LE sy-datum
                           AND endda GE sy-datum
                           AND sclas = 'O'.
        IF ld_flag_divis = 'X'.
          EXIT.
        ENDIF.
        CLEAR hrp1002.
        SELECT SINGLE subty FROM hrp1002
                            INTO hrp1002-subty
                           WHERE otype = 'O'
                             AND subty = '0024'
                             AND objid = hrp1001-sobid
                             AND plvar = '01'
                             AND istat = '1'
                             AND begda LE sy-datum
                             AND endda GE sy-datum.
        IF sy-subrc = 0.
          ft_data-objid = hrp1001-sobid.
          CLEAR hrp1000.
          SELECT SINGLE stext FROM hrp1000 INTO ft_data-divis
                                          WHERE plvar = '01'
                                            AND otype = 'O'
                                            AND objid = hrp1001-sobid
                                            AND istat = '1'
                                            AND begda LE sy-datum
                                            AND endda GE sy-datum.
        ELSE.
          PERFORM f_get_div_parent USING hrp1001-sobid
                                CHANGING ft_data-objid ft_data-divis
                                         ld_flag_divis.
        ENDIF.
      ENDSELECT.
    ENDSELECT.

    CLEAR lt_pa0002.
    READ TABLE lt_pa0002 WITH KEY pernr = lt_pernr-pernr.
    ft_data-lname = lt_pa0002-cname.
    CLEAR lt_pa0105.
    READ TABLE lt_pa0105 WITH KEY pernr = lt_pernr-pernr.
    ft_data-lemai = lt_pa0105-usrid_long.
    CLEAR lt_pa0001.
    READ TABLE lt_pa0001 WITH KEY pernr = lt_pernr-pernr.
* Get RCC from cost center
    PERFORM f_kostl_to_rcc USING lt_pa0001-kostl
                        CHANGING ft_data-norcc
                                 ld_btrtl.
    IF ld_btrtl IS INITIAL.
      ld_btrtl = lt_pa0001-btrtl.
    ENDIF.
    IF ft_data-norcc IS INITIAL.
* Get RCC from table
      SELECT SINGLE norcc FROM zbcahdt_rcc INTO ft_data-norcc
                                          WHERE werks = lt_pa0001-werks
                                            AND btrtl = ld_btrtl.
    ENDIF.
    CLEAR lt_plans.
    READ TABLE lt_plans WITH KEY objid = lt_pa0001-plans.
    ft_data-lplan = lt_pa0001-plans.
    ft_data-lpltx = lt_plans-mc_stext.
    CLEAR lt_bukrs.
    READ TABLE lt_bukrs WITH KEY bukrs = lt_pa0001-bukrs.
    ft_data-bukrs = lt_pa0001-bukrs.
    ft_data-butxt = lt_bukrs-butxt.
    CLEAR lt_werks.
    READ TABLE lt_werks WITH KEY persa = lt_pa0001-werks
                                 bukrs = lt_pa0001-bukrs.
    ft_data-werks = lt_pa0001-werks.
    ft_data-name1 = lt_werks-name1.
    CLEAR lt_btrtl.
    READ TABLE lt_btrtl WITH KEY werks = lt_pa0001-werks
                                 btrtl = ld_btrtl.
    ft_data-btrtl = ld_btrtl.
    ft_data-btext = lt_btrtl-btext.
    CLEAR lt_kostl.
    READ TABLE lt_kostl WITH KEY kokrs = lt_pa0001-kokrs
                                 kostl = lt_pa0001-kostl.
    ft_data-kostl = lt_pa0001-kostl.
    ft_data-ltext = lt_kostl-ltext.
    CLEAR lt_persk.
    READ TABLE lt_persk WITH KEY persk = lt_pa0001-persk.
    ft_data-persk = lt_pa0001-persk.
    ft_data-ptext = lt_persk-ptext.
    CLEAR lt_stell.
    READ TABLE lt_stell WITH KEY stell = lt_pa0001-stell.
    ft_data-stell = lt_pa0001-stell.
    ft_data-stext = lt_stell-stltx.
    CLEAR lt_orgeh.
    READ TABLE lt_orgeh WITH KEY orgeh = lt_pa0001-orgeh.
    ft_data-orgeh = lt_pa0001-orgeh.
    ft_data-orgtx = lt_orgeh-orgtx.
    CLEAR lt_pa0006.
    READ TABLE lt_pa0006 WITH KEY pernr = lt_pernr-pernr.
    ft_data-telnr = lt_pa0006-num01.
    CLEAR lt_pa0032.
    READ TABLE lt_pa0032 WITH KEY pernr = lt_pernr-pernr.
    ft_data-gebnr = lt_pa0032-gebnr.
    ft_data-zimnr = lt_pa0032-zimnr.
    ft_data-tel01 = lt_pa0032-tel01.
    ft_data-tel02 = lt_pa0032-tel02.
*** Get superior level
    CLEAR hrp1001.
    SELECT SINGLE sobid FROM hrp1001
                        INTO hrp1001-sobid
                       WHERE otype = 'P'
                         AND objid = lt_pernr-pernr
                         AND plvar = '01'
                         AND rsign = 'B'
                         AND relat = '008'
                         AND istat = '1'
                         AND begda LE sy-datum
                         AND endda GE sy-datum
                         AND sclas = 'S'.
    CLEAR ld_splan.
    SELECT SINGLE sobid FROM hrp1001
                        INTO ld_splan
                       WHERE otype = 'S'
                         AND objid = hrp1001-sobid
                         AND plvar = '01'
                         AND rsign = 'A'
                         AND relat = '002'
                         AND istat = '1'
                         AND begda LE sy-datum
                         AND endda GE sy-datum
                         AND sclas = 'S'.
    ft_data-splan = ld_splan.
    CLEAR ld_spern.
    SELECT SINGLE sobid FROM hrp1001
                        INTO ld_spern
                       WHERE otype = 'S'
                         AND objid = ft_data-splan
                         AND plvar = '01'
                         AND rsign = 'A'
                         AND relat = '008'
                         AND istat = '1'
                         AND begda LE sy-datum
                         AND endda GE sy-datum
                         AND sclas = 'P'.
*** Check substitute officer
    CLEAR: zesshdt_subpers, zesshdt_leavefrm.
    SELECT SINGLE * FROM zesshdt_leavefrm INTO zesshdt_leavefrm
                                         WHERE pernr = ld_spern
                                           AND tflag = 'L'
                                           AND begda LE sy-datum
                                           AND endda GE sy-datum.
    SELECT SINGLE sper1 FROM zesshdt_subpers INTO zesshdt_subpers-sper1
                       WHERE pernr = ld_spern
                         AND renum = zesshdt_leavefrm-fonum.
    IF NOT zesshdt_subpers-sper1 IS INITIAL OR
       zesshdt_subpers-sper1 NE '00000000'.
      ft_data-spern = zesshdt_subpers-sper1.
      CLEAR ld_splan.
      SELECT SINGLE sobid FROM hrp1001
                          INTO ld_splan
                         WHERE otype = 'P'
                           AND objid = ft_data-spern
                           AND plvar = '01'
                           AND rsign = 'B'
                           AND relat = '008'
                           AND istat = '1'
                           AND begda LE sy-datum
                           AND endda GE sy-datum
                           AND sclas = 'S'.
      ft_data-splan = ld_splan.
    ELSE.
      ft_data-spern = ld_spern.
    ENDIF.
    IF NOT persno IS INITIAL.
      SELECT SINGLE cname FROM pa0002 INTO ft_data-sname
                                     WHERE pernr = ft_data-spern
                                       AND begda LE sy-datum
                                       AND endda GE sy-datum.
    ELSE.
      CLEAR lt_pa0002.
      READ TABLE lt_pa0002 WITH KEY pernr = ft_data-spern.
      ft_data-sname = lt_pa0002-cname.
    ENDIF.
    IF NOT persno IS INITIAL.
      SELECT SINGLE usrid_long FROM pa0105 INTO ft_data-semai
                                          WHERE pernr = ft_data-spern
                                            AND begda LE sy-datum
                                            AND endda GE sy-datum.
    ELSE.
      CLEAR lt_pa0105.
      READ TABLE lt_pa0105 WITH KEY pernr = ft_data-spern.
      ft_data-semai = lt_pa0105-usrid_long.
    ENDIF.
    CLEAR lt_plans.
    READ TABLE lt_plans WITH KEY objid = ft_data-splan.
    ft_data-spltx = lt_plans-mc_stext.
    APPEND ft_data. CLEAR ft_data.
  ENDLOOP.

ENDFUNCTION.

===========================================================================

FORM f_get_div_parent USING    fu_sobid
                      CHANGING ft_data_objid
                               ft_data_divis
                               fc_flag_divis.

  SELECT sobid FROM hrp1001
                      INTO hrp1001-sobid
                     WHERE otype = 'O'
                       AND objid = fu_sobid
                       AND plvar = '01'
                       AND rsign = 'A'
                       AND relat = '002'
                       AND istat = '1'
                       AND begda LE sy-datum
                       AND endda GE sy-datum
                       AND sclas = 'O'.
    IF fc_flag_divis = 'X'.
      EXIT.
    ENDIF.
    CLEAR hrp1002.
    SELECT SINGLE subty FROM hrp1002
                        INTO hrp1002-subty
                       WHERE otype = 'O'
                         AND subty = '0024'
                         AND objid = hrp1001-sobid
                         AND plvar = '01'
                         AND istat = '1'
                         AND begda LE sy-datum
                         AND endda GE sy-datum.
    IF sy-subrc = 0.
      ft_data_objid = hrp1001-sobid.
      CLEAR hrp1000.
      SELECT SINGLE stext FROM hrp1000 INTO ft_data_divis
                                      WHERE plvar = '01'
                                        AND otype = 'O'
                                        AND objid = hrp1001-sobid
                                        AND istat = '1'
                                        AND begda LE sy-datum
                                        AND endda GE sy-datum.
      fc_flag_divis = 'X'.
      EXIT.
    ELSE.
      PERFORM f_get_div_parent USING hrp1001-sobid
                            CHANGING ft_data_objid ft_data_divis
                                     fc_flag_divis.
    ENDIF.
  ENDSELECT.

ENDFORM.                    " f_get_div_parent

0
vamsijatla
Asked:
vamsijatla
1 Solution
 
asian_niceguyCommented:
If you don't receive enough replies here, ppPlease post message at community support: http://www.experts-exchange.com/Community_Support/
to move this topic to the SAP Topic Area.. more experts will be able to answer you there. or post a pointer question in SAP to this link
http://www.experts-exchange.com/Applications/Q_21821803.html
0
 
jonvaughanCommented:
The way HR is designed, you shouldn't really be using direct table selects to get your data.

The key to HR ABAP is to use the supplied function modules.

HR_READ_INFOTYPE
to extract the data for a particular infotype. This handles the date and history for you.
It also handles all authorization checks.


In order to get hte relationships - like direct supervisor.
You need to use

RH_PM_GET_STRUCTURE

http://www.sapdevelopment.co.uk/fmodules/fms_orgstruc.htm

WEGID is the  evaluation path.
You can find the correct one from you functional consultant.
Or look at transaction OOAW.


Hope this helps ....



0
 
vamsijatlaAuthor Commented:
Is there any way that I can fetch the Direct Manager/Supervisor value using JCO
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now