Friday, 23 March 2012

Organization Management in ABAP HR

REPORT  ZR_H113_OM LINE-SIZE 300.

TABLES PERNR.

INFOTYPES: 1001, 1000.

DATA VAR1 TYPE PLOG-OBJID.

DATA: BEGIN OF IT_T001 OCCURS 0,
       BUKRS LIKE T001-BUKRS,
       BUTXT LIKE T001-BUTXT,
      END OF IT_T001.

DATA: BEGIN OF IT_T500P OCCURS 0,
       PERSA LIKE PERNR-WERKS,
       NAME1 LIKE T500P-NAME1,
      END OF IT_T500P.

DATA: BEGIN OF IT_T001P OCCURS 0,
       BTRTL LIKE T001P-BTRTL,
       BTEXT LIKE T001P-BTEXT,
      END OF IT_T001P.

DATA: BEGIN OF IT_T501T OCCURS 0,
       PERSG LIKE T501T-PERSG,
       PTEXT LIKE T501T-PTEXT,
      END OF IT_T501T.

DATA: BEGIN OF IT_T503T OCCURS 0,
       PERSK LIKE T503T-PERSK,
       PTEXT LIKE T503T-PTEXT,
      END OF IT_T503T.

START-OF-SELECTION.

  SELECT  BUKRS
          BUTXT INTO TABLE IT_T001 FROM T001
          WHERE SPRAS = SY-LANGU.

  SELECT  PERSA
          NAME1 INTO TABLE IT_T500P FROM T500P.

  SELECT  BTRTL
          BTEXT INTO TABLE IT_T001P FROM T001P.

  SELECT PERSG
          PTEXT INTO TABLE IT_T501T FROM T501T
          WHERE SPRSL = SY-LANGU.

  SELECT  PERSK
          PTEXT INTO TABLE IT_T503T FROM T503T
          WHERE SPRSL = SY-LANGU.

GET PERNR.

  CALL FUNCTION 'RH_READ_INFTY_1000'
 EXPORTING
*   AUTHORITY              = 'DISP'
*   WITH_STRU_AUTH         = 'X'
   PLVAR                  = '01'
   OTYPE                  = 'S'
   OBJID                  = PERNR-PLANS
*   ISTAT                  = ' '
*   EXTEND                 = 'X'
   BEGDA                  = PN-BEGDA
   ENDDA                  = PN-ENDDA
*   CONDITION              = '00000'
*   SORT                   = 'X'
  TABLES
    I1000                  = P1000
*   OBJECTS                =
* EXCEPTIONS
*   NOTHING_FOUND          = 1
*   WRONG_CONDITION        = 2
*   WRONG_PARAMETERS       = 3
*   OTHERS                 = 4
          .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  READ TABLE P1000 WITH KEY LANGU = SY-LANGU.

  READ TABLE IT_T001 WITH KEY BUKRS = PERNR-BUKRS.
  READ TABLE IT_T500P WITH KEY PERSA = PERNR-WERKS.
  READ TABLE IT_T001P WITH KEY BTRTL = PERNR-BTRTL.
  READ TABLE IT_T501T WITH KEY PERSG = PERNR-PERSG.
  READ TABLE IT_T503T WITH KEY PERSK = PERNR-PERSK.

  WRITE:/ PERNR-PERNR,
          PERNR-ENAME,
          PERNR-BUKRS,
          IT_T001-BUTXT,
          PERNR-WERKS,
          IT_T500P-NAME1,
          PERNR-BTRTL,
          IT_T001P-BTEXT,
          PERNR-PERSG,
          IT_T501T-PTEXT,
          PERNR-PERSK,
          IT_T503T-PTEXT.

  WRITE:/ PERNR-PLANS,P1000-STEXT.

  CALL FUNCTION 'RH_READ_INFTY_1001'
     EXPORTING
*   AUTHORITY              = 'DISP'
*   WITH_STRU_AUTH         = 'X'
       PLVAR               = '01'
       OTYPE               = 'S'
       OBJID               = PERNR-PLANS
*   ISTAT                  = ' '
*   EXTEND                 = 'X'
*   SUBTY                  = ' '
*   BEGDA                  = '19000101'
*   ENDDA                  = '99991231'
*   CONDITION              = '00000'
*   SORT                   = 'X'
*   WITH_EV                = ' '
*   ADATA                  = 'X'
*   AUTH_SOBID             = ' '
      TABLES
        I1001                  = P1001
*   OBJECTS                =
* EXCEPTIONS
*   NOTHING_FOUND          = 1
*   WRONG_CONDITION        = 2
*   WRONG_PARAMETERS       = 3
*   OTHERS                 = 4
              .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  READ TABLE P1001 WITH KEY RSIGN = 'A'
                            RELAT = '002'.

  WRITE:/ P1001-SOBID.

  VAR1 = P1001-SOBID.

  CLEAR P1000.

  CALL FUNCTION 'RH_READ_INFTY_1000'
  EXPORTING
*   AUTHORITY              = 'DISP'
*   WITH_STRU_AUTH         = 'X'
    PLVAR                  = '01'
    OTYPE                  = 'S'
    OBJID                  = VAR1
*   ISTAT                  = ' '
*   EXTEND                 = 'X'
    BEGDA                  = PN-BEGDA
    ENDDA                  = PN-ENDDA
*   CONDITION              = '00000'
*   SORT                   = 'X'
   TABLES
     I1000                 = P1000
*   OBJECTS                =
* EXCEPTIONS
*   NOTHING_FOUND          = 1
*   WRONG_CONDITION        = 2
*   WRONG_PARAMETERS       = 3
*   OTHERS                 = 4
           .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  READ TABLE P1000 WITH KEY LANGU = SY-LANGU.

  WRITE P1000-STEXT.

CALL FUNCTION 'RH_READ_INFTY_1001'
     EXPORTING
*   AUTHORITY              = 'DISP'
*   WITH_STRU_AUTH         = 'X'
       PLVAR               = '01'
       OTYPE               = 'S'
       OBJID               = PERNR-PLANS
*   ISTAT                  = ' '
*   EXTEND                 = 'X'
*   SUBTY                  = ' '
*   BEGDA                  = '19000101'
*   ENDDA                  = '99991231'
*   CONDITION              = '00000'
*   SORT                   = 'X'
*   WITH_EV                = ' '
*   ADATA                  = 'X'
*   AUTH_SOBID             = ' '
      TABLES
        I1001              = P1001
*   OBJECTS                =
* EXCEPTIONS
*   NOTHING_FOUND          = 1
*   WRONG_CONDITION        = 2
*   WRONG_PARAMETERS       = 3
*   OTHERS                 = 4
              .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  READ TABLE P1001 WITH KEY RSIGN = 'A'
                            RELAT = '003'.

  WRITE:/ P1001-SOBID.

  CLEAR P1000.

CALL FUNCTION 'RH_READ_INFTY_1000'
 EXPORTING
*   AUTHORITY              = 'DISP'
*   WITH_STRU_AUTH         = 'X'
   PLVAR                  = '01'
   OTYPE                  = 'O'
   OBJID                  = PERNR-ORGEH
*   ISTAT                  = ' '
*   EXTEND                 = 'X'
   BEGDA                  = PN-BEGDA
   ENDDA                  = PN-ENDDA
*   CONDITION              = '00000'
*   SORT                   = 'X'
  TABLES
    I1000                  = P1000
*   OBJECTS                =
* EXCEPTIONS
*   NOTHING_FOUND          = 1
*   WRONG_CONDITION        = 2
*   WRONG_PARAMETERS       = 3
*   OTHERS                 = 4
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

READ TABLE P1000 WITH KEY LANGU = SY-LANGU.

WRITE P1000-STEXT.