SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Download various employee data to excel/tab flat files



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> HR
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Oct 13, 2007 1:03 pm    Post subject: Download various employee data to excel/tab flat files Reply with quote

Uses Logical database 'PNP'(entered in program attributes) to retrieve various personnel data and download
it to an excel / tab delimited file.
Code:

*.......................................................................
*: Report:  ZDOWNEMPDATA                                               :
*:                                                                     :
*: Author:  www.SAPDev.co.uk                                           :
*:                                                                     :
*: Date  :  2004                                                       :
*:                                                                     :
*: Description: Downloads employee data to TAB delimited flat files    :
*:                                                                     :
*:.....................................................................:
REPORT  zdownempdata                                         .

INFOTYPES: 0000, 0001, 0007, 0008, 0121, 0615.
NODES: pernr.
TABLES: t001p.

TYPES: BEGIN OF t_employee,
*        INCLUDE STRUCTURE hrms_biw_io_occupancy.
  begda   TYPE begda,
  endda   TYPE endda,
  pernr   TYPE pernr_d,
  rfpnr   TYPE rfpnr,
  bukrs   TYPE bukrs,
  werks   TYPE persa,
  btrtl   TYPE btrtl,
  persg   TYPE persg,
  persk   TYPE persk,
  orgeh   TYPE orgeh,
  stell   TYPE stell,
  plans   TYPE plans,
  kokrs   TYPE mast_coar,
  kostl   TYPE mast_cctr,
  abkrs   TYPE abkrs,
  molga   TYPE molga,
  trfar   TYPE trfar,
  trfgb   TYPE trfgb,
  trfkz   TYPE trfkz,
  trfgr   TYPE trfgr,
  trfst   TYPE trfst,
  bsgrd   TYPE bsgrd,
  ansal   TYPE ansal_15,
  ancur   TYPE ancur,
  empct   TYPE empct,
  stat2   TYPE stat2,
  ncsdate     TYPE hiredate,
  sltyp   TYPE p_sltyp,
  slreg   TYPE p_slreg,
  slgrp   TYPE p_slgrp,
  sllev   TYPE p_sllvl,
  ansvh   TYPE ansvh,
  vdsk1   TYPE vdsk1,
  sname   TYPE smnam,
 END OF t_employee.
DATA: it_employee TYPE STANDARD TABLE OF t_employee INITIAL SIZE 0,
      wa_employee TYPE t_employee.

TYPES: BEGIN OF t_emptexts,
*        INCLUDE STRUCTURE hrms_bw_txt_employee.
  DATEFROM   TYPE RSDATEFROM,
  DATETO   TYPE RSDATETO,
  PERNR   TYPE PERSNO,
  TXTMD   TYPE EMNAM,
 END OF t_emptexts.
DATA: it_emptexts TYPE STANDARD TABLE OF t_emptexts INITIAL SIZE 0,
      wa_emptexts TYPE t_emptexts.

TYPES: BEGIN OF t_contract,
*        INCLUDE STRUCTURE pa0615.
  pernr TYPE p0615-pernr,
  begda TYPE p0615-begda,
  endda TYPE p0615-endda,
  aedtm TYPE p0615-aedtm,
  ctype TYPE p0615-ctype,
  cbeg  TYPE p0615-cbeg,
  cend  TYPE p0615-cend,
 END OF t_contract.
DATA: it_contract TYPE STANDARD TABLE OF t_contract INITIAL SIZE 0,
      wa_contract TYPE t_contract.

DATA: it_tabemp TYPE filetable,
      gd_subrcemp TYPE i,
      it_tabempt TYPE filetable,
      gd_subrcempt TYPE i,
      it_tabcont TYPE filetable,
      gd_subrccont TYPE i.

DATA: gd_downfile TYPE string.


SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
PARAMETERS: p_emp   LIKE rlgrap-filename,
            p_empt  LIKE rlgrap-filename,
            p_cont LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK block1.


***********************************************************************
*at selection-screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_emp.

  REFRESH: it_tabemp.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title      = 'Select File'
      default_filename  = '*.xls'
      initial_directory = 'C:\'
      multiselection    = ' '  "No multiple selection
    CHANGING
      file_table        = it_tabemp
      rc                = gd_subrcemp.

  LOOP AT it_tabemp INTO p_emp.
  ENDLOOP.


***********************************************************************
*at selection-screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_empt.

  REFRESH: it_tabemp.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title      = 'Select File'
      default_filename  = '*.xls'
      initial_directory = 'C:\'
      multiselection    = ' '  "No multiple selection
    CHANGING
      file_table        = it_tabempt
      rc                = gd_subrcempt.

  LOOP AT it_tabempt INTO p_empt.
  ENDLOOP.


***********************************************************************
*at selection-screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_cont.

  REFRESH: it_tabcont.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title      = 'Select File'
      default_filename  = '*.xls'
      initial_directory = 'C:\'
      multiselection    = ' '  "No multiple selection
    CHANGING
      file_table        = it_tabcont
      rc                = gd_subrccont.

  LOOP AT it_tabcont INTO p_cont.
  ENDLOOP.


************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

GET pernr.
* Selecting the latest infotype record
  rp_provide_from_last p0000 space pn-begda pn-endda.
  rp_provide_from_last p0001 space pn-begda pn-endda.
  rp_provide_from_last p0007 space pn-begda pn-endda.
  rp_provide_from_last p0008 space pn-begda pn-endda.
  rp_provide_from_last p0121 space pn-begda pn-endda.
  rp_provide_from_last p0615 space pn-begda pn-endda.

  MOVE-CORRESPONDING p0001 TO wa_employee.
  wa_employee-rfpnr = p0121-rfp01. "?????

  MOVE-CORRESPONDING p0007 TO wa_employee.
  MOVE-CORRESPONDING p0008 TO wa_employee.
  MOVE-CORRESPONDING p0000 TO wa_employee.


  SELECT SINGLE molga
    FROM t001p
    INTO wa_employee-molga
   WHERE werks EQ p0001-werks AND
         btrtl EQ p0001-btrtl.

  SELECT SINGLE trfkz
    FROM t503
    INTO wa_employee-trfkz
   WHERE persg EQ p0001-persg AND
         persk EQ p0001-persk.

  CALL FUNCTION 'HR_ENTRY_DATE'
    EXPORTING
      persnr                     = pernr-pernr
*   RCLAS                      =
*   BEGDA                      = '18000101'
*   ENDDA                      = '99991231'
*   VARKY                      =
   IMPORTING
      entrydate                  = wa_employee-ncsdate
* TABLES
*   ENTRY_DATES                =
 EXCEPTIONS
   ENTRY_DATE_NOT_FOUND       = 1
   PERNR_NOT_ASSIGNED         = 2
   OTHERS                     = 3
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* append employee data
  APPEND wa_employee TO it_employee.
  CLEAR: wa_employee.

  wa_emptexts-datefrom = p0001-begda.
  wa_emptexts-dateto   = p0001-endda.
  wa_emptexts-pernr    = p0001-pernr.
  wa_emptexts-txtmd    = p0001-ename.

* append employee texts data
  APPEND wa_emptexts TO it_emptexts.
  CLEAR: wa_emptexts.

  MOVE-CORRESPONDING p0615 TO wa_contract.
* append employee contract data
  APPEND wa_contract TO it_contract.
  CLEAR: wa_contract.


************************************************************************
*END-OF-SELECTION.
END-OF-SELECTION.

* download employee data
  IF NOT p_emp IS INITIAL.
    gd_downfile = p_emp.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename              = gd_downfile
        filetype              = 'ASC'
        write_field_separator = 'X'
      TABLES
        data_tab              = it_employee.
    IF sy-subrc EQ 0.
      WRITE:/ 'Employee file downloaded to',
              gd_downfile.
    ELSE.
      WRITE:/ 'There was an error downloading Employee file to',
              gd_downfile.
    ENDIF.
  ENDIF.

* download employee texts data
  IF NOT p_empt IS INITIAL.
    gd_downfile = p_empt.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename              = gd_downfile
        filetype              = 'ASC'
        write_field_separator = 'X'
      TABLES
        data_tab              = it_emptexts.
    IF sy-subrc EQ 0.
      WRITE:/ 'Employee text file downloaded to',
              gd_downfile.
    ELSE.
      WRITE:/ 'There was an error downloading Employee text file to',
              gd_downfile.
    ENDIF.
  ENDIF.

* download contract data
  IF NOT p_cont IS INITIAL.
    gd_downfile = p_cont.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename              = gd_downfile
        filetype              = 'ASC'
        write_field_separator = 'X'
      TABLES
        data_tab              = it_contract.
    IF sy-subrc EQ 0.
      WRITE:/ 'Employee contract file downloaded to',
              gd_downfile.
    ELSE.
      WRITE:/ 'There was an error downloading Employee contract file to',
              gd_downfile.
    ENDIF.
  ENDIF.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> HR All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.