Monday, 26 March 2012

Downloading Employee LOG details

REPORT  ZR_D200_HRAS111_EMPREPORT.

TABLES PERNR.

INFOTYPES: 0000,0001,0002,0006,0008.

RANGES:R_PERNR FOR PERNR-PERNR,
       R_INFTY FOR P0008-INFTY.

DATA IT_LOG TYPE PLDOC_KEY_TAB.
DATA WA_LOG TYPE PLDOC_KEY.

DATA IT_INFTY_B TYPE PRELP_TAB.
DATA WA_INFTY_B TYPE PRELP.

DATA IT_INFTY_A TYPE PRELP_TAB.
DATA WA_INFTY_A TYPE PRELP.

DATA IT_FIELDS LIKE HRINFTYLOG_FIELDS OCCURS 0 WITH HEADER LINE.

DATA:BEGIN OF ITAB OCCURS 0,
      FNAME(6) TYPE C,
      OLD(10)  TYPE C,
      NEW(10)  TYPE C,
      PERNR TYPE PERNR,
      NACHN TYPE NACHN,
      HIRE  TYPE PREL-BEGDA,
      WERKS TYPE P0001-WERKS,
      BTRTL TYPE P0001-BTRTL,
      STRAS TYPE P0006-STRAS,
      ORT01 TYPE P0006-ORT01,
      ORT02 TYPE P0006-ORT02,
      PSTLZ TYPE P0006-PSTLZ,
      TRFAR TYPE P0008-TRFAR,
      TRFGB TYPE P0008-TRFGB,
      TRFGR TYPE P0008-TRFGR,
      ANSAL TYPE P0008-ANSAL,
     END OF ITAB.

DATA: D_PERNR TYPE PERNR,
      D_NACHN TYPE NACHN,
      D_HIRE  TYPE PREL-BEGDA,
      D_WERKS TYPE P0001-WERKS,
      D_BTRTL TYPE P0001-BTRTL,
      D_STRAS TYPE P0006-STRAS,
      D_ORT01 TYPE P0006-ORT01,
      D_ORT02 TYPE P0006-ORT02,
      D_PSTLZ TYPE P0006-PSTLZ,
      D_TRFAR TYPE P0008-TRFAR,
      D_TRFGB TYPE P0008-TRFGB,
      D_TRFGR TYPE P0008-TRFGR,
      D_ANSAL TYPE P0008-ANSAL.

DATA IT_HIFI TYPE PHIFI OCCURS 0 WITH HEADER LINE.

DATA IT_UNAME TYPE UNAME_RANGE OCCURS 0 WITH HEADER LINE.

PARAMETER P_FNAME TYPE STRING OBLIGATORY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.

CALL METHOD CL_RSAN_UT_FILES=>F4
  EXPORTING
    I_APPLSERV              = SPACE
    I_TITLE                 = 'CHOOSE FILE FOR DOWN LOAD'
    I_GUI_EXTENSION         = '.TXT'
    I_GUI_EXT_FILTER        = SPACE
*    I_GUI_INITIAL_DIRECTORY =
*    I_APPLSERV_LOGICAL      = 'X'
*    I_APPLSERV_AL11         = 'X'
*  IMPORTING
*    E_CANCELED              =
*    E_LOGICAL_FILE          =
*    E_AL11_CHOSEN           =
  CHANGING
    C_FILE_NAME             = P_FNAME
*  EXCEPTIONS
*    FAILED                  = 1
*    others                  = 2
        .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


START-OF-SELECTION.

GET PERNR.

  RP-READ-ALL-TIME-ITY PN-BEGDA PN-ENDDA.

  CALL FUNCTION 'RP_HIRE_FIRE'
   EXPORTING
     BEG             = PN-BEGDA
     END             = PN-ENDDA
   IMPORTING
*     FIRE_DATE       =
     HIRE_DATE       = D_HIRE
    TABLES
      PPHIFI          = IT_HIFI
      PP0000          = P0000
      PP0001          = P0001
            .


  REFRESH R_PERNR[].

  R_PERNR-SIGN = 'I'.
  R_PERNR-OPTION = 'EQ'.
  R_PERNR-LOW = PERNR-PERNR.

  APPEND R_PERNR.

  REFRESH R_INFTY.

  R_INFTY-SIGN = 'I'.
  R_INFTY-OPTION = 'EQ'.
  R_INFTY-LOW = '0000'.

  APPEND R_INFTY.
  CLEAR R_INFTY.

  R_INFTY-SIGN = 'I'.
  R_INFTY-OPTION = 'EQ'.
  R_INFTY-LOW = '0001'.

  APPEND R_INFTY.
  CLEAR R_INFTY.

  R_INFTY-SIGN = 'I'.
  R_INFTY-OPTION = 'EQ'.
  R_INFTY-LOW = '0006'.

  APPEND R_INFTY.
  CLEAR R_INFTY.

  R_INFTY-SIGN = 'I'.
  R_INFTY-OPTION = 'EQ'.
  R_INFTY-LOW = '0008'.

  APPEND R_INFTY.
  CLEAR R_INFTY.

  IT_UNAME-SIGN = 'I'.
  IT_UNAME-OPTION = 'EQ'.
  IT_UNAME-LOW = 'SAPUSER'.

  APPEND IT_UNAME.
  CLEAR IT_UNAME.


  CALL FUNCTION 'HR_INFOTYPE_LOG_GET_LIST'
   EXPORTING
     TCLAS                    = 'A'
     BEGDA                    = PN-BEGDA
     ENDDA                    = PN-ENDDA
*   AUTH_CHECK               = 'X'
*   USE_ARCHIVE              = ' '
* IMPORTING
*   SUBRC                    =
   TABLES
     PERNR_TAB                = R_PERNR[]
     INFTY_TAB                = R_INFTY[]
     INFTY_LOGG_KEY_TAB       = IT_LOG
*   DATUM_TAB                =
   UNAME_TAB                = IT_UNAME
            .


  LOOP AT IT_LOG INTO WA_LOG.

    CALL FUNCTION 'HR_INFOTYPE_LOG_GET_DETAIL'
      EXPORTING
        LOGGED_INFOTYPE        = WA_LOG
*   AUTH_CHECK             = 'X'
*   USE_ARCHIVE            = ' '
* IMPORTING
*   SUBRC                  =
      TABLES
        INFTY_TAB_BEFORE       = IT_INFTY_B
        INFTY_TAB_AFTER        = IT_INFTY_A
        FIELDS                 = IT_FIELDS
              .

    MOVE:       PERNR-PERNR TO D_PERNR,
                P0002-NACHN TO D_NACHN,
                P0001-WERKS TO D_WERKS,
                P0001-BTRTL TO D_BTRTL,
                P0006-STRAS TO D_STRAS,
                P0006-ORT01 TO D_ORT01,
                P0006-ORT02 TO D_ORT02,
                P0006-PSTLZ TO D_PSTLZ,
                P0008-TRFAR TO D_TRFAR,
                P0008-TRFGB TO D_TRFGB,
                P0008-TRFGR TO D_TRFGR,
                P0008-ANSAL TO D_ANSAL.

    LOOP AT IT_FIELDS.

      IF IT_FIELDS-FNAME = 'PERSK' OR IT_FIELDS-FNAME = 'STAT2'
          OR IT_FIELDS-FNAME = 'ORT01' OR IT_FIELDS-FNAME = 'TRFGB'.

        IF IT_FIELDS-OLDDT NE IT_FIELDS-NEWDT.

          MOVE: IT_FIELDS-FNAME TO ITAB-FNAME,
                IT_FIELDS-OLDDT TO ITAB-OLD,
                IT_FIELDS-NEWDT TO ITAB-NEW,
                D_PERNR TO ITAB-PERNR,
                D_NACHN TO ITAB-NACHN,
                D_HIRE  TO ITAB-HIRE,
                D_WERKS TO ITAB-WERKS,
                D_BTRTL TO ITAB-BTRTL,
                D_STRAS TO ITAB-STRAS,
                D_ORT01 TO ITAB-ORT01,
                D_ORT02 TO ITAB-ORT02,
                D_PSTLZ TO ITAB-PSTLZ,
                D_TRFAR TO ITAB-TRFAR,
                D_TRFGB TO ITAB-TRFGB,
                D_TRFGR TO ITAB-TRFGR,
                D_ANSAL TO ITAB-ANSAL.

          APPEND ITAB.
          CLEAR ITAB.

        ENDIF.
      ENDIF.

    ENDLOOP.

  ENDLOOP.

END-OF-SELECTION.

 CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
  EXPORTING
*    BIN_FILESIZE              =
    FILENAME                  = P_FNAME
    FILETYPE                  = 'ASC'
    APPEND                    = SPACE
    WRITE_FIELD_SEPARATOR     = 'X'
*    HEADER                    = '00'
*    TRUNC_TRAILING_BLANKS     = SPACE
*    WRITE_LF                  = 'X'
*    COL_SELECT                = SPACE
*    COL_SELECT_MASK           = SPACE
    DAT_MODE                  = 'X'
*    CONFIRM_OVERWRITE         = SPACE
*    NO_AUTH_CHECK             = SPACE
*    CODEPAGE                  = SPACE
*    IGNORE_CERR               = ABAP_TRUE
*    REPLACEMENT               = '#'
*    WRITE_BOM                 = SPACE
*    TRUNC_TRAILING_BLANKS_EOL = 'X'
*    WK1_N_FORMAT              = SPACE
*    WK1_N_SIZE                = SPACE
*    WK1_T_FORMAT              = SPACE
*    WK1_T_SIZE                = SPACE
*  IMPORTING
*    FILELENGTH                =
  CHANGING
    DATA_TAB                  = ITAB[]
*  EXCEPTIONS
*    FILE_WRITE_ERROR          = 1
*    NO_BATCH                  = 2
*    GUI_REFUSE_FILETRANSFER   = 3
*    INVALID_TYPE              = 4
*    NO_AUTHORITY              = 5
*    UNKNOWN_ERROR             = 6
*    HEADER_NOT_ALLOWED        = 7
*    SEPARATOR_NOT_ALLOWED     = 8
*    FILESIZE_NOT_ALLOWED      = 9
*    HEADER_TOO_LONG           = 10
*    DP_ERROR_CREATE           = 11
*    DP_ERROR_SEND             = 12
*    DP_ERROR_WRITE            = 13
*    UNKNOWN_DP_ERROR          = 14
*    ACCESS_DENIED             = 15
*    DP_OUT_OF_MEMORY          = 16
*    DISK_FULL                 = 17
*    DP_TIMEOUT                = 18
*    FILE_NOT_FOUND            = 19
*    DATAPROVIDER_EXCEPTION    = 20
*    CONTROL_FLUSH_ERROR       = 21
*    NOT_SUPPORTED_BY_GUI      = 22
*    ERROR_NO_GUI              = 23
*    others                    = 24
        .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


Finding the Employee's Manager in OM

REPORT  ZHR_D220_OM.

TABLES PERNR.
INFOTYPES: 1000,1001,0001 MODE N.

DATA SOBID TYPE  PLOG-OBJID.

DATA: BEGIN OF IT_T500P OCCURS 0,
      PERSA TYPE T500P-PERSA,
      NAME1 TYPE T500P-NAME1,
  END OF IT_T500P.

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

DATA: BEGIN OF IT_T527X OCCURS 0,
      ORGEH TYPE T527X-ORGEH,
      ORGTX TYPE T527X-ORGTX,
  END OF IT_T527X.

DATA SOB(8) TYPE N.

START-OF-SELECTION.

  SELECT PERSA NAME1 FROM T500P INTO TABLE IT_T500P.
  SELECT PERSG PTEXT FROM T501T INTO TABLE IT_T501T WHERE SPRSL = SY-LANGU.
  SELECT ORGEH ORGTX FROM T527X INTO TABLE IT_T527X 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                  = '19000101'
*   ENDDA                  = '99991231'
*   CONDITION              = '00000'
*   SORT                   = 'X'
    TABLES
      I1000                  = P1000
*   OBJECTS                =.

  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                =

  READ TABLE IT_T500P WITH KEY PERSA = PERNR-WERKS .
  READ TABLE IT_T501T WITH KEY PERSG = PERNR-PERSG .
  READ TABLE IT_T527X WITH KEY ORGEH = PERNR-ORGEH .
  READ TABLE P1000 WITH KEY LANGU = SY-LANGU.
  READ TABLE P1001 WITH KEY RSIGN = 'B'
                            RELAT = '002'.
  SOBID = P1001-SOBID.
  REFRESH P1001[].

  CALL FUNCTION 'RH_READ_INFTY_1001'
   EXPORTING
*   AUTHORITY              = 'DISP'
*   WITH_STRU_AUTH         = 'X'
     PLVAR                  = '01'
     OTYPE                  = 'S'
     OBJID                  = SOBID
*   ISTAT                  = ' '
*   AUTH_SOBID             =
    TABLES
      I1001                  = P1001.
*   OBJECTS                =

  READ TABLE P1001 WITH KEY RSIGN = 'A'
                            RELAT = '008'.
  SOB = P1001-SOBID.

  RP-READ-INFOTYPE SOB 0001 P0001 PN-BEGDA PN-ENDDA.

  WRITE:/ PERNR-PERNR, PERNR-SNAME, PERNR-WERKS,IT_T500P-NAME1,PERNR-PERSG,IT_T501T-PTEXT, PERNR-ORGEH,IT_T527X-ORGTX,PERNR-PLANS,P1000-STEXT,P0001-SNAME.

Payoll YTD report in ABAP HR

REPORT  ZHR_D220_AS03_YTD.

TABLES PERNR.

DATA IT_RGDIR TYPE PC261 OCCURS 0 WITH HEADER LINE.

PARAMETERS P_FILE TYPE STRING OBLIGATORY.

DATA  IT_RESULT TYPE PAYIN_RESULT.

DATA : WA_CRT TYPE PC208,
       WA_RT TYPE PC207,
       G_SEQNR TYPE PC261-SEQNR.

DATA: BEGIN OF ITAB OCCURS 0,
      PERNR TYPE PERNR-PERNR,
      GROSS TYPE PC208-BETRG,
      NETPAY TYPE PC207-BETRG,
      TAX TYPE PC207-BETRG,
      END OF ITAB.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

  CALL METHOD CL_RSAN_UT_FILES=>F4
    EXPORTING
      I_APPLSERV              = SPACE
      I_TITLE                 = 'CHOOSE FILE PATH...'
      I_GUI_EXTENSION         = 'TXT'
      I_GUI_EXT_FILTER        = SPACE
*    I_GUI_INITIAL_DIRECTORY =
*    I_APPLSERV_LOGICAL      = 'X'
*    I_APPLSERV_AL11         = 'X'
*  IMPORTING
*    E_CANCELED              =
*    E_LOGICAL_FILE          =
*    E_AL11_CHOSEN           =
    CHANGING
      C_FILE_NAME             = P_FILE.

 START-OF-SELECTION.

GET PERNR.

  CALL FUNCTION 'CU_READ_RGDIR'
    EXPORTING
      PERSNR                   = PERNR-PERNR
*   BUFFER                   =
*   NO_AUTHORITY_CHECK       = ' '
* IMPORTING
*   MOLGA                    =
    TABLES
      IN_RGDIR                 = IT_RGDIR.

 *  CALL FUNCTION 'CD_READ_LAST'
*    EXPORTING
*      BEGIN_DATE      = PN-BEGDA
*      END_DATE        = PN-ENDDA
*    IMPORTING
*      OUT_SEQNR       = G_SEQNR
*    TABLES
*      RGDIR           = IT_RGDIR
*    EXCEPTIONS
*      NO_RECORD_FOUND = 1
*      OTHERS          = 2.
*  IF SY-SUBRC <> 0.
*    MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*  ENDIF.


  LOOP AT IT_RGDIR WHERE FPPER EQ PN-PAPER.

  CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT'
    EXPORTING
*   CLUSTERID                          =
   EMPLOYEENUMBER                     = PERNR-PERNR
   SEQUENCENUMBER                     = IT_RGDIR-SEQNR
*   READ_ONLY_BUFFER                   = ' '
*   READ_ONLY_INTERNATIONAL            = ' '
*   ARC_GROUP                          = ' '
*   CHECK_READ_AUTHORITY               = 'X'
*   FILTER_CUMULATIONS                 = 'X'
*   CLIENT                             =
* IMPORTING
*   VERSION_NUMBER_PAYVN               =
*   VERSION_NUMBER_PCL2                =
    CHANGING
      PAYROLL_RESULT                     = IT_RESULT.

  ENDLOOP.

  LOOP AT IT_RESULT-INTER-CRT INTO WA_CRT WHERE CUMTY = 'Y'.



    CASE WA_CRT-LGART.

      WHEN '/101'.

        MOVE: PERNR-PERNR TO ITAB-PERNR,
              WA_CRT-BETRG TO ITAB-GROSS.

      WHEN '/460'.

        MOVE:  WA_CRT-BETRG TO ITAB-TAX.

    ENDCASE.

  ENDLOOP.

  LOOP AT IT_RESULT-INTER-RT INTO WA_RT.


    CASE WA_RT-LGART.

      WHEN '/560'.

        MOVE: WA_RT-BETRG TO ITAB-NETPAY.

    ENDCASE.

  ENDLOOP.

  APPEND ITAB.
  CLEAR ITAB.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
    EXPORTING
*    BIN_FILESIZE              =
      FILENAME                  = P_FILE
*    FILETYPE                  = 'ASC'
*    APPEND                    = SPACE
     WRITE_FIELD_SEPARATOR     = 'X'
*    HEADER                    = '00'
*    TRUNC_TRAILING_BLANKS     = SPACE
*    WK1_T_SIZE                = SPACE
*  IMPORTING
*    FILELENGTH                =
    CHANGING
      DATA_TAB                  = ITAB[].
         .