Skip to Content
avatar image
Former Member

Finding the Employee's Manager (Chief of Org Unit) through infoset query

Hi,

I have a requirement to develop a report through infoset query to get the Employee's Manager or the chief of the org unit as we are not maintaining S-S relationships.

Now for the immediate manager we can use the additional field in standard query but for the next level manager I need to write a piece of code and I am totally new to ABAP coding so any sort of help would be appreciated.

This is the information I am looking to extract

e.g.

Employee: 12345

Position ID: 12345678

Position text: ABCDEF

Org Unit: 56788997

Org Unit Text: HR

Manager / Chief / N+1 = 56789

Manager Position: 50000001

Manager Position Text: GHIJK

Manager 's Manager (N+2) = 65546

Manager's Manager Position ID: 987654543

Manager's Manager Position Text: HGFDFHGJ

Manager's Manager Org Unit: 87654332

Manager's Manager Org Unit Text: AHYGRTY


I need to extract the information up to 7 levels i.e. N+1, N+2, N+3, N+4.


Regards,

Masroor Ahmed Siddique

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Apr 15, 2016 at 10:17 AM

    Hi Masroor,

    Try below code, in output N+0 means employee details, N+1 = manager details and so on. Let me know if any issues.

    *&---------------------------------------------------------------------*

    * database tables used

    *&---------------------------------------------------------------------*

    TABLES:PA0001, "Infotype 0001 (Org. Assignment)

    HRP1001, "Infotype 1001

    PA0002. "Infotype 0002 (Personal Data)

    TYPES: BEGIN OF TY_FINAL,

    LEVEL(3),

    PERNR TYPE PERNR_D,

    POS TYPE PLANS,

    POS_TXT TYPE HRP1000-STEXT,

    ORG TYPE ORGEH,

    ORG_TXT TYPE HRP1000-STEXT,

    END OF TY_FINAL.

    DATA: IT_FINAL TYPE STANDARD TABLE OF TY_FINAL,

    WA_FINAL TYPE TY_FINAL.

    *&---------------------------------------------------------------------*

    * internal tables declaration

    *&---------------------------------------------------------------------*

    *----internal tables for holding

    DATA: T1001 LIKE P1001 OCCURS 0 WITH HEADER LINE,

    T1002 LIKE P1001 OCCURS 0 WITH HEADER LINE,

    T1003 LIKE P1001 OCCURS 0 WITH HEADER LINE,

    T1004 LIKE P1001 OCCURS 0 WITH HEADER LINE.

    *&---------------------------------------------------------------------*

    * variable declaration

    *&---------------------------------------------------------------------*

    *---0 to capture the id of the object "may be orgunit, position, persion

    .

    DATA: G_SOBID1 LIKE P1001-OBJID,

    G_SOBID2 LIKE P1001-OBJID,

    G_SOBID3 LIKE P1001-OBJID,

    *--to capture the personnel number

    G_PERNR LIKE PA0002-PERNR,

    G_TABIX TYPE C.

    *&---------------------------------------------------------------------*

    * selection screen paramters

    *&---------------------------------------------------------------------*

    *----enter a valid personnel number

    PARAMETERS:P_PERNR LIKE PA0002-PERNR.

    *&---------------------------------------------------------------------*

    * start of selection

    *&---------------------------------------------------------------------*

    START-OF-SELECTION.

    G_PERNR = P_PERNR.

    DO 8 TIMES.

    REFRESH: T1001, T1002, T1003, T1004.

    CLEAR: G_SOBID1, G_SOBID2, G_SOBID3.

    *get levels: 0 for employee, 1 for manager, 2 for manager's manager and so on

    G_TABIX = SY-INDEX - 1.

    CONCATENATE 'N+' G_TABIX INTO WA_FINAL-LEVEL.

    WA_FINAL-PERNR = G_PERNR.

    *-- Get the Position for entered Personnel number

    CALL FUNCTION 'RH_READ_INFTY'

    EXPORTING

    PLVAR = '01'

    OTYPE = 'P'

    OBJID = G_PERNR

    INFTY = '1001'

    SUBTY = 'B008'

    BEGDA = SY-DATUM

    ENDDA = SY-DATUM

    TABLES

    INNNN = T1001

    EXCEPTIONS

    ALL_INFTY_WITH_SUBTY = 1

    NOTHING_FOUND = 2

    NO_OBJECTS = 3

    WRONG_CONDITION = 4

    WRONG_PARAMETERS = 5

    OTHERS = 6.

    IF SY-SUBRC <> 0.

    MESSAGE 'this number is not maintained in hrp1001' TYPE 'E'.

    ENDIF.

    *-- Get the latest position record reading T1001 with following values

    SORT T1001 BY BEGDA DESCENDING .

    READ TABLE T1001 INDEX 1.

    IF SY-SUBRC = 0.

    G_SOBID1 = T1001-SOBID.

    WA_FINAL-POS = G_SOBID1.

    *Get Position text

    SELECT SINGLE STEXT FROM HRP1000 INTO WA_FINAL-POS_TXT WHERE OTYPE = 'S'

    AND OBJID = G_SOBID1

    AND BEGDA LE SY-DATUM

    AND ENDDA GE SY-DATUM.

    *-- Get Org unit for the position obtained from above

    CALL FUNCTION 'RH_READ_INFTY'

    EXPORTING

    PLVAR = '01'

    OTYPE = 'S'

    OBJID = G_SOBID1

    INFTY = '1001'

    SUBTY = 'A003'

    BEGDA = SY-DATUM

    ENDDA = SY-DATUM

    TABLES

    INNNN = T1002

    EXCEPTIONS

    ALL_INFTY_WITH_SUBTY = 1

    NOTHING_FOUND = 2

    NO_OBJECTS = 3

    WRONG_CONDITION = 4

    WRONG_PARAMETERS = 5

    OTHERS = 6.

    IF SY-SUBRC <> 0.

    APPEND WA_FINAL TO IT_FINAL.

    CLEAR WA_FINAL.

    EXIT.

    ENDIF.

    ENDIF.

    SORT T1002 BY BEGDA DESCENDING .

    READ TABLE T1002 INDEX 1.

    IF SY-SUBRC = 0.

    G_SOBID2 = T1002-SOBID.

    WA_FINAL-ORG = G_SOBID2.

    *Get org text

    SELECT SINGLE STEXT FROM HRP1000 INTO WA_FINAL-ORG_TXT WHERE OTYPE = 'O'

    AND OBJID = G_SOBID2

    AND BEGDA LE SY-DATUM

    AND ENDDA GE SY-DATUM.

    *-- Get position for the Org unit (Manager)

    CALL FUNCTION 'RH_READ_INFTY'

    EXPORTING

    PLVAR = '01'

    OTYPE = 'O'

    OBJID = G_SOBID2

    INFTY = '1001'

    SUBTY = 'B012'

    BEGDA = SY-DATUM

    ENDDA = SY-DATUM

    TABLES

    INNNN = T1003

    EXCEPTIONS

    ALL_INFTY_WITH_SUBTY = 1

    NOTHING_FOUND = 2

    NO_OBJECTS = 3

    WRONG_CONDITION = 4

    WRONG_PARAMETERS = 5

    OTHERS = 6.

    IF SY-SUBRC <> 0.

    APPEND WA_FINAL TO IT_FINAL.

    CLEAR WA_FINAL.

    EXIT.

    ENDIF.

    ENDIF.

    SORT T1003 BY OBJID.

    READ TABLE T1003 INDEX 1.

    IF SY-SUBRC = 0.

    G_SOBID3 = T1003-SOBID.

    *-- Get Personnel number for the Manager

    CALL FUNCTION 'RH_READ_INFTY'

    EXPORTING

    PLVAR = '01'

    OTYPE = 'S'

    OBJID = G_SOBID3

    INFTY = '1001'

    SUBTY = 'A008'

    BEGDA = SY-DATUM

    ENDDA = SY-DATUM

    TABLES

    INNNN = T1004

    EXCEPTIONS

    ALL_INFTY_WITH_SUBTY = 1

    NOTHING_FOUND = 2

    NO_OBJECTS = 3

    WRONG_CONDITION = 4

    WRONG_PARAMETERS = 5

    OTHERS = 6.

    IF SY-SUBRC <> 0.

    APPEND WA_FINAL TO IT_FINAL.

    CLEAR WA_FINAL.

    EXIT.

    ENDIF.

    ENDIF.

    CLEAR G_PERNR.

    READ TABLE T1004 INDEX 1.

    IF SY-SUBRC = 0.

    G_PERNR = T1004-SOBID+0(8).

    ELSE.

    APPEND WA_FINAL TO IT_FINAL.

    CLEAR G_PERNR.

    EXIT.

    ENDIF.

    APPEND WA_FINAL TO IT_FINAL.

    CLEAR WA_FINAL.

    ENDDO.

    *Print output

    FORMAT COLOR 7 .

    SKIP 3.

    WRITE:/1(111) SY-ULINE .

    WRITE:/1 SY-VLINE,

    2 'Level',

    7 SY-VLINE,

    8 'PERNR',

    18 SY-VLINE,

    19 'Position' ,

    30 SY-VLINE,

    31 'Position Text',

    56 SY-VLINE,

    57 'Org Unit',

    66 SY-VLINE,

    67 'Org Unit Text'.

    LOOP AT IT_FINAL INTO WA_FINAL.

    FORMAT COLOR OFF.

    WRITE:/1(111) SY-ULINE .

    WRITE:/1 SY-VLINE,

    2 WA_FINAL-LEVEL COLOR 4,

    7 SY-VLINE,

    8 WA_FINAL-PERNR COLOR 4,

    18 SY-VLINE,

    19 WA_FINAL-POS COLOR 4 ,

    30 SY-VLINE,

    31 WA_FINAL-POS_TXT COLOR 4,

    56 SY-VLINE,

    57 WA_FINAL-ORG COLOR 4,

    66 SY-VLINE,

    67 WA_FINAL-ORG_TXT COLOR 4.

    ENDLOOP.

    WRITE:/1(111) SY-ULINE .

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Pranay,

      Thank you for the code. By the looks of it I believe it is a Custom report code in ABAP but the issue is that I do not have an access key so I have to rely on infoset query and additional fields. I will try to embed this code in the additional fields in infoset query somehow and let you know about the update.

      Regards,

      Masroor Ahmed Siddique